Skip to content

test: add full OIDC fake IDP #9317

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

Merged
merged 20 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Linting
  • Loading branch information
Emyrk committed Aug 25, 2023
commit 2b0ff9cea445c0030ee05066589b231430d44c15
12 changes: 6 additions & 6 deletions coderd/coderdtest/oidctest/idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
// This endpoint is required to initialize the OIDC provider.
// It is used to get the OIDC configuration.
mux.Get("/.well-known/openid-configuration", func(rw http.ResponseWriter, r *http.Request) {
f.logger.Info(r.Context(), "HTTP OIDC Config", slog.F("url", r.URL.String()))
f.logger.Info(r.Context(), "http OIDC config", slog.F("url", r.URL.String()))

_ = json.NewEncoder(rw).Encode(f.provider)
})
Expand Down Expand Up @@ -496,7 +496,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {

mux.Handle(tokenPath, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
values, err := f.authenticateOIDCClientRequest(t, r)
f.logger.Info(r.Context(), "http call token",
f.logger.Info(r.Context(), "http idp call token",
slog.Error(err),
slog.F("values", values.Encode()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potential NPE here on values

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, but this is intentional and ok. The Encode function accepts a nil pointer!
https://go.dev/play/p/tSOYbeQJJG4

)
Expand Down Expand Up @@ -595,7 +595,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {

mux.Handle(userInfoPath, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
token, err := f.authenticateBearerTokenRequest(t, r)
f.logger.Info(r.Context(), "http call user info",
f.logger.Info(r.Context(), "http call idp user info",
slog.Error(err),
slog.F("url", r.URL.String()),
)
Expand All @@ -614,7 +614,7 @@ func (f *FakeIDP) httpHandler(t testing.TB) http.Handler {
}))

mux.Handle(keysPath, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
f.logger.Info(r.Context(), "http call keys")
f.logger.Info(r.Context(), "http call idp /keys")
set := jose.JSONWebKeySet{
Keys: []jose.JSONWebKey{
{
Expand Down Expand Up @@ -691,10 +691,10 @@ func (f *FakeIDP) UpdateRefreshClaims(refreshToken string, claims jwt.MapClaims)

// SetRedirect is required for the IDP to know where to redirect and call
// Coderd.
func (f *FakeIDP) SetRedirect(t testing.TB, url string) {
func (f *FakeIDP) SetRedirect(t testing.TB, u string) {
t.Helper()

f.cfg.RedirectURL = url
f.cfg.RedirectURL = u
}

// SetCoderdCallback is optional and only works if not using the IsServing.
Expand Down
2 changes: 1 addition & 1 deletion coderd/userauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestOIDCOauthLoginWithExisting(t *testing.T) {
helper.ExpireOauthToken(t, api.Database, userClient)

// Instead of refreshing, just log in again.
userClient, _ = helper.Login(t, claims)
helper.Login(t, claims)
}

func TestUserLogin(t *testing.T) {
Expand Down