This is an automated email from the ASF dual-hosted git repository.
juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 1770596 fix: generate a uid when post a route without id (#1883)
1770596 is described below
commit 177059644e3eb5d8ddd42da6a2b48413c70eb044
Author: Peter Zhu <[email protected]>
AuthorDate: Mon May 10 19:10:47 2021 +0800
fix: generate a uid when post a route without id (#1883)
---
api/internal/handler/route/route.go | 2 +-
.../route/route_with_plugin_orchestration_test.go | 61 ++++++++++++++++++++++
2 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/api/internal/handler/route/route.go
b/api/internal/handler/route/route.go
index 2775679..fae4429 100644
--- a/api/internal/handler/route/route.go
+++ b/api/internal/handler/route/route.go
@@ -338,7 +338,7 @@ func (h *Handler) Create(c droplet.Context) (interface{},
error) {
}
if input.Script != nil {
- if input.ID == "" {
+ if utils.InterfaceToString(input.ID) == "" {
input.ID = utils.GetFlakeUidStr()
}
script := &entity.Script{}
diff --git a/api/test/e2enew/route/route_with_plugin_orchestration_test.go
b/api/test/e2enew/route/route_with_plugin_orchestration_test.go
index 57e612e..304240f 100644
--- a/api/test/e2enew/route/route_with_plugin_orchestration_test.go
+++ b/api/test/e2enew/route/route_with_plugin_orchestration_test.go
@@ -23,6 +23,7 @@ import (
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
"github.com/onsi/gomega"
+ "github.com/tidwall/gjson"
"github.com/apisix/manager-api/test/e2enew/base"
)
@@ -108,4 +109,64 @@ var _ = ginkgo.Describe("route with plugin orchestration",
func() {
Sleep: base.SleepTime,
}),
)
+
+ table.DescribeTable("test route with plugin orchestration (post
method)",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("make sure the route is not created",
base.HttpTestCase{
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ }),
+ )
+
+ var routeID string
+ ginkgo.It("create route with correct dag config by post", func() {
+ resp, code, err :=
base.HttpPost(base.ManagerAPIHost+"/apisix/admin/routes",
+ map[string]string{"Authorization": base.GetToken()},
dagConf)
+ gomega.Expect(err).To(gomega.BeNil())
+ gomega.Expect(code).Should(gomega.Equal(200))
+ routeID = gjson.Get(string(resp), "data.id").String()
+ })
+
+ ginkgo.It("test the route with plugin orchestration", func() {
+ base.RunTestCase(base.HttpTestCase{
+ Desc: "verify the route (should be blocked)",
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ Query: "t=root.exe",
+ ExpectStatus: http.StatusForbidden,
+ ExpectBody: `blocked`,
+ Sleep: base.SleepTime,
+ })
+ base.RunTestCase(base.HttpTestCase{
+ Desc: "verify the route (should not be
blocked)",
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusOK,
+ ExpectBody: `hello world`,
+ })
+ base.RunTestCase(base.HttpTestCase{
+ Desc: "delete the route by routeID",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/routes/" + routeID,
+ Headers: map[string]string{"Authorization":
base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ })
+ base.RunTestCase(base.HttpTestCase{
+ Desc: "make sure the route has been deleted",
+ Object: base.APISIXExpect(),
+ Method: http.MethodGet,
+ Path: "/hello",
+ ExpectStatus: http.StatusNotFound,
+ ExpectBody: `{"error_msg":"404 Route Not Found"}`,
+ Sleep: base.SleepTime,
+ })
+ })
})