-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Laura Brehm <[email protected]>
- Loading branch information
Showing
14 changed files
with
948 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,43 +48,18 @@ func TestOAuthStoreGet(t *testing.T) { | |
}) | ||
}) | ||
|
||
t.Run("no credentials - login", func(t *testing.T) { | ||
t.Run("no credentials - return", func(t *testing.T) { | ||
auths := map[string]types.AuthConfig{} | ||
f := newStore(auths) | ||
manager := &testManager{ | ||
loginDevice: func() (oauth.TokenResult, error) { | ||
return oauth.TokenResult{ | ||
AccessToken: "abcd1234", | ||
RefreshToken: "efgh5678", | ||
Claims: oauth.Claims{ | ||
Claims: jwt.Claims{ | ||
Expiry: jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), | ||
}, | ||
Domain: oauth.DomainClaims{Username: "bork!", Email: "[email protected]"}, | ||
}, | ||
}, nil | ||
}, | ||
} | ||
s := &oauthStore{ | ||
backingStore: NewFileStore(f), | ||
manager: manager, | ||
} | ||
|
||
auth, err := s.Get(registry.IndexServer) | ||
assert.NilError(t, err) | ||
|
||
assert.DeepEqual(t, auth, types.AuthConfig{ | ||
Username: "bork!", | ||
Password: "abcd1234", | ||
Email: "[email protected]", | ||
ServerAddress: registry.IndexServer, | ||
}) | ||
assert.DeepEqual(t, auths[registry.IndexServer], types.AuthConfig{ | ||
Username: "bork!", | ||
Password: "abcd1234..efgh5678", | ||
Email: "[email protected]", | ||
ServerAddress: registry.IndexServer, | ||
}) | ||
assert.DeepEqual(t, auth, types.AuthConfig{}) | ||
assert.Equal(t, len(auths), 0) | ||
}) | ||
|
||
t.Run("expired credentials - refresh", func(t *testing.T) { | ||
|
@@ -135,7 +110,7 @@ func TestOAuthStoreGet(t *testing.T) { | |
}) | ||
}) | ||
|
||
t.Run("expired credentials - refresh fails - login", func(t *testing.T) { | ||
t.Run("expired credentials - refresh fails - return error", func(t *testing.T) { | ||
f := newStore(map[string]types.AuthConfig{ | ||
registry.IndexServer: { | ||
Username: "bork!", | ||
|
@@ -144,46 +119,22 @@ func TestOAuthStoreGet(t *testing.T) { | |
ServerAddress: registry.IndexServer, | ||
}, | ||
}) | ||
var loginCalled bool | ||
var refreshCalled bool | ||
manager := &testManager{ | ||
refresh: func(_ string) (oauth.TokenResult, error) { | ||
return oauth.TokenResult{}, errors.New("program failed") | ||
}, | ||
loginDevice: func() (oauth.TokenResult, error) { | ||
loginCalled = true | ||
return oauth.TokenResult{ | ||
AccessToken: "abcd1234", | ||
RefreshToken: "efgh5678", | ||
Claims: oauth.Claims{ | ||
Claims: jwt.Claims{ | ||
Expiry: jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), | ||
}, | ||
Domain: oauth.DomainClaims{Username: "bork!", Email: "[email protected]"}, | ||
}, | ||
}, nil | ||
refreshCalled = true | ||
return oauth.TokenResult{}, errors.New("refresh failed") | ||
}, | ||
} | ||
s := &oauthStore{ | ||
backingStore: NewFileStore(f), | ||
manager: manager, | ||
} | ||
|
||
auth, err := s.Get(registry.IndexServer) | ||
assert.NilError(t, err) | ||
_, err := s.Get(registry.IndexServer) | ||
assert.ErrorContains(t, err, "refresh failed") | ||
|
||
assert.Check(t, loginCalled) | ||
assert.DeepEqual(t, auth, types.AuthConfig{ | ||
Username: "bork!", | ||
Password: "abcd1234", | ||
Email: "[email protected]", | ||
ServerAddress: registry.IndexServer, | ||
}) | ||
assert.DeepEqual(t, f.GetAuthConfigs()[registry.IndexServer], types.AuthConfig{ | ||
Username: "bork!", | ||
Password: "abcd1234..efgh5678", | ||
Email: "[email protected]", | ||
ServerAddress: registry.IndexServer, | ||
}) | ||
assert.Check(t, refreshCalled) | ||
}) | ||
|
||
t.Run("old non-access token credentials", func(t *testing.T) { | ||
|
Oops, something went wrong.