2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 13:08:06 +00:00

26 Commits

Author SHA1 Message Date
Matthijs Mekking
a996e18417 Convert more kasp test cases to pytest
These test cases follow the same pattern as many other, but all require
some additional checks. These are set in "additional-tests".

The "zsk-missing.autosign" zone is special handled, as it expects the
KSK to sign the SOA RRset (because the ZSK is unavailable).

The kasp/ns3/setup.sh script is updated so the SyncPublish is not set
(named will initialize it correctly). For the test zones that have
missing private key files we do need to set the expected key timing
metadata.

Remove the counterparts for the newly added test from the kasp shell
tests script.

(cherry picked from commit 5f23f750c24ea734e52798276bbeb270cec2aed2)
2025-04-23 15:53:12 +00:00
Matthijs Mekking
76edf2deb6 Update kasp check_signatures for dnssec-policy
The check_signatures code was initially created to be suitable for
the ksr system test, to test the Offline KSK feature. For that, a
key is expected to be signing if the current time is between
the timing metadata Active and Retired.

With dnssec-policy, the key timing metadata is indicative, the key
states determine the actual signing behavior.

Update the check_signatures function so that by default the signing
is derived from the key states (ksigning and zsigning). Add an
argument 'offline_ksk', if set the make sure that the zsigning is set
if the current time is between the Active and Retired timing metadata,
and for ksigning we just use the timing metadata (as the key is offline,
we cannot check the key states).

Another (upcoming) test case is where key files are missing. When the
ZSK private key file is missing, the KSK takes over. Add an argument
'zsk_missing', when set to True the expected zone signing (zsigning)
is reversed.

(cherry picked from commit fddf9f778b49f454e68cbefea8c897ac3bd0ea44)
2025-04-23 15:53:12 +00:00
Matthijs Mekking
b50333e889 Fix bugs in isctest.kasp
isctest.util was not imported so file_contents_contain could not be
found. And rename verify_keys to check_keys because it asserts in
isctest.run.retry_with_timeout.

(cherry picked from commit 62a6b9faa7ccf85b2b628fb991c8f72d2976eee3)
2025-04-17 12:27:47 +00:00
Matthijs Mekking
6650acfb2e Convert some special kasp test cases to pytest
This converts a special characters test case, a max-zone-ttl error
check, and two cases of insecure zones.

We no longer assert for having more than one DNSKEY and/or RRSIG
records. If the zone is insecure, this is no longer always true. And
we already check for the expected number of records in the
check_dnskeys/check_signatures functions.

(cherry picked from commit 07ac0e603633a701b35c92de2e3b27dc2643dcba)
2025-04-17 12:27:46 +00:00
Matthijs Mekking
e1363e8ce9 Convert kasp default test cases to pytest
This commit deals with converting the test cases related to the default
dnssec-policy.

This requires a new method 'check_update_is_signed'. This method will
be used in future tests as well, and checks if an expected record is
in the zone and is properly signed.

Remove the counterparts for the newly added test from the kasp shell
tests script.

(cherry picked from commit 4e22b019f5123c27bda7574ae1a5750f27d5bd4b)
2025-04-17 12:27:46 +00:00
Matthijs Mekking
a1f072cfec Convert kasp dnssectools tests to pytest
Convert the first couple of tests from 'kasp/tests.sh' to
'kasp/tests_kasp.py', those are test cases related to 'dnssec-keygen'
and 'dnssec-settime'.

For this, we also add a new KeyProperties method,
'policy_to_properties', that takes a list of strings which represent
the keys according to the dnssec-policy and the expected key states.

(cherry picked from commit 00ea2c256482f334e3bd9ed52f20cc3a6a53660f)
2025-04-17 12:27:46 +00:00
Matthijs Mekking
09a947be63 Update _check_dnskeys function
In the kasp system test there are cases that the SyncPublish is not
set, nor it is required to do so. Update the _check_dnskeys function
accordingly.

(cherry picked from commit 0a6cc42914964cd83fe4973456fc54f8bff90c30)
2025-04-10 21:18:34 +00:00
Matthijs Mekking
ada3b7852e Add support for TSIG in isctest.kasp
For some kasp test we are going to need TSIG based queries to
differentiate between views.

(cherry picked from commit 9cb287afa0d428820d41577601cb2a763206a48b)
2025-04-10 21:18:34 +00:00
Matthijs Mekking
e32d49e076 Introduce pytest check_next_key_event, get_keyids
For the kasp tests we need a new utility that can retrieve a list of
Keys from a given directory, belonging to a specific zone. This is
'keydir_to_keylist' and is the replacement of 'kasp.sh:get_keyids()'.

'next_key_event_eqauls' is a method to check when the next key event is
scheduled, needed for the rollover tests, and is the equivalent of shell
script 'check_next_key_event'.

(cherry picked from commit 12e57eb222c3e4e721d5978d41c84efe0caadd77)
2025-04-10 21:18:34 +00:00
Matthijs Mekking
5828430f0e Introduce pytest verify_keys and check_keytimes
This commit introduces replacements for the 'check_keys' and
'check_keytimes' from the shell test library. 'check_keys' is renamed
to 'verify_keys' because it does not assert.

For that, we introduce more functions for the class Key. The
'match_properties' function is used in 'verify_keys' to see if a set of
KeyProperties match the Key. This speficially ignores timing metadata.
The function resembles what is in 'kasp.sh:check_key()'.

The 'match_timingmetadata' function is used in 'check_keytimes' to see
if the timing metadata of a set of KeyProperties match the Key. The
values are checked in all three key files (except if the private key is
not available (set with properties["private"]), or if it is a legacy key
(set with properties["legacy"]).

An additional check function is added, to check if the key relationships
are set correctly. It follows a similar pattern as 'check_keytimes'. If
"Predecessor" and/or "Successor" are expected to be set in the state
file, this function checks so, and also verifies that they are not set
if they should not be.

(cherry picked from commit 44ff63a50d660fd5e836b9bb0365d1ae6bdbf60a)
2025-04-10 21:18:34 +00:00
Matthijs Mekking
32a58da89b Update class Key
Because we want to check the metadata in all three files, a new
value in the Key class is added: 'privatefile'. The 'get_metadata'
function is adapted so that we can also check metadata in other files.

Introduce methods to easily retrieve the TTL and public DNSKEY record
from the keyfile.

When checking if the CDS is equal to the expected value, use the DNSKEY
TTL instead of hardcoded 3600.

(cherry picked from commit 97f6b7ad11c3c1d6c1ceeaada5776759649afa49)
2025-04-10 21:18:34 +00:00
Matthijs Mekking
ed04954aa4 Introduce class KeyProperties
In isctest.kasp, introduce a new class 'KeyProperties' that can be used
to check if a Key matches expected properties. Properties are for the
time being divided in three parts: 'properties' that contain some
attributes of the expected properties (such as are we dealing with a
legacy key, is the private key available, and other things that do not
fit the metadata exactly), 'metadata' that contains expected metadata
(such as 'Algorithm', 'Lifetime', 'Length'), and 'timing', which is
metadata of the class KeyTimingMetadata.

The 'default()' method fills in the expected properties for the default
DNSSEC policy.

The 'set_expected_times()' sets the expected timing metadata, derived
from when the key was created. This method can take an offset to push
the expected timing metadata a duration in the future or back into the
past. If 'pregenerated=True', derive the expected timing metadata from
the 'Publish' metadata derived from the keyfile, rather than from the
'Created' metadata.

The calculations in the 'Ipub', 'IpubC' and 'Iret' methods are derived
from RFC 7583 DNSSEC Key Rollover Timing Considerations.

(cherry picked from commit 0b9fbca18e1bcc0e5b613fc2c49908a7550a976d)
2025-04-10 21:18:34 +00:00
Matthijs Mekking
1629a1e304 Move test code that can be reused to isctest
This is the first step of converting the kasp system test to pytest.
Well, perhaps not the first, because earlier the ksr system test was
already converted to pytest and then the `isctest/kasp.py` library
was already introduced. Lots of this code can be reused for the kasp
pytest code.

First of all, 'check_file_contents_equal' is moved out of the ksr test
and into the 'check' library. This feels the most appropriate place
for this function to be reused in other tests. Then, 'keystr_to_keylist'
is moved to the 'kasp' library.

Introduce two new methods that are unused in this point of time, but
we are going to need them for the kasp system test. 'zone_contains'
will be used to check if a signature exists in the zonefile. This way
we can tell whether the signature has been reused or refreshed.
'file_contents_contain' will be used to check if the comment and public
DNSKEY record in the keyfile is correct.

(cherry picked from commit ee8e9f1dedd2ba2bc6ef17fc9a1a687305806f51)
2025-04-10 21:18:33 +00:00
Matthijs Mekking
2e5a2f4e81 Allow empty CDNSKEY/CDS RRset in ksr system test
When the zone is initially signed, the CDNSKEY/CDS RRset is not
immediately published. The DNSKEY and signatures must propagate first.
Adjust the test to allow for this case.

(cherry picked from commit 708927e03d152983557b6a2d0d40888e0ccffad5)
2024-11-04 01:10:34 +00:00
Matthijs Mekking
9621369524 Match algorithms when checking signatures
In the ksr system test, the test_ksr_twotone case may fail if there
are two keys with the same keytag (but different algorithms), because
one key is expected to be signing and the other is not.

Switch to regular expression matching and include the algorithm in the
search string.

(cherry picked from commit 795fcc9f803068de8c5dbdbcbba69bbd0545b8be)
2024-11-01 14:16:38 +00:00
Matthijs Mekking
8a598cb3bf Fix intermittent ksr test failure
The test_ksr_twotwone may fail if the key id is shorter than 5 digits.
Add a leading space to the expected strings which start with the key
tag to avoid the issue.

(cherry picked from commit d5f32f6990b6f33405e5ca33ffbbc3912f852e3f)
2024-10-25 07:47:01 +00:00
Nicki Křížek
2cdb8c90d1 Use UTC timezone when handling keys in kasp test library
When working with key timestamps, ensure we correctly set the UTC
timezone in order for the tests to work consistently regardless of the
local time setting.

(cherry picked from commit f840deba33f0b719fed0c9b6ad33a2a181406b38)
2024-10-22 10:51:53 +02:00
Nicki Křížek
fb9a87e8c5 Disable too-many/too-few pylint checks
Enforcing pylint standards and default for our test code seems
counter-productive. Since most of the newly added code are tests or is
test-related, encountering these checks rarely make us refactor the code
in other ways and we just disable these checks individually. Code that
is too complex or convoluted will be pointed out in reviews anyways.

(cherry picked from commit 7639c58c4889003777e5da36567f84caa424f157)
2024-10-22 09:14:06 +02:00
Matthijs Mekking
b46ddad5df Retry dnssec-verify in kasp test code
It is possible that the zone is not yet fully signed because it is
signed in batches. Retry the AXFR and verify command a couple of times.

(cherry picked from commit b8b3df0676dedbca6e94340825a173ed1764f5b5)
2024-10-22 06:24:42 +00:00
Nicki Křížek
f1fc2e1db4 Address pylint issues
(cherry picked from commit 3c6124a0933d95e154ded274cea6fbef5ac60cc8)
2024-10-22 06:24:42 +00:00
Nicki Křížek
ba2fe0a830 Use f-strings
(cherry picked from commit 55ec9f94bc04eb76090528d939b798048fd7aa70)
2024-10-22 06:24:42 +00:00
Nicki Křížek
3cffc34551 Simplify command invocation
(cherry picked from commit 732a959d9a1e392f32c7365ecf270ea08f585eee)
2024-10-22 06:24:42 +00:00
Nicki Křížek
00ec96e6e6 Remove unused isctest/kasp code
(cherry picked from commit b5633462bfe7fc1e5e684680bb33fed5e8267d6d)
2024-10-22 06:24:42 +00:00
Nicki Křížek
e806d8c6f5 Rename kasp function to check_*
If a function is expected to assert / raise on failure (rather than
return boolean), its name should start with "check_".

(cherry picked from commit 67957d1f54e01bc3066effc0fa5b6486efb66178)
2024-10-22 06:24:42 +00:00
Nicki Křížek
f5adeb6800 Use convenience wrappers for kasp key operations
(cherry picked from commit 2b0a8fcfb5084b23477f1c66b9f32445422a4461)
2024-10-22 06:24:42 +00:00
Matthijs Mekking
5d0144d006 Introduce pytest kasp library
Write initial pytest kasp library. This contains everything that is
required for testing Offline KSK functionality with pytest.

This includes:
- addtime: adding a value to a timing metadata
- get_timing_metdata: retrieve timing metadata from keyfile
- get_metadata/get_keystate: retrieve metadata from statefile
- get_keytag: retrieve keytag from base keyfile string
- get_keyrole: get key role from statefile
- dnskey_equals: compare DNSKEY record from file against a string
- cds_equals: compare CDS derived from file against a string
- zone_is_signed: wait until a zone is completely signed
- dnssec_verify: verify a DNSSEC signed zone with dnssec-verify
- check_dnssecstatus: check rndc dnssec -status output
- check_signatures: check that signatures for a given RRset are correct
- check_dnskeys: check that the published DNSKEY RRset is correct
- check_cds: check that the published CDS RRset is correct
- check_apex: check SOA, DNSKEY, CDNSKEY, and CDS RRset
- check_subdomain: check an RRset below the apex

(cherry picked from commit a3829990fdb67b646f41ef69d2d4ab3b5debbc24)
2024-10-22 06:24:42 +00:00