iamapi_management_handlers_test.go 1.3 KB

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