Match a mapped project however its path is spaced: the store writes "Acme / ml / train"
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8866a1ea0f
commit
15a7237a02
3 files changed
+30
-5
No files matched your search
+10
-1
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user