Skip to content

Commit 3b6428b

Browse files
committed
WL13335: Connectors should handle expired password sandbox without SET
operations Server does not allow to run any other statement different from ALTER when user's password has been expired. This worklog ensures the user is capable to change an expired password using the ALTER statement with the use of the 'CAN_HANDLE_EXPIRED_PASSWORDS' flag, the use of this flag will make the connector skip any SET statement; normally run to set configuration options after a successfully connection.
1 parent a64e371 commit 3b6428b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/mysql/connector/abstracts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,10 @@ def connect(self, **kwargs):
779779

780780
self.disconnect()
781781
self._open_connection()
782-
self._post_connection()
782+
# Server does not allow to run any other statement different from ALTER
783+
# when user's password has been expired.
784+
if not self._client_flags & ClientFlag.CAN_HANDLE_EXPIRED_PASSWORDS:
785+
self._post_connection()
783786

784787
def reconnect(self, attempts=1, delay=0):
785788
"""Attempt to reconnect to the MySQL server

tests/test_connection.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,3 +1950,39 @@ def test_connection_attributes_user_defined(self):
19501950
"Attribute {} with value {} differs of {}"
19511951
"".format(attr_name, res_dict[attr_name],
19521952
expected_attrs[attr_name]))
1953+
1954+
1955+
class WL13335(tests.MySQLConnectorTests):
1956+
"""WL#13335: Avoid set config values whit flag CAN_HANDLE_EXPIRED_PASSWORDS
1957+
"""
1958+
def setUp(self):
1959+
self.config = tests.get_mysql_config()
1960+
cnx = connection.MySQLConnection(**self.config)
1961+
self.user = "expired_pw_user"
1962+
self.passw = "i+QEqGkFr8h5"
1963+
self.hosts = ["localhost", "127.0.0.1"]
1964+
for host in self.hosts:
1965+
cnx.cmd_query("CREATE USER '{}'@'{}' IDENTIFIED BY "
1966+
"'{}'".format(self.user, host, self.passw))
1967+
cnx.cmd_query("GRANT ALL ON *.* TO '{}'@'{}'"
1968+
"".format(self.user, host))
1969+
cnx.cmd_query("ALTER USER '{}'@'{}' PASSWORD EXPIRE"
1970+
"".format(self.user, host))
1971+
cnx.close()
1972+
1973+
def tearDown(self):
1974+
cnx = connection.MySQLConnection(**self.config)
1975+
for host in self.hosts:
1976+
cnx.cmd_query("DROP USER '{}'@'{}'".format(self.user, host))
1977+
cnx.close()
1978+
1979+
@tests.foreach_cnx()
1980+
def test_connect_with_can_handle_expired_pw_flag(self):
1981+
cnx_config = self.config.copy()
1982+
cnx_config['user'] = self.user
1983+
cnx_config['password'] = self.passw
1984+
flags = constants.ClientFlag.get_default()
1985+
flags |= constants.ClientFlag.CAN_HANDLE_EXPIRED_PASSWORDS
1986+
cnx_config['client_flags'] =flags
1987+
# connection must be successful
1988+
_ = self.cnx.__class__(**cnx_config)

0 commit comments

Comments
 (0)