You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/02/24 11:32:41 UTC

[incubator-apisix] branch master updated: bugfix: compare server_port with number data type. (#1154)

This is an automated email from the ASF dual-hosted git repository.

membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 188b184  bugfix: compare server_port with number data type. (#1154)
188b184 is described below

commit 188b1849b211362e563cf5203680f5bcb1c7aabc
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Mon Feb 24 19:32:32 2020 +0800

    bugfix: compare server_port with number data type. (#1154)
---
 lua/apisix/stream/router/ip_port.lua |  5 ++--
 t/stream-node/sanity.t               | 34 +++++++++++++++++++++++
 t/stream-plugin/mqtt-proxy.t         | 54 +++++++++++++++++++++++++++++++++++-
 3 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/lua/apisix/stream/router/ip_port.lua b/lua/apisix/stream/router/ip_port.lua
index 1a68eed..23f020d 100644
--- a/lua/apisix/stream/router/ip_port.lua
+++ b/lua/apisix/stream/router/ip_port.lua
@@ -18,6 +18,7 @@ local core      = require("apisix.core")
 local ipairs    = ipairs
 local error     = error
 local ngx_exit  = ngx.exit
+local tonumber  = tonumber
 local user_routes
 
 
@@ -40,7 +41,7 @@ local function match_opts(route, api_ctx)
 
     -- todo: use resty-ipmatcher to support multiple ip address
     if route.value.server_port and
-       route.value.server_port ~= vars.server_port then
+       route.value.server_port ~= tonumber(vars.server_port) then
         return false
     end
 
@@ -52,7 +53,7 @@ function _M.match(api_ctx)
     local routes = _M.routes()
     if not routes then
         core.log.info("not find any user stream route")
-        return ngx_exit(1)
+        return ngx_exit(200)
     end
     core.log.info("stream routes: ", core.json.delay_encode(routes))
 
diff --git a/t/stream-node/sanity.t b/t/stream-node/sanity.t
index b4a4b6c..7eaf06e 100644
--- a/t/stream-node/sanity.t
+++ b/t/stream-node/sanity.t
@@ -129,3 +129,37 @@ GET /t
 passed
 --- no_error_log
 [error]
+
+
+
+=== TEST 6: set stream route(id: 1)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/stream_routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "remote_addr": "127.0.0.1",
+                    "server_port": 1995,
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1995": 1
+                        },
+                        "type": "roundrobin"
+                    }
+                }]]
+            )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
diff --git a/t/stream-plugin/mqtt-proxy.t b/t/stream-plugin/mqtt-proxy.t
index 8dc347f..7556fcd 100644
--- a/t/stream-plugin/mqtt-proxy.t
+++ b/t/stream-plugin/mqtt-proxy.t
@@ -29,7 +29,7 @@ run_tests;
 
 __DATA__
 
-=== TEST 1: set route(id: 1)
+=== TEST 1: set route
 --- config
     location /t {
         content_by_lua_block {
@@ -38,6 +38,7 @@ __DATA__
                 ngx.HTTP_PUT,
                 [[{
                     "remote_addr": "127.0.0.1",
+                    "server_port": 1985,
                     "plugins": {
                         "mqtt-proxy": {
                             "protocol_name": "MQTT",
@@ -83,3 +84,54 @@ Received unexpected MQTT packet type+flags
 hello world
 --- no_error_log
 [error]
+
+
+
+=== TEST 4: set route (wrong server port)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/stream_routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "remote_addr": "127.0.0.1",
+                    "server_port": 2000,
+                    "plugins": {
+                        "mqtt-proxy": {
+                            "protocol_name": "MQTT",
+                            "protocol_level": 4,
+                            "upstream": {
+                                "ip": "127.0.0.1",
+                                "port": 1995
+                            }
+                        }
+                    }
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 5: failed to match route
+--- stream_enable
+--- stream_request eval
+"\x10\x0f"
+--- stream_response
+receive stream response error: connection reset by peer
+--- error_log
+receive stream response error: connection reset by peer
+--- error_log
+match(): not hit any route