From f015462a51ce999c3019c69cd689fe73918b79f6 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Mon, 1 Jul 2019 22:50:21 +0300 Subject: [PATCH] ci(travis): Add e2e smoke testing with Travis CI --- .travis.yml | 9 +++++++++ test.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .travis.yml create mode 100755 test.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8ad3f03 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: bash +services: docker + +script: + - ./install.sh + - docker-compose run --rm web createuser --superuser --email test@sentry.io --password test123TEST + - docker-compose up -d + - timeout 60 bash -c 'until $(curl -Isf -o /dev/null http://localhost:9000); do printf '.'; sleep 0.5; done' + - ./test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..0465ae1 --- /dev/null +++ b/test.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -e + +TEST_USER='test@sentry.io' +TEST_PASS='test123TEST' +COOKIE_FILE=$(mktemp) +declare -a TEST_STRINGS=( + '"isAuthenticated":true,' + '"username":"test@sentry.io",' + '"isSuperuser":true,' +) + +INITIAL_AUTH_REDIRECT=$(curl -sL -o /dev/null http://localhost:9000 -w %{url_effective}) +if [ "$INITIAL_AUTH_REDIRECT" != "http://localhost:9000/auth/login/sentry/" ]; then + echo "Initial /auth/login/ redirect failed, exiting..." + echo "$INITIAL_AUTH_REDIRECT" + exit -1 +fi + +CSRF_TOKEN=$(curl http://localhost:9000 -sL -c "$COOKIE_FILE" | awk -F "'" ' + /csrfmiddlewaretoken/ { + print $4 "=" $6; + exit; + }') +LOGIN_RESPONSE=$(curl -sL -F 'op=login' -F "username=$TEST_USER" -F "password=$TEST_PASS" -F "$CSRF_TOKEN" http://localhost:9000/auth/login/ -H 'Referer: http://localhost/auth/login/' -b "$COOKIE_FILE" -c "$COOKIE_FILE") + +TEST_RESULT=0 +for i in "${TEST_STRINGS[@]}" +do + echo "Testing '$i'..." + echo "$LOGIN_RESPONSE" | grep "$i" >& /dev/null + echo "Pass." +done