Welcome to mirror list, hosted at ThFree Co, Russian Federation.

urilimiter_test.go « acceptance « test - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e97921f0f9392168d98cdb346531973c8971850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package acceptance_test

import (
	"io"
	"net/http"
	"testing"

	"github.com/stretchr/testify/require"
)

// TestURILimits proves fix for https://gitlab.com/gitlab-org/gitlab-pages/-/issues/659
func TestURILimits(t *testing.T) {
	tests := map[string]struct {
		limit          string
		path           string
		expectedStatus int
	}{
		"with_disabled_limit": {
			limit:          "0",
			path:           "project/",
			expectedStatus: http.StatusOK,
		},
		"with_limit_set_to_request_length": {
			limit:          "19",
			path:           "/project/index.html",
			expectedStatus: http.StatusOK,
		},
		"with_uri_length_exceeding_the_limit": {
			limit:          "19",
			path:           "/project/index1.html",
			expectedStatus: http.StatusRequestURITooLong,
		},
	}

	for tn, tt := range tests {
		t.Run(tn, func(t *testing.T) {
			RunPagesProcess(t, withListeners([]ListenSpec{httpsListener}), withExtraArgument("max-uri-length", tt.limit))

			rsp, err := GetPageFromListener(t, httpsListener, "group.gitlab-example.com", tt.path)
			require.NoError(t, err)
			defer func() {
				require.NoError(t, rsp.Body.Close())
			}()

			require.Equal(t, tt.expectedStatus, rsp.StatusCode)

			b, err := io.ReadAll(rsp.Body)
			require.NoError(t, err)
			if tt.expectedStatus == http.StatusOK {
				require.Equal(t, "project-subdir\n", string(b))
			} else {
				require.Contains(t, string(b), "Request URI Too Long")
			}
		})
	}
}