From a652b0d8c59909523b5bf6e89ec20bedf7d42d8d Mon Sep 17 00:00:00 2001 From: cytopia Date: Sat, 15 Dec 2018 22:22:21 +0100 Subject: [PATCH] Create CI tests for Adminer and phpMyAdmin --- .tests/intra-tests/vendor-adminer.sh | 144 ++++++++++++++++++++++++ .tests/intra-tests/vendor-phpmyadmin.sh | 61 ++++++++++ 2 files changed, 205 insertions(+) create mode 100755 .tests/intra-tests/vendor-adminer.sh create mode 100755 .tests/intra-tests/vendor-phpmyadmin.sh diff --git a/.tests/intra-tests/vendor-adminer.sh b/.tests/intra-tests/vendor-adminer.sh new file mode 100755 index 00000000..9ee02783 --- /dev/null +++ b/.tests/intra-tests/vendor-adminer.sh @@ -0,0 +1,144 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + +### +### Retrieve URL for current Adminer version. +### + +printf "[TEST] Retrieve Adminer URL" +# 1st Try +if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then + # 2nd Try + sleep 1 + if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then + # 3rd Try + sleep 1 + if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" )"; then + printf "\r[FAILED] Retrieve Adminer URL\n" + curl -sS localhost/index.php | grep -Eo "/vendor/adminer-[.0-9]+-en\.php" || true + exit 1 + else + printf "\r[OK] Retrieve Adminer URL (3 rounds): ${URL}\n" + fi + else + printf "\r[OK] Retrieve Adminer URL (2 rounds): ${URL}\n" + fi +else + printf "\r[OK] Retrieve Adminer URL (1 round): ${URL}\n" +fi + + +### +### Ensure given Adminer version works +### + +printf "[TEST] Fetch ${URL}" +# 1st Try +if ! curl -sS localhost${URL} | grep -Eiq "Login.+Adminer"; then + # 2nd Try + sleep 1 + if ! curl -sS localhost${URL} | grep -Eiq "Login.+Adminer"; then + # 3rd Try + sleep 1 + if ! curl -sS localhost${URL} | grep -Eiq "Login.+Adminer"; then + printf "\r[FAIL] Fetch ${URL}\n" + curl -sS localhost${URL} || true + curl -sSI localhost${URL} || true + exit 1 + else + printf "\r[OK] Fetch ${URL} (3 rounds)\n" + fi + else + printf "\r[OK] Fetch ${URL} (2 rounds)\n" + fi +else + printf "\r[OK] Fetch ${URL} (1 round)\n" +fi + + +### +### Test Adminer MySQL login +### + +printf "[TEST] Adminer MySQL login" +# 1st Try +if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | grep -Eiq "Database.+Collation.+Tables"; then + # 2nd Try + sleep 1 + if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | grep -Eiq "Database.+Collation.+Tables"; then + # 3rd Try + sleep 1 + if ! curl -sS "localhost${URL}?server=127.0.0.1&username=root" | grep -Eiq "Database.+Collation.+Tables"; then + printf "\r[FAIL] Adminer MySQL login\n" + curl -sS "localhost${URL}?server=127.0.0.1&username=root" || true + curl -sSI "localhost${URL}?server=127.0.0.1&username=root" || true + exit 1 + else + printf "\r[OK] Adminer MySQL login (3 rounds)\n" + fi + else + printf "\r[OK] Adminer MySQL login (2 rounds)\n" + fi +else + printf "\r[OK] Adminer MySQL login (1 round)\n" +fi + + +### +### Test Adminer PostgreSQL login +### + +printf "[TEST] Adminer PgSQL login" +# 1st Try +if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | grep -Eiq "Database.+Collation.+Tables"; then + # 2nd Try + sleep 1 + if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | grep -Eiq "Database.+Collation.+Tables"; then + # 3rd Try + sleep 1 + if ! curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" | grep -Eiq "Database.+Collation.+Tables"; then + printf "\r[FAIL] Adminer PgSQL login\n" + curl -sS "localhost${URL}?pgsql=127.0.0.1&username=postgres" || true + curl -sSI "localhost${URL}?pgsql=127.0.0.1&username=postgres" || true + exit 1 + else + printf "\r[OK] Adminer PgSQL login (3 rounds)\n" + fi + else + printf "\r[OK] Adminer PgSQL login (2 rounds)\n" + fi +else + printf "\r[OK] Adminer PgSQL login (1 round)\n" +fi + + +### +### Test Adminer MongoDB login +### + +printf "[TEST] Adminer Mongo login" +# 1st Try +if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | grep -Eiq "Database.+Collation.+Tables"; then + # 2nd Try + sleep 1 + if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | grep -Eiq "Database.+Collation.+Tables"; then + # 3rd Try + sleep 1 + if ! curl -sS "localhost${URL}?mongo=127.0.0.1&username=" | grep -Eiq "Database.+Collation.+Tables"; then + printf "\r[FAIL] Adminer Mongo login\n" + curl -sS "localhost${URL}?mongo=127.0.0.1&username=" || true + curl -sSI "localhost${URL}?mongo=127.0.0.1&username=" || true + exit 1 + else + printf "\r[OK] Adminer Mongo login (3 rounds)\n" + fi + else + printf "\r[OK] Adminer Mongo login (2 rounds)\n" + fi +else + printf "\r[OK] Adminer Mongo login (1 round)\n" +fi diff --git a/.tests/intra-tests/vendor-phpmyadmin.sh b/.tests/intra-tests/vendor-phpmyadmin.sh new file mode 100755 index 00000000..33b14caf --- /dev/null +++ b/.tests/intra-tests/vendor-phpmyadmin.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + +### +### Retrieve URL for current PHP version. +### Older PHP versions are presented a link with a different version due to compatibility. +### + +printf "[TEST] Retrieve phpMyAdmin URL" +# 1st Try +if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/phpmyadmin-[.0-9]+/index\.php" )"; then + # 2nd Try + sleep 1 + if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/phpmyadmin-[.0-9]+/index\.php" )"; then + # 3rd Try + sleep 1 + if ! URL="$( curl -sS localhost/index.php | grep -Eo "/vendor/phpmyadmin-[.0-9]+/index\.php" )"; then + printf "\r[FAILED] Retrieve phpMyAdmin URL\n" + curl -sS localhost/index.php | grep -Eo "/vendor/phpmyadmin-[.0-9]+/index\.php" || true + exit 1 + else + printf "\r[OK] Retrieve phpMyAdmin URL (3 rounds): ${URL}\n" + fi + else + printf "\r[OK] Retrieve phpMyAdmin URL (2 rounds): ${URL}\n" + fi +else + printf "\r[OK] Retrieve phpMyAdmin URL (1 round): ${URL}\n" +fi + + +### +### Ensure given phpMyAdmin version works +### + +printf "[TEST] Fetch ${URL}" +# 1st Try +if ! curl -sS localhost${URL} | grep -Eiq "welcome to.+phpMyAdmin"; then + # 2nd Try + sleep 1 + if ! curl -sS localhost${URL} | grep -Eiq "welcome to.+phpMyAdmin"; then + # 3rd Try + sleep 1 + if ! curl -sS localhost${URL} | grep -Eiq "welcome to.+phpMyAdmin"; then + printf "\r[FAIL] Fetch ${URL}\n" + curl -sS localhost/${URL} || true + curl -sSI localhost/${URL} || true + exit 1 + else + printf "\r[OK] Fetch ${URL} (3 rounds)\n" + fi + else + printf "\r[OK] Fetch ${URL} (2 rounds)\n" + fi +else + printf "\r[OK] Fetch ${URL} (1 round)\n" +fi