Skip to content

Commit a3d26cd

Browse files
authored
Merge pull request #198 from akquinet/regex-records-permission
tests: added tests for .* regex zone
2 parents f70896b + f82cc5c commit a3d26cd

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

tests/unit/config_test.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,72 @@ def test_check_rrset_not_allowed_single_entries():
300300
assert not check_rrset_allowed(zone, rrset)
301301

302302

303+
def test_check_rrset_allowed_regex_zone_with_regex_records():
304+
zone = ProxyConfigZone(
305+
name=".*",
306+
regex=True,
307+
regex_records=["^_acme-challenge\\..*"],
308+
)
309+
310+
rrset_allowed: RRSET = {
311+
"name": "_acme-challenge.example.com.",
312+
"type": "TXT",
313+
"changetype": "REPLACE",
314+
"ttl": 3600,
315+
"records": [],
316+
"comments": [],
317+
}
318+
assert check_rrset_allowed(zone, rrset_allowed)
319+
320+
rrset_denied: RRSET = {
321+
"name": "www.example.com.",
322+
"type": "TXT",
323+
"changetype": "REPLACE",
324+
"ttl": 3600,
325+
"records": [],
326+
"comments": [],
327+
}
328+
assert not check_rrset_allowed(zone, rrset_denied)
329+
330+
331+
def test_check_rrset_allowed_regex_zone_with_multiple_regex_records():
332+
zone = ProxyConfigZone(
333+
name=".*\\.example\\.com",
334+
regex=True,
335+
regex_records=["^_.*", "^test-.*"],
336+
)
337+
338+
rrset1: RRSET = {
339+
"name": "_acme-challenge.sub.example.com.",
340+
"type": "TXT",
341+
"changetype": "REPLACE",
342+
"ttl": 3600,
343+
"records": [],
344+
"comments": [],
345+
}
346+
assert check_rrset_allowed(zone, rrset1)
347+
348+
rrset2: RRSET = {
349+
"name": "test-server.example.com.",
350+
"type": "CNAME",
351+
"changetype": "REPLACE",
352+
"ttl": 3600,
353+
"records": [],
354+
"comments": [],
355+
}
356+
assert check_rrset_allowed(zone, rrset2)
357+
358+
rrset3: RRSET = {
359+
"name": "www.example.com.",
360+
"type": "A",
361+
"changetype": "REPLACE",
362+
"ttl": 3600,
363+
"records": [],
364+
"comments": [],
365+
}
366+
assert not check_rrset_allowed(zone, rrset3)
367+
368+
303369
def test_check_rrsets_request_allowed_no_raise():
304370
zone = ProxyConfigZone(
305371
name="test-zone.example.com.",

0 commit comments

Comments
 (0)