fix(jwt): restore legacy emqx_auth_jwt hook interface

This commit is contained in:
Ilya Averyanov 2022-10-12 14:53:45 +03:00
parent 18db788662
commit 53bc2d9d58
4 changed files with 28 additions and 2 deletions

View File

@ -16,6 +16,7 @@ File format:
- Fix that after receiving publish in `idle mode` the emqx-sn gateway may panic. [#9024](https://github.com/emqx/emqx/pull/9024)
- "Pause due to rate limit" log level demoted from warning to notice [#9134](https://github.com/emqx/emqx/pull/9134)
- Restore legacy `emqx_auth_jwt` interface to keep hooks working after relup. [##9144](https://github.com/emqx/emqx/pull/9144)
## v4.3.21

View File

@ -1,7 +1,9 @@
%% -*- mode: erlang -*-
%% Unless you know what you are doing, DO NOT edit manually!!
{VSN,
[{"4.3.6",[{load_module,emqx_auth_jwt_svr,brutal_purge,soft_purge,[]}]},
[{"4.3.6",
[{load_module,emqx_auth_jwt,brutal_purge,soft_purge,[]},
{load_module,emqx_auth_jwt_svr,brutal_purge,soft_purge,[]}]},
{"4.3.5",
[{load_module,emqx_auth_jwt,brutal_purge,soft_purge,[]},
{load_module,emqx_auth_jwt_svr,brutal_purge,soft_purge,[]}]},
@ -13,7 +15,9 @@
{load_module,emqx_auth_jwt_svr,brutal_purge,soft_purge,[]}]},
{<<"4\\.3\\.[0-2]">>,[{restart_application,emqx_auth_jwt}]},
{<<".*">>,[]}],
[{"4.3.6",[{load_module,emqx_auth_jwt_svr,brutal_purge,soft_purge,[]}]},
[ {"4.3.6",
[{load_module,emqx_auth_jwt,brutal_purge,soft_purge,[]},
{load_module,emqx_auth_jwt_svr,brutal_purge,soft_purge,[]}]},
{"4.3.5",
[{load_module,emqx_auth_jwt,brutal_purge,soft_purge,[]},
{load_module,emqx_auth_jwt_svr,brutal_purge,soft_purge,[]}]},

View File

@ -23,6 +23,7 @@
-logger_header("[JWT]").
-export([ check_auth/3
, check/3
, check_acl/5
, description/0
]).
@ -33,6 +34,10 @@
%% Authentication callbacks
%%--------------------------------------------------------------------
%% for compatibility with old versions
check(ClientInfo, AuthResult, State) ->
?MODULE:check_auth(ClientInfo, AuthResult, State).
check_auth(ClientInfo, AuthResult, #{from := From, checklists := Checklists}) ->
case maps:find(From, ClientInfo) of
error ->

View File

@ -472,3 +472,19 @@ t_check_jwt_acl_no_exp(_Config) ->
emqtt:subscribe(C, <<"a/b">>, 0)),
ok = emqtt:disconnect(C).
t_check_compatibility(init, _Config) -> ok.
t_check_compatibility(_Config) ->
%% We literary want emqx_auth_jwt:check call emqx_auth_jwt:check_auth, so check with meck
ok = meck:new(emqx_auth_jwt, [passthrough, no_history]),
ok = meck:expect(emqx_auth_jwt, check_auth, fun(a, b, c) -> ok end),
?assertEqual(
ok,
emqx_auth_jwt:check(a, b, c)
),
meck:validate(emqx_auth_jwt),
meck:unload(emqx_auth_jwt).