diff --git a/internal/scim/scim.go b/internal/scim/scim.go index 697bbdf..353435b 100644 --- a/internal/scim/scim.go +++ b/internal/scim/scim.go @@ -563,7 +563,16 @@ func roleRank(r string) int { func (s *Server) place(ctx context.Context, where string) (store.Scope, string, error) { kind, path, _ := strings.Cut(where, ":") - same := func(a string) bool { return strings.EqualFold(a, path) } + // The store writes paths "Acme / ml / train"; a mapping writes them + // either way. + norm := func(s string) string { + parts := strings.Split(s, "/") + for i := range parts { + parts[i] = strings.TrimSpace(parts[i]) + } + return strings.Join(parts, "/") + } + same := func(a string) bool { return strings.EqualFold(norm(a), norm(path)) } switch kind { case "org": orgs, err := s.st.AllOrgs(ctx) diff --git a/internal/scim/scim_test.go b/internal/scim/scim_test.go index a38aa1a..aff2808 100644 --- a/internal/scim/scim_test.go +++ b/internal/scim/scim_test.go @@ -70,13 +70,16 @@ func (m *mem) AllOrgs(context.Context) ([]store.Org, error) { return nil, nil } func (m *mem) AllTeams(context.Context) ([]store.TeamPath, error) { return []store.TeamPath{{ID: "t1", Name: "ml", OrgName: "Acme"}}, nil } -func (m *mem) AllProjects(context.Context) ([]store.ProjectPath, error) { return nil, nil } +func (m *mem) AllProjects(context.Context) ([]store.ProjectPath, error) { + // As the store writes them. + return []store.ProjectPath{{ID: "p1", Path: "Acme / ml / train"}}, nil +} func server(t *testing.T) (*mem, http.Handler) { st := newMem() mux := http.NewServeMux() New(st, "s3cret", Mapping{Roles: map[string][]string{"operator": {"ops"}}, - Memberships: map[string]string{"ml": "team:Acme/ml"}}, slog.New(slog.DiscardHandler)).Register(mux) + Memberships: map[string]string{"ml": "team:Acme/ml", "trainers": "project:Acme/ml/train"}}, slog.New(slog.DiscardHandler)).Register(mux) return st, mux } @@ -144,7 +147,11 @@ func TestAProviderProvisionsAndSuspendsAccounts(t *testing.T) { if st.roles[id] != "" || st.members[id+"@team:t1"] { t.Errorf("after leaving: roles %v members %v", st.roles, st.members) } - if _, l := do(t, h, "GET", "/scim/v2/Groups", ""); l["totalResults"] != float64(2) { + do(t, h, "PATCH", "/scim/v2/Groups/trainers", `{"Operations":[{"op":"add","path":"members","value":[{"value":"`+id+`"}]}]}`) + if !st.members[id+"@project:p1"] { + t.Errorf("a project written without spaces: %v", st.members) + } + if _, l := do(t, h, "GET", "/scim/v2/Groups", ""); l["totalResults"] != float64(3) { t.Errorf("groups: %v", l) } } diff --git a/internal/web/oidc.go b/internal/web/oidc.go index 952b217..0e87d1f 100644 --- a/internal/web/oidc.go +++ b/internal/web/oidc.go @@ -313,7 +313,16 @@ func (p *AccountPages) oidcUser(ctx context.Context, claims map[string]any) (sto // oidcPlace finds org:NAME, team:ORG/TEAM, project:ORG/TEAM/PROJECT. func (p *AccountPages) oidcPlace(ctx context.Context, where string) (store.Scope, string, error) { kind, path, _ := strings.Cut(where, ":") - same := func(a string) bool { return strings.EqualFold(a, path) } + // The store writes paths "Acme / ml / train"; a mapping writes them + // either way. + norm := func(s string) string { + parts := strings.Split(s, "/") + for i := range parts { + parts[i] = strings.TrimSpace(parts[i]) + } + return strings.Join(parts, "/") + } + same := func(a string) bool { return strings.EqualFold(norm(a), norm(path)) } switch kind { case "org": orgs, err := p.oidc.st.AllOrgs(ctx)