mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-05 23:57:12 +00:00
Add callback_handler tests to confirm GitHub with downstream form_post and GitHub with an error case
Co-authored-by: Ryan Richard <richardry@vmware.com>
This commit is contained in:
co-authored by
Ryan Richard
parent
37e654faa0
commit
8b1e5aa320
+6
-4
@@ -103,17 +103,18 @@ func (p *FederationDomainResolvedGitHubIdentityProvider) LoginFromCallback(
|
||||
) (*resolvedprovider.Identity, *resolvedprovider.IdentityLoginExtras, error) {
|
||||
accessToken, err := p.Provider.ExchangeAuthcode(ctx, authCode, redirectURI)
|
||||
if err != nil {
|
||||
plog.WarningErr("error exchanging GitHub authcode", err, "upstreamName", p.Provider.GetName())
|
||||
plog.WarningErr("failed to exchange authcode using GitHub API", err, "upstreamName", p.Provider.GetName())
|
||||
return nil, nil, httperr.Wrap(http.StatusBadGateway,
|
||||
fmt.Sprintf("failed to exchange authcode using GitHub API: %s", err.Error()),
|
||||
"failed to exchange authcode using GitHub API",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
user, err := p.Provider.GetUser(ctx, accessToken, p.GetDisplayName())
|
||||
if err != nil {
|
||||
plog.WarningErr("failed to get user info from GitHub API", err, "upstreamName", p.Provider.GetName())
|
||||
return nil, nil, httperr.Wrap(http.StatusUnprocessableEntity,
|
||||
fmt.Sprintf("failed to get user info from GitHub API: %s", err.Error()),
|
||||
"failed to get user info from GitHub API",
|
||||
err,
|
||||
)
|
||||
}
|
||||
@@ -150,7 +151,8 @@ func (p *FederationDomainResolvedGitHubIdentityProvider) UpstreamRefresh(
|
||||
// Get the user's GitHub identity and groups again using the cached access token.
|
||||
refreshedUserInfo, err := p.Provider.GetUser(ctx, githubSessionData.UpstreamAccessToken, p.GetDisplayName())
|
||||
if err != nil {
|
||||
return nil, p.refreshErr(fmt.Errorf("failed to get user info from GitHub API: %w", err))
|
||||
plog.WarningErr("failed to refresh user info from GitHub API", err, "upstreamName", p.Provider.GetName())
|
||||
return nil, p.refreshErr(errors.New("failed to refresh user info from GitHub API"))
|
||||
}
|
||||
|
||||
if refreshedUserInfo.DownstreamSubject != identity.DownstreamSubject {
|
||||
|
||||
+4
-4
@@ -179,7 +179,7 @@ func TestLoginFromCallback(t *testing.T) {
|
||||
wantGetUserCall: false,
|
||||
wantIdentity: nil,
|
||||
wantExtras: nil,
|
||||
wantErr: "failed to exchange authcode using GitHub API: fake authcode exchange error: fake authcode exchange error",
|
||||
wantErr: "failed to exchange authcode using GitHub API: fake authcode exchange error",
|
||||
},
|
||||
{
|
||||
name: "error while getting user info",
|
||||
@@ -204,7 +204,7 @@ func TestLoginFromCallback(t *testing.T) {
|
||||
},
|
||||
wantIdentity: nil,
|
||||
wantExtras: nil,
|
||||
wantErr: "failed to get user info from GitHub API: fake user info error: fake user info error",
|
||||
wantErr: "failed to get user info from GitHub API: fake user info error",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ func TestUpstreamRefresh(t *testing.T) {
|
||||
name: "error while getting user info",
|
||||
provider: oidctestutil.NewTestUpstreamGitHubIdentityProviderBuilder().
|
||||
WithName("fake-provider-name").
|
||||
WithGetUserError(errors.New("fake user info error")).
|
||||
WithGetUserError(errors.New("any error message")).
|
||||
Build(),
|
||||
identity: &resolvedprovider.Identity{
|
||||
UpstreamUsername: "initial-username",
|
||||
@@ -313,7 +313,7 @@ func TestUpstreamRefresh(t *testing.T) {
|
||||
IDPDisplayName: "fake-display-name",
|
||||
},
|
||||
wantRefreshedIdentity: nil,
|
||||
wantWrappedErr: "failed to get user info from GitHub API: fake user info error",
|
||||
wantWrappedErr: "failed to refresh user info from GitHub API",
|
||||
},
|
||||
{
|
||||
name: "wrong session data type, which should not really happen",
|
||||
|
||||
Reference in New Issue
Block a user