Skip to content

Commit

Permalink
tests(wildcard zones): test regex loading from yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxd committed Nov 2, 2023
1 parent b72a7ef commit 6086950
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ In this example all zones which end with `.example.com` are allowed.
environments:
- name: "Test1"
zones:
- name: ".*\.example.com"
- name: ".*\\.example.com"
regex: true
```

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from os import path

FIXTURES_DIR = path.dirname(path.abspath(__file__))
4 changes: 4 additions & 0 deletions tests/fixtures/test_regex_parsing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
# file to test regex parsing with yaml escaping
name: ".*\\.example\\.com"
regex: true
10 changes: 10 additions & 0 deletions tests/unit/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pytest
import yaml

from powerdns_api_proxy.utils import (
check_subzone,
check_zone_in_regex,
check_zones_equal,
)
from tests.fixtures import FIXTURES_DIR


def test_check_subzone_true():
Expand All @@ -29,6 +31,7 @@ def test_zones_equal_true():
'zone, regex',
[
('prod.customer.example.com', '.*customer.example.com'),
('prod.customer.example.com', '.*\\.customer.example.com'),
('dns.prod.customer.example.com.', '.*customer.example.com'),
('prod.customer.example.com.', r'\w+\.customer.example.com'),
('customer.example.com.', r'\w*customer.example.com'),
Expand All @@ -53,3 +56,10 @@ def test_zones_in_regex_true(zone, regex):
)
def test_zones_in_regex_false(zone, regex):
assert not check_zone_in_regex(zone, regex)


def test_regex_with_parsed_yaml():
with open(FIXTURES_DIR + '/test_regex_parsing.yaml') as f:
parsed = yaml.safe_load(f)
regex_string = parsed['name']
assert check_zone_in_regex('customer.example.com.', regex_string)

0 comments on commit 6086950

Please sign in to comment.