authorizer_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "Google Web Identity": {
  52. input: &GoogleWebIdentity{
  53. RoleARN: "role arn",
  54. TokenRetriever: GoogleIDTokenRetriever{
  55. Aud: "aud",
  56. },
  57. },
  58. expected: &GoogleWebIdentity{
  59. RoleARN: "role arn",
  60. TokenRetriever: GoogleIDTokenRetriever{
  61. Aud: "aud",
  62. },
  63. },
  64. },
  65. }
  66. for name, tc := range testCases {
  67. t.Run(name, func(t *testing.T) {
  68. // Convert to AuthorizerJSON for sanitization
  69. sanitizedAuthorizer := tc.input.Sanitize()
  70. if !tc.expected.Equals(sanitizedAuthorizer) {
  71. t.Error("Authorizer was not as expected after Sanitization")
  72. }
  73. })
  74. }
  75. }