-
Notifications
You must be signed in to change notification settings - Fork 982
/
Copy pathtest.bats
221 lines (130 loc) Β· 5.89 KB
/
test.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env bats
load test_helper
@test "image build" {
run build_image
[ "$status" -eq 0 ]
}
@test "ldapsearch new database" {
run_image -h ldap.example.org -e LDAP_TLS=false
wait_process slapd
sleep 5
run docker exec $CONTAINER_ID ldapsearch -x -h ldap.example.org -b dc=example,dc=org -D "cn=admin,dc=example,dc=org" -w admin
clear_container
[ "$status" -eq 0 ]
}
@test "ldap domain with non-matching ldap base dn" {
run_image -h ldap.example.org -e LDAP_TLS=false -e LDAP_DOMAIN=example.com -e LDAP_BASE_DN="dc=example,dc=org"
sleep 5
CSTATUS=$(check_container)
clear_container
[ "$CSTATUS" != "running 0" ]
}
@test "ldap domain with matching ldap base dn subdomain" {
run_image -h ldap.example.fr -e LDAP_TLS=false -e LDAP_DOMAIN=example.fr -e LDAP_BASE_DN="ou=myou,o=example,c=fr"
sleep 5
CSTATUS=$(check_container)
clear_container
[ "$CSTATUS" == "running 0" ]
}
@test "ldap base dn domain with matching ldap subdomain" {
run_image -h ldap.example.fr -e LDAP_TLS=false -e LDAP_DOMAIN=mysub.example.fr -e LDAP_BASE_DN="o=example,c=fr"
sleep 5
CSTATUS=$(check_container)
clear_container
[ "$CSTATUS" == "running 0" ]
}
@test "ldap domain with ldap base dn subdomain included" {
run_image -h ldap.example.com -e LDAP_TLS=false -e LDAP_DOMAIN=example.com -e LDAP_BASE_DN="ou=myou,o=example,dc=com,c=fr"
sleep 5
CSTATUS=$(check_container)
clear_container
[ "$CSTATUS" != "running 0" ]
}
@test "ldapsearch database from created volumes" {
rm -rf VOLUMES && mkdir -p VOLUMES/config VOLUMES/database
LDAP_CID=$(docker run -h ldap.example.org -e LDAP_TLS=false --volume $PWD/VOLUMES/database:/var/lib/ldap --volume $PWD/VOLUMES/config:/etc/ldap/slapd.d -d $NAME:$VERSION)
wait_process_by_cid $LDAP_CID slapd
sleep 5
run docker exec $LDAP_CID ldapsearch -x -h ldap.example.org -b dc=example,dc=org -D "cn=admin,dc=example,dc=org" -w admin
docker kill $LDAP_CID
clear_containers_by_cid $LDAP_CID
[ "$status" -eq 0 ]
LDAP_CID=$(docker run -h ldap.example.org -e LDAP_TLS=false --volume $PWD/VOLUMES/database:/var/lib/ldap --volume $PWD/VOLUMES/config:/etc/ldap/slapd.d -d $NAME:$VERSION)
wait_process_by_cid $LDAP_CID slapd
sleep 5
run docker exec $LDAP_CID ldapsearch -x -h ldap.example.org -b dc=example,dc=org -D "cn=admin,dc=example,dc=org" -w admin
docker exec $LDAP_CID chown -R $UID:$UID /var/lib/ldap /etc/ldap/slapd.d
docker kill $LDAP_CID
clear_containers_by_cid $LDAP_CID
rm -rf VOLUMES
[ "$status" -eq 0 ]
}
@test "ldapsearch database with password provided from file" {
echo "strongPassword" > $PWD/password.txt
run_image -h ldap.osixia.net -e LDAP_ADMIN_PASSWORD_FILE=/run/secrets/admin_pw.txt --volume $PWD/password.txt:/run/secrets/admin_pw.txt
wait_process slapd
sleep 5
run docker exec $CONTAINER_ID ldapsearch -x -h ldap.osixia.net -b dc=example,dc=org -ZZ -D "cn=admin,dc=example,dc=org" -w strongPassword
clear_container
rm $PWD/password.txt
[ "$status" -eq 0 ]
}
@test "ldapsearch new database with strict TLS" {
run_image -h ldap.example.org
wait_process slapd
sleep 5
run docker exec $CONTAINER_ID ldapsearch -x -h ldap.example.org -b dc=example,dc=org -ZZ -D "cn=admin,dc=example,dc=org" -w admin
clear_container
[ "$status" -eq 0 ]
}
@test "ldapsearch new database with strict TLS and custom ca/crt" {
run_image -h ldap.osixia.net -v $BATS_TEST_DIRNAME/ssl:/container/service/slapd/assets/certs -e LDAP_TLS_CRT_FILENAME=ldap-test.crt -e LDAP_TLS_KEY_FILENAME=ldap-test.key -e LDAP_TLS_CA_CRT_FILENAME=ca-test.crt
wait_process slapd
sleep 5
run docker exec $CONTAINER_ID ldapsearch -x -h ldap.osixia.net -b dc=example,dc=org -ZZ -D "cn=admin,dc=example,dc=org" -w admin
clear_container
[ "$status" -eq 0 ]
}
@test "ldapsearch new database with strict TLS and custom ca/crt and custom dhparam" {
run_image -h ldap.osixia.net -v $BATS_TEST_DIRNAME/ssl:/container/service/slapd/assets/certs -e LDAP_TLS_CRT_FILENAME=ldap-test.crt -e LDAP_TLS_KEY_FILENAME=ldap-test.key -e LDAP_TLS_DH_PARAM_FILENAME=ldap-test.dhparam -e LDAP_TLS_CA_CRT_FILENAME=ca-test.crt
wait_process slapd
sleep 5
run docker exec $CONTAINER_ID ldapsearch -x -h ldap.osixia.net -b dc=example,dc=org -ZZ -D "cn=admin,dc=example,dc=org" -w admin
clear_container
[ "$status" -eq 0 ]
}
@test "ldapsearch existing hdb database and config" {
run_image -h ldap.example.org -e LDAP_TLS=false -e LDAP_BACKEND=hdb -v $BATS_TEST_DIRNAME/database:/container/test/database -v $BATS_TEST_DIRNAME/config:/container/test/config
wait_process slapd
sleep 5
run docker exec $CONTAINER_ID ldapsearch -x -h ldap.example.org -b dc=osixia,dc=net -D "cn=admin,dc=osixia,dc=net" -w admin
clear_container
[ "$status" -eq 0 ]
}
@test "replication with new databases and strict TLS" {
tmp_file="$BATS_TMPDIR/docker-test"
# replication ldap server
LDAP_REPL_CID=$(docker run -h ldap2.example.org -e LDAP_REPLICATION=true -d $NAME:$VERSION)
LDAP_REPL_IP=$(get_container_ip_by_cid $LDAP_REPL_CID)
sleep 5
# ldap server
run_image -h ldap.example.org -e LDAP_REPLICATION=true
# add route to hosts
docker exec $CONTAINER_ID bash -c "echo $LDAP_REPL_IP ldap2.example.org >> /etc/hosts"
docker exec $LDAP_REPL_CID bash -c "echo $CONTAINER_IP ldap.example.org >> /etc/hosts"
# wait services on both servers
wait_process slapd
wait_process_by_cid $LDAP_REPL_CID slapd
sleep 5
# add user on ldap2.example.org
docker exec $LDAP_REPL_CID ldapadd -x -D "cn=admin,dc=example,dc=org" -w admin -f /container/service/slapd/assets/test/new-user.ldif -h ldap2.example.org -ZZ
sleep 5
# search user on ldap.example.org
docker exec $CONTAINER_ID ldapsearch -x -h ldap.example.org -b dc=example,dc=org -D "cn=admin,dc=example,dc=org" -w admin -ZZ >> $tmp_file
run grep -c "billy" $tmp_file
rm $tmp_file
clear_container
clear_containers_by_cid $LDAP_REPL_CID
[ "$status" -eq 0 ]
[ "$output" = "6" ]
}