0
0
mirror of https://github.com/django/django.git synced 2024-11-29 14:46:18 +01:00

Fixed #31491 -- Allowed 'password' option in DATABASES['OPTIONS'] on MySQL.

This commit is contained in:
Hasan Ramezani 2020-06-11 20:12:35 +02:00 committed by Mariusz Felisiak
parent 2928019e0c
commit 9e8edc1e55
2 changed files with 22 additions and 3 deletions

View File

@ -11,7 +11,10 @@ class DatabaseClient(BaseDatabaseClient):
args = [cls.executable_name]
db = settings_dict['OPTIONS'].get('db', settings_dict['NAME'])
user = settings_dict['OPTIONS'].get('user', settings_dict['USER'])
passwd = settings_dict['OPTIONS'].get('passwd', settings_dict['PASSWORD'])
password = settings_dict['OPTIONS'].get(
'password',
settings_dict['OPTIONS'].get('passwd', settings_dict['PASSWORD'])
)
host = settings_dict['OPTIONS'].get('host', settings_dict['HOST'])
port = settings_dict['OPTIONS'].get('port', settings_dict['PORT'])
server_ca = settings_dict['OPTIONS'].get('ssl', {}).get('ca')
@ -24,8 +27,8 @@ class DatabaseClient(BaseDatabaseClient):
args += ["--defaults-file=%s" % defaults_file]
if user:
args += ["--user=%s" % user]
if passwd:
args += ["--password=%s" % passwd]
if password:
args += ["--password=%s" % password]
if host:
if '/' in host:
args += ["--socket=%s" % host]

View File

@ -43,6 +43,22 @@ class MySqlDbshellCommandTestCase(SimpleTestCase):
},
}))
def test_options_password(self):
self.assertEqual(
[
'mysql', '--user=someuser', '--password=optionpassword',
'--host=somehost', '--port=444', 'somedbname',
],
self.get_command_line_arguments({
'NAME': 'somedbname',
'USER': 'someuser',
'PASSWORD': 'settingpassword',
'HOST': 'somehost',
'PORT': 444,
'OPTIONS': {'password': 'optionpassword'},
}),
)
def test_can_connect_using_sockets(self):
self.assertEqual(
['mysql', '--user=someuser', '--password=somepassword',