Skip to content

Commit

Permalink
Merge branch 'master' into e2e-test-upstream3
Browse files Browse the repository at this point in the history
  • Loading branch information
idbeta committed Dec 2, 2020
2 parents cba999d + 95f2612 commit e5db44e
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
export GO111MOUDULE=on
export APISIX_CONF_PATH=$PWD/conf
sed -i 's/8080/8088/' conf/conf.yaml
sed -i 's/9000/8088/' conf/conf.yaml
go build -o ./manager-api
./manager-api > ./api.log 2>&1 &
sleep 2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-with-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- name: Build Docker Image
run: |
docker build -t dashboard:ci .
docker build -t dashboard:ci . --build-arg APISIX_DASHBOARD_VERSION=master
- name: Modify ETCD IP
run: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ COPY --from=fe-builder /usr/local/apisix-dashboard/output/ ./

RUN mkdir logs

EXPOSE 8080
EXPOSE 9000

CMD [ "/usr/local/apisix-dashboard/manager-api" ]
2 changes: 1 addition & 1 deletion api/conf/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
conf:
listen:
host: 127.0.0.1 # `manager api` listening ip or host name
port: 8080 # `manager api` listening port
port: 9000 # `manager api` listening port
etcd:
endpoints: # supports defining multiple etcd host addresses for an etcd cluster
- 127.0.0.1:2379
Expand Down
3 changes: 2 additions & 1 deletion api/internal/core/entity/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ func NodesFormat(obj interface{}) interface{} {
return nodes
case []*Node:
log.Infof("nodes type: %v", objType)
return nodes
return obj
case []interface{}:
log.Infof("nodes type []interface{}: %v", objType)
list := obj.([]interface{})
for _, v := range list {
val := v.(map[string]interface{})
Expand Down
21 changes: 21 additions & 0 deletions api/internal/core/entity/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ func TestNodesFormat(t *testing.T) {
assert.Contains(t, jsonStr, `"host":"127.0.0.1"`)
}

func TestNodesFormat_struct(t *testing.T) {
// route data saved in ETCD
var route Route
route.Uris = []string{"/*"}
route.Upstream = &UpstreamDef{}
route.Upstream.Type = "roundrobin"
var nodes = []*Node{{Host: "127.0.0.1", Port: 80, Weight: 0}}
route.Upstream.Nodes = nodes

// nodes format
formattedNodes := NodesFormat(route.Upstream.Nodes)

// json encode for client
res, err := json.Marshal(formattedNodes)
assert.Nil(t, err)
jsonStr := string(res)
assert.Contains(t, jsonStr, `"weight":0`)
assert.Contains(t, jsonStr, `"port":80`)
assert.Contains(t, jsonStr, `"host":"127.0.0.1"`)
}

func TestNodesFormat_Map(t *testing.T) {
// route data saved in ETCD
routeStr := `{
Expand Down
2 changes: 1 addition & 1 deletion api/test/docker-deploy/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
depends_on:
- etcd
ports:
- '8080:8080/tcp'
- '9000:9000/tcp'
networks:
apisix_dashboard_e2e:
ipv4_address: 172.16.238.40
Expand Down
2 changes: 1 addition & 1 deletion api/test/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ COPY --from=build-env /usr/share/zoneinfo/Hongkong /etc/localtime

RUN mkdir logs

EXPOSE 8080
EXPOSE 9000

RUN chmod +x ./entry.sh

Expand Down
6 changes: 3 additions & 3 deletions api/test/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ services:
context: ../../
dockerfile: test/docker/Dockerfile-apisix
args:
- APISIX_VERSION=master
- APISIX_VERSION=2.1
restart: always
volumes:
- ./apisix_config.yaml:/usr/local/apisix/conf/config.yaml:ro
Expand All @@ -153,7 +153,7 @@ services:
context: ../../
dockerfile: test/docker/Dockerfile-apisix
args:
- APISIX_VERSION=master
- APISIX_VERSION=2.1
restart: always
volumes:
- ./apisix_config.yaml:/usr/local/apisix/conf/config.yaml:ro
Expand Down Expand Up @@ -181,7 +181,7 @@ services:
- node2
- node3
ports:
- '8080:8080/tcp'
- '9000:9000/tcp'
networks:
apisix_dashboard_e2e:
ipv4_address: 172.16.238.40
Expand Down
2 changes: 1 addition & 1 deletion api/test/docker/manager-api-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
conf:
listen:
host: 0.0.0.0 # `manager api` listening ip or host name. It's for e2e test, so it is set to 0.0.0.0
port: 8080 # `manager api` listening port
port: 9000 # `manager api` listening port
etcd:
endpoints: # supports defining multiple etcd host addresses for an etcd cluster
- 172.16.238.10:2379 # ips here are defined in docker compose.
Expand Down
6 changes: 4 additions & 2 deletions api/test/e2e/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
"password": "admin"
}`)

url := "http://127.0.0.1:8080/apisix/admin/user/login"
url := "http://127.0.0.1:9000/apisix/admin/user/login"
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(requestBody))
if err != nil {
panic(err)
Expand Down Expand Up @@ -84,7 +84,7 @@ func httpGet(url string) ([]byte, int, error) {
}

func ManagerApiExpect(t *testing.T) *httpexpect.Expect {
return httpexpect.New(t, "http://127.0.0.1:8080")
return httpexpect.New(t, "http://127.0.0.1:9000")
}

func APISIXExpect(t *testing.T) *httpexpect.Expect {
Expand Down Expand Up @@ -149,6 +149,8 @@ func testCaseCheck(tc HttpTestCase) {
req = expectObj.DELETE(tc.Path)
case http.MethodPatch:
req = expectObj.PATCH(tc.Path)
case http.MethodOptions:
req = expectObj.OPTIONS(tc.Path)
default:
}

Expand Down
121 changes: 121 additions & 0 deletions api/test/e2e/route_remote_addr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* 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_add_with_invalid_remote_addr(t *testing.T) {
tests := []HttpTestCase{
{
caseDesc: "config route with invalid remote_addr",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/routes/r1",
Body: `{
"uri": "/hello",
"remote_addr": "127.0.0.",
"upstream": {
"type": "roundrobin",
"nodes": [{
"host": "172.16.238.20",
"port": 1980,
"weight": 1
}]
}
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusBadRequest,
ExpectBody: "\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match pattern '^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'\"",
},
{
caseDesc: "verify route",
Object: APISIXExpect(t),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusNotFound,
Sleep: sleepTime,
},
{
caseDesc: "config route with invalid remote_addr",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/routes/r1",
Body: `{
"uri": "/hello",
"remote_addr": "127.0.0.aa",
"upstream": {
"type": "roundrobin",
"nodes": [{
"host": "172.16.238.20",
"port": 1980,
"weight": 1
}]
}
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusBadRequest,
ExpectBody: "\"code\":10000,\"message\":\"schema validate failed: remote_addr: Must validate at least one schema (anyOf)\\nremote_addr: Does not match pattern '^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'\"",
},
{
caseDesc: "verify route",
Object: APISIXExpect(t),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusNotFound,
Sleep: sleepTime,
},
{
caseDesc: "config route with invalid remote_addrs",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/routes/r1",
Body: `{
"uri": "/hello",
"remote_addrs": ["127.0.0.1","192.168.0."],
"upstream": {
"type": "roundrobin",
"nodes": [{
"host": "172.16.238.20",
"port": 1980,
"weight": 1
}]
}
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusBadRequest,
ExpectBody: "\"code\":10000,\"message\":\"schema validate failed: remote_addrs.1: Must validate at least one schema (anyOf)\\nremote_addrs.1: Does not match pattern '^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'\"",
},
{
caseDesc: "verify route",
Object: APISIXExpect(t),
Method: http.MethodGet,
Path: "/hello",
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusNotFound,
Sleep: sleepTime,
},
}

for _, tc := range tests {
testCaseCheck(tc)
}
}
Loading

0 comments on commit e5db44e

Please sign in to comment.