|
|
@@ -348,6 +348,55 @@ t_stop_timeout(_) ->
|
|
|
snabbkaffe:stop(),
|
|
|
meck:unload(emqx_exhook_demo_svr).
|
|
|
|
|
|
+t_ssl_clear(_) ->
|
|
|
+ SvrName = <<"ssl_test">>,
|
|
|
+ SSLConf = #{
|
|
|
+ <<"cacertfile">> => cert_file("cafile"),
|
|
|
+
|
|
|
+ <<"certfile">> => cert_file("certfile"),
|
|
|
+
|
|
|
+ <<"enable">> => true,
|
|
|
+ <<"keyfile">> => cert_file("keyfile"),
|
|
|
+
|
|
|
+ <<"verify">> => <<"verify_peer">>
|
|
|
+ },
|
|
|
+ AddConf = #{
|
|
|
+ <<"auto_reconnect">> => <<"60s">>,
|
|
|
+ <<"enable">> => false,
|
|
|
+ <<"failed_action">> => <<"deny">>,
|
|
|
+ <<"name">> => <<"ssl_test">>,
|
|
|
+ <<"pool_size">> => 16,
|
|
|
+ <<"request_timeout">> => <<"5s">>,
|
|
|
+ <<"ssl">> => SSLConf,
|
|
|
+
|
|
|
+ <<"url">> => <<"http://127.0.0.1:9000">>
|
|
|
+ },
|
|
|
+ emqx_exhook_mgr:update_config([exhook, servers], {add, AddConf}),
|
|
|
+ ListResult1 = list_pem_dir(SvrName),
|
|
|
+ ?assertMatch({ok, [_, _, _]}, ListResult1),
|
|
|
+ {ok, ResultList1} = ListResult1,
|
|
|
+
|
|
|
+ UpdateConf = AddConf#{<<"ssl">> => SSLConf#{<<"keyfile">> => cert_file("keyfile2")}},
|
|
|
+ emqx_exhook_mgr:update_config([exhook, servers], {update, SvrName, UpdateConf}),
|
|
|
+ ListResult2 = list_pem_dir(SvrName),
|
|
|
+ ?assertMatch({ok, [_, _, _]}, ListResult2),
|
|
|
+ {ok, ResultList2} = ListResult2,
|
|
|
+
|
|
|
+ FindKeyFile = fun(List) ->
|
|
|
+ case lists:search(fun(E) -> lists:prefix("key", E) end, List) of
|
|
|
+ {value, Value} ->
|
|
|
+ Value;
|
|
|
+ _ ->
|
|
|
+ ?assert(false, "Can't find keyfile")
|
|
|
+ end
|
|
|
+ end,
|
|
|
+
|
|
|
+ ?assertNotEqual(FindKeyFile(ResultList1), FindKeyFile(ResultList2)),
|
|
|
+
|
|
|
+ emqx_exhook_mgr:update_config([exhook, servers], {delete, SvrName}),
|
|
|
+ ?assertMatch({error, not_dir}, list_pem_dir(SvrName)),
|
|
|
+ ok.
|
|
|
+
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% Cases Helpers
|
|
|
%%--------------------------------------------------------------------
|
|
|
@@ -414,3 +463,20 @@ loaded_exhook_hookpoints() ->
|
|
|
is_exhook_callback(Cb) ->
|
|
|
Action = element(2, Cb),
|
|
|
emqx_exhook_handler == element(1, Action).
|
|
|
+
|
|
|
+list_pem_dir(Name) ->
|
|
|
+ Dir = filename:join([emqx:mutable_certs_dir(), "exhook", Name]),
|
|
|
+ case filelib:is_dir(Dir) of
|
|
|
+ true ->
|
|
|
+ file:list_dir(Dir);
|
|
|
+ _ ->
|
|
|
+ {error, not_dir}
|
|
|
+ end.
|
|
|
+
|
|
|
+data_file(Name) ->
|
|
|
+ Dir = code:lib_dir(emqx_exhook, test),
|
|
|
+ {ok, Bin} = file:read_file(filename:join([Dir, "data", Name])),
|
|
|
+ Bin.
|
|
|
+
|
|
|
+cert_file(Name) ->
|
|
|
+ data_file(filename:join(["certs", Name])).
|