Skip to content

Commit 27171e3

Browse files
authored
Merge pull request #191 from akquinet/patch
fix: allow empty zones field
2 parents f7bdb57 + c9bafee commit 27171e3

2 files changed

Lines changed: 9 additions & 28 deletions

File tree

powerdns_api_proxy/models.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import lru_cache
22
from typing import TypedDict
33

4-
from pydantic import BaseModel, field_validator, model_validator
4+
from pydantic import BaseModel, field_validator
55

66
from powerdns_api_proxy.logging import logger
77
from powerdns_api_proxy.utils import (
@@ -77,14 +77,6 @@ def validate_token(cls, token_sha512):
7777
raise ValueError("A SHA512 hash must be 128 digits long")
7878
return token_sha512
7979

80-
@model_validator(mode="after")
81-
def validate_zones_or_global_read_only(self):
82-
if not self.zones and not self.global_read_only:
83-
raise ValueError(
84-
"Either 'zones' must be non-empty or 'global_read_only' must be True"
85-
)
86-
return self
87-
8880
def __init__(self, **data):
8981
super().__init__(**data)
9082

tests/unit/config_test.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -629,26 +629,15 @@ def test_global_read_only_without_zones():
629629
assert env.zones == []
630630

631631

632-
def test_environment_with_neither_zones_nor_global_read_only_fails():
633-
"""Test that providing neither zones nor global_read_only fails validation"""
634-
with pytest.raises(ValueError) as err:
635-
ProxyConfigEnvironment(
636-
name="test", token_sha512=dummy_proxy_environment_token_sha512
637-
)
638-
assert "Either 'zones' must be non-empty or 'global_read_only' must be True" in str(
639-
err.value
640-
)
641-
642-
643-
def test_environment_with_empty_zones_and_no_global_read_only_fails():
644-
"""Test that explicitly providing empty zones without global_read_only fails"""
645-
with pytest.raises(ValueError) as err:
646-
ProxyConfigEnvironment(
647-
name="test", token_sha512=dummy_proxy_environment_token_sha512, zones=[]
648-
)
649-
assert "Either 'zones' must be non-empty or 'global_read_only' must be True" in str(
650-
err.value
632+
def test_environment_with_empty_zones_denies_zone_access():
633+
"""Test that environment with empty zones and no global permissions denies zone access"""
634+
env = ProxyConfigEnvironment(
635+
name="test",
636+
token_sha512=dummy_proxy_environment_token_sha512,
637+
zones=[],
651638
)
639+
assert not check_pdns_zone_allowed(env, "test.example.com.")
640+
assert not check_pdns_zone_allowed(env, "any.zone.com.")
652641

653642

654643
def test_proxy_config_with_global_read_only_environment():

0 commit comments

Comments
 (0)