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
|
#!/bin/bash
set -ue
PATH="/usr/sbin:/sbin:/usr/bin:/bin"
export PATH
for ((i = 0; i < 10; i++)); do
if [ -S "/run/ldapi" ]; then
break
fi
echo "Waiting for slapd ldapi:// socket..."
sleep 1
done
# see tests/HOWTO_SETUP_OPENLDAP_TESTCASE.txt and tests/ldapconfig.ini.dist
SLAPD_ADDRESS="127.0.0.1"
SLAPD_PORT=389
BASEDN="dc=example,dc=com"
ROOTDN="cn=admin,$BASEDN"
ROOTPW="test"
DBDIR="$(mktemp --tmpdir="$AUTOPKGTEST_TMP" --directory ldap.XXXXXXXXXX)"
openssl genrsa -out "$AUTOPKGTEST_TMP/ldap.key"
openssl req -x509 \
-key "$AUTOPKGTEST_TMP/ldap.key" \
-subj "/CN=localhost" \
-addext "subjectAltName=IP:$SLAPD_ADDRESS" \
-out "$AUTOPKGTEST_TMP/ldap.pem"
chown openldap: -- "$DBDIR" "$AUTOPKGTEST_TMP/ldap.key"
chmod og-rwx -- "$DBDIR" "$AUTOPKGTEST_TMP/ldap.key"
# configure certificates for STARTTLS
ldapmodify -Y EXTERNAL -H ldapi:/// -Q <<-EOF
dn: cn=config
changetype: modify
replace: olcTLSCACertificateFile
olcTLSCACertificateFile: $AUTOPKGTEST_TMP/ldap.pem
-
replace: olcTLSCertificateFile
olcTLSCertificateFile: $AUTOPKGTEST_TMP/ldap.pem
-
replace: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: $AUTOPKGTEST_TMP/ldap.key
EOF
# configure new database with $BASEDN as suffix
ldapadd -Y EXTERNAL -H ldapi:/// -Q <<-EOF
dn: olcDatabase=mdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcMdbConfig
olcDbDirectory: $DBDIR
olcSuffix: $BASEDN
olcAccess: {0}to attrs=userPassword by self write by anonymous auth by * none
olcAccess: {1}to * by * read
olcRootDN: $ROOTDN
olcRootPW: $ROOTPW
olcDbIndex: objectClass eq
olcDbIndex: cn,uid eq
olcDbIndex: uidNumber,gidNumber eq
olcDbIndex: member,memberUid eq
EOF
# populate database with test data
ldapadd -D "$ROOTDN" -w "$ROOTPW" -H ldapi:/// \
-f tests/ldif_data/base.ldif
ldapadd -D "$ROOTDN" -w "$ROOTPW" -H ldapi:/// \
-f tests/ldif_data/INITIAL_TESTDATA.ldif
# dump database (using STARTTLS to make sure that works)
cat >>/etc/ldap/ldap.conf <<-EOF
TLS_CACERT $AUTOPKGTEST_TMP/ldap.pem
TLS_REQCERT hard
EOF
ldapsearch -D "$ROOTDN" -w "$ROOTPW" -H "ldap://$SLAPD_ADDRESS:$SLAPD_PORT/" \
-LLZZ -b "$BASEDN"
# configure the test suite
cp -vfT tests/ldapconfig.ini.dist tests/ldapconfig.ini
sed -ri "s/^(\\s*server_cap_tls)\\s*=.*/\\1 = true/;
s/^(\\s*server_address)\\s*=.*/\\1 = $SLAPD_ADDRESS/;
s/^(\\s*server_port)\\s*=.*/\\1 = $SLAPD_PORT/" \
tests/ldapconfig.ini
cat tests/ldapconfig.ini
# the test suite tries to connect to 0.0.0.1 and 0.0.0.2 in order to
# test the fallback logic, so nullroute these so we don't have to wait
# for the timeout
ip route add blackhole "0.0.0.0/30"
cd ./tests
${AUTOPKGTEST_NORMAL_USER+runuser -u "$AUTOPKGTEST_NORMAL_USER" --} phpunit \
--no-configuration --fail-on-skipped .
|