You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Testing Rails framework functionality adds no value and can create maintenance burden. Trust that Rails works correctly and focus tests on verifying our application's unique behavior.
40
+
41
+
### Integration Test Patterns
42
+
43
+
**Session handling:**
44
+
- Do NOT manually manipulate cookies in integration tests
45
+
- Use the session provided by the test framework
46
+
- To get the actual session ID, use `Session.last.id` after sign-in, not `cookies[:session_id]` (which is signed)
47
+
48
+
**Application setup:**
49
+
- Always create Application records for the domains you're testing
50
+
- Use wildcard patterns (e.g., `*.example.com`) when testing multiple subdomains
51
+
- Remember: `*` matches one level only (`*.example.com` matches `app.example.com` but NOT `sub.app.example.com`)
52
+
53
+
**Header assertions:**
54
+
- Always normalize header names to lowercase when asserting (HTTP headers are case-insensitive)
55
+
- Use `response.headers["x-remote-user"]` not `response.headers["X-Remote-User"]`
56
+
57
+
**Avoid threading in integration tests:**
58
+
- Rails integration tests use a single cookie jar
59
+
- Convert threaded tests to sequential requests instead
60
+
61
+
### Common Testing Pitfalls
62
+
63
+
1.**Don't test concurrent users with manual cookie manipulation** - Integration tests can't properly simulate multiple concurrent sessions
64
+
2.**Don't expect `cookies[:session_id]` to be the actual ID** - It's a signed cookie value
65
+
3.**Don't assume wildcard patterns match multiple levels** - `*.domain.com` only matches one level
Copy file name to clipboardExpand all lines: README.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -257,6 +257,24 @@ Configure different claims for different applications on a per-user basis:
257
257
- Proxy redirects to Clinch login page
258
258
- After login, redirect back to original URL
259
259
260
+
#### Race Condition Handling
261
+
262
+
After successful login, you may notice an `fa_token` query parameter appended to redirect URLs (e.g., `https://app.example.com/dashboard?fa_token=...`). This solves a timing issue:
263
+
264
+
**The Problem:**
265
+
1. User signs in → session cookie is set
266
+
2. Browser gets redirected to protected resource
267
+
3. Browser may not have processed the `Set-Cookie` header yet
0 commit comments