From 33112b94b0bdc67ffc21f52ccfa212838211a577 Mon Sep 17 00:00:00 2001
From: Matthias Piepkorn <mpiepk@gmail.com>
Date: Wed, 26 Jul 2017 17:04:10 +0000
Subject: [PATCH] extend integration tests (fixes #5)

---
 .travis.yml              |    2 +-
 integrationTest/suite.sh |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 606b213..02ef05d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@
     docker exec -t keycloak /opt/jboss/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080/auth --realm master --user admin --password admin &&
     docker exec -t keycloak /opt/jboss/keycloak/bin/kcadm.sh create clients -r master -s clientId=test -s protocol=cas -s enabled=true -s publicClient=true -s 'redirectUris=["http://localhost/*"]' -s baseUrl=http://localhost -s adminUrl=http://localhost &&
     docker exec -t keycloak /opt/jboss/keycloak/bin/kcadm.sh get serverinfo -r master --fields "providers(login-protocol(providers(cas)))" | grep cas &&
-    curl --fail http://localhost:8080/auth/realms/master/protocol/cas/login?service=http://localhost
+    integrationTest/suite.sh
 
 before_deploy:
   - "mvn -DskipTests package"
diff --git a/integrationTest/suite.sh b/integrationTest/suite.sh
new file mode 100755
index 0000000..35d9f00
--- /dev/null
+++ b/integrationTest/suite.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+set -e
+
+action_pattern='action="([^"]+)"'
+ticket_pattern='Location: .*\?ticket=(ST-[-A-Za-z0-9_.=]+)'
+
+get_ticket() {
+    login_response=$(curl --fail --silent -c /tmp/cookies http://localhost:8080/auth/realms/master/protocol/cas/login?service=http://localhost)
+    if [[ !($login_response =~ $action_pattern) ]] ; then
+        echo "Could not parse login form in response"
+        echo $login_response
+        exit 1
+    fi
+
+    login_url=${BASH_REMATCH[1]}
+    redirect_response=$(curl --fail --silent -D - -b /tmp/cookies --data 'username=admin&password=admin' "$login_url")
+    if [[ !($redirect_response =~ $ticket_pattern) ]] ; then
+        echo "No service ticket found in response"
+        echo $redirect_response
+        exit 1
+    fi
+
+    ticket=${BASH_REMATCH[1]}
+    echo $ticket
+}
+
+get_ticket
+curl --fail --silent "http://localhost:8080/auth/realms/master/protocol/cas/validate?service=http://localhost&ticket=$ticket"
+echo
+
+get_ticket
+curl --fail --silent "http://localhost:8080/auth/realms/master/protocol/cas/serviceValidate?service=http://localhost&format=XML&ticket=$ticket"
+echo
+
+get_ticket
+curl --fail --silent "http://localhost:8080/auth/realms/master/protocol/cas/serviceValidate?service=http://localhost&format=JSON&ticket=$ticket"
+echo
+
+get_ticket
+curl --fail --silent "http://localhost:8080/auth/realms/master/protocol/cas/p3/serviceValidate?service=http://localhost&format=JSON&ticket=$ticket"
+echo

--
Gitblit v1.9.1