This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 5b2be58 test: add cases for wss (#3961)
5b2be58 is described below
commit 5b2be581d88e43b3608f14318f76e52615045d08
Author: 罗泽轩 <[email protected]>
AuthorDate: Mon Apr 5 11:41:25 2021 +0800
test: add cases for wss (#3961)
Signed-off-by: spacewander <[email protected]>
---
t/APISIX.pm | 1 +
t/lib/server.lua | 6 +++
t/node/upstream-websocket.t | 93 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/t/APISIX.pm b/t/APISIX.pm
index a34d349..af23cd1 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -456,6 +456,7 @@ _EOC_
$config .= <<_EOC_;
$ipv6_listen_conf
+ listen 1994 ssl;
ssl_certificate cert/apisix.crt;
ssl_certificate_key cert/apisix.key;
lua_ssl_trusted_certificate cert/apisix.crt;
diff --git a/t/lib/server.lua b/t/lib/server.lua
index 4e96223..f8323ee 100644
--- a/t/lib/server.lua
+++ b/t/lib/server.lua
@@ -316,6 +316,12 @@ function _M.websocket_handshake()
ngx.log(ngx.ERR, "failed to new websocket: ", err)
return ngx.exit(400)
end
+
+ local bytes, err = wb:send_text("hello")
+ if not bytes then
+ ngx.log(ngx.ERR, "failed to send text: ", err)
+ return ngx.exit(444)
+ end
end
_M.websocket_handshake_route = _M.websocket_handshake
diff --git a/t/node/upstream-websocket.t b/t/node/upstream-websocket.t
index c3b69ed..8fb51ed 100644
--- a/t/node/upstream-websocket.t
+++ b/t/node/upstream-websocket.t
@@ -79,7 +79,8 @@ Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat
!Content-Type
--- raw_response_headers_like: ^HTTP/1.1 101 Switching Protocols\r\n
---- response_body
+--- response_body_like eval
+qr/hello/
--- no_error_log
[error]
--- error_code: 101
@@ -165,7 +166,8 @@ Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat
!Content-Type
--- raw_response_headers_like: ^HTTP/1.1 101 Switching Protocols\r\n
---- response_body
+--- response_body_like eval
+qr/hello/
--- no_error_log
[error]
--- error_code: 101
@@ -218,3 +220,90 @@ Origin: http://example.com\r
--- grep_error_log eval
qr/failed to new websocket: bad "upgrade" request header: nil/
--- grep_error_log_out
+
+
+
+=== TEST 8: set wss
+--- FIRST
+--- config
+ location /t {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local t = require("lib.test_admin")
+ local code, body = t.test('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "upstream": {
+ "scheme": "https",
+ "nodes": {
+ "127.0.0.1:1983": 1
+ },
+ "type": "roundrobin"
+ },
+ "enable_websocket": true,
+ "uri": "/websocket_handshake"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ local ssl_cert = t.read_file("t/certs/apisix.crt")
+ local ssl_key = t.read_file("t/certs/apisix.key")
+ local data = {cert = ssl_cert, key = ssl_key, sni = "127.0.0.1"}
+
+ local code, body = t.test('/apisix/admin/ssl/1',
+ ngx.HTTP_PUT,
+ core.json.encode(data)
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 9: send websocket
+--- config
+ location /t {
+ content_by_lua_block {
+ local client = require "resty.websocket.client"
+ local wb = client:new()
+ local uri = "wss://127.0.0.1:1994/websocket_handshake"
+ local ok, err = wb:connect(uri)
+ if not ok then
+ ngx.say("failed to connect: " .. err)
+ return
+ end
+
+ local typ
+ data, typ, err = wb:recv_frame()
+ if not data then
+ ngx.say("failed to receive 2nd frame: ", err)
+ return
+ end
+
+ ngx.say("received: ", data, " (", typ, ")")
+ }
+ }
+--- request
+GET /t
+--- no_error_log
+[error]
+--- response_body
+received: hello (text)