Permalink
Browse files

Tidied up tests to actually assert values and be simpler

  • Loading branch information...
jborean93 committed Jun 11, 2017
1 parent d508f75 commit f36bd10988de512bb485f007f9a781a6f34aaa11
Showing with 78 additions and 514 deletions.
  1. +15 −13 .travis.sh
  2. +1 −0 requirements-test.txt
  3. +0 −338 test.py
  4. +62 −163 tests/test_kerberos.py
View
@@ -1,12 +1,14 @@
#!/bin/bash
export KERBEROS_HOSTNAME=$(cat /etc/hostname)
export DEBIAN_FRONTEND=noninteractive
IP_ADDRESS=$(hostname -I)
HOSTNAME=$(cat /etc/hostname)
export KERBEROS_HOSTNAME=$HOSTNAME.$KERBEROS_REALM
export DEBIAN_FRONTEND=noninteractive
echo "Configure the hosts file for Kerberos to work in a container"
cp /etc/hosts ~/hosts.new
sed -i "/.*$KERBEROS_HOSTNAME/c\\$IP_ADDRESS\t$KERBEROS_HOSTNAME.$KERBEROS_REALM" ~/hosts.new
sed -i "/.*$HOSTNAME/c\\$IP_ADDRESS\t$KERBEROS_HOSTNAME" ~/hosts.new
cp -f ~/hosts.new /etc/hosts
echo "Setting up Kerberos config file at /etc/krb5.conf"
@@ -18,8 +20,8 @@ cat > /etc/krb5.conf << EOL
[realms]
${KERBEROS_REALM^^} = {
kdc = $KERBEROS_HOSTNAME.$KERBEROS_REALM
admin_server = $KERBEROS_HOSTNAME.$KERBEROS_REALM
kdc = $KERBEROS_HOSTNAME
admin_server = $KERBEROS_HOSTNAME
}
[domain_realm]
@@ -61,22 +63,22 @@ echo "Creating principals for tests"
kadmin.local -q "addprinc -pw $KERBEROS_PASSWORD $KERBEROS_USERNAME"
echo "Adding principal for Kerberos auth and creating keytabs"
kadmin.local -q "addprinc -randkey HTTP/$KERBEROS_HOSTNAME.$KERBEROS_REALM"
kadmin.local -q "addprinc -randkey host/$KERBEROS_HOSTNAME.$KERBEROS_REALM@${KERBEROS_REALM^^}"
kadmin.local -q "addprinc -randkey HTTP/$KERBEROS_HOSTNAME"
kadmin.local -q "addprinc -randkey host/$KERBEROS_HOSTNAME@${KERBEROS_REALM^^}"
kadmin.local -q "addprinc -randkey host/${KERBEROS_HOSTNAME^^}@${KERBEROS_REALM^^}"
kadmin.local -q "addprinc -randkey ${KERBEROS_HOSTNAME^^}@${KERBEROS_REALM^^}"
kadmin.local -q "ktadd -k /etc/krb5.keytab host/$KERBEROS_HOSTNAME.$KERBEROS_REALM@${KERBEROS_REALM^^}"
kadmin.local -q "ktadd -k /etc/krb5.keytab host/$KERBEROS_HOSTNAME@${KERBEROS_REALM^^}"
kadmin.local -q "ktadd -k /etc/krb5.keytab host/${KERBEROS_HOSTNAME^^}@${KERBEROS_REALM^^}"
kadmin.local -q "ktadd -k /etc/krb5.keytab ${KERBEROS_HOSTNAME^^}@${KERBEROS_REALM^^}"
kadmin.local -q "ktadd -k /etc/krb5.keytab HTTP/$KERBEROS_HOSTNAME.$KERBEROS_REALM"
kadmin.local -q "ktadd -k /etc/krb5.keytab HTTP/$KERBEROS_HOSTNAME"
chmod 777 /etc/krb5.keytab
echo "Restarting Kerberos KDS service"
service krb5-kdc restart
echo "Add ServerName to Apache config"
grep -q -F "ServerName $KERBEROS_HOSTNAME.$KERBEROS_REALM" /etc/apache2/apache2.conf || echo "ServerName $KERBEROS_HOSTNAME.$KERBEROS_REALM" >> /etc/apache2/apache2.conf
grep -q -F "ServerName $KERBEROS_HOSTNAME" /etc/apache2/apache2.conf || echo "ServerName $KERBEROS_HOSTNAME" >> /etc/apache2/apache2.conf
echo "Deleting default virtual host file"
rm /etc/apache2/sites-enabled/000-default.conf
@@ -91,8 +93,8 @@ echo "<html><head><title>Title</title></head><body>body mesage</body></html>" >
echo "Create virtual host files"
cat > /etc/apache2/sites-available/example.com.conf << EOL
<VirtualHost *:$KERBEROS_PORT>
ServerName $KERBEROS_HOSTNAME.$KERBEROS_REALM
ServerAlias $KERBEROS_HOSTNAME.$KERBEROS_REALM
ServerName $KERBEROS_HOSTNAME
ServerAlias $KERBEROS_HOSTNAME
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
@@ -113,7 +115,7 @@ echo "Getting ticket for Kerberos user"
echo -n "$KERBEROS_PASSWORD" | kinit "$KERBEROS_USERNAME@${KERBEROS_REALM^^}"
echo "Try out the curl connection"
CURL_OUTPUT=$(curl --negotiate -u : "http://$KERBEROS_HOSTNAME.$KERBEROS_REALM")
CURL_OUTPUT=$(curl --negotiate -u : "http://$KERBEROS_HOSTNAME")
if [ "$CURL_OUTPUT" != "<html><head><title>Title</title></head><body>body mesage</body></html>" ]; then
echo -e "ERROR: Did not get success message, cannot continue with actual tests:\nActual Output:\n$CURL_OUTPUT"
View
@@ -1 +1,2 @@
pytest
requests
Oops, something went wrong.

0 comments on commit f36bd10

Please sign in to comment.