fix(authn): test cases issues
This commit is contained in:
parent
ea3c809287
commit
f0c61068e8
|
@ -896,7 +896,7 @@ serialize_error({bad_ssl_config, Details}) ->
|
||||||
message => binfmt("bad_ssl_config ~p", [Details])}};
|
message => binfmt("bad_ssl_config ~p", [Details])}};
|
||||||
serialize_error({missing_parameter, Detail}) ->
|
serialize_error({missing_parameter, Detail}) ->
|
||||||
{400, #{code => <<"MISSING_PARAMETER">>,
|
{400, #{code => <<"MISSING_PARAMETER">>,
|
||||||
message => binfmt("Missing required parameter", [Detail])}};
|
message => binfmt("Missing required parameter: ~p", [Detail])}};
|
||||||
serialize_error({invalid_parameter, Name}) ->
|
serialize_error({invalid_parameter, Name}) ->
|
||||||
{400, #{code => <<"INVALID_PARAMETER">>,
|
{400, #{code => <<"INVALID_PARAMETER">>,
|
||||||
message => binfmt("Invalid value for '~p'", [Name])}};
|
message => binfmt("Invalid value for '~p'", [Name])}};
|
||||||
|
|
|
@ -136,12 +136,10 @@ test_authenticators(PathPrefix) ->
|
||||||
|
|
||||||
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 ++ ["authentication"]),
|
||||||
ValidConfig0),
|
ValidConfig0),
|
||||||
|
|
||||||
{ok, 200, _} = request(
|
{ok, 200, _} = request(
|
||||||
get,
|
get,
|
||||||
uri(PathPrefix ++ ["authentication", "password-based:http"])),
|
uri(PathPrefix ++ ["authentication", "password-based:http"])),
|
||||||
|
@ -262,9 +260,7 @@ test_authenticator_user(PathPrefix) ->
|
||||||
fun(UserUpdate) -> {ok, 200, _} = request(put, UsersUri ++ "/u1", UserUpdate) end,
|
fun(UserUpdate) -> {ok, 200, _} = request(put, UsersUri ++ "/u1", UserUpdate) end,
|
||||||
ValidUserUpdates),
|
ValidUserUpdates),
|
||||||
|
|
||||||
InvalidUserUpdates = [
|
InvalidUserUpdates = [#{user_id => <<"u1">>, password => <<"p1">>}],
|
||||||
#{user_id => <<"u1">>, password => <<"p1">>},
|
|
||||||
#{is_superuser => true}],
|
|
||||||
|
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(UserUpdate) -> {ok, 400, _} = request(put, UsersUri ++ "/u1", UserUpdate) end,
|
fun(UserUpdate) -> {ok, 400, _} = request(put, UsersUri ++ "/u1", UserUpdate) end,
|
||||||
|
|
|
@ -56,7 +56,7 @@ init_per_suite(Config) ->
|
||||||
port => 18083
|
port => 18083
|
||||||
}]
|
}]
|
||||||
}),
|
}),
|
||||||
ok = application:load(emqx_conf),
|
_ = application:load(emqx_conf),
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_bridge, emqx_dashboard]),
|
ok = emqx_common_test_helpers:start_apps([emqx_bridge, emqx_dashboard]),
|
||||||
ok = emqx_config:init_load(emqx_bridge_schema, ?CONF_DEFAULT),
|
ok = emqx_config:init_load(emqx_bridge_schema, ?CONF_DEFAULT),
|
||||||
Config.
|
Config.
|
||||||
|
|
|
@ -101,6 +101,7 @@ For example: http://localhost:9901/
|
||||||
, {request, hoconsc:mk(
|
, {request, hoconsc:mk(
|
||||||
ref("request"),
|
ref("request"),
|
||||||
#{ default => undefined
|
#{ default => undefined
|
||||||
|
, nullable => true
|
||||||
, desc => """
|
, desc => """
|
||||||
If the request is provided, the caller can send HTTP requests via
|
If the request is provided, the caller can send HTTP requests via
|
||||||
<code>emqx_resource:query(ResourceId, {send_message, BridgeId, Message})</code>
|
<code>emqx_resource:query(ResourceId, {send_message, BridgeId, Message})</code>
|
||||||
|
@ -109,13 +110,13 @@ If the request is provided, the caller can send HTTP requests via
|
||||||
] ++ emqx_connector_schema_lib:ssl_fields();
|
] ++ emqx_connector_schema_lib:ssl_fields();
|
||||||
|
|
||||||
fields("request") ->
|
fields("request") ->
|
||||||
[ {method, hoconsc:mk(hoconsc:enum([post, put, get, delete]), #{})}
|
[ {method, hoconsc:mk(hoconsc:enum([post, put, get, delete]), #{nullable => true})}
|
||||||
, {path, hoconsc:mk(binary(), #{})}
|
, {path, hoconsc:mk(binary(), #{nullable => true})}
|
||||||
, {body, hoconsc:mk(binary(), #{})}
|
, {body, hoconsc:mk(binary(), #{nullable => true})}
|
||||||
, {headers, hoconsc:mk(map(), #{})}
|
, {headers, hoconsc:mk(map(), #{nullable => true})}
|
||||||
, {request_timeout,
|
, {request_timeout,
|
||||||
sc(emqx_schema:duration_ms(),
|
sc(emqx_schema:duration_ms(),
|
||||||
#{ default => "30s"
|
#{ nullable => true
|
||||||
, desc => "The timeout when sending request to the HTTP server"
|
, desc => "The timeout when sending request to the HTTP server"
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
@ -222,20 +223,22 @@ on_health_check(_InstId, #{host := Host, port := Port} = State) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
preprocess_request(undefined) ->
|
preprocess_request(undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
|
preprocess_request(Req) when map_size(Req) == 0 ->
|
||||||
|
undefined;
|
||||||
preprocess_request(#{
|
preprocess_request(#{
|
||||||
method := Method,
|
method := Method,
|
||||||
path := Path,
|
path := Path,
|
||||||
body := Body,
|
body := Body,
|
||||||
headers := Headers,
|
headers := Headers
|
||||||
request_timeout := ReqTimeout
|
} = Req) ->
|
||||||
}) ->
|
|
||||||
#{ method => emqx_plugin_libs_rule:preproc_tmpl(bin(Method))
|
#{ method => emqx_plugin_libs_rule:preproc_tmpl(bin(Method))
|
||||||
, path => emqx_plugin_libs_rule:preproc_tmpl(Path)
|
, path => emqx_plugin_libs_rule:preproc_tmpl(Path)
|
||||||
, body => emqx_plugin_libs_rule:preproc_tmpl(Body)
|
, body => emqx_plugin_libs_rule:preproc_tmpl(Body)
|
||||||
, headers => preproc_headers(Headers)
|
, headers => preproc_headers(Headers)
|
||||||
, request_timeout => ReqTimeout
|
, request_timeout => maps:get(request_timeout, Req, 30000)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
preproc_headers(Headers) ->
|
preproc_headers(Headers) ->
|
||||||
|
|
|
@ -67,7 +67,7 @@ init_per_suite(Config) ->
|
||||||
port => 18083
|
port => 18083
|
||||||
}]
|
}]
|
||||||
}),
|
}),
|
||||||
ok = application:load(emqx_conf),
|
_ = application:load(emqx_conf),
|
||||||
ok = emqx_common_test_helpers:start_apps([emqx_connector, emqx_bridge, emqx_dashboard]),
|
ok = emqx_common_test_helpers:start_apps([emqx_connector, emqx_bridge, emqx_dashboard]),
|
||||||
ok = emqx_config:init_load(emqx_connector_schema, ?CONF_DEFAULT),
|
ok = emqx_config:init_load(emqx_connector_schema, ?CONF_DEFAULT),
|
||||||
ok = emqx_config:init_load(emqx_bridge_schema, ?BRIDGE_CONF_DEFAULT),
|
ok = emqx_config:init_load(emqx_bridge_schema, ?BRIDGE_CONF_DEFAULT),
|
||||||
|
@ -76,6 +76,7 @@ init_per_suite(Config) ->
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
ok = ekka:stop(),
|
ok = ekka:stop(),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_connector, emqx_bridge, emqx_dashboard]),
|
emqx_common_test_helpers:stop_apps([emqx_connector, emqx_bridge, emqx_dashboard]),
|
||||||
|
application:unload(emqx_conf),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
init_per_testcase(_, Config) ->
|
init_per_testcase(_, Config) ->
|
||||||
|
|
|
@ -200,7 +200,7 @@ check_request_body(#{body := Body}, Schema, Module, CheckFun, true) ->
|
||||||
_ -> Type0
|
_ -> Type0
|
||||||
end,
|
end,
|
||||||
NewSchema = ?INIT_SCHEMA#{roots => [{root, Type}]},
|
NewSchema = ?INIT_SCHEMA#{roots => [{root, Type}]},
|
||||||
Option = #{override_env => false},
|
Option = #{override_env => false, nullable => true},
|
||||||
#{<<"root">> := NewBody} = CheckFun(NewSchema, #{<<"root">> => Body}, Option),
|
#{<<"root">> := NewBody} = CheckFun(NewSchema, #{<<"root">> => Body}, Option),
|
||||||
NewBody;
|
NewBody;
|
||||||
%% TODO not support nest object check yet, please use ref!
|
%% TODO not support nest object check yet, please use ref!
|
||||||
|
|
Loading…
Reference in New Issue