1
0
mirror of https://github.com/django/django.git synced 2025-03-06 15:32:33 +00:00

Fixed #29606 -- Added type check for ALLOWED_HOSTS setting.

This commit is contained in:
Adam Donaghy 2021-03-24 11:22:27 +11:00 committed by Mariusz Felisiak
parent a96c730431
commit cdd0b213a8
2 changed files with 5 additions and 2 deletions

View File

@ -141,6 +141,7 @@ class Settings:
mod = importlib.import_module(self.SETTINGS_MODULE) mod = importlib.import_module(self.SETTINGS_MODULE)
tuple_settings = ( tuple_settings = (
'ALLOWED_HOSTS',
"INSTALLED_APPS", "INSTALLED_APPS",
"TEMPLATE_DIRS", "TEMPLATE_DIRS",
"LOCALE_PATHS", "LOCALE_PATHS",

View File

@ -438,12 +438,13 @@ class IsOverriddenTest(SimpleTestCase):
self.assertEqual(repr(lazy_settings), expected) self.assertEqual(repr(lazy_settings), expected)
class TestListSettings(unittest.TestCase): class TestListSettings(SimpleTestCase):
""" """
Make sure settings that should be lists or tuples throw Make sure settings that should be lists or tuples throw
ImproperlyConfigured if they are set to a string instead of a list or tuple. ImproperlyConfigured if they are set to a string instead of a list or tuple.
""" """
list_or_tuple_settings = ( list_or_tuple_settings = (
'ALLOWED_HOSTS',
"INSTALLED_APPS", "INSTALLED_APPS",
"TEMPLATE_DIRS", "TEMPLATE_DIRS",
"LOCALE_PATHS", "LOCALE_PATHS",
@ -452,11 +453,12 @@ class TestListSettings(unittest.TestCase):
def test_tuple_settings(self): def test_tuple_settings(self):
settings_module = ModuleType('fake_settings_module') settings_module = ModuleType('fake_settings_module')
settings_module.SECRET_KEY = 'foo' settings_module.SECRET_KEY = 'foo'
msg = 'The %s setting must be a list or a tuple.'
for setting in self.list_or_tuple_settings: for setting in self.list_or_tuple_settings:
setattr(settings_module, setting, ('non_list_or_tuple_value')) setattr(settings_module, setting, ('non_list_or_tuple_value'))
sys.modules['fake_settings_module'] = settings_module sys.modules['fake_settings_module'] = settings_module
try: try:
with self.assertRaises(ImproperlyConfigured): with self.assertRaisesMessage(ImproperlyConfigured, msg % setting):
Settings('fake_settings_module') Settings('fake_settings_module')
finally: finally:
del sys.modules['fake_settings_module'] del sys.modules['fake_settings_module']