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/11/30 02:55:47 UTC
[GitHub] [apisix-dashboard] nic-chen opened a new pull request #906: test: add e2e test cases for route with plugin cors
nic-chen opened a new pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906
Please answer these questions before submitting a pull request
- Why submit this pull request?
- [ ] Bugfix
- [ ] New feature provided
- [ ] Improve performance
- [x] E2E test
- Related issues
close #863
bug has been fixed in APISIX, just test for it.
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#issuecomment-735516563
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=h1) Report
> Merging [#906](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=desc) (210b5e1) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/aec6d6cc7613cd7f2c583e99563e01e8a3391198?el=desc) (aec6d6c) will **increase** coverage by `0.07%`.
> The diff coverage is `n/a`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/906/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #906 +/- ##
==========================================
+ Coverage 42.95% 43.03% +0.07%
==========================================
Files 18 18
Lines 1271 1271
==========================================
+ Hits 546 547 +1
+ Misses 633 632 -1
Partials 92 92
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/store/store.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmUuZ28=) | `78.94% <0.00%> (+0.65%)` | :arrow_up: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=footer). Last update [aec6d6c...210b5e1](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r533299624
##########
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:
@gxthrj
it return empty:
https://github.com/apache/apisix/blob/master/t/plugin/cors.t#L427
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#issuecomment-735516563
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=h1) Report
> Merging [#906](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=desc) (b653e99) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/aec6d6cc7613cd7f2c583e99563e01e8a3391198?el=desc) (aec6d6c) will **increase** coverage by `0.07%`.
> The diff coverage is `n/a`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/906/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #906 +/- ##
==========================================
+ Coverage 42.95% 43.03% +0.07%
==========================================
Files 18 18
Lines 1271 1271
==========================================
+ Hits 546 547 +1
+ Misses 633 632 -1
Partials 92 92
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/core/store/store.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmUuZ28=) | `78.94% <0.00%> (+0.65%)` | :arrow_up: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=footer). Last update [aec6d6c...b653e99](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] gxthrj commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r532587193
##########
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:
I think we need to do some tests on option detection scenarios ,which is useful under non-simple requests.
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r533344143
##########
File path: api/test/e2e/route_with_plugin_cors_test.go
##########
@@ -0,0 +1,226 @@
+/*
+ * 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: ManagerApiExpect(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: ManagerApiExpect(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,
+ Path: "/hello",
+ Headers: map[string]string{
+ "Origin": "http://sub3.domain.com",
+ },
+ ExpectStatus: http.StatusOK,
+ ExpectHeaders: map[string]string{
+ "Access-Control-Allow-Origin": "",
Review comment:
updated.
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#issuecomment-735516563
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=h1) Report
> Merging [#906](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=desc) (6e61c4d) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/a7d8e13e0f97b4636ab8a35576a848c0bf004221?el=desc) (a7d8e13) will **not change** coverage.
> The diff coverage is `n/a`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/906/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #906 +/- ##
=======================================
Coverage 42.82% 42.82%
=======================================
Files 18 18
Lines 1289 1289
=======================================
Hits 552 552
Misses 645 645
Partials 92 92
```
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=footer). Last update [a7d8e13...6e61c4d](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] membphis commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r532433266
##########
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,
+ Path: "/hello",
+ Headers: map[string]string{
+ "Origin": "http://sub3.domain.com",
+ },
+ ExpectStatus: http.StatusOK,
+ ExpectHeaders: map[string]string{
+ "Access-Control-Allow-Origin": "",
+ "Access-Control-Allow-Methods": "",
+ "Access-Control-Allow-Headers": "",
+ "Access-Control-Expose-Headers": "",
+ "Access-Control-Max-Age": "",
+ },
+ ExpectBody: "hello world",
+ Sleep: sleepTime,
+ },
+ {
+ caseDesc: "update route with cors setting force wildcard",
+ Object: MangerApiExpect(t),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "plugins": {
+ "cors": {
Review comment:
ditto
##########
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": {
Review comment:
bad indentation
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] codecov-io commented on pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#issuecomment-735516563
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=h1) Report
> Merging [#906](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=desc) (14749cd) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/aec6d6cc7613cd7f2c583e99563e01e8a3391198?el=desc) (aec6d6c) will **not change** coverage.
> The diff coverage is `n/a`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/906/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #906 +/- ##
=======================================
Coverage 42.95% 42.95%
=======================================
Files 18 18
Lines 1271 1271
=======================================
Hits 546 546
Misses 633 633
Partials 92 92
```
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=footer). Last update [aec6d6c...14749cd](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] codecov-io edited a comment on pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#issuecomment-735516563
# [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=h1) Report
> Merging [#906](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=desc) (83ba5c7) into [master](https://codecov.io/gh/apache/apisix-dashboard/commit/aec6d6cc7613cd7f2c583e99563e01e8a3391198?el=desc) (aec6d6c) will **decrease** coverage by `0.13%`.
> The diff coverage is `n/a`.
[![Impacted file tree graph](https://codecov.io/gh/apache/apisix-dashboard/pull/906/graphs/tree.svg?width=650&height=150&src=pr&token=Q1HERXN96P)](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree)
```diff
@@ Coverage Diff @@
## master #906 +/- ##
==========================================
- Coverage 42.95% 42.82% -0.14%
==========================================
Files 18 18
Lines 1271 1289 +18
==========================================
+ Hits 546 552 +6
- Misses 633 645 +12
Partials 92 92
```
| [Impacted Files](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [api/internal/utils/utils.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL3V0aWxzL3V0aWxzLmdv) | `51.61% <0.00%> (-7.65%)` | :arrow_down: |
| [api/internal/handler/service/service.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvc2VydmljZS9zZXJ2aWNlLmdv) | `27.65% <0.00%> (-0.61%)` | :arrow_down: |
| [api/internal/core/entity/query.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L3F1ZXJ5Lmdv) | `0.00% <0.00%> (ø)` | |
| [api/internal/core/entity/entity.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvZW50aXR5L2VudGl0eS5nbw==) | `0.00% <0.00%> (ø)` | |
| [api/internal/handler/consumer/consumer.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvY29uc3VtZXIvY29uc3VtZXIuZ28=) | `34.92% <0.00%> (ø)` | |
| [api/internal/handler/route/route.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2hhbmRsZXIvcm91dGUvcm91dGUuZ28=) | `46.56% <0.00%> (+0.11%)` | :arrow_up: |
| [api/internal/core/store/store.go](https://codecov.io/gh/apache/apisix-dashboard/pull/906/diff?src=pr&el=tree#diff-YXBpL2ludGVybmFsL2NvcmUvc3RvcmUvc3RvcmUuZ28=) | `79.22% <0.00%> (+0.93%)` | :arrow_up: |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=footer). Last update [aec6d6c...83ba5c7](https://codecov.io/gh/apache/apisix-dashboard/pull/906?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] nic-chen merged pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
nic-chen merged pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
nic-chen commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r532501720
##########
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": {
Review comment:
fixed.
##########
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,
+ Path: "/hello",
+ Headers: map[string]string{
+ "Origin": "http://sub3.domain.com",
+ },
+ ExpectStatus: http.StatusOK,
+ ExpectHeaders: map[string]string{
+ "Access-Control-Allow-Origin": "",
+ "Access-Control-Allow-Methods": "",
+ "Access-Control-Allow-Headers": "",
+ "Access-Control-Expose-Headers": "",
+ "Access-Control-Max-Age": "",
+ },
+ ExpectBody: "hello world",
+ Sleep: sleepTime,
+ },
+ {
+ caseDesc: "update route with cors setting force wildcard",
+ Object: MangerApiExpect(t),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "plugins": {
+ "cors": {
Review comment:
fixed.
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] gxthrj commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r533322863
##########
File path: api/test/e2e/route_with_plugin_cors_test.go
##########
@@ -0,0 +1,226 @@
+/*
+ * 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: ManagerApiExpect(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: ManagerApiExpect(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,
+ Path: "/hello",
+ Headers: map[string]string{
+ "Origin": "http://sub3.domain.com",
+ },
+ ExpectStatus: http.StatusOK,
+ ExpectHeaders: map[string]string{
+ "Access-Control-Allow-Origin": "",
Review comment:
It is wrong. If we return all headers with empty or no headers, the browser will block the request.
Ref to :https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS.
----------------------------------------------------------------
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
[GitHub] [apisix-dashboard] gxthrj commented on a change in pull request #906: test: add e2e test cases for route with plugin cors
Posted by GitBox <gi...@apache.org>.
gxthrj commented on a change in pull request #906:
URL: https://github.com/apache/apisix-dashboard/pull/906#discussion_r533231865
##########
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:
Sorry, I mean we had better to test the options method, it should return the `allow*` headers .
----------------------------------------------------------------
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