MCPcopy Create free account
hub / github.com/supabase/auth / TestUserUpdatePasswordViaRecovery

Method TestUserUpdatePasswordViaRecovery

internal/api/user_test.go:405–497  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

403}
404
405func (ts *UserTestSuite) TestUserUpdatePasswordViaRecovery() {
406 ts.Config.Security.UpdatePasswordRequireCurrentPassword = true
407 ts.Config.SMTP.MaxFrequency = 60
408 u, err := models.FindUserByEmailAndAudience(ts.API.db, "test@example.com", ts.Config.JWT.Aud)
409 require.NoError(ts.T(), err)
410 u.RecoverySentAt = &time.Time{}
411 require.NoError(ts.T(), ts.API.db.Update(u))
412
413 type expected struct {
414 code int
415 isAuthenticated bool
416 }
417
418 var cases = []struct {
419 desc string
420 newPassword string
421 currentPassword string
422 recoveryType models.AuthenticationMethod
423 expected expected
424 }{
425 {
426 desc: "Current password not required in OTP recovery flow",
427 newPassword: "newpassword123",
428 recoveryType: models.OTP,
429 expected: expected{code: http.StatusOK, isAuthenticated: true},
430 },
431 {
432 desc: "Current password not required in magiclink recovery flow",
433 newPassword: "newpassword456",
434 recoveryType: models.MagicLink,
435 expected: expected{code: http.StatusOK, isAuthenticated: true},
436 },
437 {
438 desc: "Current password not required in PKCE recovery flow",
439 newPassword: "newpassword789",
440 recoveryType: models.Recovery,
441 expected: expected{code: http.StatusOK, isAuthenticated: true},
442 },
443 {
444 desc: "Current password required for any other claim",
445 newPassword: "newpassword456",
446 recoveryType: models.EmailChange,
447 expected: expected{code: http.StatusBadRequest, isAuthenticated: false},
448 },
449 }
450
451 for _, c := range cases {
452 ts.Run(c.desc, func() {
453 require.NoError(ts.T(), models.ClearAllOneTimeTokensForUser(ts.API.db, u.ID))
454
455 // Create a session
456 session, err := models.NewSession(u.ID, nil)
457 require.NoError(ts.T(), err)
458 require.NoError(ts.T(), ts.API.db.Create(session))
459
460 // Add AMR claim to session to simulate recovery flow
461 require.NoError(ts.T(), models.AddClaimToSession(ts.API.db, session.ID, c.recoveryType))
462

Callers

nothing calls this directly

Calls 13

NewSessionFunction · 0.92
AddClaimToSessionFunction · 0.92
FindSessionByIDFunction · 0.92
UpdateMethod · 0.80
generateAccessTokenMethod · 0.80
EncodeMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
AuthenticateMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected