Skip to content

Commit af06e08

Browse files
authored
test: migrate route remote addr e2e (#2201)
1 parent c613573 commit af06e08

File tree

2 files changed

+145
-175
lines changed

2 files changed

+145
-175
lines changed

api/test/e2e/route_remote_addr_test.go

Lines changed: 0 additions & 124 deletions
This file was deleted.

api/test/e2enew/route/route_with_valid_remote_addr_test.go renamed to api/test/e2enew/route/route_with_remote_addr_test.go

Lines changed: 145 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
)
2727

2828
var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
29-
remote_addr := "172.16.238.1"
3029
table.DescribeTable("test route with valid remote_addr remote_addrs",
3130
func(tc base.HttpTestCase) {
3231
base.RunTestCase(tc)
@@ -36,16 +35,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
3635
Method: http.MethodPut,
3736
Path: "/apisix/admin/routes/r1",
3837
Body: `{
39-
"name": "route1",
40-
"uri": "/hello",
41-
"remote_addr": "` + remote_addr + `",
42-
"upstream": {
43-
"type": "roundrobin",
44-
"nodes": {
45-
"` + base.UpstreamIp + `:1980": 1
46-
}
47-
}
48-
}`,
38+
"name": "route1",
39+
"uri": "/hello",
40+
"remote_addr": "172.16.238.1",
41+
"upstream": {
42+
"type": "roundrobin",
43+
"nodes": {
44+
"` + base.UpstreamIp + `:1980": 1
45+
}
46+
}
47+
}`,
4948
Headers: map[string]string{"Authorization": base.GetToken()},
5049
ExpectStatus: http.StatusOK,
5150
}),
@@ -63,16 +62,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
6362
Method: http.MethodPut,
6463
Path: "/apisix/admin/routes/r1",
6564
Body: `{
66-
"name": "route1",
67-
"uri": "/hello",
68-
"remote_addr": "` + remote_addr + `/24",
69-
"upstream": {
70-
"type": "roundrobin",
71-
"nodes": {
72-
"` + base.UpstreamIp + `:1980": 1
73-
}
74-
}
75-
}`,
65+
"name": "route1",
66+
"uri": "/hello",
67+
"remote_addr": "172.16.238.1/24",
68+
"upstream": {
69+
"type": "roundrobin",
70+
"nodes": {
71+
"` + base.UpstreamIp + `:1980": 1
72+
}
73+
}
74+
}`,
7675
Headers: map[string]string{"Authorization": base.GetToken()},
7776
ExpectStatus: http.StatusOK,
7877
}),
@@ -90,16 +89,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
9089
Method: http.MethodPut,
9190
Path: "/apisix/admin/routes/r1",
9291
Body: `{
93-
"name": "route1",
94-
"uri": "/hello",
95-
"remote_addrs": ["` + remote_addr + `","192.168.0.2/24"],
96-
"upstream": {
97-
"type": "roundrobin",
98-
"nodes": {
99-
"` + base.UpstreamIp + `:1980": 1
100-
}
101-
}
102-
}`,
92+
"name": "route1",
93+
"uri": "/hello",
94+
"remote_addrs": ["172.16.238.1","192.168.0.2/24"],
95+
"upstream": {
96+
"type": "roundrobin",
97+
"nodes": {
98+
"` + base.UpstreamIp + `:1980": 1
99+
}
100+
}
101+
}`,
103102
Headers: map[string]string{"Authorization": base.GetToken()},
104103
ExpectStatus: http.StatusOK,
105104
}),
@@ -117,16 +116,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
117116
Method: http.MethodPut,
118117
Path: "/apisix/admin/routes/r1",
119118
Body: `{
120-
"name": "route1",
121-
"uri": "/hello",
122-
"remote_addr": "10.10.10.10",
123-
"upstream": {
124-
"type": "roundrobin",
125-
"nodes": {
126-
"` + base.UpstreamIp + `:1980": 1
127-
}
128-
}
129-
}`,
119+
"name": "route1",
120+
"uri": "/hello",
121+
"remote_addr": "10.10.10.10",
122+
"upstream": {
123+
"type": "roundrobin",
124+
"nodes": {
125+
"` + base.UpstreamIp + `:1980": 1
126+
}
127+
}
128+
}`,
130129
Headers: map[string]string{"Authorization": base.GetToken()},
131130
ExpectStatus: http.StatusOK,
132131
}),
@@ -144,16 +143,16 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
144143
Method: http.MethodPut,
145144
Path: "/apisix/admin/routes/r1",
146145
Body: `{
147-
"name": "route1",
148-
"uri": "/hello",
149-
"remote_addrs": ["10.10.10.10","11.11.11.1/24"],
150-
"upstream": {
151-
"type": "roundrobin",
152-
"nodes": {
153-
"` + base.UpstreamIp + `:1980": 1
154-
}
155-
}
156-
}`,
146+
"name": "route1",
147+
"uri": "/hello",
148+
"remote_addrs": ["10.10.10.10","11.11.11.1/24"],
149+
"upstream": {
150+
"type": "roundrobin",
151+
"nodes": {
152+
"` + base.UpstreamIp + `:1980": 1
153+
}
154+
}
155+
}`,
157156
Headers: map[string]string{"Authorization": base.GetToken()},
158157
ExpectStatus: http.StatusOK,
159158
}),
@@ -185,3 +184,98 @@ var _ = ginkgo.Describe("route with valid remote_addr remote_addrs", func() {
185184
}),
186185
)
187186
})
187+
188+
var _ = ginkgo.Describe("route with invalid remote_addr", func() {
189+
table.DescribeTable("route with remote_addr",
190+
func(tc base.HttpTestCase) {
191+
base.RunTestCase(tc)
192+
},
193+
table.Entry("config route with invalid remote_addr", base.HttpTestCase{
194+
Object: base.ManagerApiExpect(),
195+
Method: http.MethodPut,
196+
Path: "/apisix/admin/routes/r1",
197+
Body: `{
198+
"name": "route1",
199+
"uri": "/hello",
200+
"remote_addr": "127.0.0.",
201+
"upstream": {
202+
"type": "roundrobin",
203+
"nodes": [{
204+
"host": "` + base.UpstreamIp + `",
205+
"port": 1980,
206+
"weight": 1
207+
}]
208+
}
209+
}`,
210+
Headers: map[string]string{"Authorization": base.GetToken()},
211+
ExpectStatus: http.StatusBadRequest,
212+
ExpectBody: "{\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match format 'ipv4'\"}",
213+
}),
214+
table.Entry("verify route", base.HttpTestCase{
215+
Object: base.APISIXExpect(),
216+
Method: http.MethodGet,
217+
Path: "/hello",
218+
Headers: map[string]string{"Authorization": base.GetToken()},
219+
ExpectStatus: http.StatusNotFound,
220+
Sleep: base.SleepTime,
221+
}),
222+
table.Entry("config route with invalid remote_addr", base.HttpTestCase{
223+
Object: base.ManagerApiExpect(),
224+
Method: http.MethodPut,
225+
Path: "/apisix/admin/routes/r1",
226+
Body: `{
227+
"name": "route1",
228+
"uri": "/hello",
229+
"remote_addr": "127.0.0.aa",
230+
"upstream": {
231+
"type": "roundrobin",
232+
"nodes": [{
233+
"host": "` + base.UpstreamIp + `",
234+
"port": 1980,
235+
"weight": 1
236+
}]
237+
}
238+
}`,
239+
Headers: map[string]string{"Authorization": base.GetToken()},
240+
ExpectStatus: http.StatusBadRequest,
241+
ExpectBody: "{\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match format 'ipv4'\"}",
242+
}),
243+
table.Entry("verify route", base.HttpTestCase{
244+
Object: base.APISIXExpect(),
245+
Method: http.MethodGet,
246+
Path: "/hello",
247+
Headers: map[string]string{"Authorization": base.GetToken()},
248+
ExpectStatus: http.StatusNotFound,
249+
Sleep: base.SleepTime,
250+
}),
251+
table.Entry("config route with invalid remote_addrs", base.HttpTestCase{
252+
Object: base.ManagerApiExpect(),
253+
Method: http.MethodPut,
254+
Path: "/apisix/admin/routes/r1",
255+
Body: `{
256+
"name": "route1",
257+
"uri": "/hello",
258+
"remote_addrs": ["127.0.0.1","192.168.0."],
259+
"upstream": {
260+
"type": "roundrobin",
261+
"nodes": [{
262+
"host": "` + base.UpstreamIp + `",
263+
"port": 1980,
264+
"weight": 1
265+
}]
266+
}
267+
}`,
268+
Headers: map[string]string{"Authorization": base.GetToken()},
269+
ExpectStatus: http.StatusBadRequest,
270+
ExpectBody: "{\"code\":10000,\"message\":\"schema validate failed: remote_addrs.1: Must validate at least one schema (anyOf)\\nremote_addrs.1: Does not match format 'ipv4'\"}",
271+
}),
272+
table.Entry("verify route", base.HttpTestCase{
273+
Object: base.APISIXExpect(),
274+
Method: http.MethodGet,
275+
Path: "/hello",
276+
Headers: map[string]string{"Authorization": base.GetToken()},
277+
ExpectStatus: http.StatusNotFound,
278+
Sleep: base.SleepTime,
279+
}),
280+
)
281+
})

0 commit comments

Comments
 (0)