diff options
| author | Michael Klishin <michael@clojurewerkz.org> | 2017-06-27 10:18:01 +0300 |
|---|---|---|
| committer | Michael Klishin <michael@clojurewerkz.org> | 2017-06-27 10:18:01 +0300 |
| commit | fcc9879f56941ce004c50965dabae934b4103ab1 (patch) | |
| tree | 0b0dc6fd4aecec92ec620e1a8b9a266c636fe299 /test | |
| parent | 10fd03dbf2168aed1cb7e96da7c3603444f1e449 (diff) | |
| parent | 2e99c66d76be0fe77af51b66deb79e9ee347b208 (diff) | |
| download | rabbitmq-server-git-fcc9879f56941ce004c50965dabae934b4103ab1.tar.gz | |
Merge branch 'master' into rabbitmq-common-198
Diffstat (limited to 'test')
| -rw-r--r-- | test/backing_queue_SUITE.erl | 2 | ||||
| -rw-r--r-- | test/cluster_SUITE.erl | 2 | ||||
| -rw-r--r-- | test/cluster_formation_locking_SUITE.erl | 80 | ||||
| -rw-r--r-- | test/clustering_management_SUITE.erl | 8 | ||||
| -rw-r--r-- | test/config_schema_SUITE_data/rabbit.snippets | 106 | ||||
| -rw-r--r-- | test/crashing_queues_SUITE.erl | 2 | ||||
| -rw-r--r-- | test/partitions_SUITE.erl | 38 | ||||
| -rw-r--r-- | test/sup_delayed_restart_SUITE.erl | 1 | ||||
| -rw-r--r-- | test/term_to_binary_compat_prop_SUITE.erl | 114 | ||||
| -rw-r--r-- | test/topic_permission_SUITE.erl | 32 | ||||
| -rw-r--r-- | test/unit_SUITE.erl | 41 | ||||
| -rw-r--r-- | test/unit_inbroker_parallel_SUITE.erl | 22 |
12 files changed, 390 insertions, 58 deletions
diff --git a/test/backing_queue_SUITE.erl b/test/backing_queue_SUITE.erl index 3ff215f497..60f86e0542 100644 --- a/test/backing_queue_SUITE.erl +++ b/test/backing_queue_SUITE.erl @@ -1256,7 +1256,7 @@ make_publish_delivered(IsPersistent, PayloadFun, PropFun, N) -> PropFun(N, #message_properties{size = 10})}. queue_name(Config, Name) -> - Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name), + Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)), queue_name(Name1). queue_name(Name) -> diff --git a/test/cluster_SUITE.erl b/test/cluster_SUITE.erl index bc442ecba7..3dba65ae1f 100644 --- a/test/cluster_SUITE.erl +++ b/test/cluster_SUITE.erl @@ -355,7 +355,7 @@ test_spawn_remote() -> end. queue_name(Config, Name) -> - Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name), + Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)), queue_name(Name1). queue_name(Name) -> diff --git a/test/cluster_formation_locking_SUITE.erl b/test/cluster_formation_locking_SUITE.erl new file mode 100644 index 0000000000..25b2df308c --- /dev/null +++ b/test/cluster_formation_locking_SUITE.erl @@ -0,0 +1,80 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2017 Pivotal Software, Inc. All rights reserved. +%% +-module(cluster_formation_locking_SUITE). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +-compile(export_all). + +all() -> + [ + {group, non_parallel_tests} + ]. + +groups() -> + [ + {non_parallel_tests, [], [ + init_with_lock_exits_after_errors, + init_with_lock_ignore_after_errors, + init_with_lock_not_supported, + init_with_lock_supported + ]} + ]. + +init_per_testcase(Testcase, Config) when Testcase == init_with_lock_exits_after_errors; + Testcase == init_with_lock_not_supported; + Testcase == init_with_lock_supported -> + application:set_env(rabbit, cluster_formation, + [{peer_discover_backend, peer_discover_classic_config}, + {lock_acquisition_failure_mode, fail}]), + ok = meck:new(rabbit_peer_discovery_classic_config, [passthrough]), + Config; +init_per_testcase(init_with_lock_ignore_after_errors, Config) -> + application:set_env(rabbit, cluster_formation, + [{peer_discover_backend, peer_discover_classic_config}, + {lock_acquisition_failure_mode, ignore}]), + ok = meck:new(rabbit_peer_discovery_classic_config, [passthrough]), + Config. + +end_per_testcase(_, _) -> + meck:unload(), + application:unset_env(rabbit, cluster_formation). + +init_with_lock_exits_after_errors(_Config) -> + meck:expect(rabbit_peer_discovery_classic_config, lock, fun(_) -> {error, "test error"} end), + ?assertExit(cannot_acquire_startup_lock, rabbit_mnesia:init_with_lock(2, 10, fun() -> ok end)), + ?assert(meck:validate(rabbit_peer_discovery_classic_config)), + passed. + +init_with_lock_ignore_after_errors(_Config) -> + meck:expect(rabbit_peer_discovery_classic_config, lock, fun(_) -> {error, "test error"} end), + ?assertEqual(ok, rabbit_mnesia:init_with_lock(2, 10, fun() -> ok end)), + ?assert(meck:validate(rabbit_peer_discovery_classic_config)), + passed. + +init_with_lock_not_supported(_Config) -> + meck:expect(rabbit_peer_discovery_classic_config, lock, fun(_) -> not_supported end), + ?assertEqual(ok, rabbit_mnesia:init_with_lock(2, 10, fun() -> ok end)), + ?assert(meck:validate(rabbit_peer_discovery_classic_config)), + passed. + +init_with_lock_supported(_Config) -> + meck:expect(rabbit_peer_discovery_classic_config, lock, fun(_) -> {ok, data} end), + meck:expect(rabbit_peer_discovery_classic_config, unlock, fun(data) -> ok end), + ?assertEqual(ok, rabbit_mnesia:init_with_lock(2, 10, fun() -> ok end)), + ?assert(meck:validate(rabbit_peer_discovery_classic_config)), + passed. diff --git a/test/clustering_management_SUITE.erl b/test/clustering_management_SUITE.erl index b0a93ad208..51c0928ba5 100644 --- a/test/clustering_management_SUITE.erl +++ b/test/clustering_management_SUITE.erl @@ -135,7 +135,8 @@ join_and_part_cluster(Config) -> %% Allow clustering with already clustered node ok = stop_app(Rabbit), - {ok, already_member} = join_cluster(Rabbit, Hare), + {ok, <<"The node is already a member of this cluster">>} = + join_cluster(Rabbit, Hare), ok = start_app(Rabbit), stop_reset_start(Rabbit), @@ -388,10 +389,9 @@ force_boot(Config) -> change_cluster_node_type(Config) -> [Rabbit, Hare, _Bunny] = cluster_members(Config), - %% Trying to change the ram node when not clustered should always fail + %% Trying to change the node to the ram type when not clustered should always fail ok = stop_app(Rabbit), assert_failure(fun () -> change_cluster_node_type(Rabbit, ram) end), - assert_failure(fun () -> change_cluster_node_type(Rabbit, disc) end), ok = start_app(Rabbit), ok = stop_app(Rabbit), @@ -643,7 +643,7 @@ wait_for_pid_file_to_contain_running_process_pid(PidFile, Attempts, Timeout) -> Pid = pid_from_file(PidFile), case rabbit_misc:is_os_process_alive(Pid) of true -> ok; - false -> + false -> ct:sleep(Timeout), wait_for_pid_file_to_contain_running_process_pid(PidFile, Attempts - 1, Timeout) end. diff --git a/test/config_schema_SUITE_data/rabbit.snippets b/test/config_schema_SUITE_data/rabbit.snippets index b527b816b1..5d03ba1b13 100644 --- a/test/config_schema_SUITE_data/rabbit.snippets +++ b/test/config_schema_SUITE_data/rabbit.snippets @@ -84,30 +84,30 @@ default_permissions.write = .*", {default_user_tags,[administrator]}, {default_permissions,[<<".*">>,<<".*">>,<<".*">>]}]}], []}, - {autocluster, - "autocluster.peer_discovery_backend = rabbit_peer_discovery_classic_config -autocluster.classic_config.nodes.peer1 = rabbit@hostname1 -autocluster.classic_config.nodes.peer2 = rabbit@hostname2 -autocluster.node_type = disc", + {cluster_formation, + "cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config +cluster_formation.classic_config.nodes.peer1 = rabbit@hostname1 +cluster_formation.classic_config.nodes.peer2 = rabbit@hostname2 +cluster_formation.node_type = disc", [{rabbit, - [{autocluster, + [{cluster_formation, [{peer_discovery_backend,rabbit_peer_discovery_classic_config}, {node_type,disc}]}, {cluster_nodes,{[rabbit@hostname2,rabbit@hostname1],disc}}]}], []}, - {autocluster_disK, - "autocluster.peer_discovery_backend = rabbit_peer_discovery_classic_config - autocluster.classic_config.nodes.peer1 = rabbit@hostname1 - autocluster.classic_config.nodes.peer2 = rabbit@hostname2 - autocluster.node_type = disk", + {cluster_formation_disK, + "cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config + cluster_formation.classic_config.nodes.peer1 = rabbit@hostname1 + cluster_formation.classic_config.nodes.peer2 = rabbit@hostname2 + cluster_formation.node_type = disk", [{rabbit, - [{autocluster, + [{cluster_formation, [{peer_discovery_backend,rabbit_peer_discovery_classic_config}, {node_type,disc}]}, {cluster_nodes,{[rabbit@hostname2,rabbit@hostname1],disc}}]}], []}, - {autocluster_ram_ignored, - "autocluster.node_type = ram",[],[]}, + {cluster_formation_ram_ignored, + "cluster_formation.node_type = ram",[],[]}, {tcp_listen_options, "tcp_listen_options.backlog = 128 tcp_listen_options.nodelay = true @@ -131,6 +131,18 @@ tcp_listen_options.exit_on_close = false", [{vm_memory_high_watermark_paging_ratio,0.75}, {vm_memory_high_watermark,0.4}]}], []}, + {memory_monitor_interval, "memory_monitor_interval = 5000", + [{rabbit, + [{memory_monitor_interval, 5000}]}], + []}, + {vm_memory_calculation_strategy, "vm_memory_calculation_strategy = rss", + [{rabbit, + [{vm_memory_calculation_strategy, rss}]}], + []}, + {vm_memory_calculation_strategy, "vm_memory_calculation_strategy = erlang", + [{rabbit, + [{vm_memory_calculation_strategy, erlang}]}], + []}, {listeners_tcp_ip, "listeners.tcp.1 = 192.168.1.99:5672", [{rabbit,[{tcp_listeners,[{"192.168.1.99",5672}]}]}], @@ -298,6 +310,46 @@ tcp_listen_options.exit_on_close = false", {verify,verify_peer}, {fail_if_no_peer_cert,false}]}]}], []}, + {ssl_options_honor_cipher_order, + "listeners.ssl.1 = 5671 + ssl_options.cacertfile = test/config_schema_SUITE_data/certs/cacert.pem + ssl_options.certfile = test/config_schema_SUITE_data/certs/cert.pem + ssl_options.keyfile = test/config_schema_SUITE_data/certs/key.pem + ssl_options.depth = 2 + ssl_options.verify = verify_peer + ssl_options.fail_if_no_peer_cert = false + ssl_options.honor_cipher_order = true", + [{rabbit, + [{ssl_listeners,[5671]}, + {ssl_options, + [{cacertfile,"test/config_schema_SUITE_data/certs/cacert.pem"}, + {certfile,"test/config_schema_SUITE_data/certs/cert.pem"}, + {keyfile,"test/config_schema_SUITE_data/certs/key.pem"}, + {depth,2}, + {verify,verify_peer}, + {fail_if_no_peer_cert, false}, + {honor_cipher_order, true}]}]}], + []}, + {ssl_options_honor_ecc_order, + "listeners.ssl.1 = 5671 + ssl_options.cacertfile = test/config_schema_SUITE_data/certs/cacert.pem + ssl_options.certfile = test/config_schema_SUITE_data/certs/cert.pem + ssl_options.keyfile = test/config_schema_SUITE_data/certs/key.pem + ssl_options.depth = 2 + ssl_options.verify = verify_peer + ssl_options.fail_if_no_peer_cert = false + ssl_options.honor_ecc_order = true", + [{rabbit, + [{ssl_listeners,[5671]}, + {ssl_options, + [{cacertfile,"test/config_schema_SUITE_data/certs/cacert.pem"}, + {certfile,"test/config_schema_SUITE_data/certs/cert.pem"}, + {keyfile,"test/config_schema_SUITE_data/certs/key.pem"}, + {depth,2}, + {verify,verify_peer}, + {fail_if_no_peer_cert, false}, + {honor_ecc_order, true}]}]}], + []}, {ssl_cert_login_from, "ssl_cert_login_from = common_name", [{rabbit,[{ssl_cert_login_from,common_name}]}], @@ -320,29 +372,29 @@ tcp_listen_options.exit_on_close = false", "tcp_listen_options.linger.timeout = 100", [{rabbit,[{tcp_listen_options,[{linger,{false,100}}]}]}], []}, - {autocluster_dns, - "autocluster.peer_discovery_backend = rabbit_peer_discovery_dns - autocluster.dns.hostname = 192.168.0.2.xip.io - autocluster.node_type = disc", + {cluster_formation_dns, + "cluster_formation.peer_discovery_backend = rabbit_peer_discovery_dns + cluster_formation.dns.hostname = 192.168.0.2.xip.io + cluster_formation.node_type = disc", [{rabbit, - [{autocluster, + [{cluster_formation, [{peer_discovery_dns,[{hostname,<<"192.168.0.2.xip.io">>}]}, {peer_discovery_backend,rabbit_peer_discovery_dns}, {node_type,disc}]}]}], []}, - {autocluster_classic, - "autocluster.peer_discovery_backend = rabbit_peer_discovery_classic_config - autocluster.node_type = disc", + {cluster_formation_classic, + "cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config + cluster_formation.node_type = disc", [{rabbit, - [{autocluster, + [{cluster_formation, [{peer_discovery_backend,rabbit_peer_discovery_classic_config}, {node_type,disc}]}]}], []}, - {autocluster_classic_ram, - "autocluster.peer_discovery_backend = rabbit_peer_discovery_classic_config - autocluster.node_type = ram", + {cluster_formation_classic_ram, + "cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config + cluster_formation.node_type = ram", [{rabbit, - [{autocluster, + [{cluster_formation, [{peer_discovery_backend,rabbit_peer_discovery_classic_config}, {node_type,ram}]}]}], []}, diff --git a/test/crashing_queues_SUITE.erl b/test/crashing_queues_SUITE.erl index 6e78c1579f..fa0a695173 100644 --- a/test/crashing_queues_SUITE.erl +++ b/test/crashing_queues_SUITE.erl @@ -223,7 +223,7 @@ queue_pid(Node, QName) -> case State of crashed -> case rabbit_amqqueue_sup_sup:find_for_vhost(VHost, Node) of - {error, {queue_supervisor_not_found, Result}} -> {error, no_sup}; + {error, {queue_supervisor_not_found, _}} -> {error, no_sup}; {ok, SPid} -> case sup_child(Node, SPid) of {ok, _} -> QPid; %% restarting diff --git a/test/partitions_SUITE.erl b/test/partitions_SUITE.erl index 8c8a772987..b09d05b550 100644 --- a/test/partitions_SUITE.erl +++ b/test/partitions_SUITE.erl @@ -335,16 +335,26 @@ autoheal_unexpected_finish(Config) -> partial_false_positive(Config) -> [A, B, C] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), + suspend_node_monitor(Config, C), block([{A, B}]), timer:sleep(1000), block([{A, C}]), timer:sleep(?DELAY), + resume_node_monitor(Config, C), + timer:sleep(?DELAY), unblock([{A, B}, {A, C}]), timer:sleep(?DELAY), %% When B times out A's connection, it will check with C. C will %% not have timed out A yet, but already it can't talk to it. We %% need to not consider this a partial partition; B and C should %% still talk to each other. + %% + %% Because there is a chance that C can still talk to A when B + %% requests to check for a partial partition, we suspend C's + %% rabbit_node_monitor at the beginning and resume it after the + %% link between A and C is blocked. This way, when B asks C about + %% A, we make sure that the A<->C link is blocked before C's + %% rabbit_node_monitor processes B's request. [B, C] = partitions(A), [A] = partitions(B), [A] = partitions(C), @@ -369,7 +379,19 @@ partial_to_full(Config) -> partial_pause_minority(Config) -> [A, B, C] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), set_mode(Config, pause_minority), + %% We suspend rabbit_node_monitor on C while we block the link + %% between A and B. This should make sure C's rabbit_node_monitor + %% processes both partial partition checks from A and B at about + %% the same time, and thus increase the chance both A and B decides + %% there is a partial partition. + %% + %% Without this, one node may see the partial partition and stop, + %% before the other node sees it. In this case, the other node + %% doesn't stop and this testcase fails. + suspend_node_monitor(Config, C), block([{A, B}]), + timer:sleep(?DELAY), + resume_node_monitor(Config, C), [await_running(N, false) || N <- [A, B]], await_running(C, true), unblock([{A, B}]), @@ -394,6 +416,22 @@ set_mode(Config, Mode) -> set_mode(Config, Nodes, Mode) -> rabbit_ct_broker_helpers:set_partition_handling_mode(Config, Nodes, Mode). +suspend_node_monitor(Config, Node) -> + rabbit_ct_broker_helpers:rpc( + Config, Node, ?MODULE, suspend_or_resume_node_monitor, [suspend]). + +resume_node_monitor(Config, Node) -> + rabbit_ct_broker_helpers:rpc( + Config, Node, ?MODULE, suspend_or_resume_node_monitor, [resume]). + +suspend_or_resume_node_monitor(SuspendOrResume) -> + Action = case SuspendOrResume of + suspend -> "Suspending"; + resume -> "Resuming" + end, + rabbit_log:info("(~s) ~s node monitor~n", [?MODULE, Action]), + ok = sys:SuspendOrResume(rabbit_node_monitor). + block_unblock(Pairs) -> block(Pairs), timer:sleep(?DELAY), diff --git a/test/sup_delayed_restart_SUITE.erl b/test/sup_delayed_restart_SUITE.erl index e495f57d0e..0dffe33068 100644 --- a/test/sup_delayed_restart_SUITE.erl +++ b/test/sup_delayed_restart_SUITE.erl @@ -81,6 +81,7 @@ exit_child(SupPid) -> with_child_pid(SupPid, Fun) -> case supervisor2:which_children(SupPid) of [{_Id, undefined, worker, [?MODULE]}] -> ok; + [{_Id, restarting, worker, [?MODULE]}] -> ok; [{_Id, ChildPid, worker, [?MODULE]}] -> Fun(ChildPid); [] -> ok end. diff --git a/test/term_to_binary_compat_prop_SUITE.erl b/test/term_to_binary_compat_prop_SUITE.erl new file mode 100644 index 0000000000..ba5069860a --- /dev/null +++ b/test/term_to_binary_compat_prop_SUITE.erl @@ -0,0 +1,114 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2017 Pivotal Software, Inc. All rights reserved. +%% + + +-module(term_to_binary_compat_prop_SUITE). + +-compile(export_all). + +-include("rabbit.hrl"). +-include_lib("common_test/include/ct.hrl"). +-include_lib("proper/include/proper.hrl"). + +-define(ITERATIONS_TO_RUN_UNTIL_CONFIDENT, 10000). + +all() -> + [ + ensure_term_to_binary_defaults_to_version_1, + term_to_binary_latin_atom, + queue_name_to_binary + ]. + +erts_gt_8() -> + Vsn = erlang:system_info(version), + [Maj|_] = string:tokens(Vsn, "."), + list_to_integer(Maj) > 8. + +init_per_suite(Config) -> + rabbit_ct_helpers:log_environment(), + rabbit_ct_helpers:run_setup_steps(Config). + +end_per_suite(Config) -> + rabbit_ct_helpers:run_teardown_steps(Config). + +init_per_testcase(Testcase, Config) -> + rabbit_ct_helpers:testcase_started(Config, Testcase). + +%% R16B03 defaults term_to_binary version to 0, this test would always fail +ensure_term_to_binary_defaults_to_version_1(Config) -> + CurrentERTS = erlang:system_info(version), + MinimumTestedERTS = "6.0", + case rabbit_misc:version_compare(CurrentERTS, MinimumTestedERTS, gte) of + true -> + Property = fun () -> + prop_ensure_term_to_binary_defaults_to_version_1(Config) + end, + rabbit_ct_proper_helpers:run_proper( + Property, [], + ?ITERATIONS_TO_RUN_UNTIL_CONFIDENT); + false -> + ct:pal( + ?LOW_IMPORTANCE, + "This test require ERTS ~p or above, running on ~p~n" + "Skipping test...", + [MinimumTestedERTS, CurrentERTS]) + end. + +prop_ensure_term_to_binary_defaults_to_version_1(_Config) -> + ?FORALL(Term, any(), + begin + Current = term_to_binary(Term), + Compat = term_to_binary_compat:term_to_binary_1(Term), + Current =:= Compat + end). + +term_to_binary_latin_atom(Config) -> + Property = fun () -> prop_term_to_binary_latin_atom(Config) end, + rabbit_ct_proper_helpers:run_proper(Property, [], + ?ITERATIONS_TO_RUN_UNTIL_CONFIDENT). + +prop_term_to_binary_latin_atom(_Config) -> + ?FORALL(LatinString, list(integer(0, 255)), + begin + Length = length(LatinString), + Atom = list_to_atom(LatinString), + Binary = list_to_binary(LatinString), + <<131,100, Length:16, Binary/binary>> =:= + term_to_binary_compat:term_to_binary_1(Atom) + end). + +queue_name_to_binary(Config) -> + Property = fun () -> prop_queue_name_to_binary(Config) end, + rabbit_ct_proper_helpers:run_proper(Property, [], + ?ITERATIONS_TO_RUN_UNTIL_CONFIDENT). + + +prop_queue_name_to_binary(_Config) -> + ?FORALL({VHost, QName}, {binary(), binary()}, + begin + VHostBSize = byte_size(VHost), + NameBSize = byte_size(QName), + Expected = + <<131, %% Binary format "version" + 104, 4, %% 4-element tuple + 100, 0, 8, "resource", %% `resource` atom + 109, VHostBSize:32, VHost/binary, %% Vhost binary + 100, 0, 5, "queue", %% `queue` atom + 109, NameBSize:32, QName/binary>>, %% Name binary + Resource = rabbit_misc:r(VHost, queue, QName), + Current = term_to_binary_compat:term_to_binary_1(Resource), + Current =:= Expected + end). diff --git a/test/topic_permission_SUITE.erl b/test/topic_permission_SUITE.erl index 7b9d9f7701..c656746432 100644 --- a/test/topic_permission_SUITE.erl +++ b/test/topic_permission_SUITE.erl @@ -218,4 +218,36 @@ topic_permission_checks1(_Config) -> Perm, Context ) || Perm <- Permissions], + + %% expand variables + rabbit_auth_backend_internal:set_topic_permissions( + <<"guest">>, <<"other-vhost">>, <<"amq.topic">>, + "services.{vhost}.accounts.{username}.notifications", + "services.{vhost}.accounts.{username}.notifications", <<"acting-user">> + ), + %% routing key OK + [true = rabbit_auth_backend_internal:check_topic_access( + User, + Topic#resource{virtual_host = <<"other-vhost">>}, + Perm, + #{routing_key => <<"services.other-vhost.accounts.guest.notifications">>, + variable_map => #{ + <<"username">> => <<"guest">>, + <<"vhost">> => <<"other-vhost">> + } + } + ) || Perm <- Permissions], + %% routing key KO + [false = rabbit_auth_backend_internal:check_topic_access( + User, + Topic#resource{virtual_host = <<"other-vhost">>}, + Perm, + #{routing_key => <<"services.default.accounts.dummy.notifications">>, + variable_map => #{ + <<"username">> => <<"guest">>, + <<"vhost">> => <<"other-vhost">> + } + } + ) || Perm <- Permissions], + ok. diff --git a/test/unit_SUITE.erl b/test/unit_SUITE.erl index f3fec06cb4..11af196449 100644 --- a/test/unit_SUITE.erl +++ b/test/unit_SUITE.erl @@ -32,6 +32,7 @@ groups() -> [ {parallel_tests, [parallel], [ arguments_parser, + auth_backend_internal_expand_topic_permission, {basic_header_handling, [parallel], [ write_table_with_invalid_existing_type, invalid_existing_headers, @@ -332,7 +333,7 @@ do_decrypt_start_app(Config, Passphrase) -> %% %% We expect a failure *after* the decrypting has been done. try - rabbit:start_apps([rabbit_shovel_test]) + rabbit:start_apps([rabbit_shovel_test], #{rabbit => temporary}) catch _:_ -> ok end, @@ -359,7 +360,7 @@ decrypt_start_app_undefined(Config) -> %% %% We expect a failure during decryption because the passphrase is missing. try - rabbit:start_apps([rabbit_shovel_test]) + rabbit:start_apps([rabbit_shovel_test], #{rabbit => temporary}) catch exit:{bad_configuration, config_entry_decoder} -> ok; _:_ -> exit(unexpected_exception) @@ -379,7 +380,7 @@ decrypt_start_app_wrong_passphrase(Config) -> %% %% We expect a failure during decryption because the passphrase is wrong. try - rabbit:start_apps([rabbit_shovel_test]) + rabbit:start_apps([rabbit_shovel_test], #{rabbit => temporary}) catch exit:{decryption_error,_,_} -> ok; _:_ -> exit(unexpected_exception) @@ -1002,3 +1003,37 @@ listing_plugins_from_multiple_directories(Config) -> exit({wrong_plugins_list, Got}) end, ok. + +auth_backend_internal_expand_topic_permission(_Config) -> + ExpandMap = #{<<"username">> => <<"guest">>, <<"vhost">> => <<"default">>}, + %% simple case + <<"services/default/accounts/guest/notifications">> = + rabbit_auth_backend_internal:expand_topic_permission( + <<"services/{vhost}/accounts/{username}/notifications">>, + ExpandMap + ), + %% replace variable twice + <<"services/default/accounts/default/guest/notifications">> = + rabbit_auth_backend_internal:expand_topic_permission( + <<"services/{vhost}/accounts/{vhost}/{username}/notifications">>, + ExpandMap + ), + %% nothing to replace + <<"services/accounts/notifications">> = + rabbit_auth_backend_internal:expand_topic_permission( + <<"services/accounts/notifications">>, + ExpandMap + ), + %% the expand map isn't defined + <<"services/{vhost}/accounts/{username}/notifications">> = + rabbit_auth_backend_internal:expand_topic_permission( + <<"services/{vhost}/accounts/{username}/notifications">>, + undefined + ), + %% the expand map is empty + <<"services/{vhost}/accounts/{username}/notifications">> = + rabbit_auth_backend_internal:expand_topic_permission( + <<"services/{vhost}/accounts/{username}/notifications">>, + #{} + ), + ok. diff --git a/test/unit_inbroker_parallel_SUITE.erl b/test/unit_inbroker_parallel_SUITE.erl index f9cfd58eaa..453f4b2e72 100644 --- a/test/unit_inbroker_parallel_SUITE.erl +++ b/test/unit_inbroker_parallel_SUITE.erl @@ -146,7 +146,7 @@ on_disk_stop(Pid) -> end. queue_name(Config, Name) -> - Name1 = rabbit_ct_helpers:config_to_testcase_name(Config, Name), + Name1 = iolist_to_binary(rabbit_ct_helpers:config_to_testcase_name(Config, Name)), queue_name(Name1). queue_name(Name) -> @@ -337,26 +337,6 @@ override_group_leader() -> {group_leader, Leader} = erlang:process_info(whereis(rabbit), group_leader), erlang:group_leader(Leader, self()). -empty_files(Files) -> - [case file:read_file_info(File) of - {ok, FInfo} -> FInfo#file_info.size == 0; - Error -> Error - end || File <- Files]. - -non_empty_files(Files) -> - [case EmptyFile of - {error, Reason} -> {error, Reason}; - _ -> not(EmptyFile) - end || EmptyFile <- empty_files(Files)]. - -test_logs_working(MainLogFile, SaslLogFile) -> - ok = rabbit_log:error("Log a test message~n"), - ok = error_logger:error_report(crash_report, [fake_crash_report, ?MODULE]), - %% give the error loggers some time to catch up - timer:sleep(100), - [true, true] = non_empty_files([MainLogFile, SaslLogFile]), - ok. - set_permissions(Path, Mode) -> case file:read_file_info(Path) of {ok, FInfo} -> file:write_file_info( |
