diff options
Diffstat (limited to 'workhorse/internal/dependencyproxy/dependencyproxy_test.go')
-rw-r--r-- | workhorse/internal/dependencyproxy/dependencyproxy_test.go | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/workhorse/internal/dependencyproxy/dependencyproxy_test.go b/workhorse/internal/dependencyproxy/dependencyproxy_test.go index 18d08ef162c..b028fbcf355 100644 --- a/workhorse/internal/dependencyproxy/dependencyproxy_test.go +++ b/workhorse/internal/dependencyproxy/dependencyproxy_test.go @@ -10,11 +10,13 @@ import ( "strconv" "strings" "testing" + "time" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitlab/workhorse/internal/api" "gitlab.com/gitlab-org/gitlab/workhorse/internal/testhelper" + "gitlab.com/gitlab-org/gitlab/workhorse/internal/transport" "gitlab.com/gitlab-org/gitlab/workhorse/internal/upload" ) @@ -124,6 +126,7 @@ func TestSuccessfullRequest(t *testing.T) { w.Header().Set("Overridden-Header", overriddenHeader) w.Write(content) })) + defer originResourceServer.Close() uploadHandler := &fakeUploadHandler{ handler: func(w http.ResponseWriter, r *http.Request) { @@ -161,6 +164,7 @@ func TestValidUploadConfiguration(t *testing.T) { w.Header().Set("Content-Type", contentType) w.Write(content) })) + defer originResourceServer.Close() testCases := []struct { desc string @@ -257,6 +261,20 @@ func TestInvalidUploadConfiguration(t *testing.T) { sendData map[string]interface{} }{ { + desc: "with an invalid overriden method", + sendData: mergeMap(baseSendData, map[string]interface{}{ + "UploadConfig": map[string]string{ + "Method": "TEAPOT", + }, + }), + }, { + desc: "with an invalid url", + sendData: mergeMap(baseSendData, map[string]interface{}{ + "UploadConfig": map[string]string{ + "Url": "invalid_url", + }, + }), + }, { desc: "with an invalid headers", sendData: mergeMap(baseSendData, map[string]interface{}{ "UploadConfig": map[string]interface{}{ @@ -281,6 +299,34 @@ func TestInvalidUploadConfiguration(t *testing.T) { } } +func TestTimeoutConfiguration(t *testing.T) { + originResourceServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + time.Sleep(20 * time.Millisecond) + })) + defer originResourceServer.Close() + + injector := NewInjector() + + var oldHttpClient = httpClient + httpClient = &http.Client{ + Transport: transport.NewRestrictedTransport(transport.WithResponseHeaderTimeout(10 * time.Millisecond)), + } + + t.Cleanup(func() { + httpClient = oldHttpClient + }) + + sendData := map[string]string{ + "Url": originResourceServer.URL + "/file", + } + + sendDataJsonString, err := json.Marshal(sendData) + require.NoError(t, err) + + response := makeRequest(injector, string(sendDataJsonString)) + require.Equal(t, http.StatusGatewayTimeout, response.Result().StatusCode) +} + func mergeMap(from map[string]interface{}, into map[string]interface{}) map[string]interface{} { for k, v := range from { into[k] = v @@ -298,8 +344,8 @@ func TestIncorrectSendData(t *testing.T) { func TestIncorrectSendDataUrl(t *testing.T) { response := makeRequest(NewInjector(), `{"Token": "token", "Url": "url"}`) - require.Equal(t, 500, response.Code) - require.Equal(t, "Internal Server Error\n", response.Body.String()) + require.Equal(t, http.StatusBadGateway, response.Code) + require.Equal(t, "Bad Gateway\n", response.Body.String()) } func TestFailedOriginServer(t *testing.T) { |