fix(mnesia authz): destroy authz records on mnesia authz destroy

This commit is contained in:
Ilya Averyanov 2023-10-13 18:12:46 +03:00
parent 7a6c756b7c
commit bde8800f2e
3 changed files with 33 additions and 1 deletions

View File

@ -95,7 +95,9 @@ create(Source) -> Source.
update(Source) -> Source. update(Source) -> Source.
destroy(_Source) -> ok. destroy(_Source) ->
{atomic, ok} = mria:clear_table(?ACL_TABLE),
ok.
authorize( authorize(
#{ #{

View File

@ -221,6 +221,35 @@ t_normalize_rules(_Config) ->
) )
). ).
t_destroy(_Config) ->
ClientInfo = emqx_authz_test_lib:base_client_info(),
ok = emqx_authz_mnesia:store_rules(
{username, <<"username">>},
[#{<<"permission">> => <<"allow">>, <<"action">> => <<"publish">>, <<"topic">> => <<"t">>}]
),
?assertEqual(
allow,
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH, <<"t">>)
),
ok = emqx_authz_test_lib:reset_authorizers(),
?assertEqual(
deny,
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH, <<"t">>)
),
ok = setup_config(),
%% After destroy, the rules should be empty
?assertEqual(
deny,
emqx_access_control:authorize(ClientInfo, ?AUTHZ_PUBLISH, <<"t">>)
).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Helpers %% Helpers
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------

View File

@ -0,0 +1 @@
Fixed destruction of built_in_database authorization source. Now all the ACL records are removed when the authorization source is destroyed. Previosly, old records were left in the database, which could cause problems when creating authorization source back.