mirror of
https://github.com/lxc/incus
synced 2026-08-02 05:26:46 +00:00
internal/filter: Only allow abbreviating the namespace in DotPrefixMatch
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
parent
88d7bceb06
commit
3cdd7b9320
@ -18,8 +18,12 @@ func DotPrefixMatch(short string, full string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range fullMembs {
|
||||
if !strings.HasPrefix(fullMembs[i], shortMembs[i]) {
|
||||
if !strings.HasPrefix(fullMembs[0], shortMembs[0]) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 1; i < len(fullMembs); i++ {
|
||||
if fullMembs[i] != shortMembs[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,12 @@ func TestDotPrefixMatch(t *testing.T) {
|
||||
pass = pass && filter.DotPrefixMatch("s.privileged", "security.privileged")
|
||||
pass = pass && filter.DotPrefixMatch("u.blah", "user.blah")
|
||||
|
||||
// Only the namespace may be abbreviated.
|
||||
pass = pass && filter.DotPrefixMatch("u.foo.bar", "user.foo.bar")
|
||||
pass = pass && !filter.DotPrefixMatch("user.f.bar", "user.foo.bar")
|
||||
pass = pass && !filter.DotPrefixMatch("user.fo", "user.foo")
|
||||
pass = pass && !filter.DotPrefixMatch("s.priv", "security.privileged")
|
||||
|
||||
if !pass {
|
||||
t.Error("failed prefix matching")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user