authorizer_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package aws
  2. import (
  3. "testing"
  4. "github.com/opencost/opencost/pkg/cloud"
  5. )
  6. func TestAuthorizerJSON_Sanitize(t *testing.T) {
  7. testCases := map[string]struct {
  8. input Authorizer
  9. expected Authorizer
  10. }{
  11. "Access Key": {
  12. input: &AccessKey{
  13. ID: "ID",
  14. Secret: "Secret",
  15. },
  16. expected: &AccessKey{
  17. ID: "ID",
  18. Secret: cloud.Redacted,
  19. },
  20. },
  21. "Service Account": {
  22. input: &ServiceAccount{},
  23. expected: &ServiceAccount{},
  24. },
  25. "Master Payer Access Key": {
  26. input: &AssumeRole{
  27. Authorizer: &AccessKey{
  28. ID: "ID",
  29. Secret: "Secret",
  30. },
  31. RoleARN: "role arn",
  32. },
  33. expected: &AssumeRole{
  34. Authorizer: &AccessKey{
  35. ID: "ID",
  36. Secret: cloud.Redacted,
  37. },
  38. RoleARN: "role arn",
  39. },
  40. },
  41. "Master Payer Service Account": {
  42. input: &AssumeRole{
  43. Authorizer: &ServiceAccount{},
  44. RoleARN: "role arn",
  45. },
  46. expected: &AssumeRole{
  47. Authorizer: &ServiceAccount{},
  48. RoleARN: "role arn",
  49. },
  50. },
  51. }
  52. for name, tc := range testCases {
  53. t.Run(name, func(t *testing.T) {
  54. // Convert to AuthorizerJSON for sanitization
  55. sanitizedAuthorizer := tc.input.Sanitize()
  56. if !tc.expected.Equals(sanitizedAuthorizer) {
  57. t.Error("Authorizer was not as expected after Sanitization")
  58. }
  59. })
  60. }
  61. }