Add unit test coverage for token auth
@@ -24,6 +24,7 @@ var testAuthErrors = map[string]error{
}
var expiredPassword = "I_M_EXPIRED"
+var useToken = "I_M_TOKEN"
type fakeClient struct {
client.Client
@@ -37,6 +38,11 @@ func (c fakeClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) (r
if auth.Password == expiredPassword {
return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password")
}
+ if auth.Password == useToken {
+ return registrytypes.AuthenticateOKBody{
+ IdentityToken: auth.Password,
+ }, nil
+ }
err := testAuthErrors[auth.Username]
return registrytypes.AuthenticateOKBody{}, err
}
@@ -90,6 +96,11 @@ func TestRunLogin(t *testing.T) {
Username: validUsername,
Password: expiredPassword,
}
+ validIdentityToken := configtypes.AuthConfig{
+ ServerAddress: storedServerAddress,
+ Username: validUsername,
+ IdentityToken: useToken,
+ }
testCases := []struct {
inputLoginOption loginOptions
inputStoredCred *configtypes.AuthConfig
@@ -134,6 +145,16 @@ func TestRunLogin(t *testing.T) {
inputStoredCred: &validAuthConfig,
expectedErr: testAuthErrMsg,
},
+ {
+ inputLoginOption: loginOptions{
+ serverAddress: storedServerAddress,
+ user: validUsername,
+ password: useToken,
+ },
+ inputStoredCred: &validIdentityToken,
+ expectedErr: "",
+ expectedSavedCred: validIdentityToken,
+ },
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
