Explorar el Código

Merge pull request #6424 from savonarola/ranch-compat

[5.0] fix(wss): update cowboy & ranch for OTP24 compatibility
Ilya Averyanov hace 4 años
padre
commit
426a9908e3
Se han modificado 3 ficheros con 38 adiciones y 12 borrados
  1. 1 1
      apps/emqx/rebar.config
  2. 36 10
      apps/emqx/test/emqx_listeners_SUITE.erl
  3. 1 1
      rebar.config

+ 1 - 1
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"}}}

+ 36 - 10
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),

+ 1 - 1
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"}}}