3.8 KiB
3.8 KiB
QA procedure: registration_status_endpoint
Package: test (black-box), extending test/user_test.go (mockUserRepo, stubHasher) and
test/mail_test.go (mockMailRepo), and following the router wiring pattern in
test/registration_gate_and_verification_email_http_test.go /
test/get_current_user_http_test.go.
Setup shared by every case
- Call
validator.InitValidator()once. - Build
createUserUseCase := useCases.NewCreateUserUseCase(repo, &stubHasher{}, mailRepo, "https://cms.example.com")whererepois amockUserRepoandmailRepois amockMailRepo. - Build the auth handler(s) the same way
NewAuthRouterdoes, but only mount what each case needs:GET /v1/auth/registrationunprotected, at the router's top level (nojwtauth.Verifier, nojwtauth.Authenticator, nomiddleware.NewRateLimiter), on a freshchi.NewRouter(). No live server, no real SQLite file, no real SMTP.
HTTP-level checks
- Empty
mockUserRepo.GET /v1/auth/registrationwith no cookie → assert status200,Cache-Controlheader equals"no-store", and the decoded JSON body is exactly{"open": true}(assert there is no other top-level key by decoding intomap[string]anyand checkinglen(body) == 1). mockUserReposeeded with one user,IsVerified: false.GET /v1/auth/registration→ assert status200and body exactly{"open": true}.mockUserReposeeded with one user,IsVerified: true.GET /v1/auth/registration→ assert status200,Cache-Control: no-store, and body exactly{"open": false}.- Same seed as step 6. Attach a jwt cookie whose value is invalid/expired/garbage — e.g. a plain
string like
"jwt=not-a-real-token", or a token minted with a different signing key, or one built withtoken.Encodeand then manually expired/truncated — deliberately NOT a cookie freshly minted withtoken.Encodeagainst the router's own signing key.GET /v1/auth/registrationwith that cookie attached → assert status200, body exactly{"open": false}(identical to step 6's cookie-less result), and noSet-Cookieheader on the response. This demonstrates the route never parses or validates the cookie at all, since an invalid/expired one produces byte-identical output to no cookie. mockUserReposeeded with three users (twoIsVerified: true, oneIsVerified: false).GET /v1/auth/registration→ decode the body intomap[string]any, assert its only key is"open", and assert the raw response body (as a string) does not contain any of the seeded usernames or emails, and does not contain a numeric user count anywhere but inside the booleanopenvalue.- Empty
mockUserRepo. SendGET /v1/auth/registration20 times in a row against the same router/repo (a plain loop ofhttptest.NewRequest+ServeHTTP, no external rate limiter middleware mounted on this route) → assert every response status is200and none is429.
Use-case-level check (no HTTP)
- Build a
user.Repositoryfake (mockUserRepo) containing one user withIsVerified: true. BuildCreateUserUseCaseover that fake, astubHasher, and amockMailRepo. Call the new exported method (e.g.IsRegistrationOpen()) and assert it returnsfalse. Then callCreateUserwith a new username/email/password on the same use case instance and asserterrors.Is(err, user.ErrRegistrationClosed)— proving both entry points consult the same underlying check rather than two independently-maintained copies.
Manual verification (not exercised by the Go test)
- The SPA actually calling
GET /v1/auth/registrationbefore rendering the registration form (rather than always showing it and relying on the 403 from POST /v1/auth/register) is out of scope for this slice's automated test and should be checked by hand against a running dev build.