Skip to content

Commit

Permalink
Merge pull request #12020 from thalesmg/sync-r53-m-20231124
Browse files Browse the repository at this point in the history
chore: sync `release-53` to `master`
  • Loading branch information
zhongwencool committed Nov 24, 2023
2 parents 2d4b9a7 + 261fe8a commit 8f548f4
Show file tree
Hide file tree
Showing 26 changed files with 478 additions and 47 deletions.
15 changes: 11 additions & 4 deletions apps/emqx_auth/src/emqx_authn/emqx_authn_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1111,10 +1111,7 @@ list_users(ChainName, AuthenticatorID, QueryString) ->
{error, page_limit_invalid} ->
{400, #{code => <<"INVALID_PARAMETER">>, message => <<"page_limit_invalid">>}};
{error, Reason} ->
{400, #{
code => <<"INVALID_PARAMETER">>,
message => list_to_binary(io_lib:format("Reason ~p", [Reason]))
}};
serialize_error({user_error, Reason});
Result ->
{200, Result}
end.
Expand Down Expand Up @@ -1176,6 +1173,16 @@ serialize_error({user_error, not_found}) ->
code => <<"NOT_FOUND">>,
message => binfmt("User not found", [])
}};
serialize_error({user_error, {not_found, {chain, ?GLOBAL}}}) ->
{404, #{
code => <<"NOT_FOUND">>,
message => <<"Authenticator not found in the 'global' scope">>
}};
serialize_error({user_error, {not_found, {chain, Name}}}) ->
{400, #{
code => <<"BAD_REQUEST">>,
message => binfmt("No authentication has been created for listener ~p", [Name])
}};
serialize_error({user_error, already_exist}) ->
{409, #{
code => <<"ALREADY_EXISTS">>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
-define(SALT_ROUNDS_MIN, 5).
-define(SALT_ROUNDS_MAX, 10).

namespace() -> "authn-hash".
namespace() -> "authn_hash".
roots() -> [pbkdf2, bcrypt, bcrypt_rw, bcrypt_rw_api, simple].

fields(bcrypt_rw) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
-behaviour(emqx_authz_schema).

-export([
namespace/0,
type/0,
fields/1,
desc/1,
Expand All @@ -30,6 +31,8 @@
select_union_member/1
]).

namespace() -> "authz".

type() -> ?AUTHZ_TYPE.

fields(file) ->
Expand Down
13 changes: 13 additions & 0 deletions apps/emqx_auth/test/emqx_authn/emqx_authn_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,19 @@ test_authenticator_position(PathPrefix) ->
PathPrefix ++ [?CONF_NS]
).

t_authenticator_users_not_found(_) ->
GlobalUser = #{user_id => <<"global_user">>, password => <<"p1">>},
{ok, 404, _} = request(
get,
uri([?CONF_NS, "password_based:built_in_database", "users"])
),
{ok, 404, _} = request(
post,
uri([?CONF_NS, "password_based:built_in_database", "users"]),
GlobalUser
),
ok.

%% listener authn api is not supported since 5.1.0
%% Don't support listener switch to global chain.
ignore_switch_to_global_chain(_) ->
Expand Down
2 changes: 1 addition & 1 deletion apps/emqx_auth/test/emqx_authn/emqx_authn_schema_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ t_check_schema(_Config) ->
?assertThrow(
#{
path := "authentication.1.password_hash_algorithm.name",
matched_type := "authn:builtin_db/authn-hash:simple",
matched_type := "authn:builtin_db/authn_hash:simple",
reason := unable_to_convert_to_enum_symbol
},
Check(ConfigNotOk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,22 @@ init_per_suite(Config) ->
emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
case emqx_common_test_helpers:is_tcp_server_available(GCPEmulatorHost, GCPEmulatorPort) of
true ->
ok = emqx_common_test_helpers:start_apps([emqx_conf]),
ok = emqx_connector_test_helpers:start_apps([
emqx_resource, emqx_bridge, emqx_rule_engine
]),
{ok, _} = application:ensure_all_started(emqx_connector),
Apps = emqx_cth_suite:start(
[
emqx,
emqx_conf,
emqx_bridge_gcp_pubsub,
emqx_bridge,
emqx_rule_engine
],
#{work_dir => emqx_cth_suite:work_dir(Config)}
),
emqx_mgmt_api_test_util:init_suite(),
HostPort = GCPEmulatorHost ++ ":" ++ GCPEmulatorPortStr,
true = os:putenv("PUBSUB_EMULATOR_HOST", HostPort),
Client = start_control_client(),
[
{apps, Apps},
{proxy_name, ProxyName},
{proxy_host, ProxyHost},
{proxy_port, ProxyPort},
Expand All @@ -62,12 +68,11 @@ init_per_suite(Config) ->
end.

end_per_suite(Config) ->
Apps = ?config(apps, Config),
Client = ?config(client, Config),
stop_control_client(Client),
emqx_mgmt_api_test_util:end_suite(),
ok = emqx_common_test_helpers:stop_apps([emqx_conf]),
ok = emqx_connector_test_helpers:stop_apps([emqx_bridge, emqx_resource, emqx_rule_engine]),
_ = application:stop(emqx_connector),
emqx_cth_suite:stop(Apps),
os:unsetenv("PUBSUB_EMULATOR_HOST"),
ok.

Expand Down Expand Up @@ -1472,7 +1477,7 @@ t_pull_worker_death(Config) ->

[PullWorkerPid | _] = get_pull_worker_pids(Config),
Ref = monitor(process, PullWorkerPid),
sys:terminate(PullWorkerPid, die),
sys:terminate(PullWorkerPid, die, 20_000),
receive
{'DOWN', Ref, process, PullWorkerPid, _} ->
ok
Expand All @@ -1494,10 +1499,11 @@ t_pull_worker_death(Config) ->
ok.

t_async_worker_death_mid_pull(Config) ->
ct:timetrap({seconds, 120}),
ct:timetrap({seconds, 122}),
[#{pubsub_topic := PubSubTopic}] = ?config(topic_mapping, Config),
Payload = emqx_guid:to_hexstr(emqx_guid:gen()),
?check_trace(
#{timetrap => 120_000},
begin
start_and_subscribe_mqtt(Config),

Expand All @@ -1513,23 +1519,28 @@ t_async_worker_death_mid_pull(Config) ->
#{?snk_kind := gcp_pubsub_consumer_worker_reply_delegator}
),
spawn_link(fun() ->
ct:pal("will kill async workers"),
?tp_span(
kill_async_worker,
#{},
begin
%% produce a message while worker is being killed
Messages = [#{<<"data">> => Payload}],
ct:pal("publishing message"),
pubsub_publish(Config, PubSubTopic, Messages),
ct:pal("published message"),

AsyncWorkerPids = get_async_worker_pids(Config),
emqx_utils:pmap(
fun(AsyncWorkerPid) ->
Ref = monitor(process, AsyncWorkerPid),
sys:terminate(AsyncWorkerPid, die),
ct:pal("killing pid ~p", [AsyncWorkerPid]),
sys:terminate(AsyncWorkerPid, die, 20_000),
receive
{'DOWN', Ref, process, AsyncWorkerPid, _} ->
ct:pal("killed pid ~p", [AsyncWorkerPid]),
ok
after 500 -> ct:fail("async worker didn't die")
after 500 -> ct:fail("async worker ~p didn't die", [AsyncWorkerPid])
end,
ok
end,
Expand All @@ -1538,7 +1549,8 @@ t_async_worker_death_mid_pull(Config) ->

ok
end
)
),
ct:pal("killed async workers")
end),

?assertMatch(
Expand Down
2 changes: 1 addition & 1 deletion apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
%%=====================================================================
%% Hocon schema

namespace() -> "connector-http".
namespace() -> "connector_http".

roots() ->
fields(config).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

-define(MQTT_HOST_OPTS, #{default_port => 1883}).

namespace() -> "connector-mqtt".
namespace() -> "connector_mqtt".

roots() ->
fields("config").
Expand Down

0 comments on commit 8f548f4

Please sign in to comment.