Cleanup TestSuccessfulCredentialRequest and TestCLILoginOIDC a little.

Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
Matt Moyer 2020-12-15 12:23:52 -06:00
parent 8cdcb89cef
commit aca9af748b
No known key found for this signature in database
GPG Key ID: EAE88AD172C5AE2D
2 changed files with 9 additions and 13 deletions

View File

@ -129,7 +129,7 @@ func TestCLILoginOIDC(t *testing.T) {
pinnipedExe := library.PinnipedCLIPath(t) pinnipedExe := library.PinnipedCLIPath(t)
// Run "pinniped login oidc" to get an ExecCredential struct with an OIDC ID token. // Run "pinniped login oidc" to get an ExecCredential struct with an OIDC ID token.
credOutput, sessionCachePath := runPinniedLoginOIDC(ctx, t, pinnipedExe) credOutput, sessionCachePath := runPinnipedLoginOIDC(ctx, t, pinnipedExe)
// Assert some properties of the ExecCredential. // Assert some properties of the ExecCredential.
t.Logf("validating ExecCredential") t.Logf("validating ExecCredential")
@ -195,7 +195,7 @@ func TestCLILoginOIDC(t *testing.T) {
require.NotEqual(t, credOutput2.Status.Token, credOutput3.Status.Token) require.NotEqual(t, credOutput2.Status.Token, credOutput3.Status.Token)
} }
func runPinniedLoginOIDC( func runPinnipedLoginOIDC(
ctx context.Context, ctx context.Context,
t *testing.T, t *testing.T,
pinnipedExe string, pinnipedExe string,

View File

@ -47,26 +47,22 @@ func TestSuccessfulCredentialRequest(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
authenticator func(t *testing.T) corev1.TypedLocalObjectReference authenticator func(context.Context, *testing.T) corev1.TypedLocalObjectReference
token func(t *testing.T) (token string, username string, groups []string) token func(t *testing.T) (token string, username string, groups []string)
}{ }{
{ {
name: "webhook", name: "webhook",
authenticator: func(t *testing.T) corev1.TypedLocalObjectReference { authenticator: library.CreateTestWebhookAuthenticator,
return library.CreateTestWebhookAuthenticator(ctx, t)
},
token: func(t *testing.T) (string, string, []string) { token: func(t *testing.T) (string, string, []string) {
return library.IntegrationEnv(t).TestUser.Token, env.TestUser.ExpectedUsername, env.TestUser.ExpectedGroups return library.IntegrationEnv(t).TestUser.Token, env.TestUser.ExpectedUsername, env.TestUser.ExpectedGroups
}, },
}, },
{ {
name: "jwt authenticator", name: "jwt authenticator",
authenticator: func(t *testing.T) corev1.TypedLocalObjectReference { authenticator: library.CreateTestJWTAuthenticator,
return library.CreateTestJWTAuthenticator(ctx, t)
},
token: func(t *testing.T) (string, string, []string) { token: func(t *testing.T) (string, string, []string) {
pinnipedExe := library.PinnipedCLIPath(t) pinnipedExe := library.PinnipedCLIPath(t)
credOutput, _ := runPinniedLoginOIDC(ctx, t, pinnipedExe) credOutput, _ := runPinnipedLoginOIDC(ctx, t, pinnipedExe)
token := credOutput.Status.Token token := credOutput.Status.Token
// By default, the JWTAuthenticator expects the username to be in the "sub" claim and the // By default, the JWTAuthenticator expects the username to be in the "sub" claim and the
@ -80,7 +76,7 @@ func TestSuccessfulCredentialRequest(t *testing.T) {
for _, test := range tests { for _, test := range tests {
test := test test := test
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
authenticator := test.authenticator(t) authenticator := test.authenticator(ctx, t)
token, username, groups := test.token(t) token, username, groups := test.token(t)
var response *loginv1alpha1.TokenCredentialRequest var response *loginv1alpha1.TokenCredentialRequest