Skip to content

fix(SDK-876): prevent stale JWT on auth handler failures - #945

Open
jferrao-itrbl wants to merge 2 commits into
masterfrom
fix/SDK-876-rn-4-0-0-test-findings
Open

jferrao-itrbl wants to merge 2 commits into
masterfrom
fix/SDK-876-rn-4-0-0-test-findings

Conversation

@jferrao-itrbl

@jferrao-itrbl jferrao-itrbl commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

📝 Summary

Fix stale JWT on auth timeouts, notify native on authHandler failure, and document iOS push completion handlers.

🎟️ Jira Ticket: SDK-876

📖 Description

Outcome: When an authHandler request fails or times out, native no longer returns a stale token on Android or iOS, JS tells native immediately when authHandler fails, and the iOS push-completion gap is documented as an integrator duty. Package version stays 4.0.0.

What changed (by finding)

Finding Change
1 Android stale token (RNIterableAPIModuleImpl.java): onAuthTokenRequested clears passedAuthToken before each wait so a timed-out request does not return the previous token.
2 iOS stale token / persistent semaphore (ReactIterableAPI.swift): clear passedAuthToken and drain authHandlerSemaphore signals before each 30 s wait.
3 Push completion handlers (documentation only): example AppDelegate passes nil to IterableAppIntegration completion parameters and invokes system handlers locally; README documents nil completion handlers, the pattern, and the tradeoff that calling the fetch completion handler immediately gives iOS less background time for Iterable's work than when the native SDK holds the handler. The defect itself is in the native iOS SDK; nothing in the native repos was changed.
4 JS (Iterable.ts): passAlongAuthToken(null) on rejection, unexpected result, and synchronous throw; zombie queue entry removed.

Verification

Criteria How
6–9 Jest (Iterable.test.ts) — passAlongAuthToken(null), logging, sync throw, zombie-queue routing
1–3 Android unit tests (RNIterableAPIModuleImplAuthTokenTest.java)
4–5 Traced only (no iOS bridge test target)
10 Traced — example AppDelegate.swift
Finding 3 push Traced only — needs device or xcrun simctl push; not runnable in this repo's CI

Android Gradle in this workspace: yarn test:android:unit and yarn turbo run build:android fail in the parent iterable.sdk monorepo layout (autolink). They were run green on an isolated rsync copy at /tmp/rn-sdk-876 (same source tree).

Android auth tests hardened (f30c735a): Real 30 s timeout path, normal-return completion and exception guards, latch-synchronized reply tests (no sleeps). Earlier open nits (two 30 s waits, duplicate timeout test, indentation) are resolved; one intentional ~30 s timeout test remains by decision.

🧪 How to test?

  • yarn test --coverage — authHandler suites in Iterable.test.ts
  • yarn test:android:unit — RNIterableAPIModuleImplAuthTokenTest (note: two tests wait ~30 s each)
  • Manual: JWT app with failing authHandler; confirm native does not reuse stale token after timeout

🧾 Changelog

CHANGELOG.md ## 4.0.0 → Fixes:

  • Stale JWT / authHandler failure fixes (Android/iOS clear + JS passAlongAuthToken(null)).
  • iOS push completion handler integrator note (example AppDelegate + README).

No version bump (remains 4.0.0).

📹 Loom recording if applicable

N/A

🐞 Github Issues solved

N/A

📚 Docs PR if applicable

N/A (README updated in-repo)


Open items (not blocking merge)

  • Out of scope — Native iOS and Android SDK repos were not modified.
  • Residual late-reply window — no request-id correlation by decision; late reply during the next request's wait may still be accepted.
  • Platform parity — Android auth timeout emits no failure event; iOS emits handleAuthFailureCalled with a nil body → JS onJwtError(undefined).
  • Review nits left open — two ~30 s real-wait Android timeout tests; duplicated timeout coverage (F5); minor indentation in test helper (F6).
  • Android auth tests follow-up (f30c735a): Hardened (real timeout path, completion and exception guards, no sleeps). Earlier nits above are resolved except one real ~30 s timeout test remains by decision.
  • Finding 3 (native iOS SDK team) — Iterable-iOS-SDK 6.7.5 IterableAppIntegration drops completion handlers when implementation is nil (fetch path and notification-response path).

Clear stale tokens on Android/iOS auth waits, notify native when JS
authHandler fails, and document iOS push completion handler duty.
@qltysh

qltysh Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Qlty


Coverage Impact

⬆️ Merging this pull request will increase total coverage on master by 0.1%.

Modified Files with Diff Coverage (1)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
src/core/classes/Iterable.ts100.0%
Total100.0%
Commit f30c735 · 🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Lines Statements Branches Functions
Coverage: 88%
88.97% (775/871) 77.01% (315/409) 86.86% (238/274)

@qltysh

qltysh Bot commented Nov 23, 2026

Copy link
Copy Markdown

1 new issue

Tool Category Rule Count
qlty Structure Function with many returns (count = 4): setupEventHandlers 1

The timeout case drives the real 30 s await expiry and rejects the test
if onAuthTokenRequested throws or does not return normally before asserting
null. Reply-path tests synchronize on the auth latch instead of sleeping.
@jferrao-itrbl
jferrao-itrbl marked this pull request as ready for review November 23, 2026 18:42
@jferrao-itrbl
jferrao-itrbl requested a review from a team as a code owner November 23, 2026 18:42

This branch has not been deployed

No deployments
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.

1 participant