Skip to content

Commit 546eacc

Browse files
committed
Improve the test suite and add a test case
1 parent de7859b commit 546eacc

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed

docker/tests/data/email6.ldiff

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
dn: mail=elon@caldin.eu,o=caldin.eu,ou=people,dc=example,dc=org
2+
cn: Elon Caldin
3+
givenname: elon
4+
mail: elon@caldin.eu
5+
mailalias: elon.caldin@caldin.eu
6+
mailalias: musk@caldin.de
7+
mailenabled: TRUE
8+
mailgidnumber: 5000
9+
mailhomedirectory: /var/mail/caldin.eu/elon/
10+
mailstoragedirectory: maildir:/var/mail/caldin.eu/elon/
11+
mailuidnumber: 5000
12+
objectclass: inetOrgPerson
13+
objectclass: top
14+
objectclass: PostfixBookMailAccount
15+
sn: Caldin
16+
uid: elon
17+
userpassword: {SSHA}GA1/ggm6DAJ2AyJzJqAZsLS7YbsKklVm

docker/tests/run.sh

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,36 @@
44
# @author William Desportes <williamdes@wdes.fr>
55
##
66

7-
set -eux
7+
seedFile() {
8+
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < "/tests/data/$1.ldiff"
9+
}
810

9-
ldapwhoami -H ldap://openldap -D cn=admin,dc=example,dc=org -w "admin"
10-
ldapwhoami -H ldap://openldap -D cn=config -w "config"
11-
ldapwhoami -H ldap://openldap -D cn=monitor -w "monitor"
12-
13-
echo 'Seeding org'
14-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/org.ldiff
11+
seedEmail() {
12+
echo "Seeding email: $1"
13+
seedFile "$1"
14+
}
1515

16-
echo 'Seeding email 1'
17-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/email1.ldiff
16+
seedOrg() {
17+
echo "Seeding org: $1"
18+
seedFile "$1"
19+
}
1820

19-
echo 'Seeding email 2'
20-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/email2.ldiff
21+
set -eu
2122

22-
echo 'Seeding org for email 3'
23-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/org-email3.ldiff
24-
25-
echo 'Seeding email 3'
26-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/email3.ldiff
27-
28-
echo 'Seeding email 4'
29-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/email4.ldiff
23+
ldapwhoami -H ldap://openldap -D cn=admin,dc=example,dc=org -w "admin"
24+
ldapwhoami -H ldap://openldap -D cn=config -w "config"
25+
ldapwhoami -H ldap://openldap -D cn=monitor -w "monitor"
3026

31-
echo 'Seeding org for email 5'
32-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/org-email5.ldiff
27+
seedOrg org
28+
seedOrg org-email3
29+
seedOrg org-email5
3330

34-
echo 'Seeding email 5'
35-
ldapadd -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin < /tests/data/email5.ldiff
31+
seedEmail email1
32+
seedEmail email2
33+
seedEmail email3
34+
seedEmail email4
35+
seedEmail email5
36+
seedEmail email6
3637

3738
echo 'Print results'
3839
ldapsearch -LLL -H ldap://openldap -D "cn=admin,dc=example,dc=org" -w admin -b "ou=people,dc=example,dc=org" '*'
@@ -46,6 +47,26 @@ ldapsearch -LLL -x -H ldap://openldap -b "" -s base supportedSASLMechanisms
4647

4748
echo 'Login as email 1'
4849
ldapwhoami -H ldap://openldap -D "cn=John Pondu,ou=people,dc=example,dc=org" -w 'JohnPassWord!645987zefdm'
50+
echo 'Login as email 1 bad password'
51+
ldapwhoami -H ldap://openldap -D "cn=Pondu John,ou=people,dc=example,dc=org" -w 'JohnPassWord!s645987zefdm' && ret=$? || ret=$?
52+
if [ $ret -ne 49 ]; then
53+
echo "Login should not work as the CN is wrong ($ret)"
54+
exit 1
55+
fi
56+
57+
echo 'Login as email 1 no password'
58+
ldapwhoami -H ldap://openldap -D "cn=John Pondu,ou=people,dc=example,dc=org" && ret=$? || ret=$?
59+
if [ $ret -ne 53 ]; then
60+
echo "Login should not work as the password is missing ($ret)"
61+
exit 1
62+
fi
63+
64+
echo 'Login as email 1 bad password'
65+
ldapwhoami -H ldap://openldap -D "cn=John Pondu,ou=people,dc=example,dc=org" -w 'JohnPassWord!s645987zefdm' && ret=$? || ret=$?
66+
if [ $ret -ne 49 ]; then
67+
echo "Login should not work as the password is wrong ($ret)"
68+
exit 1
69+
fi
4970

5071
echo 'Login as email 2'
5172
ldapwhoami -H ldap://openldap -D "cn=Cyrielle Pondu,ou=people,dc=example,dc=org" -w 'PassCyrielle!ILoveDogs'
@@ -63,4 +84,22 @@ echo -e "\tUsing simple auth"
6384
ldapwhoami -H ldap://openldap -D "mail=edwin@warz.eu,o=warz.eu,ou=people,dc=example,dc=org" -w 'oHHGf7YyJSihb6ifSwNWZPtEGzijjp8'
6485

6586
echo 'Login as email 5'
87+
echo -e "\tUsing simple auth"
6688
ldapwhoami -H ldap://openldap -D "mail=elana@caldin.eu,o=caldin.eu,ou=people,dc=example,dc=org" -w 'bandedetsylish'
89+
echo -e "\tUsing SASL auth"
90+
ldapwhoami -Q -H ldap://openldap -U elana@caldin.eu -w 'bandedetsylish' && ret=$? || ret=$?
91+
if [ $ret -ne 49 ]; then
92+
echo "Login can not work because the password is not usable for SASL and SRP secret is not set ($ret)"
93+
exit 1
94+
fi
95+
96+
echo 'Login as email 6'
97+
echo -e "\tUsing SASL auth"
98+
ldapwhoami -Q -H ldap://openldap -U elon@caldin.eu -w 'HVxmD6ejZ9nUX6MSnQUvqKui5YYG56P' && ret=$? || ret=$?
99+
if [ $ret -ne 49 ]; then
100+
echo "Login should not work for clear text passwords in the DB ($ret)"
101+
exit 1
102+
fi
103+
104+
echo -e "\tUsing simple auth"
105+
ldapwhoami -H ldap://openldap -D "mail=elon@caldin.eu,o=caldin.eu,ou=people,dc=example,dc=org" -w 'HVxmD6ejZ9nUX6MSnQUvqKui5YYG56P'

0 commit comments

Comments
 (0)