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])}};
|
||||
serialize_error({missing_parameter, Detail}) ->
|
||||
{400, #{code => <<"MISSING_PARAMETER">>,
|
||||
message => binfmt("Missing required parameter", [Detail])}};
|
||||
message => binfmt("Missing required parameter: ~p", [Detail])}};
|
||||
serialize_error({invalid_parameter, Name}) ->
|
||||
{400, #{code => <<"INVALID_PARAMETER">>,
|
||||
message => binfmt("Invalid value for '~p'", [Name])}};
|
||||
|
|
|
@ -136,12 +136,10 @@ test_authenticators(PathPrefix) ->
|
|||
|
||||
test_authenticator(PathPrefix) ->
|
||||
ValidConfig0 = emqx_authn_test_lib:http_example(),
|
||||
|
||||
{ok, 200, _} = request(
|
||||
post,
|
||||
uri(PathPrefix ++ ["authentication"]),
|
||||
ValidConfig0),
|
||||
|
||||
{ok, 200, _} = request(
|
||||
get,
|
||||
uri(PathPrefix ++ ["authentication", "password-based:http"])),
|
||||
|
@ -262,9 +260,7 @@ test_authenticator_user(PathPrefix) ->
|
|||
fun(UserUpdate) -> {ok, 200, _} = request(put, UsersUri ++ "/u1", UserUpdate) end,
|
||||
ValidUserUpdates),
|
||||
|
||||
InvalidUserUpdates = [
|
||||
#{user_id => <<"u1">>, password => <<"p1">>},
|
||||
#{is_superuser => true}],
|
||||
InvalidUserUpdates = [#{user_id => <<"u1">>, password => <<"p1">>}],
|
||||
|
||||
lists:foreach(
|
||||
fun(UserUpdate) -> {ok, 400, _} = request(put, UsersUri ++ "/u1", UserUpdate) end,
|
||||
|
|
|
@ -56,7 +56,7 @@ init_per_suite(Config) ->
|
|||
port => 18083
|
||||
}]
|
||||
}),
|
||||
ok = application:load(emqx_conf),
|
||||
_ = application:load(emqx_conf),
|
||||
ok = emqx_common_test_helpers:start_apps([emqx_bridge, emqx_dashboard]),
|
||||
ok = emqx_config:init_load(emqx_bridge_schema, ?CONF_DEFAULT),
|
||||
Config.
|
||||
|
|
|
@ -101,6 +101,7 @@ For example: http://localhost:9901/
|
|||
, {request, hoconsc:mk(
|
||||
ref("request"),
|
||||
#{ default => undefined
|
||||
, nullable => true
|
||||
, desc => """
|
||||
If the request is provided, the caller can send HTTP requests via
|
||||
<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();
|
||||
|
||||
fields("request") ->
|
||||
[ {method, hoconsc:mk(hoconsc:enum([post, put, get, delete]), #{})}
|
||||
, {path, hoconsc:mk(binary(), #{})}
|
||||
, {body, hoconsc:mk(binary(), #{})}
|
||||
, {headers, hoconsc:mk(map(), #{})}
|
||||
[ {method, hoconsc:mk(hoconsc:enum([post, put, get, delete]), #{nullable => true})}
|
||||
, {path, hoconsc:mk(binary(), #{nullable => true})}
|
||||
, {body, hoconsc:mk(binary(), #{nullable => true})}
|
||||
, {headers, hoconsc:mk(map(), #{nullable => true})}
|
||||
, {request_timeout,
|
||||
sc(emqx_schema:duration_ms(),
|
||||
#{ default => "30s"
|
||||
#{ nullable => true
|
||||
, 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
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
preprocess_request(undefined) ->
|
||||
undefined;
|
||||
preprocess_request(Req) when map_size(Req) == 0 ->
|
||||
undefined;
|
||||
preprocess_request(#{
|
||||
method := Method,
|
||||
path := Path,
|
||||
body := Body,
|
||||
headers := Headers,
|
||||
request_timeout := ReqTimeout
|
||||
}) ->
|
||||
headers := Headers
|
||||
} = Req) ->
|
||||
#{ method => emqx_plugin_libs_rule:preproc_tmpl(bin(Method))
|
||||
, path => emqx_plugin_libs_rule:preproc_tmpl(Path)
|
||||
, body => emqx_plugin_libs_rule:preproc_tmpl(Body)
|
||||
, headers => preproc_headers(Headers)
|
||||
, request_timeout => ReqTimeout
|
||||
, request_timeout => maps:get(request_timeout, Req, 30000)
|
||||
}.
|
||||
|
||||
preproc_headers(Headers) ->
|
||||
|
|
|
@ -67,7 +67,7 @@ init_per_suite(Config) ->
|
|||
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_config:init_load(emqx_connector_schema, ?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) ->
|
||||
ok = ekka:stop(),
|
||||
emqx_common_test_helpers:stop_apps([emqx_connector, emqx_bridge, emqx_dashboard]),
|
||||
application:unload(emqx_conf),
|
||||
ok.
|
||||
|
||||
init_per_testcase(_, Config) ->
|
||||
|
|
|
@ -200,7 +200,7 @@ check_request_body(#{body := Body}, Schema, Module, CheckFun, true) ->
|
|||
_ -> Type0
|
||||
end,
|
||||
NewSchema = ?INIT_SCHEMA#{roots => [{root, Type}]},
|
||||
Option = #{override_env => false},
|
||||
Option = #{override_env => false, nullable => true},
|
||||
#{<<"root">> := NewBody} = CheckFun(NewSchema, #{<<"root">> => Body}, Option),
|
||||
NewBody;
|
||||
%% TODO not support nest object check yet, please use ref!
|
||||
|
|
Loading…
Reference in New Issue