| 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | generateCert () { |
| 5 | openssl genrsa -out server.key 2048 |
| 6 | openssl req -new -key server.key -out server.csr -subj "/C=XX/CN=bonsai.test" |
| 7 | openssl x509 -req -days 500 -in server.csr -CA ./tests/testenv/certs/cacert.pem -CAkey ./tests/testenv/certs/cacert.key -CAcreateserial -out server.pem -sha256 |
| 8 | echo "Server cert is generated..." |
| 9 | |
| 10 | mkdir -p /usr/local/var/openldap-certs |
| 11 | |
| 12 | cp ./tests/testenv/certs/cacert.pem /usr/local/var/openldap-certs/ |
| 13 | mv server.key /usr/local/var/openldap-certs/ |
| 14 | mv server.pem /usr/local/var/openldap-certs/ |
| 15 | echo "Moved certs..." |
| 16 | } |
| 17 | |
| 18 | setLDAP () { |
| 19 | sudo /usr/local/opt/openldap/libexec/slapd -h "ldap:// ldapi:// ldaps://" |
| 20 | sleep 4 |
| 21 | echo "Slapd is started..." |
| 22 | ps aux | grep slapd |
| 23 | # Change jpeg file path. |
| 24 | sed -i.bak "s|/home/ldap/test.jpeg|$TRAVIS_BUILD_DIR/tests/testenv/test.jpeg|g" ./tests/testenv/ldifs/base.ldif |
| 25 | # Create base entry and populate the dictionary. |
| 26 | ldapadd -x -D "cn=admin,dc=bonsai,dc=test" -w p@ssword -H ldap:/// -f ./tests/testenv/ldifs/base.ldif |
| 27 | ldapadd -x -D "cn=admin,dc=bonsai,dc=test" -w p@ssword -H ldap:/// -f ./tests/testenv/ldifs/users.ldif |
| 28 | ldapadd -x -D "cn=admin,dc=bonsai,dc=test" -w p@ssword -H ldap:/// -f ./tests/testenv/ldifs/referrals.ldif |
| 29 | echo "Directory is populated..." |
| 30 | # Set default password policy. |
| 31 | ldapadd -x -D "cn=admin,dc=bonsai,dc=test" -w p@ssword -H ldap:/// -f ./tests/testenv/ldifs/ppolicy.ldif |
| 32 | # Stop the slapd. |
| 33 | sudo kill $(ps aux | grep /usr/local/opt/openldap/libexec/slapd | grep -v grep | awk '{print $2}') |
| 34 | echo "Slapd is stopped..." |
| 35 | } |
| 36 | |
| 37 | #Set passsword for SASL DIGEST-MD5. |
| 38 | setDigest () { |
| 39 | echo "p@ssword" | sudo /usr/local/opt/cyrussasl/sbin/saslpasswd2 -p -c admin |
| 40 | echo "p@ssword" | sudo /usr/local/opt/cyrussasl/sbin/saslpasswd2 -p -c chuck |
| 41 | echo "Passwords are set..." |
| 42 | } |
| 43 | |
| 44 | generateCert |
| 45 | setDigest |
| 46 | setLDAP |