Merge pull request #12937 from kjellwinblad/kjell/add_use_legacy_protocol_option_to_mongodb_auth/EMQX-12245

test(mongodb authn, authz): add test cases for use_legacy_protocol
This commit is contained in:
Kjell Winblad 2024-05-16 10:10:17 +02:00 committed by GitHub
commit cf5b464777
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 7 deletions

View File

@ -285,11 +285,12 @@ raw_mongo_auth_config() ->
<<"filter">> => #{<<"username">> => <<"${username}">>},
<<"password_hash_field">> => <<"password_hash">>,
<<"salt_field">> => <<"salt">>,
<<"is_superuser_field">> => <<"is_superuser">>
<<"is_superuser_field">> => <<"is_superuser">>,
<<"use_legacy_protocol">> => <<"auto">>
}.
user_seeds() ->
[
PlainSeed =
#{
data => #{
username => <<"plain">>,
@ -304,7 +305,10 @@ user_seeds() ->
config_params => #{},
result => {ok, #{is_superuser => true}}
},
[
PlainSeed#{config_params => #{<<"use_legacy_protocol">> => <<"auto">>}},
PlainSeed#{config_params => #{<<"use_legacy_protocol">> => <<"true">>}},
PlainSeed#{config_params => #{<<"use_legacy_protocol">> => <<"false">>}},
#{
data => #{
username => <<"md5">>,

View File

@ -75,9 +75,14 @@ end_per_testcase(_TestCase, _Config) ->
%%------------------------------------------------------------------------------
t_run_case(Config) ->
run_case(Config, true),
run_case(Config, false),
run_case(Config, auto).
run_case(Config, UseLegacyProtocol) ->
Case = ?config(test_case, Config),
ok = setup_source_data(Case),
ok = setup_authz_source(Case),
ok = setup_authz_source(Case#{use_legacy_protocol => UseLegacyProtocol}),
ok = emqx_authz_test_lib:run_checks(Case).
%%------------------------------------------------------------------------------
@ -374,10 +379,11 @@ setup_source_data(#{records := Records}) ->
{{true, _}, _} = mc_worker_api:insert(?MONGO_CLIENT, <<"acl">>, Records),
ok.
setup_authz_source(#{filter := Filter}) ->
setup_authz_source(#{filter := Filter, use_legacy_protocol := UseLegacyProtocol}) ->
setup_config(
#{
<<"filter">> => Filter
<<"filter">> => Filter,
<<"use_legacy_protocol">> => UseLegacyProtocol
}
).
@ -401,7 +407,8 @@ raw_mongo_authz_config() ->
<<"username">> => mongo_username(),
<<"password">> => mongo_password(),
<<"filter">> => #{<<"username">> => <<"${username}">>}
<<"filter">> => #{<<"username">> => <<"${username}">>},
<<"use_legacy_protocol">> => <<"auto">>
}.
mongo_server() ->