Skip to content

Commit

Permalink
v0.23.15: test: continue refactor & coverage in 'test_PackageSigner.py'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmlibre committed Aug 18, 2024
1 parent 2c6cfb7 commit 1285288
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Minor Changes
- test: cover input combinations for ``(a)test_timestamp``
- test: import ``hypothesis`` in 'conftest.py'
- test: parametrize & fuzz 'test_gentools.py' to cover branches
- test: continue refactor & coverage in 'test_PackageSigner.py'
- refactor: remove unnecessary variable alias
- refactor: specify input types as positive integers

Expand Down
52 changes: 23 additions & 29 deletions tests/test_PackageSigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def test_path_needed_to_verify_file_hashes(
"without specifying a relative directory to locate files."
)
with Ignore(TypeError, if_else=violation(problem)):
PackageVerifier(bytes.fromhex(aiootp.__PUBLIC_ED25519_KEY__))
PackageVerifier(pkg_signer.signing_key.public_bytes)

verifier = PackageVerifier(
pkg_signer.signing_key.public_bytes, verify_files=False
Expand Down Expand Up @@ -53,12 +53,12 @@ async def test_verifier_detects_wrong_file_digest(
filename = randoms.choice(list(summary[CHECKSUMS]))
summary[CHECKSUMS][filename] = pkg_signer._Hasher().hexdigest()
problem = ( # fmt: skip
"An invalid file digest wasn't detected."
f"An digest for file {filename=} wasn't detected."
)
with Ignore(InvalidDigest, if_else=violation(problem)):
verifier._verify_file_checksums(summary)

async def test_signing_key_interface_is_accepted(
async def test_signing_key_input_acceptable_types(
self, pkg_context: Namespace, pkg_signer: PackageSigner
) -> None:
summary = pkg_signer.summarize()
Expand All @@ -67,60 +67,54 @@ async def test_signing_key_interface_is_accepted(
path=pkg_context.test_path,
)
verifier.verify_summary(summary)

async def test_altering_signing_key_fails(
self, pkg_context: Namespace, pkg_signer: PackageSigner
) -> None:
summary = pkg_signer.summarize()
verifier = PackageVerifier(
pkg_signer.signing_key.public_key, path=pkg_context.test_path
)
verifier.verify_summary(summary)
verifier = PackageVerifier(
pkg_signer.signing_key.public_bytes, path=pkg_context.test_path
)
verifier.verify_summary(summary)

async def test_altering_signing_key_fails(
self,
pkg_signer: PackageSigner,
pkg_verifier: PackageVerifier,
) -> None:
summary = pkg_signer.summarize()
summary["signing_key"] = X25519().generate().public_bytes.hex()
problem = ( # fmt: skip
"Changed signing_key went uncaught."
"An altered `signing_key` went uncaught."
)
with Ignore(ValueError, if_else=violation(problem)):
verifier.verify_summary(summary)
pkg_verifier.verify_summary(summary)

# returning to the original signing key succeeds
summary["signing_key"] = pkg_signer.signing_key.public_bytes.hex()
verifier.verify_summary(summary)
pkg_verifier.verify_summary(summary)

async def test_altering_checksum_fails(
self, pkg_context: Namespace, pkg_signer: PackageSigner
self,
pkg_signer: PackageSigner,
pkg_verifier: PackageVerifier,
) -> None:
summary = pkg_signer.summarize()
summary["checksum"] = summary["checksum"][::-1]
verifier = PackageVerifier(
pkg_signer.signing_key.public_bytes, path=pkg_context.test_path
)
problem = ( # fmt: skip
"Summary alteration uncaught."
)
with Ignore(ValueError, if_else=violation(problem)):
verifier.verify_summary(summary)
pkg_verifier.verify_summary(summary)

# returning the checksum to the original value succeeds
summary["checksum"] = summary["checksum"][::-1]
verifier.verify_summary(summary)
pkg_verifier.verify_summary(summary)

# a json summary also works
verifier.verify_summary(json.dumps(summary))
pkg_verifier.verify_summary(json.dumps(summary))


class TestPackageSigner:
async def test_signing_key_interface_is_accepted(
self, pkg_context: Namespace, pkg_signer: PackageSigner
) -> None:
summary = pkg_signer.summarize()

# The package verifier successfully verifies a correct summary
verifier = PackageVerifier(
pkg_signer.signing_key.public_bytes, path=pkg_context.test_path
)
verifier.verify_summary(summary)

async def test_changing_signature_detected_during_summarization(
self, pkg_context: Namespace, pkg_signer: PackageSigner
) -> None:
Expand Down

0 comments on commit 1285288

Please sign in to comment.