You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/01 07:54:24 UTC

[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #906: test: add e2e test cases for route with plugin cors

nic-chen commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r533133619



##########
File path: api/test/e2e/route_with_plugin_cors_test.go
##########
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package e2e
+
+import (
+	"net/http"
+	"testing"
+)
+
+func TestRoute_With_Plugin_Cors(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "make sure the route is not created",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+		},
+		{
+			caseDesc: "create route with cors default setting",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"cors": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "172.16.238.20",
+						"port": 1981,
+						"weight": 1
+					}]
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route with cors default setting",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusOK,
+			ExpectHeaders: map[string]string{
+				"Access-Control-Allow-Origin":  "*",
+				"Access-Control-Allow-Methods": "*",
+			},
+			ExpectBody: "hello world",
+			Sleep:      sleepTime,
+		},
+		{
+			caseDesc: "update route with specified setting",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+			"uri": "/hello",
+				"plugins": {
+					"cors": {
+						"allow_origins": "http://sub.domain.com,http://sub2.domain.com",
+						"allow_methods": "GET,POST",
+						"allow_headers": "headr1,headr2",
+						"expose_headers": "ex-headr1,ex-headr2",
+						"max_age": 50,
+						"allow_credential": true
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "172.16.238.20",
+						"port": 1981,
+						"weight": 1
+					}]
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "verify route with cors specified setting",
+			Object:   APISIXExpect(t),
+			Method:   http.MethodGet,
+			Path:     "/hello",
+			Headers: map[string]string{
+				"Origin":    "http://sub2.domain.com",
+				"resp-vary": "Via",
+			},
+			ExpectStatus: http.StatusOK,
+			ExpectHeaders: map[string]string{
+				"Access-Control-Allow-Origin":   "http://sub2.domain.com",
+				"Access-Control-Allow-Methods":  "GET,POST",
+				"Access-Control-Allow-Headers":  "headr1,headr2",
+				"Access-Control-Expose-Headers": "ex-headr1,ex-headr2",
+				"Access-Control-Max-Age":        "50",
+			},
+			ExpectBody: "hello world",
+			Sleep:      sleepTime,
+		},
+		{
+			caseDesc: "verify route with cors specified no match origin",
+			Object:   APISIXExpect(t),
+			Method:   http.MethodGet,

Review comment:
       updated. @gxthrj 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org