-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: create upstream error when pass host is node and nodes without port #2421
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,63 @@ var _ = ginkgo.Describe("Upstream", func() { | |
ExpectStatus: http.StatusOK, | ||
}) | ||
}) | ||
ginkgo.It("create upstream3 success when pass host is 'node' and nodes without port", func() { | ||
ginkgo.By("create upstream3", func() { | ||
createUpstreamBody := make(map[string]interface{}) | ||
createUpstreamBody["name"] = "upstream3" | ||
createUpstreamBody["nodes"] = map[string]float64{base.UpstreamIp: 100} | ||
nic-chen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
createUpstreamBody["type"] = "roundrobin" | ||
createUpstreamBody["pass_host"] = "node" | ||
|
||
_createUpstreamBody, err := json.Marshal(createUpstreamBody) | ||
gomega.Expect(err).To(gomega.BeNil()) | ||
base.RunTestCase(base.HttpTestCase{ | ||
Object: base.ManagerApiExpect(), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/upstreams/3", | ||
Body: string(_createUpstreamBody), | ||
Headers: map[string]string{"Authorization": base.GetToken()}, | ||
ExpectStatus: http.StatusOK, | ||
}) | ||
}) | ||
|
||
ginkgo.By("create route using the upstream3", func() { | ||
base.RunTestCase(base.HttpTestCase{ | ||
Object: base.ManagerApiExpect(), | ||
Method: http.MethodPut, | ||
Path: "/apisix/admin/routes/1", | ||
Body: `{ | ||
"name": "route1", | ||
"uri": "/hello", | ||
"upstream_id": "3" | ||
}`, | ||
Headers: map[string]string{"Authorization": base.GetToken()}, | ||
ExpectStatus: http.StatusOK, | ||
Sleep: base.SleepTime, | ||
}) | ||
}) | ||
|
||
ginkgo.By("hit the route just created", func() { | ||
base.RunTestCase(base.HttpTestCase{ | ||
Object: base.APISIXExpect(), | ||
Method: http.MethodGet, | ||
Path: "/hello", | ||
ExpectStatus: http.StatusOK, | ||
ExpectBody: "hello", | ||
Sleep: base.SleepTime, | ||
}) | ||
}) | ||
|
||
ginkgo.By("delete route", func() { | ||
base.RunTestCase(base.HttpTestCase{ | ||
Object: base.ManagerApiExpect(), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/routes/1", | ||
Headers: map[string]string{"Authorization": base.GetToken()}, | ||
ExpectStatus: http.StatusOK, | ||
}) | ||
}) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add test to check the upstream is work ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a test case for DP There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. it is done now |
||
ginkgo.It("create upstream failed, name existed", func() { | ||
createUpstreamBody := make(map[string]interface{}) | ||
createUpstreamBody["name"] = "upstream2" | ||
|
@@ -252,6 +309,15 @@ var _ = ginkgo.Describe("Upstream", func() { | |
ExpectStatus: http.StatusOK, | ||
}) | ||
}) | ||
ginkgo.It("delete upstream3", func() { | ||
base.RunTestCase(base.HttpTestCase{ | ||
Object: base.ManagerApiExpect(), | ||
Method: http.MethodDelete, | ||
Path: "/apisix/admin/upstreams/3", | ||
Headers: map[string]string{"Authorization": base.GetToken()}, | ||
ExpectStatus: http.StatusOK, | ||
}) | ||
}) | ||
ginkgo.It("hit the route just deleted", func() { | ||
base.RunTestCase(base.HttpTestCase{ | ||
Object: base.APISIXExpect(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it appropriate to use port 0 by default? Should port 80 be used by default? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apisix-dashboard/api/internal/core/entity/entity.go
Lines 99 to 105 in 92f46d9
We cannot give default values to port, the value of 0 is assigned because the zero value is ignored during
json.Marshal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When there is no port in host, port
0
will be used by default, which I think is wrong. For HTTP it should be80
and for HTTPS it should be443
, so I think it should be set to 80 by default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Port is not required, when using https and not configured port it will cause problems, if we do not configure the port there is no such problem
If 80 is given, you need to determine the schema type, when it is https and then change the port default back to 443. I think the first one is more convenient, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to put it another way, if the port is 0, the JSON will not contain the port field when it is encoded in JSON? The
port
is required.