11
11
-include_lib (" common_test/include/ct.hrl" ).
12
12
-include_lib (" eunit/include/eunit.hrl" ).
13
13
-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" ).
91
16
92
17
all () ->
93
18
[
@@ -127,70 +52,16 @@ suite() ->
127
52
128
53
init_per_suite (Config ) ->
129
54
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 ]).
131
56
132
57
end_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 ]).
134
59
135
60
init_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 ).
188
62
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 ).
194
65
195
66
init_internal (Config ) ->
196
67
ok = control_action (Config , add_user , [? ALICE_NAME , " " ]),
@@ -206,6 +77,7 @@ end_internal(Config) ->
206
77
ok = control_action (Config , delete_user , [? BOB_NAME ]),
207
78
ok = control_action (Config , delete_user , [? PETER_NAME ]).
208
79
80
+
209
81
init_per_testcase (Testcase , Config )
210
82
when Testcase == ldap_and_internal ;
211
83
Testcase == internal_followed_ldap_and_internal ->
@@ -265,6 +137,11 @@ end_per_testcase(Testcase, Config)
265
137
end_per_testcase (Testcase , Config ) ->
266
138
rabbit_ct_helpers :testcase_finished (Config , Testcase ).
267
139
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 ).
268
145
269
146
% % -------------------------------------------------------------------
270
147
% % Testsuite cases
@@ -688,10 +565,7 @@ vhost_access_query_nested_groups_env() ->
688
565
[{vhost_access_query , {in_group_nested , " cn=admins,ou=groups,dc=rabbitmq,dc=com" }}].
689
566
690
567
vhost_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 ()}].
695
569
696
570
resource_access_query_match_gh_100 () ->
697
571
[{resource_access_query ,
@@ -724,10 +598,7 @@ resource_access_query_match_query_and_re_query_are_strings() ->
724
598
}].
725
599
726
600
topic_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 ()}].
731
602
732
603
test_login (Config , {N , Env }, Login , FilterList , ResultFun ) ->
733
604
case lists :member (N , FilterList ) of
0 commit comments