diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-07-01 18:09:08 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-07-01 18:09:08 +0300 |
commit | 29fb0c4e98a4a775d9af8e917730e065f7971376 (patch) | |
tree | 359fbcdd7f2ee3cfb85bb7637c32434c31d8cd82 /test/acceptance | |
parent | 30f67e89a01173207bd1e40d151c700c18ccddc7 (diff) |
Add tls support to gitlab stub server
Diffstat (limited to 'test/acceptance')
-rw-r--r-- | test/acceptance/artifacts_test.go | 31 | ||||
-rw-r--r-- | test/acceptance/helpers_test.go | 11 | ||||
-rw-r--r-- | test/acceptance/stub_test.go | 6 |
3 files changed, 24 insertions, 24 deletions
diff --git a/test/acceptance/artifacts_test.go b/test/acceptance/artifacts_test.go index e56a1390..6283d896 100644 --- a/test/acceptance/artifacts_test.go +++ b/test/acceptance/artifacts_test.go @@ -150,20 +150,6 @@ func TestArtifactProxyRequest(t *testing.T) { } func TestPrivateArtifactProxyRequest(t *testing.T) { - testServer, err := gitlabstub.NewUnstartedServer() - require.NoError(t, err) - - keyFile, certFile := CreateHTTPSFixtureFiles(t) - cert, err := tls.LoadX509KeyPair(certFile, keyFile) - require.NoError(t, err) - - testServer.TLS = &tls.Config{Certificates: []tls.Certificate{cert}} - testServer.StartTLS() - - t.Cleanup(func() { - testServer.Close() - }) - tests := []struct { name string host string @@ -202,23 +188,22 @@ func TestPrivateArtifactProxyRequest(t *testing.T) { }, } - // Ensure the IP address is used in the URL, as we're relying on IP SANs to - // validate - artifactServerURL := testServer.URL + "/api/v4" - t.Log("Artifact server URL", artifactServerURL) + configFile := defaultConfigFileWith(t) - configFile := defaultConfigFileWith(t, - "gitlab-server="+testServer.URL, - "artifacts-server="+artifactServerURL, - "auth-redirect-uri=https://projects.gitlab-example.com/auth", - "artifacts-server-timeout=1") + keyFile, certFile := CreateHTTPSFixtureFiles(t) + cert, err := tls.LoadX509KeyPair(certFile, keyFile) + require.NoError(t, err) RunPagesProcess(t, withListeners([]ListenSpec{httpsListener}), withArguments([]string{ "-config=" + configFile, }), + withPublicServer, + withExtraArgument("auth-redirect-uri", "https://projects.gitlab-example.com/auth"), + withExtraArgument("artifacts-server-timeout", "1"), withEnv([]string{"SSL_CERT_FILE=" + certFile}), + withStubOptions(gitlabstub.WithCertificate(cert)), ) for _, tt := range tests { diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index 4c365c5e..1539df01 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -247,7 +247,12 @@ func RunPagesProcess(t *testing.T, opts ...processOption) *LogCaptureBuffer { source, err := gitlabstub.NewUnstartedServer(processCfg.gitlabStubOpts...) require.NoError(t, err) - source.Start() + + if source.TLS != nil { + source.StartTLS() + } else { + source.Start() + } gitLabAPISecretKey := CreateGitLabAPISecretKeyFixtureFile(t) processCfg.extraArgs = append( @@ -257,6 +262,10 @@ func RunPagesProcess(t *testing.T, opts ...processOption) *LogCaptureBuffer { "-api-secret-key", gitLabAPISecretKey, ) + if processCfg.publicServer { + processCfg.extraArgs = append(processCfg.extraArgs, "-gitlab-server", source.URL) + } + logBuf, cleanup := runPagesProcess(t, processCfg.wait, processCfg.pagesBinary, processCfg.listeners, "", processCfg.envs, processCfg.extraArgs...) t.Cleanup(func() { diff --git a/test/acceptance/stub_test.go b/test/acceptance/stub_test.go index 3d54b4d4..e65a86cc 100644 --- a/test/acceptance/stub_test.go +++ b/test/acceptance/stub_test.go @@ -27,6 +27,7 @@ type processConfig struct { envs []string extraArgs []string gitlabStubOpts []gitlabstub.Option + publicServer bool } type processOption func(*processConfig) @@ -52,12 +53,17 @@ func withExtraArgument(key, value string) processOption { config.extraArgs = append(config.extraArgs, fmt.Sprintf("-%s=%s", key, value)) } } + func withArguments(args []string) processOption { return func(config *processConfig) { config.extraArgs = append(config.extraArgs, args...) } } +func withPublicServer(config *processConfig) { + config.publicServer = true +} + func withStubOptions(opts ...gitlabstub.Option) processOption { return func(config *processConfig) { config.gitlabStubOpts = opts |