Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ jobs:
strategy:
matrix:
include:
- db: "mariadb:10.0"
- db: "mariadb:10.2"
py: "3.9"

- db: "mariadb:10.3"
py: "3.8"
mariadb_auth: true

- db: "mariadb:10.5"
py: "3.7"
mariadb_auth: true

- db: "mysql:5.6"
py: "3.6"
Expand Down Expand Up @@ -69,10 +67,9 @@ jobs:
mysql -h127.0.0.1 -uroot -e 'select version()' && break
done
mysql -h127.0.0.1 -uroot -e "SET GLOBAL local_infile=on"
mysql -h127.0.0.1 -uroot -e 'create database test1 DEFAULT CHARACTER SET utf8mb4'
mysql -h127.0.0.1 -uroot -e 'create database test2 DEFAULT CHARACTER SET utf8mb4'
mysql -h127.0.0.1 -uroot -e "create user test2 identified ${WITH_PLUGIN} by 'some password'; grant all on test2.* to test2;"
mysql -h127.0.0.1 -uroot -e "create user test2@localhost identified ${WITH_PLUGIN} by 'some password'; grant all on test2.* to test2@localhost;"
mysql -h127.0.0.1 -uroot --comments < ci/docker-entrypoint-initdb.d/init.sql
mysql -h127.0.0.1 -uroot --comments < ci/docker-entrypoint-initdb.d/mysql.sql
mysql -h127.0.0.1 -uroot --comments < ci/docker-entrypoint-initdb.d/mariadb.sql
cp ci/docker.json pymysql/tests/databases.json

- name: Run test
Expand All @@ -87,27 +84,8 @@ jobs:
docker cp mysqld:/var/lib/mysql/server-cert.pem "${HOME}"
docker cp mysqld:/var/lib/mysql/client-key.pem "${HOME}"
docker cp mysqld:/var/lib/mysql/client-cert.pem "${HOME}"
mysql -uroot -h127.0.0.1 -e '
CREATE USER
user_sha256 IDENTIFIED WITH "sha256_password" BY "pass_sha256_01234567890123456789",
nopass_sha256 IDENTIFIED WITH "sha256_password",
user_caching_sha2 IDENTIFIED WITH "caching_sha2_password" BY "pass_caching_sha2_01234567890123456789",
nopass_caching_sha2 IDENTIFIED WITH "caching_sha2_password"
PASSWORD EXPIRE NEVER;
GRANT RELOAD ON *.* TO user_caching_sha2;'
pytest -v --cov --cov-config .coveragerc tests/test_auth.py;

- name: Run MariaDB auth test
if: ${{ matrix.mariadb_auth }}
run: |
mysql -uroot -h127.0.0.1 -e '
INSTALL SONAME "auth_ed25519";
CREATE FUNCTION ed25519_password RETURNS STRING SONAME "auth_ed25519.so";'
# we need to pass the hashed password manually until 10.4, so hide it here
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
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
pytest -v --cov --cov-config .coveragerc tests/test_mariadb_auth.py

- name: Report coverage
run: coveralls --service=github
env:
Expand Down
12 changes: 12 additions & 0 deletions ci/docker-entrypoint-initdb.d/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To test with a MariaDB or MySQL container image:

docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=1 \
--name=mysqld -v ./ci/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d:z \
mysql:8.0.26 --local-infile=1

cp ci/docker.json pymysql/tests/databases.json

pytest


Note: Some authentication tests that don't match the image version will fail.
7 changes: 7 additions & 0 deletions ci/docker-entrypoint-initdb.d/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
create database test1 DEFAULT CHARACTER SET utf8mb4;
create database test2 DEFAULT CHARACTER SET utf8mb4;
create user test2 identified by 'some password';
grant all on test2.* to test2;
create user test2@localhost identified by 'some password';
grant all on test2.* to test2@localhost;

2 changes: 2 additions & 0 deletions ci/docker-entrypoint-initdb.d/mariadb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*M!100122 INSTALL SONAME "auth_ed25519" */;
/*M!100122 CREATE FUNCTION ed25519_password RETURNS STRING SONAME "auth_ed25519.so" */;
8 changes: 8 additions & 0 deletions ci/docker-entrypoint-initdb.d/mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!80001 CREATE USER
user_sha256 IDENTIFIED WITH "sha256_password" BY "pass_sha256_01234567890123456789",
nopass_sha256 IDENTIFIED WITH "sha256_password",
user_caching_sha2 IDENTIFIED WITH "caching_sha2_password" BY "pass_caching_sha2_01234567890123456789",
nopass_caching_sha2 IDENTIFIED WITH "caching_sha2_password"
PASSWORD EXPIRE NEVER */;

/*!80001 GRANT RELOAD ON *.* TO user_caching_sha2 */;
32 changes: 32 additions & 0 deletions pymysql/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class TestAuthentication(base.PyMySQLTestCase):
pam_found = False
mysql_old_password_found = False
sha256_password_found = False
ed25519_found = False

import os

Expand Down Expand Up @@ -97,6 +98,8 @@ class TestAuthentication(base.PyMySQLTestCase):
mysql_old_password_found = True
elif r[0] == "sha256_password":
sha256_password_found = True
elif r[0] == "ed25519":
ed25519_found = True
# else:
# print("plugin: %r" % r[0])

Expand Down Expand Up @@ -412,6 +415,35 @@ def testAuthSHA256(self):
with self.assertRaises(pymysql.err.OperationalError):
pymysql.connect(user="pymysql_sha256", **db)

@pytest.mark.skipif(not ed25519_found, reason="no ed25519 authention plugin")
def testAuthEd25519(self):
db = self.db.copy()
del db["password"]
conn = self.connect()
c = conn.cursor()
c.execute("select ed25519_password(''), ed25519_password('ed25519_password')")
for r in c:
empty_pass = r[0].decode("ascii")
non_empty_pass = r[1].decode("ascii")

with TempUser(
c,
"pymysql_ed25519",
self.databases[0]["database"],
"ed25519",
empty_pass,
) as u:
pymysql.connect(user="pymysql_ed25519", password="", **db)

with TempUser(
c,
"pymysql_ed25519",
self.databases[0]["database"],
"ed25519",
non_empty_pass,
) as u:
pymysql.connect(user="pymysql_ed25519", password="ed25519_password", **db)


class TestConnection(base.PyMySQLTestCase):
def test_utf8mb4(self):
Expand Down
24 changes: 0 additions & 24 deletions tests/test_mariadb_auth.py

This file was deleted.