From fddb28a4b08f5da5462240138626fdc43b45a22c Mon Sep 17 00:00:00 2001 From: Ilya Averyanov Date: Fri, 10 Dec 2021 17:12:04 +0300 Subject: [PATCH] fix(wss): update cowboy & ranch for OTP24 compatibility --- apps/emqx/rebar.config | 2 +- apps/emqx/test/emqx_listeners_SUITE.erl | 46 +++++++++++++++++++------ rebar.config | 2 +- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/apps/emqx/rebar.config b/apps/emqx/rebar.config index f8c6c23ce..330291def 100644 --- a/apps/emqx/rebar.config +++ b/apps/emqx/rebar.config @@ -13,7 +13,7 @@ , {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.8.0"}}} , {typerefl, {git, "https://github.com/k32/typerefl", {tag, "0.8.5"}}} , {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}} - , {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.8.3"}}} + , {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.0"}}} , {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.0"}}} , {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.11.1"}}} , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.5.1"}}} diff --git a/apps/emqx/test/emqx_listeners_SUITE.erl b/apps/emqx/test/emqx_listeners_SUITE.erl index 0733bad53..a9ee0d7d9 100644 --- a/apps/emqx/test/emqx_listeners_SUITE.erl +++ b/apps/emqx/test/emqx_listeners_SUITE.erl @@ -24,6 +24,8 @@ -include_lib("eunit/include/eunit.hrl"). -include_lib("common_test/include/ct.hrl"). +-define(CERTS_PATH(CertName), filename:join(["../../lib/emqx/etc/certs/", CertName])). + all() -> emqx_common_test_helpers:all(?MODULE). init_per_suite(Config) -> @@ -43,20 +45,34 @@ init_per_testcase(Case, Config) {ok, _} = emqx_config_handler:start_link(), PrevListeners = emqx_config:get([listeners, tcp], #{}), PrevRateLimit = emqx_config:get([rate_limit], #{}), - emqx_config:put([listeners, tcp], #{ listener_test => - #{ bind => {"127.0.0.1", 9999} - , max_connections => 4321 - , limiter => #{} - } - }), + emqx_config:put( + [listeners, tcp], + #{listener_test => #{bind => {"127.0.0.1", 9999}, + max_connections => 4321, + limiter => #{} + } + }), emqx_config:put([rate_limit], #{max_conn_rate => 1000}), - ListenerConf = #{ bind => {"127.0.0.1", 9999} - }, ok = emqx_listeners:start(), - [ {listener_conf, ListenerConf} - , {prev_listener_conf, PrevListeners} + [ {prev_listener_conf, PrevListeners} , {prev_rate_limit_conf, PrevRateLimit} | Config]; +init_per_testcase(t_wss_conn, Config) -> + {ok, _} = emqx_config_handler:start_link(), + PrevListeners = emqx_config:get([listeners, wss], #{}), + emqx_config:put( + [listeners, wss], + #{listener_test => #{bind => {{127,0,0,1}, 9998}, + limiter => #{}, + ssl => #{cacertfile => ?CERTS_PATH("cacert.pem"), + certfile => ?CERTS_PATH("cert.pem"), + keyfile => ?CERTS_PATH("key.pem") + } + } + }), + ok = emqx_listeners:start(), + [ {prev_listener_conf, PrevListeners} + | Config]; init_per_testcase(_, Config) -> {ok, _} = emqx_config_handler:start_link(), Config. @@ -70,6 +86,12 @@ end_per_testcase(Case, Config) emqx_listeners:stop(), _ = emqx_config_handler:stop(), ok; +end_per_testcase(t_wss_conn, Config) -> + PrevListener = ?config(prev_listener_conf, Config), + emqx_config:put([listeners, wss], PrevListener), + emqx_listeners:stop(), + _ = emqx_config_handler:stop(), + ok; end_per_testcase(_, _Config) -> _ = emqx_config_handler:stop(), ok. @@ -93,6 +115,10 @@ t_max_conns_tcp(_) -> t_current_conns_tcp(_) -> ?assertEqual(0, emqx_listeners:current_conns('tcp:listener_test', {{127,0,0,1}, 9999})). +t_wss_conn(_) -> + {ok, Socket} = ssl:connect({127, 0, 0, 1}, 9998, [{verify, verify_none}], 1000), + ok = ssl:close(Socket). + render_config_file() -> Path = local_path(["etc", "emqx.conf"]), {ok, Temp} = file:read_file(Path), diff --git a/rebar.config b/rebar.config index 9d923da9d..1604c7696 100644 --- a/rebar.config +++ b/rebar.config @@ -50,7 +50,7 @@ , {ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.1.12"}}} , {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.8.0"}}} , {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}} - , {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.8.3"}}} + , {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.0"}}} , {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.0"}}} , {mria, {git, "https://github.com/emqx/mria", {tag, "0.1.4"}}} , {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.11.1"}}}