|
| 1 | +package elbv2 |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + awssdk "github.com/aws/aws-sdk-go/aws" |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestAuthenticateOIDCActionConfig_MarshalJSON(t *testing.T) { |
| 11 | + deny := AuthenticateOIDCActionConditionalBehaviorDeny |
| 12 | + type fields struct { |
| 13 | + AuthenticationRequestExtraParams map[string]string |
| 14 | + OnUnauthenticatedRequest *AuthenticateOIDCActionConditionalBehavior |
| 15 | + Scope *string |
| 16 | + SessionCookieName *string |
| 17 | + SessionTimeout *int64 |
| 18 | + Issuer string |
| 19 | + AuthorizationEndpoint string |
| 20 | + TokenEndpoint string |
| 21 | + UserInfoEndpoint string |
| 22 | + ClientID string |
| 23 | + ClientSecret string |
| 24 | + } |
| 25 | + tests := []struct { |
| 26 | + name string |
| 27 | + cfg *AuthenticateOIDCActionConfig |
| 28 | + want string |
| 29 | + }{ |
| 30 | + { |
| 31 | + name: "clientID and clientSecret should be redacted", |
| 32 | + cfg: &AuthenticateOIDCActionConfig{ |
| 33 | + AuthenticationRequestExtraParams: map[string]string{"key": "value"}, |
| 34 | + OnUnauthenticatedRequest: &deny, |
| 35 | + Scope: awssdk.String("oidc"), |
| 36 | + SessionCookieName: awssdk.String("my-cookie"), |
| 37 | + Issuer: "my-issuer", |
| 38 | + AuthorizationEndpoint: "my-auth-endpoint", |
| 39 | + TokenEndpoint: "my-token-endpoint", |
| 40 | + UserInfoEndpoint: "my-user-endpoint", |
| 41 | + ClientID: "client-id", |
| 42 | + ClientSecret: "client-secret", |
| 43 | + }, |
| 44 | + want: `{"authenticationRequestExtraParams":{"key":"value"},"onUnauthenticatedRequest":"deny","scope":"oidc","sessionCookieName":"my-cookie","issuer":"my-issuer","authorizationEndpoint":"my-auth-endpoint","tokenEndpoint":"my-token-endpoint","userInfoEndpoint":"my-user-endpoint","clientID":"[REDACTED]","clientSecret":"[REDACTED]"}`, |
| 45 | + }, |
| 46 | + } |
| 47 | + for _, tt := range tests { |
| 48 | + t.Run(tt.name, func(t *testing.T) { |
| 49 | + payload, _ := json.Marshal(tt.cfg) |
| 50 | + got := string(payload) |
| 51 | + assert.JSONEq(t, tt.want, got) |
| 52 | + }) |
| 53 | + } |
| 54 | +} |
0 commit comments