forked from TrueCloudLab/frostfs-node
[#1601] util: Correctly parse 'root' name for container resources
* 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:
parent
05fd999162
commit
c3c034ecca
2 changed files with 10 additions and 1 deletions
|
@ -261,7 +261,7 @@ func parseResource(lexeme string, isObj bool) (string, error) {
|
||||||
} else {
|
} else {
|
||||||
if lexeme == "*" {
|
if lexeme == "*" {
|
||||||
return nativeschema.ResourceFormatAllContainers, nil
|
return nativeschema.ResourceFormatAllContainers, nil
|
||||||
} else if lexeme == "/*" {
|
} else if lexeme == "/*" || lexeme == "root/*" {
|
||||||
return nativeschema.ResourceFormatRootContainers, nil
|
return nativeschema.ResourceFormatRootContainers, nil
|
||||||
} else if strings.HasPrefix(lexeme, "/") && len(lexeme) > 1 {
|
} else if strings.HasPrefix(lexeme, "/") && len(lexeme) > 1 {
|
||||||
lexeme = lexeme[1:]
|
lexeme = lexeme[1:]
|
||||||
|
|
|
@ -43,6 +43,15 @@ func TestParseAPERule(t *testing.T) {
|
||||||
Resources: policyengine.Resources{Names: []string{nativeschema.ResourceFormatRootObjects}},
|
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",
|
name: "Valid rule for all objects in root namespace and container",
|
||||||
rule: "allow Object.Put /cid/*",
|
rule: "allow Object.Put /cid/*",
|
||||||
|
|
Loading…
Add table
Reference in a new issue