Fix tests for verifying otp using mfa session
This commit is contained in:
@@ -2,13 +2,18 @@ package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/db"
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
"github.com/authorizerdev/authorizer/server/memorystore"
|
||||
"github.com/authorizerdev/authorizer/server/refs"
|
||||
"github.com/authorizerdev/authorizer/server/resolvers"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -63,7 +68,16 @@ func verifyOTPTest(t *testing.T, s TestSetup) {
|
||||
otp, err := db.Provider.GetOTPByEmail(ctx, email)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, otp.Otp)
|
||||
|
||||
// Get user by email
|
||||
user, err := db.Provider.GetUserByEmail(ctx, email)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, user)
|
||||
// Set mfa cookie session
|
||||
mfaSession := uuid.NewString()
|
||||
memorystore.Provider.SetMfaSession(user.ID, mfaSession, time.Now().Add(1*time.Minute).Unix())
|
||||
cookie := fmt.Sprintf("%s=%s;", constants.MfaCookieName+"_session", mfaSession)
|
||||
cookie = strings.TrimSuffix(cookie, ";")
|
||||
req.Header.Set("Cookie", cookie)
|
||||
verifyOtpRes, err := resolvers.VerifyOtpResolver(ctx, model.VerifyOTPRequest{
|
||||
Email: &email,
|
||||
Otp: otp.Otp,
|
||||
|
Reference in New Issue
Block a user