Skip to content

chore: instrument external oauth2 requests #11519

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
Jan 10, 2024
Merged
Prev Previous commit
no panic
  • Loading branch information
Emyrk committed Jan 10, 2024
commit 85e2d91ace97cc1177db1c67c7aba6697899824f
14 changes: 8 additions & 6 deletions coderd/promoauth/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package promoauth_test

import (
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -30,7 +31,7 @@ func TestInstrument(t *testing.T) {
cfg := externalauth.Config{
InstrumentedOAuth2Config: factory.New(id, idp.OIDCConfig(t, []string{})),
ID: "test",
ValidateURL: must(idp.IssuerURL().Parse("/oauth2/userinfo")).String(),
ValidateURL: must[*url.URL](t)(idp.IssuerURL().Parse("/oauth2/userinfo")).String(),
}

// 0 Requests before we start
Expand Down Expand Up @@ -60,7 +61,7 @@ func TestInstrument(t *testing.T) {
// extend the http.DefaultTransport. If a `.Clone()` is not done, this can be
// mis-used. It is cheap to run this quick check.
req, err := http.NewRequestWithContext(ctx, http.MethodGet,
must(idp.IssuerURL().Parse("/.well-known/openid-configuration")).String(), nil)
must[*url.URL](t)(idp.IssuerURL().Parse("/.well-known/openid-configuration")).String(), nil)
require.NoError(t, err)

resp, err := http.DefaultClient.Do(req)
Expand All @@ -70,9 +71,10 @@ func TestInstrument(t *testing.T) {
require.Equal(t, count(), 3)
}

func must[V any](v V, err error) V {
if err != nil {
panic(err)
func must[V any](t *testing.T) func(v V, err error) V {
return func(v V, err error) V {
t.Helper()
require.NoError(t, err)
return v
}
return v
}