Skip to content

Use a frozen clock in the mas-oidc-client integration tests - #5963

Open
barodeur wants to merge 2 commits into
element-hq:mainfrom
barodeur:fix-flaky-oidc-client-clock
Open

Use a frozen clock in the mas-oidc-client integration tests#5963
barodeur wants to merge 2 commits into
element-hq:mainfrom
barodeur:fix-flaky-oidc-client-clock

Conversation

@barodeur

@barodeur barodeur commented Sep 3, 2026

Copy link
Copy Markdown

TLDR: the mas-oidc-client integration tests read the real system clock, which makes fail_verify_id_token_wrong_auth_time fail when the CI runner is slow. Make the tests' now() helper return a fixed MockClock timestamp instead.

Seen on the coverage job of #5961: https://github.com/element-hq/matrix-authentication-service/actions/runs/33742437377/job/100607201186

test requests::jose::fail_verify_id_token_wrong_auth_time has been running for over 60 seconds
test requests::jose::fail_verify_id_token_wrong_auth_time ... FAILED

thread 'requests::jose::fail_verify_id_token_wrong_auth_time' panicked at crates/oidc-client/tests/it/requests/jose.rs:241:5:
assertion failed: `Claim(ValidationError { claim: "iat", source: TimeTooFarError })` does not match `IdTokenError::WrongAuthTime`

The proposed solution here is to:

  • add mas-data-model as a dev-dependency of mas-oidc-client
  • make the test crate's now() return MockClock::default().now()

The oidc-client integration tests read the real system clock through a
`now()` helper. The ID token builder generates a fresh RSA key before
stamping `iat`, while each test captured its own `now` earlier for
verification. Under coverage instrumentation on a loaded CI runner, the
two key generations in `fail_verify_id_token_wrong_auth_time` took more
than the 5 minute `iat` leeway, so verification failed on `iat` before
ever reaching the `auth_time` check the test asserts on.

Make the helper return a frozen `MockClock` timestamp instead. Every
token and verification in the binary now shares one instant, so setup
duration can no longer affect the outcome, and the clippy opt-out for
`Utc::now()` goes away.
@barodeur
barodeur marked this pull request as ready for review September 3, 2026 14:34
@barodeur
barodeur requested a review from a team as a code owner September 3, 2026 14:34
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