Skip to content

Commit

Permalink
fix: set the otp if it's not a test otp (#1223)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* OTP should be test if not using the test OTP

---------

Co-authored-by: Stojan Dimitrovski <[email protected]>
  • Loading branch information
kangmingtay and hf authored Aug 17, 2023
1 parent 4ff1fe0 commit 3afc8a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/api/phone.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,15 @@ func (a *API) sendPhoneConfirmation(ctx context.Context, tx *storage.Connection,
now := time.Now()

var otp, messageID string
var err error

if testOTP, ok := config.Sms.GetTestOTP(phone, now); ok {
otp = testOTP
messageID = "test-otp"
}

if otp == "" { // not using test OTPs
otp, err := crypto.GenerateOtp(config.Sms.OtpLength)
otp, err = crypto.GenerateOtp(config.Sms.OtpLength)
if err != nil {
return "", internalServerError("error generating otp").WithInternalError(err)
}
Expand Down
7 changes: 5 additions & 2 deletions internal/api/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ func (ts *VerifyTestSuite) TestInvalidOtp() {
},
}

for _, c := range cases {
for _, caseItem := range cases {
c := caseItem

ts.Run(c.desc, func() {
// update token sent time
sentTime = time.Now()
Expand Down Expand Up @@ -904,7 +906,8 @@ func (ts *VerifyTestSuite) TestVerifyValidOtp() {
},
}

for _, c := range cases {
for _, caseItem := range cases {
c := caseItem
ts.Run(c.desc, func() {
// create user
u.ConfirmationSentAt = &c.sentTime
Expand Down

0 comments on commit 3afc8a9

Please sign in to comment.