Skip to content

Fix flaky SupertabConnectStatusTest - #32

Merged
filias merged 1 commit into
mainfrom
fix/status-test-ec-padding
Oct 16, 2026
Merged

filias merged 1 commit into
mainfrom
fix/status-test-ec-padding

Conversation

@filias

@filias filias commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

SupertabConnectStatusTest fails about once in every 15-20 runs. It just failed on #31 (PHP 8.2), which doesn't touch it.

The test builds its JWK from openssl_pkey_get_details(), which strips leading zero bytes from the EC coordinates. About 1 in 128 random P-256 keys has a 31-byte x or y. The JWK then describes a different point, so the status challenge fails verification and whichever test drew that key fails. Each of the class's 7 tests generates a fresh key, so roughly 1 run in 18 fails.

The fix left-pads both coordinates to 32 bytes. This change is test-only; the SDK reads JWKS from the backend and isn't affected.


Review notes (delete on merge)

Out of 3000 generated keys, 19 had a short coordinate. All 19 failed verification unpadded and passed once padded. With the fix, 40 runs of the class on 8.2 all passed.

🤖 Generated with Claude Code

@filias
filias marked this pull request as ready for review October 16, 2026 13:19
@filias
filias requested review from tomasstark and a balanced review from Copilot and removed request for tomasstark October 16, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow test-only fix correctly restores shortened coordinates without changing full-length values.

0 open findings

What changed in this PR

Fixes intermittent SupertabConnectStatusTest failures by preserving fixed-width P-256 coordinates in test-generated JWKs. Production SDK behavior is unchanged.

Changes:

  • Left-pads both EC coordinates to 32 bytes before base64url encoding.
  • Documents why padding is required.
File Description
tests/​SupertabConnectStatusTest.php Corrects JWK coordinate encoding to prevent random verification failures.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@filias
filias merged commit 473ad04 into main Oct 16, 2026
6 checks passed
nick434434 added a commit that referenced this pull request Nov 4, 2026
## Why
WordPress adds backslashes to `$_SERVER` (`wp_magic_quotes()`). `handleRequest()` reads headers from there through `fromGlobals()`. As a result, `Signature-Input`, `Signature-Agent` and `User-Agent` arrive as `\"https://crawler.exa.ai\"`, and no signature from a WordPress merchant verifies. Five merchants that send events over HTTP are affected, about 16k signed requests a week, all `unverifiable/unsupported_agent`. Removing the backslashes makes 40 of 40 sampled rows valid.

The SDK stays framework-agnostic. The WordPress-specific unslashing goes in the plugin (getsupertab/connect-wp, PR to follow). This PR only lets callers pass their own `$_SERVER`-shaped array.

## Changes
- New `RequestContext::fromServer(array $server, array $requestHeaders = [])` with the old `fromGlobals()` body.
- `fromGlobals()` now calls `fromServer($_SERVER, getallheaders())`. No behavior change.
- Test in `tests/Http/RequestContextTest.php`.

## Release notes (v2.2.0, all changes since v2.1.0)

### Added
- `RequestContext::fromServer(array $server, array $requestHeaders = [])` builds a context from a `$_SERVER`-shaped array. Hosts that modify `$_SERVER` can pass a cleaned copy. WordPress, for example, adds backslashes to it, which broke signature verification for plugin merchants. `fromGlobals()` now delegates to it and behaves the same. (this PR)

### Internal (no runtime changes)
- Added `conformance/run.php`, the PHP runner for the cross-SDK parity suite (#31).
- CI runs the cross-SDK conformance corpus (#33), now pinned to v0.5.0 (#34).
- On a no-match, the conformance runner now reports the SDK's Agreement-lane result instead of "no token needed" (#34).
- Fixed a flaky status test by padding EC coordinates in the test JWK (#32).

`CHANGELOG.md` has these entries under `[2.2.0] - 2026-11-04`, and `composer.json` is set to `v2.2.0`. After merging, tag `v2.2.0`.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants