# information regarding copyright ownership.
import os
-import re
+from re import compile as Re
import subprocess
import pytest
)
-# helper functions
-def grep_c(regex, data):
- blob = data.splitlines()
- results = [x for x in blob if re.search(regex, x)]
- return len(results)
-
-
# run delv
def delv(*args, tkeys=False):
delv_cmd = [os.environ.get("DELV")]
def test_positive_validation_delv():
# check positive validation NSEC
response = delv("a", "a.example")
- assert grep_c("a.example..*10.0.0.1", response.out)
- assert grep_c("a.example..*.RRSIG.A [0-9][0-9]* 2 300 .*", response.out)
+ assert Re("a.example..*10.0.0.1") in response.out
+ assert Re("a.example..*.RRSIG.A [0-9][0-9]* 2 300 .*") in response.out
# check positive validation NSEC (trsuted-keys)
response = delv("a", "a.example", tkeys=True)
- assert grep_c("a.example..*10.0.0.1", response.out)
- assert grep_c("a.example..*.RRSIG.A [0-9][0-9]* 2 300 .*", response.out)
+ assert Re("a.example..*10.0.0.1") in response.out
+ assert Re("a.example..*.RRSIG.A [0-9][0-9]* 2 300 .*") in response.out
# check positive validation NSEC3
response = delv("a", "a.nsec3.example")
- assert grep_c("a.nsec3.example..*10.0.0.1", response.out)
- assert grep_c("a.nsec3.example..*.RRSIG.A [0-9][0-9]* 3 300 .*", response.out)
+ assert Re("a.nsec3.example..*10.0.0.1") in response.out
+ assert Re("a.nsec3.example..*.RRSIG.A [0-9][0-9]* 3 300 .*") in response.out
# check positive validation OPTOUT
response = delv("a", "a.optout.example")
- assert grep_c("a.optout.example..*10.0.0.1", response.out)
- assert grep_c("a.optout.example..*.RRSIG.A [0-9][0-9]* 3 300 .*", response.out)
+ assert Re("a.optout.example..*10.0.0.1") in response.out
+ assert Re("a.optout.example..*.RRSIG.A [0-9][0-9]* 3 300 .*") in response.out
# check positive wildcard validation NSEC
response = delv("a", "a.wild.example")
- assert grep_c("a.wild.example..*10.0.0.27", response.out)
- assert grep_c("a.wild.example..*.RRSIG.A [0-9][0-9]* 2 300 .*", response.out)
+ assert Re("a.wild.example..*10.0.0.27") in response.out
+ assert Re("a.wild.example..*.RRSIG.A [0-9][0-9]* 2 300 .*") in response.out
# check positive wildcard validation NSEC3
response = delv("a", "a.wild.nsec3.example")
- assert grep_c("a.wild.nsec3.example..*10.0.0.6", response.out)
- assert grep_c("a.wild.nsec3.example..*.RRSIG.A [0-9][0-9]* 3 300 .*", response.out)
+ assert Re("a.wild.nsec3.example..*10.0.0.6") in response.out
+ assert Re("a.wild.nsec3.example..*.RRSIG.A [0-9][0-9]* 3 300 .*") in response.out
# check positive wildcard validation OPTOUT
response = delv("a", "a.wild.optout.example")
- assert grep_c("a.wild.optout.example..*10.0.0.6", response.out)
- assert grep_c("a.wild.optout.example..*.RRSIG.A [0-9][0-9]* 3 300 .*", response.out)
+ assert Re("a.wild.optout.example..*10.0.0.6") in response.out
+ assert Re("a.wild.optout.example..*.RRSIG.A [0-9][0-9]* 3 300 .*") in response.out
def test_negative_validation_delv():
# checking negative validation NXDOMAIN NSEC
response = delv("a", "q.example")
- assert grep_c("resolution failed: ncache nxdomain", response.out)
+ assert "resolution failed: ncache nxdomain" in response.out
# checking negative validation NODATA NSEC
response = delv("txt", "a.example")
- assert grep_c("resolution failed: ncache nxrrset", response.out)
+ assert "resolution failed: ncache nxrrset" in response.out
# checking negative validation NXDOMAIN NSEC3
response = delv("a", "q.nsec3.example")
- assert grep_c("resolution failed: ncache nxdomain", response.out)
+ assert "resolution failed: ncache nxdomain" in response.out
# checking negative validation NODATA NSEC3
response = delv("txt", "a.nsec3.example")
- assert grep_c("resolution failed: ncache nxrrset", response.out)
+ assert "resolution failed: ncache nxrrset" in response.out
# checking negative validation NXDOMAIN OPTOUT
response = delv("a", "q.optout.example")
- assert grep_c("resolution failed: ncache nxdomain", response.out)
+ assert "resolution failed: ncache nxdomain" in response.out
# checking negative validation NODATA OPTOUT
response = delv("txt", "a.optout.example")
- assert grep_c("resolution failed: ncache nxrrset", response.out)
+ assert "resolution failed: ncache nxrrset" in response.out
# checking negative wildcard validation NSEC
response = delv("txt", "b.wild.example")
- assert grep_c("resolution failed: ncache nxrrset", response.out)
+ assert "resolution failed: ncache nxrrset" in response.out
# checking negative wildcard validation NSEC3
response = delv("txt", "b.wild.nsec3.example")
- assert grep_c("resolution failed: ncache nxrrset", response.out)
+ assert "resolution failed: ncache nxrrset" in response.out
# checking negative wildcard validation OPTOUT
response = delv("txt", "b.wild.optout.example")
- assert grep_c("resolution failed: ncache nxrrset", response.out)
+ assert "resolution failed: ncache nxrrset" in response.out
def test_insecure_validation_delv():
# check 1-server insecurity proof NSEC
response = delv("a", "a.insecure.example")
- assert grep_c("a.insecure.example..*10.0.0.1", response.out)
+ assert Re("a.insecure.example..*10.0.0.1") in response.out
# check 1-server insecurity proof NSEC3
response = delv("a", "a.insecure.nsec3.example")
- assert grep_c("a.insecure.nsec3.example..*10.0.0.1", response.out)
+ assert Re("a.insecure.nsec3.example..*10.0.0.1") in response.out
# check 1-server insecurity proof NSEC3
response = delv("a", "a.insecure.optout.example")
- assert grep_c("a.insecure.optout.example..*10.0.0.1", response.out)
+ assert Re("a.insecure.optout.example..*10.0.0.1") in response.out
# check 1-server negative insecurity proof NSEC
response = delv("a", "q.insecure.example")
- assert grep_c("resolution failed: ncache nxdomain", response.out)
+ assert "resolution failed: ncache nxdomain" in response.out
# check 1-server negative insecurity proof NSEC3
response = delv("a", "q.insecure.nsec3.example")
- assert grep_c("resolution failed: ncache nxdomain", response.out)
+ assert "resolution failed: ncache nxdomain" in response.out
# check 1-server negative insecurity proof OPTOUT
response = delv("a", "q.insecure.optout.example")
- assert grep_c("resolution failed: ncache nxdomain", response.out)
+ assert "resolution failed: ncache nxdomain" in response.out
def test_validation_failure_delv():
# check failed validation due to bogus data
response = delv("+cd", "a", "a.bogus.example")
- assert grep_c("resolution failed: RRSIG failed to verify", response.out)
+ assert "resolution failed: RRSIG failed to verify" in response.out
# check failed validation due to missing key record
response = delv("+cd", "a", "a.b.keyless.example")
- assert grep_c("resolution failed: insecurity proof failed", response.out)
+ assert "resolution failed: insecurity proof failed" in response.out
def test_revoked_key_delv():
# check failed validation succeeds when a revoked key is encountered
response = delv("+cd", "soa", "revkey.example")
- assert grep_c("fully validated", response.out)
+ assert "fully validated" in response.out
import os
import re
-import subprocess
+from re import compile as Re
import pytest
)
-def get_bad_zone_output(zone):
- only_opt = ["-z"] if re.match(r"[zk]sk-only", zone) else []
+def verify_bad_zone(zone):
+ only_opt = ["-z"] if re.search(r"^[zk]sk-only", zone) else []
cmd = isctest.run.cmd(
[VERIFY, *only_opt, "-o", zone, f"zones/{zone}.bad"],
- stderr=subprocess.STDOUT,
raise_on_exception=False,
)
- return cmd.out
+ assert cmd.rc != 0
+ return cmd
@pytest.mark.parametrize(
],
)
def test_verify_bad_zone_files_dnskeyonly(zone):
- assert re.match(r".*DNSKEY is not signed.*", get_bad_zone_output(zone))
+ cmd = verify_bad_zone(zone)
+ assert "DNSKEY is not signed" in cmd.err
@pytest.mark.parametrize(
],
)
def test_verify_bad_zone_files_expired(zone):
- assert re.match(
- r".*signature has expired.*|.*No self-signed .*DNSKEY found.*",
- get_bad_zone_output(zone),
- )
+ cmd = verify_bad_zone(zone)
+ assert Re("signature has expired|No self-signed DNSKEY found") in cmd.err
@pytest.mark.parametrize(
],
)
def test_verify_bad_zone_files_unexpected_nsec_rrset(zone):
- assert re.match(r".*unexpected NSEC RRset at.*", get_bad_zone_output(zone))
+ cmd = verify_bad_zone(zone)
+ assert "unexpected NSEC RRset at" in cmd.err
def test_verify_bad_zone_files_bad_nsec_record():
- assert re.match(
- r".*Bad NSEC record for.*, next name mismatch.*",
- get_bad_zone_output("ksk+zsk.nsec.broken-chain"),
- )
+ cmd = verify_bad_zone("ksk+zsk.nsec.broken-chain")
+ assert Re("Bad NSEC record for.*, next name mismatch") in cmd.err
def test_verify_bad_zone_files_bad_bitmap():
- assert re.match(
- r".*bit map mismatch.*", get_bad_zone_output("ksk+zsk.nsec.bad-bitmap")
- )
+ cmd = verify_bad_zone("ksk+zsk.nsec.bad-bitmap")
+ assert "bit map mismatch" in cmd.err
def test_verify_bad_zone_files_missing_nsec3_record():
- assert re.match(
- r".*Missing NSEC3 record for.*",
- get_bad_zone_output("ksk+zsk.nsec3.missing-empty"),
- )
+ cmd = verify_bad_zone("ksk+zsk.nsec3.missing-empty")
+ assert "Missing NSEC3 record for" in cmd.err
def test_verify_bad_zone_files_no_dnssec_keys():
- assert re.match(
- r".*Zone contains no DNSSEC keys.*", get_bad_zone_output("unsigned")
- )
+ cmd = verify_bad_zone("unsigned")
+ assert "Zone contains no DNSSEC keys" in cmd.err
def test_verify_bad_zone_files_unequal_nsec3_chains():
- assert re.match(
- r".*Expected and found NSEC3 chains not equal.*",
- get_bad_zone_output("ksk+zsk.nsec3.extra-nsec3"),
- )
+ cmd = verify_bad_zone("ksk+zsk.nsec3.extra-nsec3")
+ assert "Expected and found NSEC3 chains not equal" in cmd.err
# checking error message when -o is not used