Don't hand out auth tokens if they're not verified

This commit is contained in:
Daniel Krol 2022-07-26 10:53:31 -04:00
parent 55db62e2f9
commit 5985631410
3 changed files with 13 additions and 0 deletions

View file

@ -41,6 +41,10 @@ func (s *Server) getAuthToken(w http.ResponseWriter, req *http.Request) {
errorJson(w, http.StatusUnauthorized, "No match for email and password")
return
}
if err == store.ErrNotVerified {
errorJson(w, http.StatusUnauthorized, "Account is not verified")
return
}
if err != nil {
internalServiceErrorJson(w, err, "Error getting User Id")
return

View file

@ -69,6 +69,14 @@ func TestServerAuthHandlerErrors(t *testing.T) {
storeErrors: TestStoreFunctionsErrors{GetUserId: store.ErrWrongCredentials},
},
{
name: "unverified account",
email: "abc@example.com",
expectedStatusCode: http.StatusUnauthorized,
expectedErrorString: http.StatusText(http.StatusUnauthorized) + ": Account is not verified",
storeErrors: TestStoreFunctionsErrors{GetUserId: store.ErrNotVerified},
},
{
name: "generate token fail",
email: "abc@example.com",

View file

@ -30,6 +30,7 @@ var (
ErrDuplicateAccount = fmt.Errorf("User already has an account")
ErrWrongCredentials = fmt.Errorf("No match for email and password")
ErrNotVerified = fmt.Errorf("User account is not verified")
)
// For test stubs