38 changed files with 415 additions and 311 deletions
-
2test/s3/iam/README-Docker.md
-
2test/s3/iam/README.md
-
2test/s3/iam/STS_DISTRIBUTED.md
-
40test/s3/iam/iam_config.github.json
-
40test/s3/iam/iam_config.json
-
40test/s3/iam/iam_config.local.json
-
14test/s3/iam/iam_config_distributed.json
-
14test/s3/iam/iam_config_docker.json
-
4test/s3/iam/s3_iam_framework.go
-
4test/s3/iam/s3_iam_integration_test.go
-
28test/s3/iam/test_config.json
-
44weed/iam/integration/iam_integration_test.go
-
2weed/iam/integration/iam_manager.go
-
6weed/iam/integration/role_store_test.go
-
6weed/iam/oidc/oidc_provider_test.go
-
2weed/iam/policy/policy_engine.go
-
30weed/iam/policy/policy_engine_distributed_test.go
-
48weed/iam/policy/policy_engine_test.go
-
10weed/iam/sts/cross_instance_token_test.go
-
18weed/iam/sts/session_policy_test.go
-
4weed/iam/sts/sts_service.go
-
18weed/iam/sts/sts_service_test.go
-
6weed/iam/sts/token_utils.go
-
12weed/iam/utils/arn_utils.go
-
8weed/s3api/auth_credentials.go
-
6weed/s3api/auth_credentials_test.go
-
26weed/s3api/s3_end_to_end_test.go
-
8weed/s3api/s3_iam_middleware.go
-
16weed/s3api/s3_iam_simple_test.go
-
20weed/s3api/s3_jwt_auth_test.go
-
14weed/s3api/s3_multipart_iam_test.go
-
56weed/s3api/s3_policy_templates.go
-
32weed/s3api/s3_policy_templates_test.go
-
4weed/s3api/s3_presigned_url_iam.go
-
12weed/s3api/s3_presigned_url_iam_test.go
-
20weed/s3api/s3api_bucket_handlers.go
-
104weed/s3api/s3api_bucket_policy_arn_test.go
-
4weed/s3api/s3api_bucket_policy_handlers.go
@ -0,0 +1,104 @@ |
|||
package s3api |
|||
|
|||
import ( |
|||
"testing" |
|||
) |
|||
|
|||
// TestBuildResourceARN verifies that resource ARNs use the AWS-compatible format
|
|||
func TestBuildResourceARN(t *testing.T) { |
|||
tests := []struct { |
|||
name string |
|||
bucket string |
|||
object string |
|||
expected string |
|||
}{ |
|||
{ |
|||
name: "bucket only", |
|||
bucket: "my-bucket", |
|||
object: "", |
|||
expected: "arn:aws:s3:::my-bucket", |
|||
}, |
|||
{ |
|||
name: "bucket with slash", |
|||
bucket: "my-bucket", |
|||
object: "/", |
|||
expected: "arn:aws:s3:::my-bucket", |
|||
}, |
|||
{ |
|||
name: "bucket and object", |
|||
bucket: "my-bucket", |
|||
object: "path/to/object.txt", |
|||
expected: "arn:aws:s3:::my-bucket/path/to/object.txt", |
|||
}, |
|||
{ |
|||
name: "bucket and object with leading slash", |
|||
bucket: "my-bucket", |
|||
object: "/path/to/object.txt", |
|||
expected: "arn:aws:s3:::my-bucket/path/to/object.txt", |
|||
}, |
|||
} |
|||
|
|||
for _, tt := range tests { |
|||
t.Run(tt.name, func(t *testing.T) { |
|||
result := buildResourceARN(tt.bucket, tt.object) |
|||
if result != tt.expected { |
|||
t.Errorf("buildResourceARN(%q, %q) = %q, want %q", tt.bucket, tt.object, result, tt.expected) |
|||
} |
|||
}) |
|||
} |
|||
} |
|||
|
|||
// TestBuildPrincipalARN verifies that principal ARNs use the AWS-compatible format
|
|||
func TestBuildPrincipalARN(t *testing.T) { |
|||
tests := []struct { |
|||
name string |
|||
identity *Identity |
|||
expected string |
|||
}{ |
|||
{ |
|||
name: "nil identity (anonymous)", |
|||
identity: nil, |
|||
expected: "*", |
|||
}, |
|||
{ |
|||
name: "identity with account and name", |
|||
identity: &Identity{ |
|||
Name: "test-user", |
|||
Account: &Account{ |
|||
Id: "123456789012", |
|||
}, |
|||
}, |
|||
expected: "arn:aws:iam::123456789012:user/test-user", |
|||
}, |
|||
{ |
|||
name: "identity without account ID", |
|||
identity: &Identity{ |
|||
Name: "test-user", |
|||
Account: &Account{ |
|||
Id: "", |
|||
}, |
|||
}, |
|||
expected: "arn:aws:iam::000000000000:user/test-user", |
|||
}, |
|||
{ |
|||
name: "identity without name", |
|||
identity: &Identity{ |
|||
Name: "", |
|||
Account: &Account{ |
|||
Id: "123456789012", |
|||
}, |
|||
}, |
|||
expected: "arn:aws:iam::123456789012:user/unknown", |
|||
}, |
|||
} |
|||
|
|||
for _, tt := range tests { |
|||
t.Run(tt.name, func(t *testing.T) { |
|||
result := buildPrincipalARN(tt.identity) |
|||
if result != tt.expected { |
|||
t.Errorf("buildPrincipalARN() = %q, want %q", result, tt.expected) |
|||
} |
|||
}) |
|||
} |
|||
} |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue