Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix statement.IsAllowed when bucket disallowed #132

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions policy/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func (statement Statement) IsAllowed(args Args) bool {
}

resource += args.ObjectName
} else {
resource += "/"
}

if statement.isKMS() {
Expand Down
42 changes: 38 additions & 4 deletions policy/statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ import (
)

func TestStatementIsAllowed(t *testing.T) {
case1Statement := NewStatement("",
case1Statement := NewStatement(
"",
Allow,
NewActionSet(GetBucketLocationAction, PutObjectAction),
NewResourceSet(NewResource("*")),
condition.NewFunctions(),
)

case2Statement := NewStatement("",
case2Statement := NewStatement(
"",
Allow,
NewActionSet(GetObjectAction, PutObjectAction),
NewResourceSet(NewResource("mybucket/myobject*")),
Expand All @@ -53,14 +55,16 @@ func TestStatementIsAllowed(t *testing.T) {
t.Fatalf("unexpected error. %v\n", err)
}

case3Statement := NewStatement("",
case3Statement := NewStatement(
"",
Allow,
NewActionSet(GetObjectAction, PutObjectAction),
NewResourceSet(NewResource("mybucket/myobject*")),
condition.NewFunctions(func1),
)

case4Statement := NewStatement("",
case4Statement := NewStatement(
"",
Deny,
NewActionSet(GetObjectAction, PutObjectAction),
NewResourceSet(NewResource("mybucket/myobject*")),
Expand All @@ -83,6 +87,22 @@ func TestStatementIsAllowed(t *testing.T) {
condition.NewFunctions(func1),
)

case7Statement := NewStatement(
"",
Allow,
NewActionSet(GetBucketLocationAction),
NewResourceSet(NewResource("mybucket")),
condition.NewFunctions(),
)

case8Statement := NewStatement(
"",
Allow,
NewActionSet(GetBucketLocationAction, GetObjectAction, PutObjectAction),
NewResourceSet(NewResource("mybucket/*")),
condition.NewFunctions(),
)

anonGetBucketLocationArgs := Args{
AccountName: "Q3AM3UQ867SPQQA43P2F",
Action: GetBucketLocationAction,
Expand Down Expand Up @@ -181,6 +201,20 @@ func TestStatementIsAllowed(t *testing.T) {
{case6Statement, getBucketLocationArgs, true},
{case6Statement, putObjectActionArgs, false},
{case6Statement, getObjectActionArgs, true},

{case7Statement, anonGetBucketLocationArgs, true},
{case7Statement, anonPutObjectActionArgs, false},
{case7Statement, anonGetObjectActionArgs, false},
{case7Statement, getBucketLocationArgs, true},
{case7Statement, putObjectActionArgs, false},
{case7Statement, getObjectActionArgs, false},

{case8Statement, anonGetBucketLocationArgs, false},
{case8Statement, anonPutObjectActionArgs, true},
{case8Statement, anonGetObjectActionArgs, true},
{case8Statement, getBucketLocationArgs, false},
{case8Statement, putObjectActionArgs, true},
{case8Statement, getObjectActionArgs, true},
}

for i, testCase := range testCases {
Expand Down
Loading