Skip to content

Commit b2e9636

Browse files
MarTrepodiclaude
andcommitted
fix(tests): switch HMAC rejection tests from GET to POST endpoint
The four rejection tests in tests/integration/test_hmac.py (test_hmac_no_key_rejected, test_hmac_wrong_key_rejected, and their async variants) were calling client.get_enums(), which is a GET request. The Comlink HMAC service does not protect GET endpoints, so the server returned 200 OK regardless of authentication and the expected SwgohComlinkException was never raised, causing all four tests to fail with "DID NOT RAISE". Switch to client.get_player_arena(allycode=TEST_ALLYCODE, player_details_only=True), which is a POST request to /playerArena (an HMAC-protected endpoint). Use the shared TEST_ALLYCODE constant from conftest so the rejection tests align with the existing get_player and get_player_arena success tests. Verified end-to-end against a live HMAC-protected Comlink container: all four tests now correctly observe HTTP 403 HMACValidationError responses and pass; a positive control with valid keys returns a real playerDetailsOnly response. Fixes #88 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c9e3f59 commit b2e9636

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

tests/integration/test_hmac.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
COMLINK_HMAC_URL,
1515
HMAC_ACCESS_KEY,
1616
HMAC_SECRET_KEY,
17+
TEST_ALLYCODE,
1718
)
1819

1920
pytestmark = pytest.mark.integration
@@ -48,14 +49,24 @@ def test_hmac_sync_player_request_succeeds(comlink_hmac):
4849

4950
@hmac_configured
5051
def test_hmac_no_key_rejected():
51-
"""Sync client without HMAC keys is rejected by the protected endpoint."""
52+
"""Sync client without HMAC keys is rejected by the protected endpoint.
53+
54+
Uses a POST endpoint (`playerArena`) because the Comlink HMAC service
55+
only enforces HMAC on POST; GET endpoints like `/enums` are
56+
unauthenticated.
57+
"""
5258
with SwgohComlink(url=COMLINK_HMAC_URL) as client, pytest.raises(SwgohComlinkException):
53-
client.get_enums()
59+
client.get_player_arena(allycode=TEST_ALLYCODE, player_details_only=True)
5460

5561

5662
@hmac_configured
5763
def test_hmac_wrong_key_rejected():
58-
"""Sync client with wrong secret key is rejected by the protected endpoint."""
64+
"""Sync client with wrong secret key is rejected by the protected endpoint.
65+
66+
Uses a POST endpoint (`playerArena`) because the Comlink HMAC service
67+
only enforces HMAC on POST; GET endpoints like `/enums` are
68+
unauthenticated.
69+
"""
5970
with (
6071
SwgohComlink(
6172
url=COMLINK_HMAC_URL,
@@ -64,7 +75,7 @@ def test_hmac_wrong_key_rejected():
6475
) as client,
6576
pytest.raises(SwgohComlinkException),
6677
):
67-
client.get_enums()
78+
client.get_player_arena(allycode=TEST_ALLYCODE, player_details_only=True)
6879

6980

7081
# ── Async: valid HMAC ───────────────────────────────────────────────────
@@ -94,23 +105,33 @@ async def test_hmac_async_player_request_succeeds(async_comlink_hmac):
94105
@hmac_configured
95106
@pytest.mark.asyncio
96107
async def test_hmac_no_key_async_rejected():
97-
"""Async client without HMAC keys is rejected by the protected endpoint."""
108+
"""Async client without HMAC keys is rejected by the protected endpoint.
109+
110+
Uses a POST endpoint (`playerArena`) because the Comlink HMAC service
111+
only enforces HMAC on POST; GET endpoints like `/enums` are
112+
unauthenticated.
113+
"""
98114
async with SwgohComlinkAsync(url=COMLINK_HMAC_URL) as client:
99115
with pytest.raises(SwgohComlinkException):
100-
await client.get_enums()
116+
await client.get_player_arena(allycode=TEST_ALLYCODE, player_details_only=True)
101117

102118

103119
@hmac_configured
104120
@pytest.mark.asyncio
105121
async def test_hmac_wrong_key_async_rejected():
106-
"""Async client with wrong secret key is rejected by the protected endpoint."""
122+
"""Async client with wrong secret key is rejected by the protected endpoint.
123+
124+
Uses a POST endpoint (`playerArena`) because the Comlink HMAC service
125+
only enforces HMAC on POST; GET endpoints like `/enums` are
126+
unauthenticated.
127+
"""
107128
async with SwgohComlinkAsync(
108129
url=COMLINK_HMAC_URL,
109130
access_key=HMAC_ACCESS_KEY,
110131
secret_key="wrong_secret_key",
111132
) as client:
112133
with pytest.raises(SwgohComlinkException):
113-
await client.get_enums()
134+
await client.get_player_arena(allycode=TEST_ALLYCODE, player_details_only=True)
114135

115136

116137
# ── HMAC header verification ────────────────────────────────────────────

0 commit comments

Comments
 (0)