chore: no type check for 3rd party auth

This commit is contained in:
Zaiming (Stone) Shi 2023-01-11 20:00:28 +01:00
parent fbc52330f3
commit 65319567cc
2 changed files with 10 additions and 49 deletions

View File

@ -759,9 +759,10 @@ maybe_unhook(State) ->
State. State.
do_create_authenticator(AuthenticatorID, #{enable := Enable} = Config, Providers) -> do_create_authenticator(AuthenticatorID, #{enable := Enable} = Config, Providers) ->
case maps:get(authn_type(Config), Providers, undefined) of Type = authn_type(Config),
case maps:get(Type, Providers, undefined) of
undefined -> undefined ->
{error, no_available_provider}; {error, {no_available_provider_for, Type}};
Provider -> Provider ->
case Provider:create(AuthenticatorID, Config) of case Provider:create(AuthenticatorID, Config) of
{ok, State} -> {ok, State} ->

View File

@ -52,50 +52,10 @@
) )
). ).
%%------------------------------------------------------------------------------
%% Hocon Schema
%%------------------------------------------------------------------------------
roots() ->
[
{config, #{
type => hoconsc:union([
hoconsc:ref(?MODULE, type1),
hoconsc:ref(?MODULE, type2)
])
}}
].
fields(type1) ->
[
{mechanism, {enum, [password_based]}},
{backend, {enum, [built_in_database]}},
{enable, fun enable/1}
];
fields(type2) ->
[
{mechanism, {enum, [password_based]}},
{backend, {enum, [mysql]}},
{enable, fun enable/1}
].
enable(type) -> boolean();
enable(default) -> true;
enable(_) -> undefined.
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Callbacks %% Callbacks
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
check_config(C) ->
#{config := R} =
hocon_tconf:check_plain(
?MODULE,
#{<<"config">> => C},
#{atom_key => true}
),
R.
create(_AuthenticatorID, _Config) -> create(_AuthenticatorID, _Config) ->
{ok, #{mark => 1}}. {ok, #{mark => 1}}.
@ -200,7 +160,7 @@ t_authenticator(Config) when is_list(Config) ->
% Create an authenticator when the provider does not exist % Create an authenticator when the provider does not exist
?assertEqual( ?assertEqual(
{error, no_available_provider}, {error, {no_available_provider_for, {password_based, built_in_database}}},
?AUTHN:create_authenticator(ChainName, AuthenticatorConfig1) ?AUTHN:create_authenticator(ChainName, AuthenticatorConfig1)
), ),
@ -335,14 +295,14 @@ t_update_config(Config) when is_list(Config) ->
ok = register_provider(?config("auth2"), ?MODULE), ok = register_provider(?config("auth2"), ?MODULE),
Global = ?config(global), Global = ?config(global),
AuthenticatorConfig1 = #{ AuthenticatorConfig1 = #{
<<"mechanism">> => <<"password_based">>, mechanism => password_based,
<<"backend">> => <<"built_in_database">>, backend => built_in_database,
<<"enable">> => true enable => true
}, },
AuthenticatorConfig2 = #{ AuthenticatorConfig2 = #{
<<"mechanism">> => <<"password_based">>, mechanism => password_based,
<<"backend">> => <<"mysql">>, backend => mysql,
<<"enable">> => true enable => true
}, },
ID1 = <<"password_based:built_in_database">>, ID1 = <<"password_based:built_in_database">>,
ID2 = <<"password_based:mysql">>, ID2 = <<"password_based:mysql">>,