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

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-08-02 02:03:35 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-08-09 15:35:06 +0300
commit39fe221ca877c22e828a4099d9126e89d409f776 (patch)
tree02d33bb48cb2b1a473ff6c62ee5a80b0ab47c8e7 /test
parenta6a353bb9b4939073d6344d86b292eed7488a4b3 (diff)
test: merge cors tests to avoid duplicate code
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/serving_test.go79
1 files changed, 46 insertions, 33 deletions
diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go
index 1349f7ff..74c14700 100644
--- a/test/acceptance/serving_test.go
+++ b/test/acceptance/serving_test.go
@@ -215,7 +215,7 @@ func TestCORSWhenDisabled(t *testing.T) {
RunPagesProcessWithStubGitLabServer(t, withExtraArgument("disable-cross-origin-requests", "true"))
for _, spec := range supportedListeners() {
- for _, method := range []string{http.MethodGet, http.MethodOptions} {
+ for _, method := range []string{http.MethodGet, http.MethodHead, http.MethodOptions} {
rsp := doCrossOriginRequest(t, spec, method, method, spec.URL("project/"))
require.Equal(t, http.StatusOK, rsp.StatusCode)
@@ -225,43 +225,56 @@ func TestCORSWhenDisabled(t *testing.T) {
}
}
-func TestCORSAllowsGET(t *testing.T) {
+func TestCORSAllowsMethod(t *testing.T) {
RunPagesProcessWithStubGitLabServer(t)
- for _, spec := range supportedListeners() {
- for _, method := range []string{http.MethodGet, http.MethodOptions} {
- rsp := doCrossOriginRequest(t, spec, method, method, spec.URL("project/"))
-
- require.Equal(t, http.StatusOK, rsp.StatusCode)
- require.Equal(t, "*", rsp.Header.Get("Access-Control-Allow-Origin"))
- require.Equal(t, "", rsp.Header.Get("Access-Control-Allow-Credentials"))
- }
- }
-}
-
-func TestCORSAllowsHEAD(t *testing.T) {
- RunPagesProcessWithStubGitLabServer(t)
-
- for _, spec := range supportedListeners() {
- for _, method := range []string{http.MethodGet, http.MethodOptions, http.MethodHead} {
- rsp := doCrossOriginRequest(t, spec, method, method, spec.URL("project/"))
-
- require.Equal(t, http.StatusOK, rsp.StatusCode)
- require.Equal(t, "*", rsp.Header.Get("Access-Control-Allow-Origin"))
- require.Equal(t, "", rsp.Header.Get("Access-Control-Allow-Credentials"))
- }
+ tests := []struct {
+ name string
+ method string
+ expectedStatus int
+ expectedOrigin string
+ expectedCredentials string
+ }{
+ {
+ name: "cors-allows-get",
+ method: http.MethodGet,
+ expectedStatus: http.StatusOK,
+ expectedOrigin: "*",
+ expectedCredentials: "",
+ },
+ {
+ name: "cors-allows-options",
+ method: http.MethodOptions,
+ expectedStatus: http.StatusOK,
+ expectedOrigin: "*",
+ expectedCredentials: "",
+ },
+ {
+ name: "cors-allows-head",
+ method: http.MethodHead,
+ expectedStatus: http.StatusOK,
+ expectedOrigin: "*",
+ expectedCredentials: "",
+ },
+ {
+ name: "cors-forbids-post",
+ method: http.MethodPost,
+ expectedStatus: http.StatusOK,
+ expectedOrigin: "",
+ expectedCredentials: "",
+ },
}
-}
-func TestCORSForbidsPOST(t *testing.T) {
- RunPagesProcessWithStubGitLabServer(t)
-
- for _, spec := range supportedListeners() {
- rsp := doCrossOriginRequest(t, spec, http.MethodOptions, http.MethodPost, spec.URL("project/"))
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ for _, spec := range supportedListeners() {
+ rsp := doCrossOriginRequest(t, spec, tt.method, tt.method, spec.URL("project/"))
- require.Equal(t, http.StatusOK, rsp.StatusCode)
- require.Equal(t, "", rsp.Header.Get("Access-Control-Allow-Origin"))
- require.Equal(t, "", rsp.Header.Get("Access-Control-Allow-Credentials"))
+ require.Equal(t, tt.expectedStatus, rsp.StatusCode)
+ require.Equal(t, tt.expectedOrigin, rsp.Header.Get("Access-Control-Allow-Origin"))
+ require.Equal(t, tt.expectedCredentials, rsp.Header.Get("Access-Control-Allow-Credentials"))
+ }
+ })
}
}