1111-include_lib (" common_test/include/ct.hrl" ).
1212-include_lib (" eunit/include/eunit.hrl" ).
1313-include_lib (" amqp_client/include/amqp_client.hrl" ).
14-
15- -define (ALICE_NAME , " Alice" ).
16- -define (BOB_NAME , " Bob" ).
17- -define (CAROL_NAME , " Carol" ).
18- -define (PETER_NAME , " Peter" ).
19- -define (JIMMY_NAME , " Jimmy" ).
20-
21- -define (VHOST , " test" ).
22-
23- -define (ALICE , # amqp_params_network {username = <<? ALICE_NAME >>,
24- password = <<" password" >>,
25- virtual_host = <<? VHOST >>}).
26-
27- -define (BOB , # amqp_params_network {username = <<? BOB_NAME >>,
28- password = <<" password" >>,
29- virtual_host = <<? VHOST >>}).
30-
31- -define (CAROL , # amqp_params_network {username = <<? CAROL_NAME >>,
32- password = <<" password" >>,
33- virtual_host = <<? VHOST >>}).
34-
35- -define (PETER , # amqp_params_network {username = <<? PETER_NAME >>,
36- password = <<" password" >>,
37- virtual_host = <<? VHOST >>}).
38-
39- -define (JIMMY , # amqp_params_network {username = <<? JIMMY_NAME >>,
40- password = <<" password" >>,
41- virtual_host = <<? VHOST >>}).
42-
43- -define (BASE_CONF_RABBIT , {rabbit , [{default_vhost , <<" test" >>}]}).
44-
45- base_conf_ldap (LdapPort , IdleTimeout , PoolSize ) ->
46- {rabbitmq_auth_backend_ldap , [{servers , [" localhost" ]},
47- {user_dn_pattern , " cn=${username},ou=People,dc=rabbitmq,dc=com" },
48- {other_bind , anon },
49- {use_ssl , false },
50- {port , LdapPort },
51- {idle_timeout , IdleTimeout },
52- {pool_size , PoolSize },
53- {log , true },
54- {group_lookup_base , " ou=groups,dc=rabbitmq,dc=com" },
55- {vhost_access_query , vhost_access_query_base ()},
56- {resource_access_query ,
57- {for , [{resource , exchange ,
58- {for , [{permission , configure ,
59- {in_group , " cn=wheel,ou=groups,dc=rabbitmq,dc=com" }
60- },
61- {permission , write , {constant , true }},
62- {permission , read ,
63- {match , {string , " ${name}" },
64- {string , " ^xch-${username}-.*" }}
65- }
66- ]}},
67- {resource , queue ,
68- {for , [{permission , configure ,
69- {match , {attribute , " ${user_dn}" , " description" },
70- {string , " can-declare-queues" }}
71- },
72- {permission , write , {constant , true }},
73- {permission , read ,
74- {'or' ,
75- [{'and' ,
76- [{equals , " ${name}" , " test1" },
77- {equals , " ${username}" , " Alice" }]},
78- {'and' ,
79- [{equals , " ${name}" , " test2" },
80- {'not' , {equals , " ${username}" , " Bob" }}]}
81- ]}}
82- ]}}
83- ]}},
84- {topic_access_query , topic_access_query_base ()},
85- {tag_queries , [{monitor , {constant , true }},
86- {administrator , {constant , false }},
87- {management , {constant , false }}]}
88- ]}.
89-
90- % %--------------------------------------------------------------------
14+ -include_lib (" rabbitmq_ct_helpers/include/rabbit_mgmt_test.hrl" ).
15+ -include_lib (" rabbitmq_ct_helpers/include/rabbit_ldap_test.hrl" ).
9116
9217all () ->
9318 [
@@ -127,70 +52,16 @@ suite() ->
12752
12853init_per_suite (Config ) ->
12954 rabbit_ct_helpers :log_environment (),
130- rabbit_ct_helpers :run_setup_steps (Config , [fun init_slapd /1 ]).
55+ rabbit_ct_helpers :run_setup_steps (Config , [fun rabbit_ct_ldap_utils : init_slapd /1 ]).
13156
13257end_per_suite (Config ) ->
133- rabbit_ct_helpers :run_teardown_steps (Config , [fun stop_slapd /1 ]).
58+ rabbit_ct_helpers :run_teardown_steps (Config , [fun rabbit_ct_ldap_utils : stop_slapd /1 ]).
13459
13560init_per_group (Group , Config ) ->
136- Config1 = rabbit_ct_helpers :set_config (Config , [
137- {rmq_nodename_suffix , Group }
138- ]),
139- LdapPort = ? config (ldap_port , Config ),
140- Config2 = rabbit_ct_helpers :merge_app_env (Config1 , ? BASE_CONF_RABBIT ),
141- Config3 = rabbit_ct_helpers :merge_app_env (Config2 ,
142- base_conf_ldap (LdapPort ,
143- idle_timeout (Group ),
144- pool_size (Group ))),
145- rabbit_ldap_seed :seed ({" localhost" , LdapPort }),
146- Config4 = rabbit_ct_helpers :set_config (Config3 , {ldap_port , LdapPort }),
147-
148- rabbit_ct_helpers :run_steps (Config4 ,
149- rabbit_ct_broker_helpers :setup_steps () ++
150- rabbit_ct_client_helpers :setup_steps ()).
151-
152- end_per_group (_ , Config ) ->
153- rabbit_ldap_seed :delete ({" localhost" , ? config (ldap_port , Config )}),
154- rabbit_ct_helpers :run_steps (Config ,
155- rabbit_ct_client_helpers :teardown_steps () ++
156- rabbit_ct_broker_helpers :teardown_steps ()).
157-
158- init_slapd (Config ) ->
159- DataDir = ? config (data_dir , Config ),
160- PrivDir = ? config (priv_dir , Config ),
161- TcpPort = 25389 ,
162- SlapdDir = filename :join ([PrivDir , " openldap" ]),
163- InitSlapd = filename :join ([DataDir , " init-slapd.sh" ]),
164- Cmd = [InitSlapd , SlapdDir , {" ~b " , [TcpPort ]}],
165- case rabbit_ct_helpers :exec (Cmd ) of
166- {ok , Stdout } ->
167- {match , [SlapdPid ]} = re :run (
168- Stdout ,
169- " ^SLAPD_PID=([0-9]+)$" ,
170- [{capture , all_but_first , list },
171- multiline ]),
172- ct :pal (? LOW_IMPORTANCE ,
173- " slapd(8) PID: ~ts~n slapd(8) listening on: ~b " ,
174- [SlapdPid , TcpPort ]),
175- rabbit_ct_helpers :set_config (Config ,
176- [{slapd_pid , SlapdPid },
177- {ldap_port , TcpPort }]);
178- _ ->
179- _ = rabbit_ct_helpers :exec ([" pkill" , " -INT" , " slapd" ]),
180- {skip , " Failed to initialize slapd(8)" }
181- end .
182-
183- stop_slapd (Config ) ->
184- SlapdPid = ? config (slapd_pid , Config ),
185- Cmd = [" kill" , " -INT" , SlapdPid ],
186- _ = rabbit_ct_helpers :exec (Cmd ),
187- Config .
61+ rabbit_ct_ldap_utils :init_per_group (Group , Config ).
18862
189- idle_timeout (with_idle_timeout ) -> 2000 ;
190- idle_timeout (non_parallel_tests ) -> infinity .
191-
192- pool_size (with_idle_timeout ) -> 1 ;
193- pool_size (non_parallel_tests ) -> 10 .
63+ end_per_group (Group , Config ) ->
64+ rabbit_ct_ldap_utils :end_per_group (Group , Config ).
19465
19566init_internal (Config ) ->
19667 ok = control_action (Config , add_user , [? ALICE_NAME , " " ]),
@@ -206,6 +77,7 @@ end_internal(Config) ->
20677 ok = control_action (Config , delete_user , [? BOB_NAME ]),
20778 ok = control_action (Config , delete_user , [? PETER_NAME ]).
20879
80+
20981init_per_testcase (Testcase , Config )
21082 when Testcase == ldap_and_internal ;
21183 Testcase == internal_followed_ldap_and_internal ->
@@ -265,6 +137,11 @@ end_per_testcase(Testcase, Config)
265137end_per_testcase (Testcase , Config ) ->
266138 rabbit_ct_helpers :testcase_finished (Config , Testcase ).
267139
140+ idle_timeout (Arg ) ->
141+ rabbit_ct_ldap_utils :idle_timeout (Arg ).
142+
143+ pool_size (Arg ) ->
144+ rabbit_ct_ldap_utils :pool_size (Arg ).
268145
269146% % -------------------------------------------------------------------
270147% % Testsuite cases
@@ -688,10 +565,7 @@ vhost_access_query_nested_groups_env() ->
688565 [{vhost_access_query , {in_group_nested , " cn=admins,ou=groups,dc=rabbitmq,dc=com" }}].
689566
690567vhost_access_query_base_env () ->
691- [{vhost_access_query , vhost_access_query_base ()}].
692-
693- vhost_access_query_base () ->
694- {exists , " ou=${vhost},ou=vhosts,dc=rabbitmq,dc=com" }.
568+ [{vhost_access_query , rabbit_ct_ldap_utils :vhost_access_query_base ()}].
695569
696570resource_access_query_match_gh_100 () ->
697571 [{resource_access_query ,
@@ -724,10 +598,7 @@ resource_access_query_match_query_and_re_query_are_strings() ->
724598 }].
725599
726600topic_access_query_base_env () ->
727- [{topic_access_query , topic_access_query_base ()}].
728-
729- topic_access_query_base () ->
730- {constant , true }.
601+ [{topic_access_query , rabbit_ct_ldap_utils :topic_access_query_base ()}].
731602
732603test_login (Config , {N , Env }, Login , FilterList , ResultFun ) ->
733604 case lists :member (N , FilterList ) of
0 commit comments