diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2021-07-19 08:35:34 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2021-07-19 08:35:34 +0300 |
commit | 29ecc9c59162fa0a1a9eb3f6545d4d36bfa6d51e (patch) | |
tree | b6f3293e98684fe984288172325ca518f89fd063 /test | |
parent | b72ce71418f5474b1e7dc455052a32b12ae67c39 (diff) |
Update acceptance tls_test.go
Diffstat (limited to 'test')
-rw-r--r-- | test/acceptance/tls_test.go | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/test/acceptance/tls_test.go b/test/acceptance/tls_test.go index a332e407..17e5263d 100644 --- a/test/acceptance/tls_test.go +++ b/test/acceptance/tls_test.go @@ -8,8 +8,9 @@ import ( ) func TestAcceptsSupportedCiphers(t *testing.T) { - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpsListener}), + ) tlsConfig := &tls.Config{ CipherSuites: []uint16{ @@ -25,12 +26,11 @@ func TestAcceptsSupportedCiphers(t *testing.T) { defer cleanup() rsp, err := client.Get(httpsListener.URL("/")) + require.NoError(t, err) - if rsp != nil { + t.Cleanup(func() { rsp.Body.Close() - } - - require.NoError(t, err) + }) } func tlsConfigWithInsecureCiphersOnly() *tls.Config { @@ -44,36 +44,32 @@ func tlsConfigWithInsecureCiphersOnly() *tls.Config { } func TestRejectsUnsupportedCiphers(t *testing.T) { - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "") - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpsListener}), + ) client, cleanup := ClientWithConfig(tlsConfigWithInsecureCiphersOnly()) defer cleanup() rsp, err := client.Get(httpsListener.URL("/")) - - if rsp != nil { - rsp.Body.Close() - } - - require.Error(t, err) require.Nil(t, rsp) + require.Error(t, err) } func TestEnableInsecureCiphers(t *testing.T) { - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "", "-insecure-ciphers") - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpsListener}), + withExtraArgument("-insecure-ciphers", "true"), + ) client, cleanup := ClientWithConfig(tlsConfigWithInsecureCiphersOnly()) defer cleanup() rsp, err := client.Get(httpsListener.URL("/")) - - if rsp != nil { - rsp.Body.Close() - } - require.NoError(t, err) + t.Cleanup(func() { + rsp.Body.Close() + }) } func TestTLSVersions(t *testing.T) { @@ -90,7 +86,7 @@ func TestTLSVersions(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - args := []string{} + var args []string if tc.tlsMin != "" { args = append(args, "-tls-min-version", tc.tlsMin) } @@ -98,8 +94,10 @@ func TestTLSVersions(t *testing.T) { args = append(args, "-tls-max-version", tc.tlsMax) } - teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "", args...) - defer teardown() + RunPagesProcessWithStubGitLabServer(t, + withListeners([]ListenSpec{httpsListener}), + withArguments(args), + ) tlsConfig := &tls.Config{} if tc.tlsClient != 0 { @@ -111,14 +109,11 @@ func TestTLSVersions(t *testing.T) { rsp, err := client.Get(httpsListener.URL("/")) - if rsp != nil { - rsp.Body.Close() - } - if tc.expectError { require.Error(t, err) } else { require.NoError(t, err) + rsp.Body.Close() } }) } |