Пример #1
0
def test_acceptance_sign_unsign_symmetry(image_config: ImageConfig,
                                         image_config_signed: ImageConfig):
    """Tests that sign and unsign are (mostly) symmetric operations."""

    config_digest = image_config.get_config_digest()

    # 1. Sign
    signer = FakeSigner()
    assert image_config.sign(signer) == signer.signature_value
    assert image_config_signed.sign(signer) == signer.signature_value

    # Previously unsigned configurations should now contain the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config.get_config()

    # Previously signed configurations should now contain the original signature(s) and the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" in image_config_signed.get_config()

    # 2. Unsign
    image_config.unsign()
    image_config_signed.unsign()

    # Configurations where we added the first signature should be reverted.
    assert b"BEGIN FAKE SIGNATURE" not in image_config.get_config()

    # Configurations where we appended a signature should now contain no signature(s).
    assert b"BEGIN FAKE SIGNATURE" not in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" not in image_config_signed.get_config()

    assert image_config.get_config_digest() == config_digest
Пример #2
0
def test_get_config_digest(
    image_config: ImageConfig,
    image_config_signed: ImageConfig,
    config_digest: str,
    config_digest_signed: str,
):
    """Test digest calculation for signed and unsigned configurations."""
    assert image_config.get_config_digest() == config_digest
    assert image_config_signed.get_config_digest() == config_digest_signed