Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the 'dev_addr' warning not affect --strict mode #3509

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions mkdocs/commands/serve.py
Expand Up @@ -55,6 +55,14 @@ def get_config():
config.plugins.on_startup(command=('build' if is_clean else 'serve'), dirty=is_dirty)

host, port = config.dev_addr
if host in ('0.0.0.0', '::'):
log.warning(
"Config value 'dev_addr': "
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."
)
mount_path = urlsplit(config.site_url or '/').path
config.site_url = serve_url = _serve_url(host, port, mount_path)

Expand Down
10 changes: 0 additions & 10 deletions mkdocs/config/config_options.py
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
31 changes: 0 additions & 31 deletions mkdocs/tests/config/config_options_legacy_tests.py
Expand Up @@ -381,37 +381,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
31 changes: 0 additions & 31 deletions mkdocs/tests/config/config_options_tests.py
Expand Up @@ -369,37 +369,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