Skip to content

Commit 677b310

Browse files
committed
BUG19703022: Fix using passwords with integers only in option files
Passwords consisting of only integers were raising error when used with option files. We fix this by not evaluating value for password option in option files. Unit tests are updated.
1 parent b0c02e5 commit 677b310

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/mysql/connector/optionfiles.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ def read_option_files(**config):
101101
except KeyError:
102102
continue
103103

104+
not_evaluate = ('password', 'passwd')
104105
for option, value in config_options.items():
105106
if option not in config:
106107
try:
107-
config[option] = eval(value[0]) # pylint: disable=W0123
108+
if option in not_evaluate:
109+
config[option] = value[0]
110+
else:
111+
config[option] = eval(value[0]) # pylint: disable=W0123
108112
except (NameError, SyntaxError):
109113
config[option] = value[0]
110114

tests/data/option_files/my.cnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
[client]
3+
password=12345
34
port=1000
45
socket=/var/run/mysqld/mysqld.sock
56
ssl-ca=dummyCA

tests/test_optionfiles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def test_read(self,):
9999

100100
def test_get_groups(self):
101101
exp = {
102+
'password': '12345',
102103
'port': '1001',
103104
'socket': '/var/run/mysqld/mysqld2.sock',
104105
'ssl-ca': 'dummyCA',
@@ -122,6 +123,7 @@ def test_get_groups(self):
122123
def test_get_groups_as_dict(self):
123124
exp = dict([
124125
('client', {'port': '1000',
126+
'password': '12345',
125127
'socket': '/var/run/mysqld/mysqld.sock',
126128
'ssl-ca': 'dummyCA',
127129
'ssl-cert': 'dummyCert',
@@ -167,6 +169,7 @@ def test_read_option_files(self):
167169

168170
option_file_dir = os.path.join('tests', 'data', 'option_files')
169171
exp = {
172+
'password': '12345',
170173
'port': 1000,
171174
'unix_socket': '/var/run/mysqld/mysqld.sock',
172175
'ssl_ca': 'dummyCA',
@@ -177,6 +180,7 @@ def test_read_option_files(self):
177180
option_file_dir, 'my.cnf'))
178181
self.assertEqual(exp, result)
179182
exp = {
183+
'password': '12345',
180184
'port': 1001,
181185
'unix_socket': '/var/run/mysqld/mysqld2.sock',
182186
'ssl_ca': 'dummyCA',

0 commit comments

Comments
 (0)