-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[idp] Add email to ID token #17678
Merged
+48
−17
Merged
[idp] Add email to ID token #17678
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |||||
"github.com/google/go-cmp/cmp" | ||||||
"github.com/google/go-cmp/cmp/cmpopts" | ||||||
"github.com/sourcegraph/jsonrpc2" | ||||||
"github.com/stretchr/testify/require" | ||||||
"github.com/zitadel/oidc/pkg/oidc" | ||||||
) | ||||||
|
||||||
|
@@ -31,17 +32,22 @@ func TestGetIDToken(t *testing.T) { | |||||
} | ||||||
tests := []struct { | ||||||
Name string | ||||||
TokenSource IDTokenSource | ||||||
TokenSource func(t *testing.T) IDTokenSource | ||||||
ServerSetup func(*protocol.MockAPIInterface) | ||||||
Request *v1.GetIDTokenRequest | ||||||
|
||||||
Expectation Expectation | ||||||
}{ | ||||||
{ | ||||||
Name: "happy path", | ||||||
TokenSource: functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "foobar", nil | ||||||
}), | ||||||
TokenSource: func(t *testing.T) IDTokenSource { | ||||||
return functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
require.Equal(t, "[email protected]", userInfo.GetEmail()) | ||||||
require.False(t, userInfo.IsEmailVerified()) | ||||||
|
||||||
return "foobar", nil | ||||||
}) | ||||||
}, | ||||||
ServerSetup: func(ma *protocol.MockAPIInterface) { | ||||||
ma.EXPECT().GetIDToken(gomock.Any()).MinTimes(1).Return(nil) | ||||||
ma.EXPECT().GetWorkspace(gomock.Any(), workspaceID).MinTimes(1).Return( | ||||||
|
@@ -55,6 +61,11 @@ func TestGetIDToken(t *testing.T) { | |||||
ma.EXPECT().GetLoggedInUser(gomock.Any()).Return( | ||||||
&protocol.User{ | ||||||
Name: "foobar", | ||||||
Identities: []*protocol.Identity{ | ||||||
nil, | ||||||
{Deleted: true, PrimaryEmail: "[email protected]"}, | ||||||
{PrimaryEmail: "[email protected]"}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I know it's the default, but visually grepping the tests the symmetry makes it easier |
||||||
}, | ||||||
}, | ||||||
nil, | ||||||
) | ||||||
|
@@ -71,9 +82,11 @@ func TestGetIDToken(t *testing.T) { | |||||
}, | ||||||
{ | ||||||
Name: "workspace not found", | ||||||
TokenSource: functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "foobar", nil | ||||||
}), | ||||||
TokenSource: func(t *testing.T) IDTokenSource { | ||||||
return functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "foobar", nil | ||||||
}) | ||||||
}, | ||||||
ServerSetup: func(ma *protocol.MockAPIInterface) { | ||||||
ma.EXPECT().GetIDToken(gomock.Any()).MinTimes(1).Return(nil) | ||||||
ma.EXPECT().GetWorkspace(gomock.Any(), workspaceID).MinTimes(1).Return( | ||||||
|
@@ -91,9 +104,11 @@ func TestGetIDToken(t *testing.T) { | |||||
}, | ||||||
{ | ||||||
Name: "no logged in user", | ||||||
TokenSource: functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "foobar", nil | ||||||
}), | ||||||
TokenSource: func(t *testing.T) IDTokenSource { | ||||||
return functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "foobar", nil | ||||||
}) | ||||||
}, | ||||||
ServerSetup: func(ma *protocol.MockAPIInterface) { | ||||||
ma.EXPECT().GetIDToken(gomock.Any()).MinTimes(1).Return(nil) | ||||||
ma.EXPECT().GetWorkspace(gomock.Any(), workspaceID).MinTimes(1).Return( | ||||||
|
@@ -119,9 +134,11 @@ func TestGetIDToken(t *testing.T) { | |||||
}, | ||||||
{ | ||||||
Name: "no audience", | ||||||
TokenSource: functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "foobar", nil | ||||||
}), | ||||||
TokenSource: func(t *testing.T) IDTokenSource { | ||||||
return functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "foobar", nil | ||||||
}) | ||||||
}, | ||||||
Request: &v1.GetIDTokenRequest{ | ||||||
WorkspaceId: workspaceID, | ||||||
}, | ||||||
|
@@ -131,9 +148,11 @@ func TestGetIDToken(t *testing.T) { | |||||
}, | ||||||
{ | ||||||
Name: "token source error", | ||||||
TokenSource: functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "", fmt.Errorf("cannot produce token") | ||||||
}), | ||||||
TokenSource: func(t *testing.T) IDTokenSource { | ||||||
return functionIDTokenSource(func(ctx context.Context, org string, audience []string, userInfo oidc.UserInfo) (string, error) { | ||||||
return "", fmt.Errorf("cannot produce token") | ||||||
}) | ||||||
}, | ||||||
ServerSetup: func(ma *protocol.MockAPIInterface) { | ||||||
ma.EXPECT().GetIDToken(gomock.Any()).MinTimes(1).Return(nil) | ||||||
ma.EXPECT().GetWorkspace(gomock.Any(), workspaceID).MinTimes(1).Return( | ||||||
|
@@ -170,7 +189,7 @@ func TestGetIDToken(t *testing.T) { | |||||
test.ServerSetup(serverMock) | ||||||
} | ||||||
|
||||||
svc := NewIdentityProviderService(&FakeServerConnPool{api: serverMock}, test.TokenSource) | ||||||
svc := NewIdentityProviderService(&FakeServerConnPool{api: serverMock}, test.TokenSource(t)) | ||||||
_, handler := v1connect.NewIdentityProviderServiceHandler(svc, connect.WithInterceptors(auth.NewServerInterceptor())) | ||||||
srv := httptest.NewServer(handler) | ||||||
t.Cleanup(srv.Close) | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could drop the
if
, it would set it to the empty string, which is the default value in the struct anyway - it's omitempty in the JSON structThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. I like the explicitness of this code though :)