From 6f454ad9a07e3b779769c217f1affbedc8b59ea9 Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 11 Feb 2019 17:46:14 +0100 Subject: [PATCH 1/2] Ensure old authentication works with MySQL|Percona 8.0 --- Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Makefile b/Makefile index 3d5661e..a2f0c21 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,14 @@ build-mysql-5.7: docker tag mysql:5.7 $(IMAGE):mysql-5.7 build-mysql-8.0: while ! docker pull mysql:8.0; do sleep 1; done + # Adjust and commit authentication + docker run -it -d --rm -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --name devilbox-mysql-commit mysql:8.0 + docker exec -it devilbox-mysql-commit \ + sed -i'' "s/^symbolic-links.*$$/symbolic-links=0\ndefault-authentication-plugin=mysql_native_password/g" /etc/mysql/my.cnf + docker diff devilbox-mysql-commit + docker commit devilbox-mysql-commit mysql:8.0 + docker stop devilbox-mysql-commit + # /Adjust and commit authentication docker tag mysql:8.0 $(IMAGE):mysql-8.0 test-mysql-5.5: @@ -89,6 +97,15 @@ build-percona-5.7: docker tag percona:5.7 $(IMAGE):percona-5.7 build-percona-8.0: while ! docker pull percona:8.0; do sleep 1; done + # Adjust and commit authentication + docker run -it -d --rm -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --name devilbox-mysql-commit percona:8.0 + docker exec -it --user root devilbox-mysql-commit \ + sed -i'' "s|^pid-file=.*$$|pid-file=/var/run/mysqld/mysqld.pid\ndefault-authentication-plugin=mysql_native_password|g" /etc/my.cnf + #docker exec -it --user root devilbox-mysql-commit rm -rf /var/log/mysql + docker diff devilbox-mysql-commit + docker commit devilbox-mysql-commit percona:8.0 + docker stop devilbox-mysql-commit + # /Adjust and commit authentication docker tag percona:8.0 $(IMAGE):percona-8.0 test-percona-5.5: From 8fd006ee174c81caddda42390eca4c38f5401f06 Mon Sep 17 00:00:00 2001 From: cytopia Date: Mon, 11 Feb 2019 17:46:40 +0100 Subject: [PATCH 2/2] Add regression tests for MySQL authentication --- Makefile | 42 ++++++++++++++++++++++----------- tests/01-version.sh | 25 ++++++++++++++++++++ tests/02-mysqli.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++ tests/mysql.php | 40 +++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 14 deletions(-) create mode 100755 tests/01-version.sh create mode 100755 tests/02-mysqli.sh create mode 100644 tests/mysql.php diff --git a/Makefile b/Makefile index a2f0c21..dcf9202 100644 --- a/Makefile +++ b/Makefile @@ -38,13 +38,17 @@ build-mysql-8.0: docker tag mysql:8.0 $(IMAGE):mysql-8.0 test-mysql-5.5: - docker run --rm -it $(IMAGE):mysql-5.5 -V | grep 'MySQL' | grep '5\.5' + ./tests/01-version.sh "mysql" "5.5" + ./tests/02-mysqli.sh "mysql" "5.5" test-mysql-5.6: - docker run --rm -it $(IMAGE):mysql-5.6 -V | grep 'MySQL' | grep '5\.6' + ./tests/01-version.sh "mysql" "5.6" + ./tests/02-mysqli.sh "mysql" "5.6" test-mysql-5.7: - docker run --rm -it $(IMAGE):mysql-5.7 -V | grep 'MySQL' | grep '5\.7' + ./tests/01-version.sh "mysql" "5.7" + ./tests/02-mysqli.sh "mysql" "5.7" test-mysql-8.0: - docker run --rm -it $(IMAGE):mysql-8.0 -V | grep 'MySQL' | grep '8\.0' + ./tests/01-version.sh "mysql" "8.0" + ./tests/02-mysqli.sh "mysql" "8.0" # ------------------------------------------------------------------------------------------------- @@ -70,17 +74,23 @@ build-mariadb-10.4: docker tag mariadb:10.4 $(IMAGE):mariadb-10.4 test-mariadb-5.5: - docker run --rm -it $(IMAGE):mariadb-5.5 -V | grep 'MariaDB' | grep '5\.5' + ./tests/01-version.sh "mariadb" "5.5" + ./tests/02-mysqli.sh "mariadb" "5.5" test-mariadb-10.0: - docker run --rm -it $(IMAGE):mariadb-10.0 -V | grep 'MariaDB' | grep '10\.0' + ./tests/01-version.sh "mariadb" "10.0" + ./tests/02-mysqli.sh "mariadb" "10.0" test-mariadb-10.1: - docker run --rm -it $(IMAGE):mariadb-10.1 -V | grep 'MariaDB' | grep '10\.1' + ./tests/01-version.sh "mariadb" "10.1" + ./tests/02-mysqli.sh "mariadb" "10.1" test-mariadb-10.2: - docker run --rm -it $(IMAGE):mariadb-10.2 -V | grep 'MariaDB' | grep '10\.2' + ./tests/01-version.sh "mariadb" "10.2" + ./tests/02-mysqli.sh "mariadb" "10.2" test-mariadb-10.3: - docker run --rm -it $(IMAGE):mariadb-10.3 -V | grep 'MariaDB' | grep '10\.3' + ./tests/01-version.sh "mariadb" "10.3" + ./tests/02-mysqli.sh "mariadb" "10.3" test-mariadb-10.4: - docker run --rm -it $(IMAGE):mariadb-10.4 -V | grep 'MariaDB' | grep '10\.4' + ./tests/01-version.sh "mariadb" "10.4" + ./tests/02-mysqli.sh "mariadb" "10.4" # ------------------------------------------------------------------------------------------------- @@ -109,10 +119,14 @@ build-percona-8.0: docker tag percona:8.0 $(IMAGE):percona-8.0 test-percona-5.5: - docker run --rm -it $(IMAGE):percona-5.5 -V | grep 'Percona' | grep '5\.5' + ./tests/01-version.sh "percona" "5.5" + ./tests/02-mysqli.sh "percona" "5.5" test-percona-5.6: - docker run --rm -it $(IMAGE):percona-5.6 -V | grep 'Percona' | grep '5\.6' + ./tests/01-version.sh "percona" "5.6" + ./tests/02-mysqli.sh "percona" "5.6" test-percona-5.7: - docker run --rm -it $(IMAGE):percona-5.7 -V | grep 'Percona' | grep '5\.7' + ./tests/01-version.sh "percona" "5.7" + ./tests/02-mysqli.sh "percona" "5.7" test-percona-8.0: - docker run --rm -it $(IMAGE):percona-8.0 -V | grep 'Percona' | grep '8\.0' + ./tests/01-version.sh "percona" "8.0" + ./tests/02-mysqli.sh "percona" "8.0" diff --git a/tests/01-version.sh b/tests/01-version.sh new file mode 100755 index 0000000..8accabd --- /dev/null +++ b/tests/01-version.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +echo "# --------------------------------------------------------------------------------------------------" +echo "# Testing MySQL server version" +echo "# --------------------------------------------------------------------------------------------------" + +set -e +set -u +set -o pipefail + +IMAGE="devilbox/mysql" +TYPE="${1}" +VERSION="${2}" + + +if [ "${TYPE}" = "mysql" ]; then + docker run --rm -it "${IMAGE}:${TYPE}-${VERSION}" -V | grep 'MySQL' | grep "${VERSION/./\\.}" +elif [ "${TYPE}" = "mariadb" ]; then + docker run --rm -it "${IMAGE}:${TYPE}-${VERSION}" -V | grep 'MariaDB' | grep "${VERSION/./\\.}" +elif [ "${TYPE}" = "percona" ]; then + docker run --rm -it "${IMAGE}:${TYPE}-${VERSION}" -V | grep 'Percona' | grep "${VERSION/./\\.}" +else + >&2 echo "[ERROR] Wrong type: ${TYPE}" + exit 1 +fi diff --git a/tests/02-mysqli.sh b/tests/02-mysqli.sh new file mode 100755 index 0000000..b8d2205 --- /dev/null +++ b/tests/02-mysqli.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +echo "# --------------------------------------------------------------------------------------------------" +echo "# Testing mysqli connectivity to MySQL" +echo "# --------------------------------------------------------------------------------------------------" + +set -e +set -u +set -o pipefail + +IMAGE="devilbox/mysql" +TYPE="${1}" +VERSION="${2}" + +SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" + +# Start MySQL +docker run \ + -d \ + -it \ + --rm \ + --hostname=mysql \ + --name devilbox-test-mysql \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + "${IMAGE}:${TYPE}-${VERSION}" + +# Start PHP 7.2 +docker run \ + -d \ + -it \ + --rm \ + --hostname=php \ + --entrypoint=bash \ + --name devilbox-test-php \ + --volume="${SCRIPTPATH}:/tmp" \ + --link devilbox-test-mysql php:7.2 + +# Install PHP mysqli module +docker exec -it devilbox-test-php docker-php-ext-install mysqli + +# Test MySQL connectivity +max=100 +i=0 +while ! docker exec -it devilbox-test-php php /tmp/mysql.php >/dev/null 2>&1; do + sleep 1 + i=$(( i + 1)) + if [ "${i}" -ge "${max}" ]; then + docker stop devilbox-test-php || true + docker stop devilbox-test-mysql || true + >&2 echo "Failed" + exit 1 + fi +done + +docker stop devilbox-test-php || true +docker stop devilbox-test-mysql || true +echo "Success" diff --git a/tests/mysql.php b/tests/mysql.php new file mode 100644 index 0000000..d3d95ed --- /dev/null +++ b/tests/mysql.php @@ -0,0 +1,40 @@ +fetch_array(MYSQLI_ASSOC)) { + $data[] = $row; +} +mysqli_free_result($result); +mysqli_close($link); + +if (!isset($data[0])) { + echo 'FAIL'; + exit(1); +} +if ($data[0]['User'] == 'root') { + echo 'OK'; + exit(0); +} else { + echo 'FAIL'; + exit(1); +}