[#1601] util: Correctly parse 'root' name for container resources
All checks were successful
Vulncheck / Vulncheck (push) Successful in 56s
Pre-commit hooks / Pre-commit (push) Successful in 1m20s
Build / Build Components (push) Successful in 1m39s
Tests and linters / gopls check (push) Successful in 2m15s
Tests and linters / Run gofumpt (push) Successful in 2m51s
Tests and linters / Tests (push) Successful in 3m0s
Tests and linters / Staticcheck (push) Successful in 3m11s
Tests and linters / Lint (push) Successful in 3m20s
Tests and linters / Tests with -race (push) Successful in 3m28s

* Convert `root/*` to `//`;
* Add unit-test case for parses to check parsing correctness.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2025-01-15 14:19:56 +03:00 committed by Evgenii Stratonikov
parent 05fd999162
commit c3c034ecca
2 changed files with 10 additions and 1 deletions

View file

@ -261,7 +261,7 @@ func parseResource(lexeme string, isObj bool) (string, error) {
} else {
if lexeme == "*" {
return nativeschema.ResourceFormatAllContainers, nil
} else if lexeme == "/*" {
} else if lexeme == "/*" || lexeme == "root/*" {
return nativeschema.ResourceFormatRootContainers, nil
} else if strings.HasPrefix(lexeme, "/") && len(lexeme) > 1 {
lexeme = lexeme[1:]

View file

@ -43,6 +43,15 @@ func TestParseAPERule(t *testing.T) {
Resources: policyengine.Resources{Names: []string{nativeschema.ResourceFormatRootObjects}},
},
},
{
name: "Valid rule for all containers in explicit root namespace",
rule: "allow Container.Put root/*",
expectRule: policyengine.Rule{
Status: policyengine.Allow,
Actions: policyengine.Actions{Names: []string{nativeschema.MethodPutContainer}},
Resources: policyengine.Resources{Names: []string{nativeschema.ResourceFormatRootContainers}},
},
},
{
name: "Valid rule for all objects in root namespace and container",
rule: "allow Object.Put /cid/*",