iamapi_management_handlers_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package iamapi
  2. import (
  3. "testing"
  4. "github.com/seaweedfs/seaweedfs/weed/s3api/policy_engine"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestGetActionsUserPath(t *testing.T) {
  8. policyDocument := policy_engine.PolicyDocument{
  9. Version: "2012-10-17",
  10. Statement: []policy_engine.PolicyStatement{
  11. {
  12. Effect: policy_engine.PolicyEffectAllow,
  13. Action: policy_engine.NewStringOrStringSlice("s3:Put*", "s3:PutBucketAcl", "s3:Get*", "s3:GetBucketAcl", "s3:List*", "s3:Tagging*", "s3:DeleteBucket*"),
  14. Resource: policy_engine.NewStringOrStringSlice("arn:aws:s3:::shared/user-Alice/*"),
  15. },
  16. },
  17. }
  18. actions, _ := GetActions(&policyDocument)
  19. expectedActions := []string{
  20. "Write:shared/user-Alice/*",
  21. "WriteAcp:shared/user-Alice/*",
  22. "Read:shared/user-Alice/*",
  23. "ReadAcp:shared/user-Alice/*",
  24. "List:shared/user-Alice/*",
  25. "Tagging:shared/user-Alice/*",
  26. "DeleteBucket:shared/user-Alice/*",
  27. }
  28. assert.Equal(t, expectedActions, actions)
  29. }
  30. func TestGetActionsWildcardPath(t *testing.T) {
  31. policyDocument := policy_engine.PolicyDocument{
  32. Version: "2012-10-17",
  33. Statement: []policy_engine.PolicyStatement{
  34. {
  35. Effect: policy_engine.PolicyEffectAllow,
  36. Action: policy_engine.NewStringOrStringSlice("s3:Get*", "s3:PutBucketAcl"),
  37. Resource: policy_engine.NewStringOrStringSlice("arn:aws:s3:::*"),
  38. },
  39. },
  40. }
  41. actions, _ := GetActions(&policyDocument)
  42. expectedActions := []string{
  43. "Read",
  44. "WriteAcp",
  45. }
  46. assert.Equal(t, expectedActions, actions)
  47. }
  48. func TestGetActionsInvalidAction(t *testing.T) {
  49. policyDocument := policy_engine.PolicyDocument{
  50. Version: "2012-10-17",
  51. Statement: []policy_engine.PolicyStatement{
  52. {
  53. Effect: policy_engine.PolicyEffectAllow,
  54. Action: policy_engine.NewStringOrStringSlice("s3:InvalidAction"),
  55. Resource: policy_engine.NewStringOrStringSlice("arn:aws:s3:::shared/user-Alice/*"),
  56. },
  57. },
  58. }
  59. _, err := GetActions(&policyDocument)
  60. assert.NotNil(t, err)
  61. assert.Equal(t, "not a valid action: 'InvalidAction'", err.Error())
  62. }