Skip to content

Commit

Permalink
Merge pull request #3784 from squidfunk/fix/docker-warning
Browse files Browse the repository at this point in the history
Fix strict mode in Docker by removing 0.0.0.0 warning
  • Loading branch information
tomchristie authored Aug 23, 2024
2 parents d737625 + 52b4512 commit e72c7d0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 72 deletions.
10 changes: 0 additions & 10 deletions mkdocs/config/config_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,6 @@ def run_validation(self, value: object) -> _IpAddressValue:

return _IpAddressValue(host, port)

def post_validation(self, config: Config, key_name: str):
host = config[key_name].host
if key_name == 'dev_addr' and host in ['0.0.0.0', '::']:
self.warnings.append(
f"The use of the IP address '{host}' suggests a production environment "
"or the use of a proxy to connect to the MkDocs server. However, "
"the MkDocs' server is intended for local development purposes only. "
"Please use a third party production-ready server instead."
)


class URL(OptionallyRequired[str]):
"""
Expand Down
53 changes: 22 additions & 31 deletions mkdocs/tests/config/config_options_legacy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,28 @@ class Schema:
self.assertEqual(conf['option'].host, '127.0.0.1')
self.assertEqual(conf['option'].port, 8000)

def test_bind_all_IPv4_address(self):
addr = '0.0.0.0:8000'

class Schema:
option = c.IpAddress(default=addr)

conf = self.get_config(Schema, {'option': None})
self.assertEqual(str(conf['option']), addr)
self.assertEqual(conf['option'].host, '0.0.0.0')
self.assertEqual(conf['option'].port, 8000)

def test_bind_all_IPv6_address(self):
addr = ':::8000'

class Schema:
option = c.IpAddress(default=addr)

conf = self.get_config(Schema, {'option': None})
self.assertEqual(str(conf['option']), addr)
self.assertEqual(conf['option'].host, '::')
self.assertEqual(conf['option'].port, 8000)

@unittest.skipIf(
sys.version_info < (3, 9, 5),
"Leading zeros allowed in IP addresses before Python3.9.5",
Expand Down Expand Up @@ -381,37 +403,6 @@ def test_invalid_address_missing_port(self):
with self.expect_error(option="Must be a string of format 'IP:PORT'"):
self.get_config(self.Schema, {'option': '127.0.0.1'})

def test_unsupported_address(self):
class Schema:
dev_addr = c.IpAddress()

self.get_config(
Schema,
{'dev_addr': '0.0.0.0:8000'},
warnings=dict(
dev_addr="The use of the IP address '0.0.0.0' suggests a production "
"environment or the use of a proxy to connect to the MkDocs "
"server. However, the MkDocs' server is intended for local "
"development purposes only. Please use a third party "
"production-ready server instead."
),
)

def test_unsupported_IPv6_address(self):
class Schema:
dev_addr = c.IpAddress()

self.get_config(
Schema,
{'dev_addr': ':::8000'},
warnings=dict(
dev_addr="The use of the IP address '::' suggests a production environment "
"or the use of a proxy to connect to the MkDocs server. However, "
"the MkDocs' server is intended for local development purposes "
"only. Please use a third party production-ready server instead."
),
)


class URLTest(TestCase):
def test_valid_url(self):
Expand Down
53 changes: 22 additions & 31 deletions mkdocs/tests/config/config_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,28 @@ class Schema(Config):
self.assertEqual(conf.option.host, '127.0.0.1')
self.assertEqual(conf.option.port, 8000)

def test_bind_all_IPv4_address(self):
addr = '0.0.0.0:8000'

class Schema(Config):
option = c.IpAddress(default=addr)

conf = self.get_config(Schema, {'option': None})
self.assertEqual(str(conf['option']), addr)
self.assertEqual(conf['option'].host, '0.0.0.0')
self.assertEqual(conf['option'].port, 8000)

def test_bind_all_IPv6_address(self):
addr = ':::8000'

class Schema(Config):
option = c.IpAddress(default=addr)

conf = self.get_config(Schema, {'option': None})
self.assertEqual(str(conf['option']), addr)
self.assertEqual(conf['option'].host, '::')
self.assertEqual(conf['option'].port, 8000)

@unittest.skipIf(
sys.version_info < (3, 9, 5),
"Leading zeros allowed in IP addresses before Python3.9.5",
Expand Down Expand Up @@ -369,37 +391,6 @@ def test_invalid_address_missing_port(self) -> None:
with self.expect_error(option="Must be a string of format 'IP:PORT'"):
self.get_config(self.Schema, {'option': '127.0.0.1'})

def test_unsupported_address(self) -> None:
class Schema(Config):
dev_addr = c.IpAddress()

self.get_config(
Schema,
{'dev_addr': '0.0.0.0:8000'},
warnings=dict(
dev_addr="The use of the IP address '0.0.0.0' suggests a production "
"environment or the use of a proxy to connect to the MkDocs "
"server. However, the MkDocs' server is intended for local "
"development purposes only. Please use a third party "
"production-ready server instead."
),
)

def test_unsupported_IPv6_address(self) -> None:
class Schema(Config):
dev_addr = c.IpAddress()

self.get_config(
Schema,
{'dev_addr': ':::8000'},
warnings=dict(
dev_addr="The use of the IP address '::' suggests a production environment "
"or the use of a proxy to connect to the MkDocs server. However, "
"the MkDocs' server is intended for local development purposes "
"only. Please use a third party production-ready server instead."
),
)


class URLTest(TestCase):
def test_valid_url(self) -> None:
Expand Down

0 comments on commit e72c7d0

Please sign in to comment.