Skip to content
Snippets Groups Projects
Verified Commit fa7a1db8 authored by Igor Drozdov's avatar Igor Drozdov :two: Committed by GitLab
Browse files

Merge branch '433440-replace-cleanup-testAuthServer' into 'master'

Add cleanup to testAuthServer

See merge request !143200



Merged-by: Igor Drozdov's avatarIgor Drozdov <idrozdov@gitlab.com>
Approved-by: Igor Drozdov's avatarIgor Drozdov <idrozdov@gitlab.com>
Approved-by: Sylvester Chin's avatarSylvester Chin <schin@gitlab.com>
Co-authored-by: default avatarghinfey <ghinfey@gitlab.com>
parents 7ed591e2 7b6a08ea
No related branches found
No related tags found
2 merge requests!144312Change service start (cut-off) date for code suggestions to March 15th,!143200Add cleanup to testAuthServer
Pipeline #1158618731 passed with warnings
Pipeline: E2E Omnibus GitLab EE

#1158675373

    Pipeline: GitLab

    #1158632000

      Pipeline: E2E GDK

      #1158620924

        +26
        ......@@ -28,7 +28,6 @@ func okHandler(w http.ResponseWriter, _ *http.Request, _ *api.Response) {
        func runPreAuthorizeHandler(t *testing.T, ts *httptest.Server, suffix string, url *regexp.Regexp, apiResponse interface{}, returnCode, expectedCode int) *httptest.ResponseRecorder {
        if ts == nil {
        ts = testAuthServer(t, url, nil, returnCode, apiResponse)
        defer ts.Close()
        }
        // Create http request
        ......
        ......@@ -42,8 +42,7 @@ func TestChannelHappyPath(t *testing.T) {
        }
        for _, test := range tests {
        t.Run(test.name, func(t *testing.T) {
        serverConns, clientURL, close := wireupChannel(t, test.channelPath, nil, "channel.k8s.io")
        defer close()
        serverConns, clientURL := wireupChannel(t, test.channelPath, nil, "channel.k8s.io")
        client, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
        require.NoError(t, err)
        ......@@ -70,16 +69,14 @@ func TestChannelHappyPath(t *testing.T) {
        }
        func TestChannelBadTLS(t *testing.T) {
        _, clientURL, close := wireupChannel(t, envTerminalPath, badCA, "channel.k8s.io")
        defer close()
        _, clientURL := wireupChannel(t, envTerminalPath, badCA, "channel.k8s.io")
        _, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
        require.Equal(t, websocket.ErrBadHandshake, err, "unexpected error %v", err)
        }
        func TestChannelSessionTimeout(t *testing.T) {
        serverConns, clientURL, close := wireupChannel(t, envTerminalPath, timeout, "channel.k8s.io")
        defer close()
        serverConns, clientURL := wireupChannel(t, envTerminalPath, timeout, "channel.k8s.io")
        client, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
        require.NoError(t, err)
        ......@@ -96,8 +93,7 @@ func TestChannelSessionTimeout(t *testing.T) {
        func TestChannelProxyForwardsHeadersFromUpstream(t *testing.T) {
        hdr := make(http.Header)
        hdr.Set("Random-Header", "Value")
        serverConns, clientURL, close := wireupChannel(t, envTerminalPath, setHeader(hdr), "channel.k8s.io")
        defer close()
        serverConns, clientURL := wireupChannel(t, envTerminalPath, setHeader(hdr), "channel.k8s.io")
        client, _, err := dialWebsocket(clientURL, nil, "terminal.gitlab.com")
        require.NoError(t, err)
        ......@@ -109,8 +105,7 @@ func TestChannelProxyForwardsHeadersFromUpstream(t *testing.T) {
        }
        func TestChannelProxyForwardsXForwardedForFromClient(t *testing.T) {
        serverConns, clientURL, close := wireupChannel(t, envTerminalPath, nil, "channel.k8s.io")
        defer close()
        serverConns, clientURL := wireupChannel(t, envTerminalPath, nil, "channel.k8s.io")
        hdr := make(http.Header)
        hdr.Set("X-Forwarded-For", "127.0.0.2")
        ......@@ -127,7 +122,7 @@ func TestChannelProxyForwardsXForwardedForFromClient(t *testing.T) {
        require.Equal(t, "127.0.0.2, "+clientIP, sc.req.Header.Get("X-Forwarded-For"), "X-Forwarded-For from client not sent to remote")
        }
        func wireupChannel(t *testing.T, channelPath string, modifier func(*api.Response), subprotocols ...string) (chan connWithReq, string, func()) {
        func wireupChannel(t *testing.T, channelPath string, modifier func(*api.Response), subprotocols ...string) (chan connWithReq, string) {
        serverConns, remote := startWebsocketServer(t, subprotocols...)
        authResponse := channelOkBody(remote, nil, subprotocols...)
        if modifier != nil {
        ......@@ -136,9 +131,7 @@ func wireupChannel(t *testing.T, channelPath string, modifier func(*api.Response
        upstream := testAuthServer(t, nil, nil, 200, authResponse)
        workhorse := startWorkhorseServer(t, upstream.URL)
        return serverConns, websocketURL(workhorse.URL, channelPath), func() {
        upstream.Close()
        }
        return serverConns, websocketURL(workhorse.URL, channelPath)
        }
        func startWebsocketServer(t *testing.T, subprotocols ...string) (chan connWithReq, *httptest.Server) {
        ......
        ......@@ -133,7 +133,6 @@ func TestAllowedClone(t *testing.T) {
        // Prepare test server and backend
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        // Do the git clone
        ......@@ -160,7 +159,6 @@ func TestAllowedShallowClone(t *testing.T) {
        // Prepare test server and backend
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        // Shallow git clone (depth 1)
        ......@@ -187,7 +185,6 @@ func TestAllowedPush(t *testing.T) {
        // Prepare the test server and backend
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        // Do the git clone
        ......
        ......@@ -40,7 +40,6 @@ func TestFailedCloneNoGitaly(t *testing.T) {
        // Prepare test server and backend
        ts := testAuthServer(t, nil, nil, 200, authBody)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        // Do the git clone
        ......@@ -91,7 +90,6 @@ func TestGetInfoRefsProxiedToGitalySuccessfully(t *testing.T) {
        apiResponse.ShowAllRefs = tc.showAllRefs
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -142,7 +140,6 @@ func TestGetInfoRefsProxiedToGitalyInterruptedStream(t *testing.T) {
        apiResponse.GitalyServer.Address = gitalyAddress
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -169,7 +166,6 @@ func TestGetInfoRefsRouting(t *testing.T) {
        apiResponse := gitOkBody(t)
        apiResponse.GitalyServer.Address = "unix:" + socketPath
        ts := testAuthServer(t, nil, url.Values{"service": {"git-receive-pack"}}, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -236,7 +232,6 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
        apiResponse.GitalyServer.Address = "unix:" + socketPath
        apiResponse.GitConfigOptions = []string{"git-config-hello=world"}
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -280,7 +275,6 @@ func TestPostReceivePackProxiedToGitalyInterrupted(t *testing.T) {
        apiResponse.GitalyServer.Address = "unix:" + socketPath
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -312,7 +306,6 @@ func TestPostReceivePackRouting(t *testing.T) {
        apiResponse := gitOkBody(t)
        apiResponse.GitalyServer.Address = "unix:" + socketPath
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -388,7 +381,6 @@ func TestPostUploadPackProxiedToGitalySuccessfully(t *testing.T) {
        apiResponse.GitalyServer.Address = "unix:" + socketPath
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -454,7 +446,6 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) {
        apiResponse.GitalyServer.Address = "unix:" + socketPath
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......@@ -486,7 +477,6 @@ func TestPostUploadPackRouting(t *testing.T) {
        apiResponse.GitalyServer.Address = "unix:" + socketPath
        ts := testAuthServer(t, nil, nil, 200, apiResponse)
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        ......
        ......@@ -62,7 +62,6 @@ func TestMain(m *testing.M) {
        func TestDeniedClone(t *testing.T) {
        // Prepare test server and backend
        ts := testAuthServer(t, nil, nil, 403, "Access denied")
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        // Do the git clone
        ......@@ -75,7 +74,6 @@ func TestDeniedClone(t *testing.T) {
        func TestDeniedPush(t *testing.T) {
        // Prepare the test server and backend
        ts := testAuthServer(t, nil, nil, 403, "Access denied")
        defer ts.Close()
        ws := startWorkhorseServer(t, ts.URL)
        // Perform the git push
        ......@@ -701,7 +699,7 @@ func newBranch() string {
        }
        func testAuthServer(t *testing.T, url *regexp.Regexp, params url.Values, code int, body interface{}) *httptest.Server {
        return testhelper.TestServerWithHandler(url, func(w http.ResponseWriter, r *http.Request) {
        ts := testhelper.TestServerWithHandler(url, func(w http.ResponseWriter, r *http.Request) {
        require.NotEmpty(t, r.Header.Get("X-Request-Id"))
        // return a 204 No Content response if we don't receive the JWT header
        ......@@ -753,6 +751,12 @@ func testAuthServer(t *testing.T, url *regexp.Regexp, params url.Values, code in
        w.WriteHeader(code)
        w.Write(data)
        })
        t.Cleanup(func() {
        ts.Close()
        })
        return ts
        }
        func newUpstreamConfig(authBackend string) *config.Config {
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment