| 44 | |
| 45 | |
| 46 | class TestAuthentication(base.PyMySQLTestCase): |
| 47 | socket_auth = False |
| 48 | socket_found = False |
| 49 | two_questions_found = False |
| 50 | three_attempts_found = False |
| 51 | pam_found = False |
| 52 | mysql_old_password_found = False |
| 53 | sha256_password_found = False |
| 54 | ed25519_found = False |
| 55 | |
| 56 | import os |
| 57 | |
| 58 | osuser = os.environ.get("USER") |
| 59 | |
| 60 | # socket auth requires the current user and for the connection to be a socket |
| 61 | # rest do grants @localhost due to incomplete logic - TODO change to @% then |
| 62 | db = base.PyMySQLTestCase.databases[0].copy() |
| 63 | |
| 64 | socket_auth = db.get("unix_socket") is not None and db.get("host") in ( |
| 65 | "localhost", |
| 66 | "127.0.0.1", |
| 67 | ) |
| 68 | |
| 69 | cur = pymysql.connect(**db).cursor() |
| 70 | del db["user"] |
| 71 | cur.execute("SHOW PLUGINS") |
| 72 | for r in cur: |
| 73 | if (r[1], r[2]) != ("ACTIVE", "AUTHENTICATION"): |
| 74 | continue |
| 75 | if r[3] == "auth_socket.so" or r[0] == "unix_socket": |
| 76 | socket_plugin_name = r[0] |
| 77 | socket_found = True |
| 78 | elif r[3] == "dialog_examples.so": |
| 79 | if r[0] == "two_questions": |
| 80 | two_questions_found = True |
| 81 | elif r[0] == "three_attempts": |
| 82 | three_attempts_found = True |
| 83 | elif r[0] == "pam": |
| 84 | pam_found = True |
| 85 | pam_plugin_name = r[3].split(".")[0] |
| 86 | if pam_plugin_name == "auth_pam": |
| 87 | pam_plugin_name = "pam" |
| 88 | # MySQL: authentication_pam |
| 89 | # https://dev.mysql.com/doc/refman/5.5/en/pam-authentication-plugin.html |
| 90 | |
| 91 | # MariaDB: pam |
| 92 | # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/ |
| 93 | |
| 94 | # Names differ but functionality is close |
| 95 | elif r[0] == "mysql_old_password": |
| 96 | mysql_old_password_found = True |
| 97 | elif r[0] == "sha256_password": |
| 98 | sha256_password_found = True |
| 99 | elif r[0] == "ed25519": |
| 100 | ed25519_found = True |
| 101 | # else: |
| 102 | # print("plugin: %r" % r[0]) |
| 103 | |