Testing Slack OAuth App Installation Flows in CI

A stateful simulator proves what stubs can't: install, revoke, reinstall.

· 8 min read · Updated
Cover illustration for “Testing Slack OAuth App Installation Flows in CI”
Auth Flow Testing · October 27, 2026 · 8 min read · 1,755 words

Testing Slack OAuth app installation flows in CI requires a stateful simulator that remembers what happened across the redirect chain. For integration tests against APIs where order of operations determines correctness, fixed responses cannot prove that later calls use state created by earlier ones. Unit tests validate isolated logic, a local simulator validates the full flow without live credentials, and periodic live runs detect platform drift.

Why the Slack OAuth installation flow is inherently stateful

An API call can often be tested as a request-response pair, but Slack OAuth installation is a stateful redirect chain. Each step depends on data produced earlier. Three things link those steps: the state nonce that survives the browser round-trip, the one-time authorization code, and the bot token stored for each workspace. The nonce must be consumed exactly once, the code becomes unusable after exchange, and later calls must retrieve the correct workspace’s token.

The callback has a distinct security constraint. It cannot rely on an authenticated caller because Slack redirects the operator’s browser to it, so the state nonce protects the route. The everruns OAuth PR documents the attack that becomes possible without a stored single-use nonce. An attacker can submit a code from their own workspace to bind that workspace to someone else’s endpoint. Its nonce design uses 256 random bits, constant-time comparison, and a 30-minute window, and spends the nonce on both success and refusal.

The exchange response also demands more than a transport-level assertion. oauth.v2.access returns HTTP 200 even for failed grants, with failure expressed as ok: false in the body. A successful status therefore does not establish a successful installation. Enterprise Grid introduces another boundary because org-wide installs have no single team_id to key on. Implementations that refuse those installs must do so without creating an installation record.

Where stateless stubs and live credentials both fail in CI

A stateless stub can return a hardcoded installation object and a matching bot token. Because the stub has no memory, it cannot establish that a token retrieved later is the token stored during installation. That gap appears in install, revoke, and reinstall sequences, OAuth-over-legacy token precedence, and workspace-scoped routing. These are tests of accumulated state.

Stateless stubs still have a precise role. They can support isolated tests for state tampering, expiry, wrong keys, missing or mismatched cookies, AES-GCM sealing, and org-wide rejection. Event parsing for app_uninstalled and tokens_revoked can also be tested without persisting an installation. What those tests cannot establish is whether event handling changes the record that a subsequent lookup reads. State-machine logic and the changes it saves need their own assertions.

Live Slack addresses fidelity but introduces another obstacle. Driving the full redirect chain in headless CI requires live secrets and a real workspace admin. The everruns PR states, “no end-to-end smoke test; it needs a real Slack app configuration token and a running stack, neither of which this environment has”. The resulting test architecture must distinguish logic bugs, HTTP wire-format bugs, and Slack platform changes. In-process tests check for the first, a local HTTP stand-in checks for the second, and live runs from time to time or a manifest sync check catch the third.

How can integration tests track state across the full OAuth flow?

A stateful simulator and its test-side installation store need four categories of state, namely pending nonces, in-flight authorization codes, per-workspace installation records, and revocation history. Each supports a different negative assertion. Pending nonces need timestamps and single-use enforcement across the install redirect and callback. Without that memory, a replay can pass because the test accepts a state string without checking whether it remains valid. Authorization codes likewise need a lifecycle that rejects a second exchange.

Installation records must persist across separate calls. The uploads.sh OAuth PR implements a slack_installations D1 table keyed by team ID, with botTokenFor reading the team’s installation. It falls back to SLACK_BOT_TOKEN only for SLACK_TEAM_ID. A corresponding test store must overwrite the workspace’s record on reinstall. Otherwise, a successful exchange says nothing about which token the next lookup will return.

Revocation makes that distinction observable after installation succeeds. Processing app_uninstalled or tokens_revoked must stamp revoked_at and prevent token retrieval until a fresh installation. Without that transition, a revoke-and-reinstall test can pass while never demonstrating that revocation took effect. In multi-tenant applications, storeInstallation, fetchInstallation, and deleteInstallation must each work on the records for the right workspace. An in-memory implementation is sufficient if those operations share state throughout the test.

The test-side store must accept sealed payloads and return them intact so that the AES-GCM envelope is exercised in context. The everruns PR supplies the single-use nonce requirement, while the uploads.sh PR supplies the workspace-keyed storage and fallback example.

Structuring the test suite by stage and layer

The first layer consists of in-process unit tests with no network or simulator. These isolate sealing round-trips and wrong-key failures, state-token tampering and expiry, and missing or mismatched cookies. They also check that code exchange stores tokens in sealed form rather than as plaintext, and that nothing is stored for failed grants, org-wide installs, or access denial. Revoke-and-reinstall logic, team-scoped legacy fallback, and uninstall or revocation event parsing belong here without claiming persistence coverage. The uploads.sh PR includes exactly 32 tests in pnpm test:slack, with D1 tests running the real migration on node:sqlite.

The second layer tests through a local HTTP simulator. It follows installation through token storage and retrieval, then checks that reinstall overwrites the existing record. Revocation must make the next fetch empty, and a fresh install must restore retrieval. The same layer checks that an OAuth installation takes precedence over the legacy token and that two workspaces never retrieve each other’s tokens. Double-exchange rejection and HTTP 200 responses containing ok: false complete the connection between protocol behavior and stored results.

The third layer checks for platform drift. It is a periodic, gated live-API smoke test. The weekly-feedback-tool issue makes a documented way to exercise OAuth locally against a Slack dev app an explicit acceptance criterion. That live test needs credentials and a real workspace admin, so it stays outside the main CI pipeline.

Driving the redirect chain in CI without a browser

The runner drives the flow by making HTTP calls directly, without a browser to follow redirects. It begins with GET /slack/install and captures both the state cookie and the state parameter from the redirect URL. The assertions start at this first response. The cookie must be short-lived and host-only, with the __Host- prefix, while the simulator’s authorization endpoint must replace slack.com as the redirect target.com`. The uploads.sh PR uses a 10-minute cookie, distinct from the everruns design’s 30-minute nonce window.

The runner then calls the authorization endpoint directly with the captured state and test workspace credentials. It asserts that the simulator issues a one-time code and redirects to the callback URL. Next, it calls GET /slack/oauth/callback with that code and state, passing the original cookie. The application verifies the state and exchanges the code through the simulator’s oauth.v2.access endpoint. In the uploads.sh flow, the state must be signed, unexpired, and matched to the cookie.

For the final persistence assertion, the runner queries the installation store directly or calls fetchInstallation to establish that the token is sealed and keyed to the correct team_id. This connects the stored result to the authorization the simulator issued. Callback verification also includes a strict CSP and no-store cache control. The uploads.sh callback uses a small result page without scripts, making those response headers part of the testable flow.

Fault injection cases specific to the OAuth flow

For expiry, the harness returns a callback with a state timestamp outside the acceptance window, and the application must refuse it without storing a token. For replay, the runner submits the same state twice and expects the second callback to be refused. This catches implementations that validate a nonce without consuming it. Repeating the case after refusal tests the requirement that unsuccessful authorization also spends the nonce.

Exchanging the same code twice must produce ok: false on the second attempt, exposing double-exchange bugs hidden by a constant token response. An expired-code response tests what happens when the code’s time runs out. Separately, returning HTTP 200 with ok: false checks that the application recognizes OAuthExchangeRefused from the body. The store must still be empty after that refused grant.

The simulator fires tokens_revoked between installation and first API use, after which botTokenFor must return nothing. A later reinstall tests recovery from that revoked state. Rate-limit injection returns 429 from oauth.v2.access to test retry logic without using real quota. Delaying the exchange response tests timeout handling, including for agentic callers that drive installation programmatically and may escalate to higher-privilege paths under transient failures.

These cases define concrete simulator selection criteria. Expired nonces, double-exchange refusals, failed grants, 429 responses, and latency delays should be configurable without patching simulator code. Workspace records and team IDs seeded ahead of time, along with bot token shapes that look real, help keep fixtures from drifting. The simulator’s contract also needs to be checked against live Slack on an ongoing basis and before each release, including the HTTP 200 failed-grant response.

CI pipeline configuration for the full OAuth test suite

The main pipeline runs two jobs that each have all they need on every push. The unit job needs neither a network connection nor a simulator, and covers the sealing, state-validation, grant-rejection, fallback, and event-handling cases described above. It also runs the D1/SQLite migration tests to check that the installation schema applies cleanly. Assertions must distinguish a successful HTTP response from a successful grant. The 32-test uploads.sh suite shows what a suite can cover, without setting a test-count target for every suite.

The integration job starts the simulator as a local process or sidecar container and points SLACK_API_BASE_URL, or its equivalent, at that instance. It drives initiation, approval, callback, and stored-state assertions programmatically. Its fault cases include expired state, state mismatch, nonce replay, double exchange, failed grants, and mid-flow revocation. Two independent workspace installs test isolation, while reinstall tests confirm that the existing record is overwritten. No live Slack credentials are needed for this job.

The live smoke job is credential-protected and runs on a schedule or explicit trigger outside the every-push pipeline. Its purpose is to detect contract drift. Failures trigger a simulator fidelity update. Separately, slack manifest sync checks that redirect URLs and event subscriptions match the deployed configuration, covering failures where correct code meets drifted Slack settings. Rate limits and live credentials have no place in the development or routine CI workflow. The first two jobs must remain self-contained.

Sources

  1. Authenticating with OAuth

More in Auth Flow Testing