Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/api/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,13 @@ func (a *API) smsVerify(r *http.Request, conn *storage.Connection, user *models.

switch params.Type {
case smsVerification:
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, models.UserSignedUpAction, "", map[string]interface{}{
// A phone that is already confirmed belongs to an existing user,
// so this verification is a sign-in, not a signup.
action := models.UserSignedUpAction
if user.IsPhoneConfirmed() {
action = models.LoginAction
}
if terr := models.NewAuditLogEntry(config.AuditLog, r, tx, user, action, "", map[string]interface{}{
"provider": PhoneProvider,
}); terr != nil {
return terr
Expand Down
18 changes: 18 additions & 0 deletions internal/api/verify_ott_parity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ func (ts *VerifyTestSuite) TestVerifyOTPParityPhoneFlows() {
Phone: parityPhone,
}

phoneLoggedIn := otpParityOutcome{
Status: http.StatusOK,
Action: string(models.LoginAction),
PhoneConfirmed: true,
Email: parityEmail,
Phone: parityPhone,
}

phoneChanged := otpParityOutcome{
Status: http.StatusOK,
Action: string(models.UserModifiedAction),
Expand All @@ -242,6 +250,16 @@ func (ts *VerifyTestSuite) TestVerifyOTPParityPhoneFlows() {
requestBody: phoneOTPBody(smsVerification, parityPhone),
expected: phoneSignedUp,
},
// An existing user signing in with an SMS code is a login. Only the
// verification that first confirms the phone is a signup.
"sms with a valid code signs a confirmed user in": {
seed: func(u *models.User) {
u.PhoneConfirmedAt = &now
ts.seedChallenge(u, models.ConfirmationToken, parityPhone, phoneHash, now, time.Hour)
},
requestBody: phoneOTPBody(smsVerification, parityPhone),
expected: phoneLoggedIn,
},
"sms with an expired code is rejected": {
seed: func(u *models.User) {
ts.seedChallenge(u, models.ConfirmationToken, parityPhone, phoneHash, expired, -time.Hour)
Expand Down