pulp-python 3.34.0__py3-none-any.whl → 3.35.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pulp_python/app/__init__.py +1 -1
- pulp_python/app/pypi/views.py +22 -5
- pulp_python/tests/functional/api/test_simple_cache.py +173 -0
- {pulp_python-3.34.0.dist-info → pulp_python-3.35.0.dist-info}/METADATA +1 -1
- {pulp_python-3.34.0.dist-info → pulp_python-3.35.0.dist-info}/RECORD +9 -9
- {pulp_python-3.34.0.dist-info → pulp_python-3.35.0.dist-info}/WHEEL +0 -0
- {pulp_python-3.34.0.dist-info → pulp_python-3.35.0.dist-info}/entry_points.txt +0 -0
- {pulp_python-3.34.0.dist-info → pulp_python-3.35.0.dist-info}/licenses/LICENSE +0 -0
- {pulp_python-3.34.0.dist-info → pulp_python-3.35.0.dist-info}/top_level.txt +0 -0
pulp_python/app/__init__.py
CHANGED
pulp_python/app/pypi/views.py
CHANGED
|
@@ -72,17 +72,32 @@ PYPI_SIMPLE_V1_HTML = "application/vnd.pypi.simple.v1+html"
|
|
|
72
72
|
PYPI_SIMPLE_V1_JSON = "application/vnd.pypi.simple.v1+json"
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def
|
|
76
|
-
"""
|
|
75
|
+
def _get_repo_version(path):
|
|
76
|
+
"""Resolve path to a RepositoryVersion, or None if not found."""
|
|
77
77
|
try:
|
|
78
78
|
distro = PyPIMixin.get_distribution(path)
|
|
79
|
-
|
|
79
|
+
return PyPIMixin.get_repository_version(distro)
|
|
80
80
|
except Http404:
|
|
81
81
|
return None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _etag_func(request, path, **kwargs):
|
|
85
|
+
"""Compute unquoted ETag for the condition decorator. Returns None if no repo."""
|
|
86
|
+
repo_ver = _get_repo_version(path)
|
|
87
|
+
if repo_ver is None:
|
|
88
|
+
return None
|
|
82
89
|
raw = f"{repo_ver.number}:{repo_ver.pulp_created.isoformat()}"
|
|
83
90
|
return hashlib.sha256(raw.encode()).hexdigest()[:16]
|
|
84
91
|
|
|
85
92
|
|
|
93
|
+
def _last_modified_func(request, path, **kwargs):
|
|
94
|
+
"""Return the repository version creation timestamp for Last-Modified."""
|
|
95
|
+
repo_ver = _get_repo_version(path)
|
|
96
|
+
if repo_ver is None:
|
|
97
|
+
return None
|
|
98
|
+
return repo_ver.pulp_created
|
|
99
|
+
|
|
100
|
+
|
|
86
101
|
class PyPISimpleHTMLRenderer(TemplateHTMLRenderer):
|
|
87
102
|
media_type = PYPI_SIMPLE_V1_HTML
|
|
88
103
|
|
|
@@ -317,7 +332,7 @@ class SimpleView(PackageUploadMixin, ViewSet):
|
|
|
317
332
|
|
|
318
333
|
@extend_schema(summary="Get index simple page")
|
|
319
334
|
@method_decorator(cache_control(max_age=600, public=True))
|
|
320
|
-
@method_decorator(condition(etag_func=_etag_func))
|
|
335
|
+
@method_decorator(condition(etag_func=_etag_func, last_modified_func=_last_modified_func))
|
|
321
336
|
@PythonApiCache(base_key=find_base_path_cached)
|
|
322
337
|
def list(self, request, path):
|
|
323
338
|
"""Gets the simple api html page for the index."""
|
|
@@ -379,7 +394,7 @@ class SimpleView(PackageUploadMixin, ViewSet):
|
|
|
379
394
|
|
|
380
395
|
@extend_schema(operation_id="pypi_simple_package_read", summary="Get package simple page")
|
|
381
396
|
@method_decorator(cache_control(max_age=600, public=True))
|
|
382
|
-
@method_decorator(condition(etag_func=_etag_func))
|
|
397
|
+
@method_decorator(condition(etag_func=_etag_func, last_modified_func=_last_modified_func))
|
|
383
398
|
@PythonApiCache(base_key=find_base_path_cached)
|
|
384
399
|
def retrieve(self, request, path, package):
|
|
385
400
|
"""Retrieves the simple api html/json page for a package."""
|
|
@@ -482,6 +497,8 @@ class MetadataView(PyPIMixin, ViewSet):
|
|
|
482
497
|
responses={200: PackageMetadataSerializer},
|
|
483
498
|
summary="Get package metadata",
|
|
484
499
|
)
|
|
500
|
+
@method_decorator(cache_control(max_age=900, public=True))
|
|
501
|
+
@method_decorator(condition(etag_func=_etag_func, last_modified_func=_last_modified_func))
|
|
485
502
|
def retrieve(self, request, path, meta):
|
|
486
503
|
"""
|
|
487
504
|
Retrieves the package's core-metadata specified by
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from email.utils import parsedate_to_datetime
|
|
1
2
|
from urllib.parse import urljoin
|
|
2
3
|
|
|
3
4
|
import pytest
|
|
@@ -35,6 +36,20 @@ def synced_distro(
|
|
|
35
36
|
return python_distribution_factory(repository=repo)
|
|
36
37
|
|
|
37
38
|
|
|
39
|
+
@pytest.fixture
|
|
40
|
+
def synced_distro_no_cache(
|
|
41
|
+
python_remote_factory,
|
|
42
|
+
python_repo_with_sync,
|
|
43
|
+
python_distribution_factory,
|
|
44
|
+
):
|
|
45
|
+
"""
|
|
46
|
+
Sync a repo and create a distribution (no cache requirement).
|
|
47
|
+
"""
|
|
48
|
+
remote = python_remote_factory(includes=PYTHON_SM_PROJECT_SPECIFIER)
|
|
49
|
+
repo = python_repo_with_sync(remote)
|
|
50
|
+
return python_distribution_factory(repository=repo)
|
|
51
|
+
|
|
52
|
+
|
|
38
53
|
@pytest.mark.parallel
|
|
39
54
|
def test_simple_cache_hit_miss_and_headers(synced_distro):
|
|
40
55
|
"""
|
|
@@ -139,3 +154,161 @@ def test_simple_cache_etag_conditional_request(synced_distro):
|
|
|
139
154
|
assert r3.headers["Cache-Control"] == cache_control
|
|
140
155
|
assert r3.headers["X-PULP-CACHE"] == "HIT"
|
|
141
156
|
assert len(r3.content) > 0
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
@pytest.mark.parallel
|
|
160
|
+
def test_simple_last_modified_header(synced_distro_no_cache):
|
|
161
|
+
"""Simple API responses include Last-Modified header."""
|
|
162
|
+
index_url = urljoin(synced_distro_no_cache.base_url, "simple/")
|
|
163
|
+
detail_url = f"{index_url}aiohttp"
|
|
164
|
+
|
|
165
|
+
for url in [index_url, detail_url]:
|
|
166
|
+
r = requests.get(url)
|
|
167
|
+
assert r.status_code == 200
|
|
168
|
+
assert "Last-Modified" in r.headers
|
|
169
|
+
parsedate_to_datetime(r.headers["Last-Modified"])
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
@pytest.mark.parallel
|
|
173
|
+
def test_simple_if_modified_since_304(synced_distro_no_cache):
|
|
174
|
+
"""If-Modified-Since with matching timestamp returns 304."""
|
|
175
|
+
url = urljoin(synced_distro_no_cache.base_url, "simple/")
|
|
176
|
+
|
|
177
|
+
r1 = requests.get(url)
|
|
178
|
+
assert r1.status_code == 200
|
|
179
|
+
last_modified = r1.headers["Last-Modified"]
|
|
180
|
+
|
|
181
|
+
r2 = requests.get(url, headers={"If-Modified-Since": last_modified})
|
|
182
|
+
assert r2.status_code == 304
|
|
183
|
+
assert len(r2.content) == 0
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@pytest.mark.parallel
|
|
187
|
+
def test_simple_if_modified_since_old_timestamp_200(synced_distro_no_cache):
|
|
188
|
+
"""If-Modified-Since with old timestamp returns 200 with content."""
|
|
189
|
+
url = urljoin(synced_distro_no_cache.base_url, "simple/")
|
|
190
|
+
|
|
191
|
+
r1 = requests.get(url)
|
|
192
|
+
assert r1.status_code == 200
|
|
193
|
+
|
|
194
|
+
r2 = requests.get(url, headers={"If-Modified-Since": "Thu, 01 Jan 2009 00:00:00 GMT"})
|
|
195
|
+
assert r2.status_code == 200
|
|
196
|
+
assert len(r2.content) > 0
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
@pytest.mark.parallel
|
|
200
|
+
def test_metadata_conditional_request_headers(synced_distro_no_cache):
|
|
201
|
+
"""JSON metadata responses include ETag, Last-Modified, and Cache-Control headers."""
|
|
202
|
+
url = urljoin(synced_distro_no_cache.base_url, "pypi/aiohttp/json/")
|
|
203
|
+
|
|
204
|
+
r = requests.get(url)
|
|
205
|
+
assert r.status_code == 200
|
|
206
|
+
assert r.headers["Cache-Control"] == "max-age=900, public"
|
|
207
|
+
assert "ETag" in r.headers
|
|
208
|
+
assert r.headers["ETag"].startswith('"') and r.headers["ETag"].endswith('"')
|
|
209
|
+
assert "Last-Modified" in r.headers
|
|
210
|
+
parsedate_to_datetime(r.headers["Last-Modified"])
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@pytest.mark.parallel
|
|
214
|
+
def test_metadata_etag_conditional_request(synced_distro_no_cache):
|
|
215
|
+
"""JSON metadata: matching If-None-Match returns 304, non-matching returns 200."""
|
|
216
|
+
url = urljoin(synced_distro_no_cache.base_url, "pypi/aiohttp/json/")
|
|
217
|
+
|
|
218
|
+
r1 = requests.get(url)
|
|
219
|
+
assert r1.status_code == 200
|
|
220
|
+
etag = r1.headers["ETag"]
|
|
221
|
+
|
|
222
|
+
r2 = requests.get(url, headers={"If-None-Match": etag})
|
|
223
|
+
assert r2.status_code == 304
|
|
224
|
+
assert len(r2.content) == 0
|
|
225
|
+
|
|
226
|
+
r3 = requests.get(url, headers={"If-None-Match": '"old"'})
|
|
227
|
+
assert r3.status_code == 200
|
|
228
|
+
assert r3.headers["ETag"] == etag
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@pytest.mark.parallel
|
|
232
|
+
def test_metadata_if_modified_since_304(synced_distro_no_cache):
|
|
233
|
+
"""JSON metadata: If-Modified-Since with matching timestamp returns 304."""
|
|
234
|
+
url = urljoin(synced_distro_no_cache.base_url, "pypi/aiohttp/json/")
|
|
235
|
+
|
|
236
|
+
r1 = requests.get(url)
|
|
237
|
+
assert r1.status_code == 200
|
|
238
|
+
last_modified = r1.headers["Last-Modified"]
|
|
239
|
+
|
|
240
|
+
r2 = requests.get(url, headers={"If-Modified-Since": last_modified})
|
|
241
|
+
assert r2.status_code == 304
|
|
242
|
+
assert len(r2.content) == 0
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
@pytest.mark.parallel
|
|
246
|
+
def test_metadata_if_modified_since_old_timestamp_200(synced_distro_no_cache):
|
|
247
|
+
"""JSON metadata: If-Modified-Since with old timestamp returns 200."""
|
|
248
|
+
url = urljoin(synced_distro_no_cache.base_url, "pypi/aiohttp/json/")
|
|
249
|
+
|
|
250
|
+
r1 = requests.get(url)
|
|
251
|
+
assert r1.status_code == 200
|
|
252
|
+
|
|
253
|
+
r2 = requests.get(url, headers={"If-Modified-Since": "Thu, 01 Jan 2009 00:00:00 GMT"})
|
|
254
|
+
assert r2.status_code == 200
|
|
255
|
+
assert len(r2.content) > 0
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def test_unauthenticated_gets_401_not_304(synced_distro_no_cache, pulpcore_bindings, bindings_cfg):
|
|
259
|
+
"""Unauthenticated client gets 401, not 304, even with conditional request headers."""
|
|
260
|
+
admin_auth = (bindings_cfg.username, bindings_cfg.password)
|
|
261
|
+
simple_url = urljoin(synced_distro_no_cache.base_url, "simple/")
|
|
262
|
+
|
|
263
|
+
r1 = requests.get(simple_url, auth=admin_auth)
|
|
264
|
+
assert r1.status_code == 200
|
|
265
|
+
last_modified = r1.headers["Last-Modified"]
|
|
266
|
+
etag = r1.headers["ETag"]
|
|
267
|
+
|
|
268
|
+
ap_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="pypi/simple")
|
|
269
|
+
assert ap_response.count == 1
|
|
270
|
+
ap_href = ap_response.results[0].pulp_href
|
|
271
|
+
original_statements = pulpcore_bindings.AccessPoliciesApi.read(ap_href).statements
|
|
272
|
+
|
|
273
|
+
anon = requests.Session()
|
|
274
|
+
anon.trust_env = False
|
|
275
|
+
anon.verify = False
|
|
276
|
+
|
|
277
|
+
try:
|
|
278
|
+
pulpcore_bindings.AccessPoliciesApi.partial_update(
|
|
279
|
+
ap_href,
|
|
280
|
+
{
|
|
281
|
+
"statements": [
|
|
282
|
+
{
|
|
283
|
+
"action": ["list", "retrieve"],
|
|
284
|
+
"principal": "authenticated",
|
|
285
|
+
"effect": "allow",
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"action": ["create"],
|
|
289
|
+
"principal": "authenticated",
|
|
290
|
+
"effect": "allow",
|
|
291
|
+
"condition": "index_has_repo_perm:python.modify_pythonrepository",
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
r_ims = anon.get(simple_url, headers={"If-Modified-Since": last_modified})
|
|
298
|
+
assert r_ims.status_code == 401, (
|
|
299
|
+
f"Expected 401 for unauthenticated If-Modified-Since, got {r_ims.status_code}"
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
r_inm = anon.get(simple_url, headers={"If-None-Match": etag})
|
|
303
|
+
assert r_inm.status_code == 401, (
|
|
304
|
+
f"Expected 401 for unauthenticated If-None-Match, got {r_inm.status_code}"
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
r_authed = requests.get(
|
|
308
|
+
simple_url, auth=admin_auth, headers={"If-Modified-Since": last_modified}
|
|
309
|
+
)
|
|
310
|
+
assert r_authed.status_code == 304
|
|
311
|
+
finally:
|
|
312
|
+
pulpcore_bindings.AccessPoliciesApi.partial_update(
|
|
313
|
+
ap_href, {"statements": original_statements}
|
|
314
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
pulp_python/__init__.py,sha256=GIuTLoBTc-07dSLJUh8xrZPRz8x-jJ61pfR0J1IjnzI,65
|
|
2
2
|
pulp_python/pytest_plugin.py,sha256=8Ko-O87JGPC79h8-Ecw2gJLxa6q1Ng8wD6WxbinOnVs,8573
|
|
3
|
-
pulp_python/app/__init__.py,sha256=
|
|
3
|
+
pulp_python/app/__init__.py,sha256=xCiOvju9NA-wwP5pFMObXN703f04RwfZ6kns18Y7bns,2490
|
|
4
4
|
pulp_python/app/cache.py,sha256=Zl2nb4uKyPYp5a3FBrdRZ_-cXfofNMQmIRaQ6dUZZ1g,1037
|
|
5
5
|
pulp_python/app/exceptions.py,sha256=mPNcWyuzF0XeOPybm-G6oDKtRqvfj4jyp41iaYqcqkA,1314
|
|
6
6
|
pulp_python/app/global_access_conditions.py,sha256=MZJtyoVsr-4hRaty6mKDqh3caOHd5UKJjEWLV2crOLs,1080
|
|
@@ -44,7 +44,7 @@ pulp_python/app/migrations/0024_pythonrepository_error_on_reject.py,sha256=p10wp
|
|
|
44
44
|
pulp_python/app/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
45
45
|
pulp_python/app/pypi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
46
46
|
pulp_python/app/pypi/serializers.py,sha256=VDV4REMltZr98bxulgOGoGLnBxUtDod0t1fg_lDFpcs,5601
|
|
47
|
-
pulp_python/app/pypi/views.py,sha256=
|
|
47
|
+
pulp_python/app/pypi/views.py,sha256=9smlBKDtSNTDH5heuKTkAoW4qVGejIkZbdzhijYcVJs,26917
|
|
48
48
|
pulp_python/app/tasks/__init__.py,sha256=JplOj2JtE_i4sQYqV7JnDY7zkraU_KlsCaNnYYaZ1x4,346
|
|
49
49
|
pulp_python/app/tasks/publish.py,sha256=bjsJzqJbLu7TF5rLb-UsZMmlNnc_LKw-sdHX9Gcatbw,4334
|
|
50
50
|
pulp_python/app/tasks/repair.py,sha256=5InzdbjW8y3AC4Vj2PsNLm3wGGTr8D3LcfPw_WA2Fks,12257
|
|
@@ -75,7 +75,7 @@ pulp_python/tests/functional/api/test_pypi_apis.py,sha256=iZnoSN2wCczXh14KJDH8pS
|
|
|
75
75
|
pulp_python/tests/functional/api/test_pypi_simple_api.py,sha256=tOUl8WXgJkMoxGyLbA-WorCxIRKfGWM-27_dK_Jc0Q4,7171
|
|
76
76
|
pulp_python/tests/functional/api/test_rbac.py,sha256=-xNWqvKKU-v1uC6tCRGBK0aWaff25K9C-AfzQkdHhhI,10513
|
|
77
77
|
pulp_python/tests/functional/api/test_repair.py,sha256=4FR7jx_LA2K-pnRJXKkhq-1uUoWXST1leZ9XdyhGM2U,12909
|
|
78
|
-
pulp_python/tests/functional/api/test_simple_cache.py,sha256=
|
|
78
|
+
pulp_python/tests/functional/api/test_simple_cache.py,sha256=jTEvn1qUjtzbG0qi_57J0yk_CQGe_0L31_0giwz7hbY,11141
|
|
79
79
|
pulp_python/tests/functional/api/test_sync.py,sha256=TTHR1CpZeRoD97RKxj2pZPsP0OS9ibYKGPOh1WfKISg,13801
|
|
80
80
|
pulp_python/tests/functional/api/test_upload.py,sha256=f21Li9agJ5fdBqErVg1j6v5FDVdazB5mNClmGOjLUq8,5981
|
|
81
81
|
pulp_python/tests/functional/api/test_version_specifier_filter.py,sha256=nmnBbhwxCEmcHOyFbS1uvemar67sONBGM9SsNn79LCc,1063
|
|
@@ -83,9 +83,9 @@ pulp_python/tests/functional/api/test_vulnerability_report.py,sha256=Rv492Wrvu1F
|
|
|
83
83
|
pulp_python/tests/functional/api/test_yank.py,sha256=qyZbAJ6bJO-4LPkVfVxKuWFjypJ8BmBrCnLo0luAhVk,11913
|
|
84
84
|
pulp_python/tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
85
85
|
pulp_python/tests/unit/test_models.py,sha256=TBI0yKsrdbnJSPeBFfxSqhXK7zaNvR6qg5JehGH3Pds,229
|
|
86
|
-
pulp_python-3.
|
|
87
|
-
pulp_python-3.
|
|
88
|
-
pulp_python-3.
|
|
89
|
-
pulp_python-3.
|
|
90
|
-
pulp_python-3.
|
|
91
|
-
pulp_python-3.
|
|
86
|
+
pulp_python-3.35.0.dist-info/licenses/LICENSE,sha256=2ylvL381vKOhdO-w6zkrOxe9lLNBhRQpo9_0EbHC_HM,18046
|
|
87
|
+
pulp_python-3.35.0.dist-info/METADATA,sha256=luSkmQkUbBLrLQd7dvHrWwQXTe39mNvQomvQpjYUUBw,1744
|
|
88
|
+
pulp_python-3.35.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
89
|
+
pulp_python-3.35.0.dist-info/entry_points.txt,sha256=HvqLEXjw_dS5jqAwnE5JiRZFE6f-y5SRtitKLPml2To,115
|
|
90
|
+
pulp_python-3.35.0.dist-info/top_level.txt,sha256=X0hXgXc_bpbiKqVrkt8jD5_QEiQviKbHDwveQcOcJjo,12
|
|
91
|
+
pulp_python-3.35.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|