Skip to content

Commit

Permalink
fixup: Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
endocrimes committed Dec 12, 2018
1 parent db635bf commit 4e59d47
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 2 additions & 5 deletions acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ func (a *ACL) matchingCapabilitySet(ns string) (capabilitySet, bool) {
}

// We didn't find a concrete match, so lets try and evaluate globs.
cs, ok := a.findClosestMatchingGlob(ns)

return cs, ok
return a.findClosestMatchingGlob(ns)
}

type matchingGlob struct {
Expand Down Expand Up @@ -251,10 +249,9 @@ func (a *ACL) findAllMatchingWildcards(ns string) []matchingGlob {

isMatch := glob.Glob(k, ns)
if isMatch {
globLen := len(strings.Replace(k, glob.GLOB, "", -1))
pair := matchingGlob{
ns: k,
difference: nsLen - globLen,
difference: nsLen - len(k) + strings.Count(k, glob.GLOB),
capabilitySet: v,
}
matches = append(matches, pair)
Expand Down
22 changes: 21 additions & 1 deletion acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,12 @@ func TestWildcardNamespaceMatching(t *testing.T) {
},
{ // The closest character match wins
Policy: `namespace "*-api-services" { policy = "deny" }
namespace "prod-api-*" { policy = "write" }`, // 5 vs 8 chars
namespace "prod-api-*" { policy = "write" }`, // 4 vs 8 chars
Allow: false,
},
{
Policy: `namespace "prod-api-*" { policy = "write" }
namespace "*-api-services" { policy = "deny" }`, // 4 vs 8 chars
Allow: false,
},
}
Expand Down Expand Up @@ -371,6 +376,21 @@ func TestACL_matchingCapabilitySet_difference(t *testing.T) {
NS: "production-admin-api",
Difference: 9,
},
{
Policy: `namespace "production-**" { policy = "write" }`,
NS: "production-admin-api",
Difference: 9,
},
{
Policy: `namespace "*" { policy = "write" }`,
NS: "production-admin-api",
Difference: 20,
},
{
Policy: `namespace "*admin*" { policy = "write" }`,
NS: "production-admin-api",
Difference: 15,
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 4e59d47

Please sign in to comment.