Repository navigation
fix(ci): repair pre-existing base-branch test failures (closes #993) - #1119
Conversation
Two tests fail on a pristine checkout of feat/multicloud-web-frontend,
turning base CI red and marking every open PR UNSTABLE:
1. internal/server TestAuthServiceAdapter_ValidateCSRFToken
The mock service was built via NewService without a CSRFKey, so it
generated a random ephemeral key each run. The test then asserted a
literal "csrf-token" validated, which the HMAC derivation can never
match. Make the test hermetic: pin a deterministic key with the new
auth.TestCSRFKey() and assert the real derived token via
auth.DeriveTestCSRFToken(). The CSRF validation logic is untouched.
2. frontend utils.test.ts (formatDate / getDateParts)
A date-only string ("2024-03-15") was parsed as UTC midnight, so
toLocaleDateString / getDate() shifted it to the previous day in any
browser west of UTC. This is a real off-by-one for users (purchase
scheduled_date, reservation end_date) and made the test pass only in
UTC. Fix at root: parse bare "YYYY-MM-DD" as local midnight via a new
parseDateInput helper (with round-trip validation so out-of-range
digits like "2024-13-45" still reject). Full timestamps and Date
objects are left untouched. Add timezone-invariance regression tests.
Issue #993 (TestLogin_WithMFA_NoSecret) no longer reproduces on the
current base: service.go already routes every login-failure path through
the single genericLoginError constant, so unknown-email and wrong-password
return a byte-identical message (no enumeration oracle). Closing it here
with the other base-CI repairs.
|
@coderabbitai review |
|
Warning Review limit reached
More reviews will be available in 40 minutes and 17 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
✅ Action performedReview finished.
|
Summary
Repairs the pre-existing test failures that make a pristine checkout of
feat/multicloud-web-frontendred, so every open PR stops inheriting an UNSTABLE base. Fixed in one focused commit; CSRF logic and CSRF/login security behavior are untouched.Closes #993.
Fixes
1.
internal/serverTestAuthServiceAdapter_ValidateCSRFToken(base flake, was red)Root cause:
createMockAuthServicebuilt the service viaauth.NewServicewithout aCSRFKey, soNewServicegenerated a random ephemeral key on every run. The test then asserted that the literal"csrf-token"validates, butValidateCSRFTokenrecomputes the expected token asHMAC-SHA256(csrfKey, rawSessionToken), which a random key can never make equal to a fixed literal. It only ever "passed" if an ambientCSRFKeyhappened to derive that value, which a clean checkout never has.Fix (test-side, hermetic): pin a deterministic key via a new exported
auth.TestCSRFKey()and assert the real derived token via a newauth.DeriveTestCSRFToken()(which reuses the productionderiveCSRFToken, no crypto duplication). The actual CSRF validation logic is unchanged; the test now exercises the real end-to-end path deterministically.2.
frontendutils.test.tsformatDate/getDateParts(base flake, was red outside UTC)Root cause (genuine code bug, not just a test-env assumption): a date-only string like
"2024-03-15"is parsed bynew Date()as UTC midnight, thentoLocaleDateString/getDate()shifts it into the browser's local timezone, so any user west of UTC saw the previous day ("Mar 14") for dates the backend means as plain calendar days (purchasescheduled_date, reservationend_date, etc.). The test only passed in a UTC runner.Fix (code-side, root cause): parse bare
"YYYY-MM-DD"as local midnight via a newparseDateInputhelper, with round-trip validation so out-of-range digits ("2024-13-45") still reject as invalid instead of silently rolling over. Full timestamps (...T..:..Z) andDateobjects are left untouched (formatDateTime/formatRelativeTimekeep their time-of-day behavior). Added timezone-invariance regression tests; the full frontend suite (2510 tests, 74 suites) passes in UTC,America/Los_Angeles,Asia/Tokyo, andAmerica/New_York.3.
internal/authTestLogin_WithMFA_NoSecret(#993 - already resolved on base)#993no longer reproduces on the current base:service.goalready routes every login-failure branch (unknown email, store error, inactive/locked account, wrong password, MFA-secret anomaly) through the singlegenericLoginErrorconstant"Check your email address and password and try again". Unknown-email and wrong-password therefore return a byte-identical message, preserving the anti-enumeration property the test guards. Both subcases pass. A previously-merged PR fixed it; this PR closes the issue alongside the remaining base-CI repairs.Verification
go build ./...— successgo test ./internal/auth/... ./internal/server/...— 909 passednpx tsc --noEmit(frontend) — cleanjestfull frontend suite — 2510 passed / 1 skipped across UTC, LA, Tokyo, NY timezones