MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / TestAuthentication

Class TestAuthentication

pymysql/tests/test_connection.py:47–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

getMethod · 0.80
cursorMethod · 0.80
executeMethod · 0.80
connectMethod · 0.45

Tested by

no test coverage detected