diff --git a/integration_test/credetial_plugin_test.go b/integration_test/credetial_plugin_test.go index 52bcb30..dcd172f 100644 --- a/integration_test/credetial_plugin_test.go +++ b/integration_test/credetial_plugin_test.go @@ -43,7 +43,7 @@ func TestCredentialPlugin(t *testing.T) { args: []string{"--certificate-authority", keypair.Server.CACertPath}, }, } { - httpDriverOption := httpdriver.Option{ + httpDriverConfig := httpdriver.Config{ TLSConfig: tc.keyPair.TLSConfig, BodyContains: "Authenticated", } @@ -53,7 +53,7 @@ func TestCredentialPlugin(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, tc.keyPair, testconfig.TestConfig{ + svc := oidcserver.New(t, tc.keyPair, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -67,20 +67,20 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpDriverOption), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpDriverConfig), now: now, stdout: &stdout, args: tc.args, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("ROPC", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, tc.keyPair, testconfig.TestConfig{ + svc := oidcserver.New(t, tc.keyPair, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -95,7 +95,7 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), + issuerURL: svc.IssuerURL(), httpDriver: httpdriver.Zero(t), now: now, stdout: &stdout, @@ -104,17 +104,17 @@ func TestCredentialPlugin(t *testing.T) { "--password", "PASS1", }, tc.args...), }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("TokenCacheLifecycle", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, tc.keyPair, testconfig.TestConfig{}) + svc := oidcserver.New(t, tc.keyPair, testconfig.Config{}) t.Run("NoCache", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{ + svc.SetConfig(testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -129,29 +129,29 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpDriverOption), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpDriverConfig), now: now, stdout: &stdout, args: tc.args, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("Valid", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{}) + svc.SetConfig(testconfig.Config{}) var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), + issuerURL: svc.IssuerURL(), httpDriver: httpdriver.Zero(t), now: now, stdout: &stdout, args: tc.args, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("Refresh", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{ + svc.SetConfig(testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -166,16 +166,16 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpDriverOption), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpDriverConfig), now: now.Add(2 * time.Hour), stdout: &stdout, args: tc.args, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(3*time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(3*time.Hour)) }) t.Run("RefreshAgain", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{ + svc.SetConfig(testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -189,13 +189,13 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpDriverOption), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpDriverConfig), now: now.Add(4 * time.Hour), stdout: &stdout, args: tc.args, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(5*time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(5*time.Hour)) }) }) }) @@ -206,7 +206,7 @@ func TestCredentialPlugin(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -220,19 +220,19 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{BodyContains: "Authenticated"}), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{BodyContains: "Authenticated"}), now: now, stdout: &stdout, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("Enforce", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -246,13 +246,13 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{BodyContains: "Authenticated"}), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{BodyContains: "Authenticated"}), now: now, stdout: &stdout, args: []string{"--oidc-use-pkce"}, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) }) @@ -260,7 +260,7 @@ func TestCredentialPlugin(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.Server, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.Server, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -274,20 +274,20 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{TLSConfig: keypair.Server.TLSConfig, BodyContains: "Authenticated"}), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{TLSConfig: keypair.Server.TLSConfig, BodyContains: "Authenticated"}), now: now, stdout: &stdout, args: []string{"--certificate-authority-data", keypair.Server.CACertBase64}, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("ExtraScopes", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "email profile openid", RedirectURIPrefix: "http://localhost:", @@ -301,8 +301,8 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{BodyContains: "Authenticated"}), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{BodyContains: "Authenticated"}), now: now, stdout: &stdout, args: []string{ @@ -310,14 +310,14 @@ func TestCredentialPlugin(t *testing.T) { "--oidc-extra-scope", "profile", }, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("OpenURLAfterAuthentication", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -331,20 +331,20 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{BodyContains: "URL=https://example.com/success"}), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{BodyContains: "URL=https://example.com/success"}), now: now, stdout: &stdout, args: []string{"--open-url-after-authentication", "https://example.com/success"}, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("RedirectURLHostname", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://127.0.0.1:", @@ -358,20 +358,20 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{BodyContains: "Authenticated"}), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{BodyContains: "Authenticated"}), now: now, stdout: &stdout, args: []string{"--oidc-redirect-url-hostname", "127.0.0.1"}, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("RedirectURLHTTPS", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "https://localhost:", @@ -385,8 +385,8 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{ + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{ TLSConfig: keypair.Server.TLSConfig, BodyContains: "Authenticated", }), @@ -397,14 +397,14 @@ func TestCredentialPlugin(t *testing.T) { "--local-server-key", keypair.Server.KeyPath, }, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) t.Run("ExtraParams", func(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + svc := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -422,8 +422,8 @@ func TestCredentialPlugin(t *testing.T) { var stdout bytes.Buffer runGetToken(t, ctx, getTokenConfig{ tokenCacheDir: tokenCacheDir, - issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{BodyContains: "Authenticated"}), + issuerURL: svc.IssuerURL(), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{BodyContains: "Authenticated"}), now: now, stdout: &stdout, args: []string{ @@ -431,7 +431,7 @@ func TestCredentialPlugin(t *testing.T) { "--oidc-auth-request-extra-params", "reauth=false", }, }) - assertCredentialPluginStdout(t, &stdout, sv.LastTokenResponse().IDToken, now.Add(time.Hour)) + assertCredentialPluginStdout(t, &stdout, svc.LastTokenResponse().IDToken, now.Add(time.Hour)) }) } diff --git a/integration_test/httpdriver/http_driver.go b/integration_test/httpdriver/http_driver.go index 0905808..dea72e1 100644 --- a/integration_test/httpdriver/http_driver.go +++ b/integration_test/httpdriver/http_driver.go @@ -10,14 +10,14 @@ import ( "testing" ) -type Option struct { +type Config struct { TLSConfig *tls.Config BodyContains string } // New returns a client to simulate browser access. -func New(ctx context.Context, t *testing.T, o Option) *client { - return &client{ctx, t, o} +func New(ctx context.Context, t *testing.T, config Config) *client { + return &client{ctx, t, config} } // Zero returns a client which call is not expected. @@ -26,13 +26,13 @@ func Zero(t *testing.T) *zeroClient { } type client struct { - ctx context.Context - t *testing.T - o Option + ctx context.Context + t *testing.T + config Config } func (c *client) Open(url string) error { - client := http.Client{Transport: &http.Transport{TLSClientConfig: c.o.TLSConfig}} + client := http.Client{Transport: &http.Transport{TLSClientConfig: c.config.TLSConfig}} req, err := http.NewRequest("GET", url, nil) if err != nil { c.t.Errorf("could not create a request: %s", err) @@ -54,8 +54,8 @@ func (c *client) Open(url string) error { return nil } body := string(b) - if !strings.Contains(body, c.o.BodyContains) { - c.t.Errorf("body should contain %s but was %s", c.o.BodyContains, body) + if !strings.Contains(body, c.config.BodyContains) { + c.t.Errorf("body should contain %s but was %s", c.config.BodyContains, body) } return nil } diff --git a/integration_test/oidcserver/handler/handler.go b/integration_test/oidcserver/handler/handler.go index 7004993..b55051d 100644 --- a/integration_test/oidcserver/handler/handler.go +++ b/integration_test/oidcserver/handler/handler.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "net/url" "testing" "github.com/int128/kubelogin/integration_test/oidcserver/service" @@ -28,10 +29,8 @@ type Handlers struct { } func (h *Handlers) handleError(w http.ResponseWriter, r *http.Request, f func() error) { - wr := &responseWriterRecorder{w, 200} err := f() if err == nil { - h.t.Logf("%d %s %s", wr.statusCode, r.Method, r.RequestURI) return } if errResp := new(service.ErrorResponse); errors.As(err, &errResp) { @@ -48,16 +47,6 @@ func (h *Handlers) handleError(w http.ResponseWriter, r *http.Request, f func() http.Error(w, err.Error(), 500) } -type responseWriterRecorder struct { - http.ResponseWriter - statusCode int -} - -func (w *responseWriterRecorder) WriteHeader(statusCode int) { - w.ResponseWriter.WriteHeader(statusCode) - w.statusCode = statusCode -} - func (h *Handlers) Discovery(w http.ResponseWriter, r *http.Request) { h.handleError(w, r, func() error { discoveryResponse := h.provider.Discovery() @@ -98,8 +87,12 @@ func (h *Handlers) AuthenticateCode(w http.ResponseWriter, r *http.Request) { if err != nil { return fmt.Errorf("authentication error: %w", err) } - to := fmt.Sprintf("%s?state=%s&code=%s", redirectURI, state, code) - http.Redirect(w, r, to, 302) + redirectTo, err := url.Parse(redirectURI) + if err != nil { + return fmt.Errorf("invalid redirect_uri: %w", err) + } + redirectTo.RawQuery = url.Values{"state": {state}, "code": {code}}.Encode() + http.Redirect(w, r, redirectTo.String(), http.StatusFound) return nil }) } diff --git a/integration_test/oidcserver/oidcserver.go b/integration_test/oidcserver/oidcserver.go index 36265d3..759a890 100644 --- a/integration_test/oidcserver/oidcserver.go +++ b/integration_test/oidcserver/oidcserver.go @@ -17,20 +17,20 @@ import ( ) // New starts a server for the OpenID Connect provider. -func New(t *testing.T, k keypair.KeyPair, c testconfig.TestConfig) service.Service { +func New(t *testing.T, kp keypair.KeyPair, config testconfig.Config) service.Service { mux := http.NewServeMux() - serverURL := startServer(t, mux, k) + serverURL := startServer(t, mux, kp) - svc := service.New(t, serverURL, c) + svc := service.New(t, serverURL, config) handler.Register(t, mux, svc) return svc } -func startServer(t *testing.T, h http.Handler, k keypair.KeyPair) string { - if k == keypair.None { - sv := httptest.NewServer(h) - t.Cleanup(sv.Close) - return sv.URL +func startServer(t *testing.T, h http.Handler, kp keypair.KeyPair) string { + if kp == keypair.None { + srv := httptest.NewServer(h) + t.Cleanup(srv.Close) + return srv.URL } // Unfortunately, httptest package did not work with keypair.KeyPair. @@ -38,15 +38,15 @@ func startServer(t *testing.T, h http.Handler, k keypair.KeyPair) string { portAllocator := httptest.NewUnstartedServer(h) t.Cleanup(portAllocator.Close) serverURL := fmt.Sprintf("https://localhost:%d", portAllocator.Listener.Addr().(*net.TCPAddr).Port) - sv := &http.Server{Handler: h} + srv := &http.Server{Handler: h} go func() { - err := sv.ServeTLS(portAllocator.Listener, k.CertPath, k.KeyPath) + err := srv.ServeTLS(portAllocator.Listener, kp.CertPath, kp.KeyPath) if err != nil && !errors.Is(err, http.ErrServerClosed) { t.Error(err) } }() t.Cleanup(func() { - if err := sv.Shutdown(context.TODO()); err != nil { + if err := srv.Shutdown(context.TODO()); err != nil { t.Errorf("could not shutdown the server: %s", err) } }) diff --git a/integration_test/oidcserver/service/service.go b/integration_test/oidcserver/service/service.go index d0177b1..0b6f05d 100644 --- a/integration_test/oidcserver/service/service.go +++ b/integration_test/oidcserver/service/service.go @@ -15,7 +15,7 @@ import ( testingJWT "github.com/int128/kubelogin/pkg/testing/jwt" ) -func New(t *testing.T, issuerURL string, config testconfig.TestConfig) Service { +func New(t *testing.T, issuerURL string, config testconfig.Config) Service { return &service{ config: config, t: t, @@ -24,7 +24,7 @@ func New(t *testing.T, issuerURL string, config testconfig.TestConfig) Service { } type service struct { - config testconfig.TestConfig + config testconfig.Config t *testing.T issuerURL string lastAuthenticationRequest *AuthenticationRequest @@ -35,7 +35,7 @@ func (svc *service) IssuerURL() string { return svc.issuerURL } -func (svc *service) SetConfig(cfg testconfig.TestConfig) { +func (svc *service) SetConfig(cfg testconfig.Config) { svc.config = cfg } diff --git a/integration_test/oidcserver/service/types.go b/integration_test/oidcserver/service/types.go index a27c42f..02820ce 100644 --- a/integration_test/oidcserver/service/types.go +++ b/integration_test/oidcserver/service/types.go @@ -13,7 +13,7 @@ type Service interface { Provider IssuerURL() string - SetConfig(config testconfig.TestConfig) + SetConfig(config testconfig.Config) LastTokenResponse() *TokenResponse } diff --git a/integration_test/oidcserver/testconfig/types.go b/integration_test/oidcserver/testconfig/types.go index ffb6831..33d37e1 100644 --- a/integration_test/oidcserver/testconfig/types.go +++ b/integration_test/oidcserver/testconfig/types.go @@ -21,8 +21,8 @@ type Response struct { CodeChallengeMethodsSupported []string } -// TestConfig represents a configuration of the OpenID Connect provider. -type TestConfig struct { +// Config represents a configuration of the OpenID Connect provider. +type Config struct { Want Want Response Response } diff --git a/integration_test/standalone_test.go b/integration_test/standalone_test.go index 7c57afe..68c54fe 100644 --- a/integration_test/standalone_test.go +++ b/integration_test/standalone_test.go @@ -36,7 +36,7 @@ func TestStandalone(t *testing.T) { keyPair: keypair.Server, }, } { - httpDriverOption := httpdriver.Option{ + httpDriverOption := httpdriver.Config{ TLSConfig: tc.keyPair.TLSConfig, BodyContains: "Authenticated", } @@ -46,7 +46,7 @@ func TestStandalone(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, tc.keyPair, testconfig.TestConfig{ + sv := oidcserver.New(t, tc.keyPair, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -75,7 +75,7 @@ func TestStandalone(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, tc.keyPair, testconfig.TestConfig{ + sv := oidcserver.New(t, tc.keyPair, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -110,14 +110,14 @@ func TestStandalone(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, tc.keyPair, testconfig.TestConfig{}) + sv := oidcserver.New(t, tc.keyPair, testconfig.Config{}) kubeConfigFilename := kubeconfig.Create(t, &kubeconfig.Values{ Issuer: sv.IssuerURL(), IDPCertificateAuthority: tc.keyPair.CACertPath, }) t.Run("NoToken", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{ + sv.SetConfig(testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -139,7 +139,7 @@ func TestStandalone(t *testing.T) { }) }) t.Run("Valid", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{}) + sv.SetConfig(testconfig.Config{}) runStandalone(t, ctx, standaloneConfig{ issuerURL: sv.IssuerURL(), kubeConfigFilename: kubeConfigFilename, @@ -152,7 +152,7 @@ func TestStandalone(t *testing.T) { }) }) t.Run("Refresh", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{ + sv.SetConfig(testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -175,7 +175,7 @@ func TestStandalone(t *testing.T) { }) }) t.Run("RefreshAgain", func(t *testing.T) { - sv.SetConfig(testconfig.TestConfig{ + sv.SetConfig(testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -204,7 +204,7 @@ func TestStandalone(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.Server, testconfig.TestConfig{ + sv := oidcserver.New(t, keypair.Server, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -220,7 +220,7 @@ func TestStandalone(t *testing.T) { runStandalone(t, ctx, standaloneConfig{ issuerURL: sv.IssuerURL(), kubeConfigFilename: kubeConfigFilename, - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{TLSConfig: keypair.Server.TLSConfig}), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{TLSConfig: keypair.Server.TLSConfig}), now: now, }) kubeconfig.Verify(t, kubeConfigFilename, kubeconfig.AuthProviderConfig{ @@ -232,7 +232,7 @@ func TestStandalone(t *testing.T) { t.Run("env_KUBECONFIG", func(t *testing.T) { ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + sv := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "openid", RedirectURIPrefix: "http://localhost:", @@ -247,7 +247,7 @@ func TestStandalone(t *testing.T) { t.Setenv("KUBECONFIG", kubeConfigFilename+string(os.PathListSeparator)+"kubeconfig/testdata/dummy.yaml") runStandalone(t, ctx, standaloneConfig{ issuerURL: sv.IssuerURL(), - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{}), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{}), now: now, }) kubeconfig.Verify(t, kubeConfigFilename, kubeconfig.AuthProviderConfig{ @@ -260,7 +260,7 @@ func TestStandalone(t *testing.T) { t.Parallel() ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - sv := oidcserver.New(t, keypair.None, testconfig.TestConfig{ + sv := oidcserver.New(t, keypair.None, testconfig.Config{ Want: testconfig.Want{ Scope: "profile groups openid", RedirectURIPrefix: "http://localhost:", @@ -276,7 +276,7 @@ func TestStandalone(t *testing.T) { runStandalone(t, ctx, standaloneConfig{ issuerURL: sv.IssuerURL(), kubeConfigFilename: kubeConfigFilename, - httpDriver: httpdriver.New(ctx, t, httpdriver.Option{}), + httpDriver: httpdriver.New(ctx, t, httpdriver.Config{}), now: now, }) kubeconfig.Verify(t, kubeConfigFilename, kubeconfig.AuthProviderConfig{ diff --git a/mocks/github.com/int128/kubelogin/integration_test/oidcserver/service_mock/mock_Service.go b/mocks/github.com/int128/kubelogin/integration_test/oidcserver/service_mock/mock_Service.go index f3d08b5..d52965d 100644 --- a/mocks/github.com/int128/kubelogin/integration_test/oidcserver/service_mock/mock_Service.go +++ b/mocks/github.com/int128/kubelogin/integration_test/oidcserver/service_mock/mock_Service.go @@ -440,7 +440,7 @@ func (_c *MockService_Refresh_Call) RunAndReturn(run func(string) (*service.Toke } // SetConfig provides a mock function with given fields: config -func (_m *MockService) SetConfig(config testconfig.TestConfig) { +func (_m *MockService) SetConfig(config testconfig.Config) { _m.Called(config) } @@ -450,14 +450,14 @@ type MockService_SetConfig_Call struct { } // SetConfig is a helper method to define mock.On call -// - config testconfig.TestConfig +// - config testconfig.Config func (_e *MockService_Expecter) SetConfig(config interface{}) *MockService_SetConfig_Call { return &MockService_SetConfig_Call{Call: _e.mock.On("SetConfig", config)} } -func (_c *MockService_SetConfig_Call) Run(run func(config testconfig.TestConfig)) *MockService_SetConfig_Call { +func (_c *MockService_SetConfig_Call) Run(run func(config testconfig.Config)) *MockService_SetConfig_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(testconfig.TestConfig)) + run(args[0].(testconfig.Config)) }) return _c } @@ -467,7 +467,7 @@ func (_c *MockService_SetConfig_Call) Return() *MockService_SetConfig_Call { return _c } -func (_c *MockService_SetConfig_Call) RunAndReturn(run func(testconfig.TestConfig)) *MockService_SetConfig_Call { +func (_c *MockService_SetConfig_Call) RunAndReturn(run func(testconfig.Config)) *MockService_SetConfig_Call { _c.Run(run) return _c }