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

NAS-133211 / 25.04 / Fix validate_nameservers() #15257

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/middlewared/middlewared/plugins/network_/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ def network_config_extend(self, data):

@private
async def validate_nameservers(self, verrors, data, schema):
verrors = ValidationErrors()

ns_ints = []
for ns, ns_value in filter(lambda x: x[0].startswith('nameserver') and x[1], data.items()):
schema = f'{schema}.{ns}'
Expand Down
27 changes: 27 additions & 0 deletions tests/api2/test_nameservers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from contextlib import contextmanager

import pytest

from middlewared.test.integration.utils import call
from middlewared.service_exception import ValidationErrors


@contextmanager
def revert_nameservers():
to_revert = call("network.general.summary")["nameservers"]
payload = dict()
for idx, i in enumerate(to_revert, start=1):
payload[f"nameserver{idx}"] = i

try:
yield
finally:
call("network.configuration.update", payload)


def test_invalid_nameserver():
with revert_nameservers():
with pytest.raises(
ValidationErrors, match="Loopback is not a valid nameserver"
):
call("network.configuration.update", {"nameserver1": "127.0.0.1"})
Loading