fixup: Code Review
This commit is contained in:
parent
1ee0777521
commit
cbfa1388db
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue