This commit is contained in:
Joshua Casey
2024-05-20 11:34:52 -05:00
parent 938bea9910
commit ba2d122308
4 changed files with 17 additions and 7 deletions

View File

@@ -25,8 +25,8 @@ func OIDC(upstreamIssuerAsString string, upstreamSubject string, idpDisplayName
)
}
func GitHub(APIBaseURL, idpDisplayName, login, id string) string {
return fmt.Sprintf("%s?%s=%s&login=%s&id=%s", APIBaseURL,
func GitHub(apiBaseURL, idpDisplayName, login, id string) string {
return fmt.Sprintf("%s?%s=%s&login=%s&id=%s", apiBaseURL,
oidc.IDTokenSubClaimIDPNameQueryParam, url.QueryEscape(idpDisplayName),
url.QueryEscape(login), url.QueryEscape(id),
)

View File

@@ -93,7 +93,7 @@ func TestOIDC(t *testing.T) {
func TestGitHub(t *testing.T) {
tests := []struct {
name string
APIBaseURL string
apiBaseURL string
idpDisplayName string
login string
id string
@@ -101,7 +101,7 @@ func TestGitHub(t *testing.T) {
}{
{
name: "simple display name",
APIBaseURL: "https://github.com",
apiBaseURL: "https://github.com",
idpDisplayName: "simpleName",
login: "some login",
id: "some id",
@@ -109,7 +109,7 @@ func TestGitHub(t *testing.T) {
},
{
name: "interesting display name",
APIBaseURL: "https://server.example.com:1234/path",
apiBaseURL: "https://server.example.com:1234/path",
idpDisplayName: "this is a 👍 display name that 🦭 can handle",
login: "some other login",
id: "some other id",
@@ -121,7 +121,7 @@ func TestGitHub(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
actual := GitHub(test.APIBaseURL, test.idpDisplayName, test.login, test.id)
actual := GitHub(test.apiBaseURL, test.idpDisplayName, test.login, test.id)
require.Equal(t, test.wantSubject, actual)
})

View File

@@ -1,3 +1,6 @@
// Copyright 2024 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package githubclient
import (

View File

@@ -1,3 +1,6 @@
// Copyright 2024 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package githubclient
import (
@@ -107,7 +110,11 @@ func TestNewGitHubClient(t *testing.T) {
require.Equal(t, test.wantBaseURL, actual.client.BaseURL.String())
// Force the githubClient's httpClient roundTrippers to run and add the Authorization header
_, err = actual.client.Client().Get(testServer.URL)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, testServer.URL, nil)
require.NoError(t, err)
_, err = actual.client.Client().Do(req) //nolint:bodyclose
require.NoError(t, err)
})
}