Skip to content

Commit 260d812

Browse files
committed
move test initialization to docker-entrypoint-initdb.d
This allows easier local testing in a container image.
1 parent 78f0cf9 commit 260d812

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ jobs:
6969
mysql -h127.0.0.1 -uroot -e 'select version()' && break
7070
done
7171
mysql -h127.0.0.1 -uroot -e "SET GLOBAL local_infile=on"
72-
mysql -h127.0.0.1 -uroot -e 'create database test1 DEFAULT CHARACTER SET utf8mb4'
73-
mysql -h127.0.0.1 -uroot -e 'create database test2 DEFAULT CHARACTER SET utf8mb4'
74-
mysql -h127.0.0.1 -uroot -e "create user test2 identified ${WITH_PLUGIN} by 'some password'; grant all on test2.* to test2;"
75-
mysql -h127.0.0.1 -uroot -e "create user test2@localhost identified ${WITH_PLUGIN} by 'some password'; grant all on test2.* to test2@localhost;"
72+
mysql -h127.0.0.1 -uroot < ci/docker-entrypoint-initdb.d/init.sql
73+
mysql -h127.0.0.1 -uroot < ci/docker-entrypoint-initdb.d/mysql.sql
74+
mysql -h127.0.0.1 -uroot < ci/docker-entrypoint-initdb.d/mariadb.sql
7675
cp ci/docker.json pymysql/tests/databases.json
7776
7877
- name: Run test
@@ -87,25 +86,11 @@ jobs:
8786
docker cp mysqld:/var/lib/mysql/server-cert.pem "${HOME}"
8887
docker cp mysqld:/var/lib/mysql/client-key.pem "${HOME}"
8988
docker cp mysqld:/var/lib/mysql/client-cert.pem "${HOME}"
90-
mysql -uroot -h127.0.0.1 -e '
91-
CREATE USER
92-
user_sha256 IDENTIFIED WITH "sha256_password" BY "pass_sha256_01234567890123456789",
93-
nopass_sha256 IDENTIFIED WITH "sha256_password",
94-
user_caching_sha2 IDENTIFIED WITH "caching_sha2_password" BY "pass_caching_sha2_01234567890123456789",
95-
nopass_caching_sha2 IDENTIFIED WITH "caching_sha2_password"
96-
PASSWORD EXPIRE NEVER;
97-
GRANT RELOAD ON *.* TO user_caching_sha2;'
9889
pytest -v --cov --cov-config .coveragerc tests/test_auth.py;
9990
10091
- name: Run MariaDB auth test
10192
if: ${{ matrix.mariadb_auth }}
10293
run: |
103-
mysql -uroot -h127.0.0.1 -e '
104-
INSTALL SONAME "auth_ed25519";
105-
CREATE FUNCTION ed25519_password RETURNS STRING SONAME "auth_ed25519.so";'
106-
# we need to pass the hashed password manually until 10.4, so hide it here
107-
mysql -uroot -h127.0.0.1 -sNe "SELECT CONCAT('CREATE USER nopass_ed25519 IDENTIFIED VIA ed25519 USING \"',ed25519_password(\"\"),'\";');" | mysql -uroot -h127.0.0.1
108-
mysql -uroot -h127.0.0.1 -sNe "SELECT CONCAT('CREATE USER user_ed25519 IDENTIFIED VIA ed25519 USING \"',ed25519_password(\"pass_ed25519\"),'\";');" | mysql -uroot -h127.0.0.1
10994
pytest -v --cov --cov-config .coveragerc tests/test_mariadb_auth.py
11095
11196
- name: Report coverage

ci/docker-entrypoint-initdb.d/README

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
To test with a MariaDB or MySQL container image:
2+
3+
docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=1 \
4+
--name=mysqld -v ./ci/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d:z \
5+
mysql:8.0.26 --local-infile=1
6+
7+
cp ci/docker.json pymysql/tests/databases.json
8+
9+
pytest
10+
11+
12+
Note: Some authentication tests that don't match the image version will fail.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
create database test1 DEFAULT CHARACTER SET utf8mb4;
2+
create database test2 DEFAULT CHARACTER SET utf8mb4;
3+
create user test2 identified by 'some password';
4+
grant all on test2.* to test2;
5+
create user test2@localhost identified by 'some password';
6+
grant all on test2.* to test2@localhost;
7+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*M!100401 CREATE USER nopass_ed25519 IDENTIFIED VIA ed25519 USING PASSWORD('') */;
2+
/*M!100401 CREATE USER user_ed25519 IDENTIFIED VIA ed25519 USING PASSWORD('pass_ed25519') */;
3+
/*M!100122 INSTALL SONAME "auth_ed25519" */;
4+
--
5+
-- MariaDB [(none)]> select ed25519_password("");
6+
-- +---------------------------------------------+
7+
-- | ed25519_password("") |
8+
-- +---------------------------------------------+
9+
-- | 4LH+dBF+G5W2CKTyId8xR3SyDqZoQjUNUVNxx8aWbG4 |
10+
-- +---------------------------------------------+
11+
--
12+
13+
/*M!100401 CREATE USER nopass_ed25519 IDENTIFIED VIA ed25519 USING '4LH+dBF+G5W2CKTyId8xR3SyDqZoQjUNUVNxx8aWbG4' */;
14+
/*M!100401 CREATE USER user_ed25519 IDENTIFIED VIA ed25519 USING PASSWORD('pass_ed25519') */;
15+
/*M!100122 CREATE FUNCTION ed25519_password RETURNS STRING SONAME "auth_ed25519.so" */;
16+
/*M!100203 EXECUTE IMMEDIATE CONCAT('CREATE USER IF NOT EXISTS nopass_ed25519 IDENTIFIED VIA ed25519 USING "', ed25519_password("") ,'";') */;
17+
/*M!100203 EXECUTE IMMEDIATE CONCAT('CREATE USER IF NOT EXISTS user_ed25519 IDENTIFIED VIA ed25519 USING "', ed25519_password("pass_ed25519") ,'";') */;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*!80001 CREATE USER
2+
user_sha256 IDENTIFIED WITH "sha256_password" BY "pass_sha256_01234567890123456789",
3+
nopass_sha256 IDENTIFIED WITH "sha256_password",
4+
user_caching_sha2 IDENTIFIED WITH "caching_sha2_password" BY "pass_caching_sha2_01234567890123456789",
5+
nopass_caching_sha2 IDENTIFIED WITH "caching_sha2_password"
6+
PASSWORD EXPIRE NEVER */;
7+
8+
/*!80001 GRANT RELOAD ON *.* TO user_caching_sha2 */;

0 commit comments

Comments
 (0)