Skip to content

fix(tests): switch HMAC rejection tests from GET to POST endpoint - #89

Merged
MarTrepodi merged 1 commit into
developfrom
fix/hmac-integration-tests
May 10, 2026
Merged

fix(tests): switch HMAC rejection tests from GET to POST endpoint#89
MarTrepodi merged 1 commit into
developfrom
fix/hmac-integration-tests

Conversation

@MarTrepodi

Copy link
Copy Markdown
Collaborator

Closes #88

Summary

The four HMAC 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 to /enums. The Comlink HMAC service does not enforce HMAC on GET endpoints — only on POST — so the server returned 200 OK regardless of authentication and the expected SwgohComlinkException was never raised. All four tests failed with Failed: DID NOT RAISE.

This PR switches those tests to call client.get_player_arena(allycode=TEST_ALLYCODE, player_details_only=True), a POST request to /playerArena (HMAC-protected). Uses the shared TEST_ALLYCODE constant from conftest.py so the rejection tests align with the existing get_player and get_player_arena success tests.

Why this only surfaced now

Integration tests never ran on PRs targeting develop until #85 landed and integration.yml started triggering on develop PRs. PRs to main had been skipping these tests because develop was not in the trigger list, so the latent bug went unnoticed.

Verification

Probed a live HMAC-protected Comlink container directly to confirm the diagnosis and exercised the new test code end-to-end:

Scenario Endpoint Result
no auth GET /enums 200 OK (server doesn't protect GET — root cause)
no auth POST /playerArena 403 HMACValidationError (Authorization header missing)
wrong secret POST /playerArena 403 HMACValidationError (HMAC validation failed)
valid test_key/test_secret POST /playerArena 200 OK with real playerDetailsOnly response

All four updated tests PASS against the live container.

Test plan

  • CI Integration Tests check passes on this PR (was failing on every PR since ci: align workflow triggers with develop branch model #85 merged due to this bug).
  • Other CI checks (Lint, Type Check, Test (Python 3.10..3.13), Docs, Build, Validate Commit Messages) remain green.
  • No changes outside tests/integration/test_hmac.py; client and server code untouched.

Notes

  • Production HMAC client behavior is correct and unchanged — verified by the existing test_hmac_*_request_succeeds tests (which continue to pass) and by the positive-control valid-auth probe in this PR's verification.
  • Bug was purely in test scaffolding.

Generated with Claude Code

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>
@MarTrepodi MarTrepodi self-assigned this May 10, 2026
@MarTrepodi MarTrepodi added bug Unintended functionality or behavior test Test related tasks ci Changes related to continuous integration processes and removed testing labels May 10, 2026
@MarTrepodi
MarTrepodi merged commit 75feb67 into develop May 10, 2026
15 checks passed
@MarTrepodi
MarTrepodi deleted the fix/hmac-integration-tests branch May 10, 2026 13:07
MarTrepodi added a commit that referenced this pull request May 11, 2026
**Draft release PR — promotes the current `develop` tip to `main`.**
Once merged, dispatch the `comlink-python release` workflow from `main`
to bump the version, regenerate `CHANGELOG.md`, tag, and publish to PyPI
via OIDC.

## Contents — 6 commits since `v2.0.7`

```
75feb67 fix(tests): switch HMAC rejection tests from GET to POST endpoint (#89)
c9e3f59 fix(helpers): ensure arena payout time adjusts correctly when shifted to past
e8a6e05 fix(helpers): handle multi-day offsets in get_arena_payout
51235c1 chore(dependabot): set target branch to `develop`, limit open PRs to 10
8c0aa3a ci(release): guard release workflow against non-main dispatch (#86)
523a2ca ci: align workflow triggers with develop branch model (#85)
```

## What's in this release

### Bug fixes
- **`get_arena_payout` returns past datetime when offset spans more than
one day**
([#87](#87)) — `if`
→ `while` so payouts shifted into the past by 24+ hour offsets advance
day-by-day until landing in the future.

### CI / infrastructure
- **Workflow triggers aligned with the new `develop`-based branch
model** ([#85](#85)) —
`ci.yml`, `commitlint.yml`, and `integration.yml` now run on `[main,
develop]` PRs and pushes; stale references to `1.0-maintenance` and
`2.0-development` removed; redundant `test.yml` deleted.
- **Release workflow hardened with a branch guard**
([#86](#86)) — both
jobs in `release.yml` now require `github.ref == 'refs/heads/main'`,
preventing accidental dispatch from `develop` or feature branches.
- **HMAC integration tests fixed**
([#89](#89)) —
rejection tests now call a POST endpoint (`/playerArena`) instead of
`/enums` (GET, which the server doesn't HMAC-protect).

### Chore
- **Dependabot configuration** ([commit
`51235c1`](51235c1))
— `target-branch: develop` and `open-pull-requests-limit: 10` for the
pip ecosystem.

## No user-facing API changes

All changes are internal: bug fix in a helper, CI/test changes,
dependabot config. No new methods, no signature changes, no removals.

## Release plan

After this PR merges:

1. Trigger `comlink-python release` workflow from `main`: `gh workflow
run release.yml --ref main`.
2. Workflow performs (gated by the new branch guard from #86):
   - `uvx hatch version minor` → `2.0.7` → `2.1.0`
- `uvx git-changelog` regenerates `CHANGELOG.md` from commit history
(Angular convention, semver)
   - Commit + tag (`v2.1.0`) + push
   - `uvx hatch build` (sdist + wheel)
- Publish to PyPI via Trusted Publishing OIDC
(`pypa/gh-action-pypi-publish` SHA-pinned at `v1.13.0`)
3. GitHub auto-creates a release from the tag.

## Test plan

- [ ] All required CI checks pass on this PR (`Lint`, `Type Check`,
`Test (Python 3.10..3.13)`, `Docs`, `Build`, `Validate Commit Messages`,
`Integration Tests`).
- [ ] Merge method: **rebase** (not squash) to preserve the individual
PR commits on `main`'s linear history.
- [ ] After merge, dispatch `release.yml` from `main` and verify:
  - Version bumps to `2.1.0` in `src/swgoh_comlink/version.py`.
  - `CHANGELOG.md` gets a new `## [v2.1.0]` section.
  - PyPI receives the new release.
  - GitHub Release is auto-created.

## Notes

- This is a **draft PR** because the release cadence is your call — mark
ready for review when you're prepared to cut `v2.1.0`.
- Branch protection on `main` currently has `contexts: []` (no required
checks). Consider applying the required-contexts list documented in
`workflow-review-plan.md` once stable.

Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unintended functionality or behavior ci Changes related to continuous integration processes test Test related tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant