mirror of
https://github.com/ferdzo/fs.git
synced 2026-06-04 05:06:46 +00:00
Harden S3 auth boundaries
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
52
auth/policy_test.go
Normal file
52
auth/policy_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"fs/models"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListBucketPolicyAppliesPrefix(t *testing.T) {
|
||||
policy := &models.AuthPolicy{
|
||||
Statements: []models.AuthPolicyStatement{
|
||||
{
|
||||
Effect: "allow",
|
||||
Actions: []string{"s3:ListBucket"},
|
||||
Bucket: "test-bucket",
|
||||
Prefix: "allowed/",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if !isAllowed(policy, RequestTarget{Action: ActionListBucket, Bucket: "test-bucket", Prefix: "allowed/"}) {
|
||||
t.Fatalf("expected matching list prefix to be allowed")
|
||||
}
|
||||
if !isAllowed(policy, RequestTarget{Action: ActionListBucket, Bucket: "test-bucket", Prefix: "allowed/nested/"}) {
|
||||
t.Fatalf("expected nested list prefix to be allowed")
|
||||
}
|
||||
if isAllowed(policy, RequestTarget{Action: ActionListBucket, Bucket: "test-bucket"}) {
|
||||
t.Fatalf("expected empty list prefix to be denied")
|
||||
}
|
||||
if isAllowed(policy, RequestTarget{Action: ActionListBucket, Bucket: "test-bucket", Prefix: "private/"}) {
|
||||
t.Fatalf("expected non-matching list prefix to be denied")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWildcardListBucketPolicyAllowsAnyPrefix(t *testing.T) {
|
||||
policy := &models.AuthPolicy{
|
||||
Statements: []models.AuthPolicyStatement{
|
||||
{
|
||||
Effect: "allow",
|
||||
Actions: []string{"s3:ListBucket"},
|
||||
Bucket: "test-bucket",
|
||||
Prefix: "*",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if !isAllowed(policy, RequestTarget{Action: ActionListBucket, Bucket: "test-bucket"}) {
|
||||
t.Fatalf("expected wildcard list policy to allow empty prefix")
|
||||
}
|
||||
if !isAllowed(policy, RequestTarget{Action: ActionListBucket, Bucket: "test-bucket", Prefix: "private/"}) {
|
||||
t.Fatalf("expected wildcard list policy to allow arbitrary prefix")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user