test: use macro for authentication root name
This commit is contained in:
parent
a1f79850b4
commit
89614245f6
|
@ -44,11 +44,11 @@ groups() ->
|
||||||
|
|
||||||
init_per_testcase(_, Config) ->
|
init_per_testcase(_, Config) ->
|
||||||
emqx_authn_test_lib:delete_authenticators(
|
emqx_authn_test_lib:delete_authenticators(
|
||||||
[authentication],
|
[?CONF_NS_ATOM],
|
||||||
?GLOBAL),
|
?GLOBAL),
|
||||||
|
|
||||||
emqx_authn_test_lib:delete_authenticators(
|
emqx_authn_test_lib:delete_authenticators(
|
||||||
[listeners, tcp, default, authentication],
|
[listeners, tcp, default, ?CONF_NS_ATOM],
|
||||||
?TCP_DEFAULT),
|
?TCP_DEFAULT),
|
||||||
|
|
||||||
{atomic, ok} = mria:clear_table(emqx_authn_mnesia),
|
{atomic, ok} = mria:clear_table(emqx_authn_mnesia),
|
||||||
|
@ -87,8 +87,8 @@ set_special_configs(_App) ->
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
|
||||||
t_invalid_listener(_) ->
|
t_invalid_listener(_) ->
|
||||||
{ok, 404, _} = request(get, uri(["listeners", "invalid", "authentication"])),
|
{ok, 404, _} = request(get, uri(["listeners", "invalid", ?CONF_NS])),
|
||||||
{ok, 404, _} = request(get, uri(["listeners", "in:valid", "authentication"])).
|
{ok, 404, _} = request(get, uri(["listeners", "in:valid", ?CONF_NS])).
|
||||||
|
|
||||||
t_authenticators(_) ->
|
t_authenticators(_) ->
|
||||||
test_authenticators([]).
|
test_authenticators([]).
|
||||||
|
@ -131,86 +131,86 @@ test_authenticators(PathPrefix) ->
|
||||||
ValidConfig = emqx_authn_test_lib:http_example(),
|
ValidConfig = emqx_authn_test_lib:http_example(),
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
ValidConfig),
|
ValidConfig),
|
||||||
|
|
||||||
{ok, 409, _} = request(
|
{ok, 409, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
ValidConfig),
|
ValidConfig),
|
||||||
|
|
||||||
InvalidConfig0 = ValidConfig#{method => <<"delete">>},
|
InvalidConfig0 = ValidConfig#{method => <<"delete">>},
|
||||||
{ok, 400, _} = request(
|
{ok, 400, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
InvalidConfig0),
|
InvalidConfig0),
|
||||||
|
|
||||||
InvalidConfig1 = ValidConfig#{method => <<"get">>,
|
InvalidConfig1 = ValidConfig#{method => <<"get">>,
|
||||||
headers => #{<<"content-type">> => <<"application/json">>}},
|
headers => #{<<"content-type">> => <<"application/json">>}},
|
||||||
{ok, 400, _} = request(
|
{ok, 400, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
InvalidConfig1),
|
InvalidConfig1),
|
||||||
|
|
||||||
?assertAuthenticatorsMatch(
|
?assertAuthenticatorsMatch(
|
||||||
[#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"http">>}],
|
[#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"http">>}],
|
||||||
PathPrefix ++ ["authentication"]).
|
PathPrefix ++ [?CONF_NS]).
|
||||||
|
|
||||||
test_authenticator(PathPrefix) ->
|
test_authenticator(PathPrefix) ->
|
||||||
ValidConfig0 = emqx_authn_test_lib:http_example(),
|
ValidConfig0 = emqx_authn_test_lib:http_example(),
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
ValidConfig0),
|
ValidConfig0),
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
get,
|
get,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:http"])),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:http"])),
|
||||||
|
|
||||||
{ok, 404, _} = request(
|
{ok, 404, _} = request(
|
||||||
get,
|
get,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:redis"])),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:redis"])),
|
||||||
|
|
||||||
|
|
||||||
{ok, 404, _} = request(
|
{ok, 404, _} = request(
|
||||||
put,
|
put,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:built-in-database"]),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:built-in-database"]),
|
||||||
emqx_authn_test_lib:built_in_database_example()),
|
emqx_authn_test_lib:built_in_database_example()),
|
||||||
|
|
||||||
InvalidConfig0 = ValidConfig0#{method => <<"delete">>},
|
InvalidConfig0 = ValidConfig0#{method => <<"delete">>},
|
||||||
{ok, 400, _} = request(
|
{ok, 400, _} = request(
|
||||||
put,
|
put,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:http"]),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:http"]),
|
||||||
InvalidConfig0),
|
InvalidConfig0),
|
||||||
|
|
||||||
InvalidConfig1 = ValidConfig0#{method => <<"get">>,
|
InvalidConfig1 = ValidConfig0#{method => <<"get">>,
|
||||||
headers => #{<<"content-type">> => <<"application/json">>}},
|
headers => #{<<"content-type">> => <<"application/json">>}},
|
||||||
{ok, 400, _} = request(
|
{ok, 400, _} = request(
|
||||||
put,
|
put,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:http"]),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:http"]),
|
||||||
InvalidConfig1),
|
InvalidConfig1),
|
||||||
|
|
||||||
ValidConfig1 = ValidConfig0#{pool_size => 9},
|
ValidConfig1 = ValidConfig0#{pool_size => 9},
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
put,
|
put,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:http"]),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:http"]),
|
||||||
ValidConfig1),
|
ValidConfig1),
|
||||||
|
|
||||||
{ok, 404, _} = request(
|
{ok, 404, _} = request(
|
||||||
delete,
|
delete,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:redis"])),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:redis"])),
|
||||||
|
|
||||||
{ok, 204, _} = request(
|
{ok, 204, _} = request(
|
||||||
delete,
|
delete,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:http"])),
|
uri(PathPrefix ++ [?CONF_NS, "password-based:http"])),
|
||||||
|
|
||||||
?assertAuthenticatorsMatch([], PathPrefix ++ ["authentication"]).
|
?assertAuthenticatorsMatch([], PathPrefix ++ [?CONF_NS]).
|
||||||
|
|
||||||
test_authenticator_users(PathPrefix) ->
|
test_authenticator_users(PathPrefix) ->
|
||||||
UsersUri = uri(PathPrefix ++ ["authentication", "password-based:built-in-database", "users"]),
|
UsersUri = uri(PathPrefix ++ [?CONF_NS, "password-based:built-in-database", "users"]),
|
||||||
|
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
emqx_authn_test_lib:built_in_database_example()),
|
emqx_authn_test_lib:built_in_database_example()),
|
||||||
|
|
||||||
InvalidUsers = [
|
InvalidUsers = [
|
||||||
|
@ -261,11 +261,11 @@ test_authenticator_users(PathPrefix) ->
|
||||||
lists:usort([ UserId || #{<<"user_id">> := UserId} <- Page1Users ++ Page2Users])).
|
lists:usort([ UserId || #{<<"user_id">> := UserId} <- Page1Users ++ Page2Users])).
|
||||||
|
|
||||||
test_authenticator_user(PathPrefix) ->
|
test_authenticator_user(PathPrefix) ->
|
||||||
UsersUri = uri(PathPrefix ++ ["authentication", "password-based:built-in-database", "users"]),
|
UsersUri = uri(PathPrefix ++ [?CONF_NS, "password-based:built-in-database", "users"]),
|
||||||
|
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
emqx_authn_test_lib:built_in_database_example()),
|
emqx_authn_test_lib:built_in_database_example()),
|
||||||
|
|
||||||
User = #{user_id => <<"u1">>, password => <<"p1">>},
|
User = #{user_id => <<"u1">>, password => <<"p1">>},
|
||||||
|
@ -309,7 +309,7 @@ test_authenticator_move(PathPrefix) ->
|
||||||
fun(Conf) ->
|
fun(Conf) ->
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
Conf)
|
Conf)
|
||||||
end,
|
end,
|
||||||
AuthenticatorConfs),
|
AuthenticatorConfs),
|
||||||
|
@ -320,40 +320,40 @@ test_authenticator_move(PathPrefix) ->
|
||||||
#{<<"mechanism">> := <<"jwt">>},
|
#{<<"mechanism">> := <<"jwt">>},
|
||||||
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>}
|
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>}
|
||||||
],
|
],
|
||||||
PathPrefix ++ ["authentication"]),
|
PathPrefix ++ [?CONF_NS]),
|
||||||
|
|
||||||
% Invalid moves
|
% Invalid moves
|
||||||
|
|
||||||
{ok, 400, _} = request(
|
{ok, 400, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"up">>}),
|
#{position => <<"up">>}),
|
||||||
|
|
||||||
{ok, 400, _} = request(
|
{ok, 400, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{}),
|
#{}),
|
||||||
|
|
||||||
{ok, 404, _} = request(
|
{ok, 404, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"before:invalid">>}),
|
#{position => <<"before:invalid">>}),
|
||||||
|
|
||||||
{ok, 404, _} = request(
|
{ok, 404, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"before:password-based:redis">>}),
|
#{position => <<"before:password-based:redis">>}),
|
||||||
|
|
||||||
{ok, 404, _} = request(
|
{ok, 404, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"before:password-based:redis">>}),
|
#{position => <<"before:password-based:redis">>}),
|
||||||
|
|
||||||
% Valid moves
|
% Valid moves
|
||||||
|
|
||||||
{ok, 204, _} = request(
|
{ok, 204, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"top">>}),
|
#{position => <<"top">>}),
|
||||||
|
|
||||||
?assertAuthenticatorsMatch(
|
?assertAuthenticatorsMatch(
|
||||||
|
@ -362,11 +362,11 @@ test_authenticator_move(PathPrefix) ->
|
||||||
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"http">>},
|
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"http">>},
|
||||||
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>}
|
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>}
|
||||||
],
|
],
|
||||||
PathPrefix ++ ["authentication"]),
|
PathPrefix ++ [?CONF_NS]),
|
||||||
|
|
||||||
{ok, 204, _} = request(
|
{ok, 204, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"bottom">>}),
|
#{position => <<"bottom">>}),
|
||||||
|
|
||||||
?assertAuthenticatorsMatch(
|
?assertAuthenticatorsMatch(
|
||||||
|
@ -375,11 +375,11 @@ test_authenticator_move(PathPrefix) ->
|
||||||
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>},
|
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>},
|
||||||
#{<<"mechanism">> := <<"jwt">>}
|
#{<<"mechanism">> := <<"jwt">>}
|
||||||
],
|
],
|
||||||
PathPrefix ++ ["authentication"]),
|
PathPrefix ++ [?CONF_NS]),
|
||||||
|
|
||||||
{ok, 204, _} = request(
|
{ok, 204, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication", "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"before:password-based:built-in-database">>}),
|
#{position => <<"before:password-based:built-in-database">>}),
|
||||||
|
|
||||||
?assertAuthenticatorsMatch(
|
?assertAuthenticatorsMatch(
|
||||||
|
@ -388,17 +388,17 @@ test_authenticator_move(PathPrefix) ->
|
||||||
#{<<"mechanism">> := <<"jwt">>},
|
#{<<"mechanism">> := <<"jwt">>},
|
||||||
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>}
|
#{<<"mechanism">> := <<"password-based">>, <<"backend">> := <<"built-in-database">>}
|
||||||
],
|
],
|
||||||
PathPrefix ++ ["authentication"]).
|
PathPrefix ++ [?CONF_NS]).
|
||||||
|
|
||||||
test_authenticator_import_users(PathPrefix) ->
|
test_authenticator_import_users(PathPrefix) ->
|
||||||
ImportUri = uri(
|
ImportUri = uri(
|
||||||
PathPrefix ++
|
PathPrefix ++
|
||||||
["authentication", "password-based:built-in-database", "import_users"]),
|
[?CONF_NS, "password-based:built-in-database", "import_users"]),
|
||||||
|
|
||||||
|
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ ["authentication"]),
|
uri(PathPrefix ++ [?CONF_NS]),
|
||||||
emqx_authn_test_lib:built_in_database_example()),
|
emqx_authn_test_lib:built_in_database_example()),
|
||||||
|
|
||||||
{ok, 400, _} = request(post, ImportUri, #{}),
|
{ok, 400, _} = request(post, ImportUri, #{}),
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("emqx/include/emqx_placeholder.hrl").
|
-include_lib("emqx/include/emqx_placeholder.hrl").
|
||||||
|
|
||||||
-define(PATH, [authentication]).
|
-define(PATH, [?CONF_NS_ATOM]).
|
||||||
|
|
||||||
-define(HTTP_PORT, 33333).
|
-define(HTTP_PORT, 33333).
|
||||||
-define(HTTP_PATH, "/auth").
|
-define(HTTP_PATH, "/auth").
|
||||||
|
|
Loading…
Reference in New Issue