|
| 1 | +"""Tests for deleting manifests via the Docker v2 API.""" |
| 2 | + |
| 3 | +import subprocess |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from pulp_container.tests.functional.constants import REGISTRY_V2_REPO_PULP |
| 8 | + |
| 9 | + |
| 10 | +def test_delete_manifest_by_digest( |
| 11 | + add_to_cleanup, |
| 12 | + local_registry, |
| 13 | + registry_client, |
| 14 | + container_bindings, |
| 15 | + full_path, |
| 16 | +): |
| 17 | + """Delete a manifest by digest via DELETE /v2/<name>/manifests/<digest>.""" |
| 18 | + repo_name = "delete/manifest" |
| 19 | + local_url = full_path(f"{repo_name}:manifest_a") |
| 20 | + image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a" |
| 21 | + registry_client.pull(image_path) |
| 22 | + local_registry.tag_and_push(image_path, local_url) |
| 23 | + |
| 24 | + namespace = container_bindings.PulpContainerNamespacesApi.list(name="delete").results[0] |
| 25 | + add_to_cleanup(container_bindings.PulpContainerNamespacesApi, namespace.pulp_href) |
| 26 | + |
| 27 | + local_image = local_registry.inspect(f"{local_registry.name}/{local_url}") |
| 28 | + digest = local_image[0]["Digest"] |
| 29 | + |
| 30 | + delete_path = f"/v2/{full_path(repo_name)}/manifests/{digest}" |
| 31 | + response, _ = local_registry.get_response("DELETE", delete_path) |
| 32 | + assert response.status_code == 202 |
| 33 | + |
| 34 | + with pytest.raises(subprocess.CalledProcessError): |
| 35 | + local_registry.pull(f"{local_registry.name}/{full_path(repo_name)}:manifest_a") |
| 36 | + |
| 37 | + |
| 38 | +def test_delete_manifest_by_tag_rejected( |
| 39 | + add_to_cleanup, |
| 40 | + local_registry, |
| 41 | + registry_client, |
| 42 | + container_bindings, |
| 43 | + full_path, |
| 44 | +): |
| 45 | + """Delete by tag name is not allowed.""" |
| 46 | + repo_name = "delete/by-tag" |
| 47 | + local_url = full_path(f"{repo_name}:manifest_a") |
| 48 | + image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a" |
| 49 | + registry_client.pull(image_path) |
| 50 | + local_registry.tag_and_push(image_path, local_url) |
| 51 | + |
| 52 | + namespace = container_bindings.PulpContainerNamespacesApi.list(name="delete").results[0] |
| 53 | + add_to_cleanup(container_bindings.PulpContainerNamespacesApi, namespace.pulp_href) |
| 54 | + |
| 55 | + delete_path = f"/v2/{full_path(repo_name)}/manifests/manifest_a" |
| 56 | + response, _ = local_registry.get_response("DELETE", delete_path) |
| 57 | + assert response.status_code == 400 |
| 58 | + assert response.json()["errors"][0]["code"] == "INVALID_REQUEST" |
| 59 | + |
| 60 | + |
| 61 | +def test_delete_manifest_not_found( |
| 62 | + add_to_cleanup, |
| 63 | + local_registry, |
| 64 | + registry_client, |
| 65 | + container_bindings, |
| 66 | + full_path, |
| 67 | +): |
| 68 | + """Deleting a non-existent manifest returns 404.""" |
| 69 | + repo_name = "delete/not-found" |
| 70 | + local_url = full_path(f"{repo_name}:manifest_a") |
| 71 | + image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a" |
| 72 | + registry_client.pull(image_path) |
| 73 | + local_registry.tag_and_push(image_path, local_url) |
| 74 | + |
| 75 | + namespace = container_bindings.PulpContainerNamespacesApi.list(name="delete").results[0] |
| 76 | + add_to_cleanup(container_bindings.PulpContainerNamespacesApi, namespace.pulp_href) |
| 77 | + |
| 78 | + digest = f"sha256:{'0' * 64}" |
| 79 | + delete_path = f"/v2/{full_path(repo_name)}/manifests/{digest}" |
| 80 | + response, _ = local_registry.get_response("DELETE", delete_path) |
| 81 | + assert response.status_code == 404 |
| 82 | + assert response.json()["errors"][0]["code"] == "MANIFEST_UNKNOWN" |
| 83 | + |
| 84 | + |
| 85 | +def test_delete_manifest_without_login( |
| 86 | + anonymous_user, |
| 87 | + local_registry, |
| 88 | + full_path, |
| 89 | +): |
| 90 | + """Delete requires authentication.""" |
| 91 | + digest = f"sha256:{'0' * 64}" |
| 92 | + delete_path = f"/v2/{full_path('delete/unauth')}/manifests/{digest}" |
| 93 | + with anonymous_user: |
| 94 | + response, _ = local_registry.get_response("DELETE", delete_path) |
| 95 | + assert response.status_code == 401 |
0 commit comments