|
1 | 1 | import pytest |
| 2 | +import requests |
2 | 3 | from pulp_python.tests.functional.constants import ( |
3 | 4 | PYTHON_EGG_FILENAME, |
4 | 5 | PYTHON_EGG_URL, |
5 | 6 | PYTHON_WHEEL_FILENAME, |
6 | 7 | PYTHON_WHEEL_URL, |
| 8 | + PYTHON_EGG_SHA256, |
| 9 | + PYTHON_WHEEL_SHA256, |
7 | 10 | ) |
| 11 | +from urllib.parse import urljoin |
8 | 12 |
|
9 | 13 |
|
10 | 14 | @pytest.mark.parametrize( |
@@ -42,3 +46,79 @@ def test_synchronous_package_upload( |
42 | 46 | with pytest.raises(python_bindings.ApiException) as ctx: |
43 | 47 | python_bindings.ContentPackagesApi.upload(**content_body) |
44 | 48 | assert ctx.value.status == 403 |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.parallel |
| 52 | +def test_legacy_upload_invalid_protocol_version( |
| 53 | + python_empty_repo_distro, python_package_dist_directory |
| 54 | +): |
| 55 | + _, egg_file, _ = python_package_dist_directory |
| 56 | + _, distro = python_empty_repo_distro() |
| 57 | + url = urljoin(distro.base_url, "legacy/") |
| 58 | + with open(egg_file, "rb") as f: |
| 59 | + response = requests.post( |
| 60 | + url, |
| 61 | + data={"sha256_digest": PYTHON_EGG_SHA256, "protocol_version": 2}, |
| 62 | + files={"content": f}, |
| 63 | + auth=("admin", "password"), |
| 64 | + ) |
| 65 | + assert response.status_code == 400 |
| 66 | + assert response.json()["protocol_version"] == ['"2" is not a valid choice.'] |
| 67 | + |
| 68 | + with open(egg_file, "rb") as f: |
| 69 | + response = requests.post( |
| 70 | + url, |
| 71 | + data={"sha256_digest": PYTHON_EGG_SHA256, "protocol_version": 0}, |
| 72 | + files={"content": f}, |
| 73 | + auth=("admin", "password"), |
| 74 | + ) |
| 75 | + assert response.status_code == 400 |
| 76 | + assert response.json()["protocol_version"] == ['"0" is not a valid choice.'] |
| 77 | + |
| 78 | + |
| 79 | +@pytest.mark.parallel |
| 80 | +def test_legacy_upload_invalid_filetype(python_empty_repo_distro, python_package_dist_directory): |
| 81 | + _, egg_file, wheel_file = python_package_dist_directory |
| 82 | + _, distro = python_empty_repo_distro() |
| 83 | + url = urljoin(distro.base_url, "legacy/") |
| 84 | + with open(egg_file, "rb") as f: |
| 85 | + response = requests.post( |
| 86 | + url, |
| 87 | + data={"sha256_digest": PYTHON_EGG_SHA256, "filetype": "bdist_wheel"}, |
| 88 | + files={"content": f}, |
| 89 | + auth=("admin", "password"), |
| 90 | + ) |
| 91 | + assert response.status_code == 400 |
| 92 | + assert response.json()["filetype"] == [ |
| 93 | + "filetype bdist_wheel does not match found filetype sdist for file shelf-reader-0.1.tar.gz" |
| 94 | + ] |
| 95 | + |
| 96 | + with open(wheel_file, "rb") as f: |
| 97 | + response = requests.post( |
| 98 | + url, |
| 99 | + data={"sha256_digest": PYTHON_WHEEL_SHA256, "filetype": "sdist"}, |
| 100 | + files={"content": f}, |
| 101 | + auth=("admin", "password"), |
| 102 | + ) |
| 103 | + assert response.status_code == 400 |
| 104 | + assert response.json()["filetype"] == [ |
| 105 | + "filetype sdist does not match found filetype bdist_wheel for file shelf_reader-0.1-py2-none-any.whl" # noqa: E501 |
| 106 | + ] |
| 107 | + |
| 108 | + |
| 109 | +@pytest.mark.parallel |
| 110 | +def test_legacy_upload_invalid_metadata_version( |
| 111 | + python_empty_repo_distro, python_package_dist_directory |
| 112 | +): |
| 113 | + _, egg_file, _ = python_package_dist_directory |
| 114 | + _, distro = python_empty_repo_distro() |
| 115 | + url = urljoin(distro.base_url, "legacy/") |
| 116 | + with open(egg_file, "rb") as f: |
| 117 | + response = requests.post( |
| 118 | + url, |
| 119 | + data={"sha256_digest": PYTHON_EGG_SHA256, "metadata_version": "3.0"}, |
| 120 | + files={"content": f}, |
| 121 | + auth=("admin", "password"), |
| 122 | + ) |
| 123 | + assert response.status_code == 400 |
| 124 | + assert response.json()["metadata_version"] == ['"3.0" is not a valid choice.'] |
0 commit comments