test(api): merge repeated cases into tables, drop skips dbtest already makes (#8295)
release / web (push) Successful in 1m34s
release / go (push) Successful in 2m0s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m24s
release / android (push) Successful in 4m46s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
release / web (push) Successful in 1m34s
release / go (push) Successful in 2m0s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m24s
release / android (push) Successful in 4m46s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- The like/unlike story runs as one sequence that checks the rows after each step. - The invite-only sign-up cases are one test, which now also checks that a refused sign-up creates no account. - Demoting an admin, and stopping at the last one, is one test. - A wrong password and an unknown user are one test, which now also checks that the two refusals are identical. - The cover-path resolver tests repeated the cover handler's tests branch for branch; the handler tests stay. - The Range-from-start stream test only re-checked http.ServeContent. - The APK's nil-user 401 is covered by the mounted-route walk. - 68 copies of the MINSTREL_TEST_DATABASE_URL skip go: every one of those tests reaches dbtest.Pool, which already skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+25
-28
@@ -128,34 +128,6 @@ func TestHandleLogin_SuccessSetsCookieAndReturnsToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleLogin_WrongPasswordReturns401(t *testing.T) {
|
||||
h, pool := testHandlers(t)
|
||||
seedUser(t, pool, "alice", "hunter2", false)
|
||||
|
||||
body := strings.NewReader(`{"username":"test-alice","password":"wrong"}`)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/auth/login", body)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
w := httptest.NewRecorder()
|
||||
h.handleLogin(w, req)
|
||||
|
||||
if w.Code != http.StatusUnauthorized {
|
||||
t.Errorf("status = %d, want 401", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleLogin_UnknownUserReturns401(t *testing.T) {
|
||||
h, _ := testHandlers(t)
|
||||
body := strings.NewReader(`{"username":"ghost","password":"whatever"}`)
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/auth/login", body)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
w := httptest.NewRecorder()
|
||||
h.handleLogin(w, req)
|
||||
|
||||
if w.Code != http.StatusUnauthorized {
|
||||
t.Errorf("status = %d, want 401", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// A guesser who reaches the account limit is refused with 429 before any
|
||||
// password check, so even the right password is turned away until the window
|
||||
// passes, and the response says when to come back.
|
||||
@@ -284,3 +256,28 @@ func TestHandleLogout_BearerHeaderWithTrailingWhitespaceDeletesSession(t *testin
|
||||
t.Error("session row still present after bearer logout with trailing whitespace")
|
||||
}
|
||||
}
|
||||
|
||||
// A wrong password and an unknown username get the same 401 and the same
|
||||
// body, so a failed sign-in never tells anyone whether an account exists.
|
||||
func TestHandleLogin_AWrongPasswordAndAnUnknownUserLookAlike(t *testing.T) {
|
||||
h, pool := testHandlers(t)
|
||||
seedUser(t, pool, "alice", "hunter2", false)
|
||||
|
||||
var bodies []string
|
||||
for _, creds := range []string{
|
||||
`{"username":"test-alice","password":"wrong"}`,
|
||||
`{"username":"ghost","password":"whatever"}`,
|
||||
} {
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/auth/login", strings.NewReader(creds))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
w := httptest.NewRecorder()
|
||||
h.handleLogin(w, req)
|
||||
if w.Code != http.StatusUnauthorized {
|
||||
t.Errorf("%s: status %d, want 401", creds, w.Code)
|
||||
}
|
||||
bodies = append(bodies, w.Body.String())
|
||||
}
|
||||
if bodies[0] != bodies[1] {
|
||||
t.Errorf("the refusals differ: %q vs %q", bodies[0], bodies[1])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user