Skip to content

Commit 9f0ef76

Browse files
dklibanclaude
andcommitted
Address review feedback on conditional-request PR
- Remove Akamai reference from changelog (not relevant to upstream) - Add test that unauthorized clients get 403 (not 304) when sending conditional request headers with authentication required Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 44019ef commit 9f0ef76

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎CHANGES/1338.feature‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Added conditional request support (`Last-Modified` / `If-Modified-Since` and `ETag` / `If-None-Match`) to the Simple API and JSON Metadata API for Akamai Centralized Authorization and client cache efficiency.
1+
Added conditional request support (`Last-Modified` / `If-Modified-Since` and `ETag` / `If-None-Match`) to the Simple API and JSON Metadata API for improved cache efficiency.

‎pulp_python/tests/functional/api/test_simple_cache.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from email.utils import parsedate_to_datetime
23
from urllib.parse import urljoin
34

@@ -253,3 +254,58 @@ def test_metadata_if_modified_since_old_timestamp_200(synced_distro_no_cache):
253254
r2 = requests.get(url, headers={"If-Modified-Since": "Thu, 01 Jan 2009 00:00:00 GMT"})
254255
assert r2.status_code == 200
255256
assert len(r2.content) > 0
257+
258+
259+
def test_unauthorized_gets_403_not_304(synced_distro_no_cache, pulpcore_bindings):
260+
"""Unauthorized client gets 403, not 304, even with conditional request headers."""
261+
admin_auth = (
262+
os.environ.get("ADMIN_USERNAME", "admin"),
263+
os.environ.get("ADMIN_PASSWORD", "password"),
264+
)
265+
simple_url = urljoin(synced_distro_no_cache.base_url, "simple/")
266+
267+
r1 = requests.get(simple_url, auth=admin_auth)
268+
assert r1.status_code == 200
269+
last_modified = r1.headers["Last-Modified"]
270+
etag = r1.headers["ETag"]
271+
272+
ap_response = pulpcore_bindings.AccessPoliciesApi.list(viewset_name="pypi/simple")
273+
assert ap_response.count == 1
274+
ap_href = ap_response.results[0].pulp_href
275+
276+
try:
277+
pulpcore_bindings.AccessPoliciesApi.partial_update(
278+
ap_href,
279+
{
280+
"statements": [
281+
{
282+
"action": ["list", "retrieve"],
283+
"principal": "authenticated",
284+
"effect": "allow",
285+
},
286+
{
287+
"action": ["create"],
288+
"principal": "authenticated",
289+
"effect": "allow",
290+
"condition": "index_has_repo_perm:python.modify_pythonrepository",
291+
},
292+
],
293+
},
294+
)
295+
296+
r_ims = requests.get(simple_url, headers={"If-Modified-Since": last_modified})
297+
assert r_ims.status_code == 403, (
298+
f"Expected 403 for unauthorized If-Modified-Since, got {r_ims.status_code}"
299+
)
300+
301+
r_inm = requests.get(simple_url, headers={"If-None-Match": etag})
302+
assert r_inm.status_code == 403, (
303+
f"Expected 403 for unauthorized If-None-Match, got {r_inm.status_code}"
304+
)
305+
306+
r_authed = requests.get(
307+
simple_url, auth=admin_auth, headers={"If-Modified-Since": last_modified}
308+
)
309+
assert r_authed.status_code == 304
310+
finally:
311+
pulpcore_bindings.AccessPoliciesApi.reset(ap_href)

0 commit comments

Comments
 (0)