|
| 1 | +"""Negative tests for model signing failure scenarios (TC-011b, TC-011c).""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
| 6 | +from model_registry.signing.exceptions import SigningError |
| 7 | +from simple_logger.logger import get_logger |
| 8 | + |
| 9 | +LOGGER = get_logger(name=__name__) |
| 10 | + |
| 11 | +pytestmark = pytest.mark.usefixtures("skip_if_not_managed_cluster", "tas_connection_type") |
| 12 | + |
| 13 | +INVALID_IMAGE_REF = "quay.io/invalid-no-access-repo/nonexistent-image:latest" |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.tier3 |
| 17 | +@pytest.mark.usefixtures("set_environment_variables") |
| 18 | +class TestSigningNegative: |
| 19 | + """Negative test suite for signing failure scenarios.""" |
| 20 | + |
| 21 | + def test_sign_image_invalid_registry_credentials(self, signer): |
| 22 | + """TC-011b: Sign container image with invalid registry credentials. |
| 23 | +
|
| 24 | + Verifies that signing an image to a registry where the user has no write |
| 25 | + permissions fails with a SigningError indicating an authentication/authorization issue. |
| 26 | + """ |
| 27 | + LOGGER.info(f"Attempting to sign image with no write access: {INVALID_IMAGE_REF}") |
| 28 | + with pytest.raises(SigningError): |
| 29 | + signer.sign_image(image=INVALID_IMAGE_REF) |
| 30 | + LOGGER.info("SigningError raised as expected for invalid registry credentials") |
| 31 | + |
| 32 | + def test_verify_model_missing_signature(self, signer, tmp_path: Path): |
| 33 | + """TC-011c: Verify model with missing signature file. |
| 34 | +
|
| 35 | + Verifies that attempting to verify a model directory that has no model.sig |
| 36 | + file fails with a FileNotFoundError indicating the signature is missing. |
| 37 | + """ |
| 38 | + model_file = tmp_path / "model.onnx" |
| 39 | + model_file.write_bytes(data=b"fake onnx model content for testing") |
| 40 | + |
| 41 | + LOGGER.info(f"Attempting to verify model without signature: {tmp_path}") |
| 42 | + with pytest.raises(FileNotFoundError, match=r"model\.sig"): |
| 43 | + signer.verify_model(model_path=str(tmp_path)) |
| 44 | + LOGGER.info("FileNotFoundError raised as expected for missing signature") |
0 commit comments