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

Method TestUserUpdatePassword

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

Source from the content-addressed store, hash-verified

269}
270
271func (ts *UserTestSuite) TestUserUpdatePassword() {
272 u, err := models.FindUserByEmailAndAudience(ts.API.db, "test@example.com", ts.Config.JWT.Aud)
273 require.NoError(ts.T(), err)
274
275 r, err := models.GrantAuthenticatedUser(ts.API.db, u, models.GrantParams{})
276 require.NoError(ts.T(), err)
277
278 r2, err := models.GrantAuthenticatedUser(ts.API.db, u, models.GrantParams{})
279 require.NoError(ts.T(), err)
280
281 // create a session and modify it's created_at time to simulate a session that is not recently logged in
282 notRecentlyLoggedIn, err := models.FindSessionByID(ts.API.db, *r2.SessionId, true)
283 require.NoError(ts.T(), err)
284
285 // cannot use Update here because Update doesn't removes the created_at field
286 require.NoError(ts.T(), ts.API.db.RawQuery(
287 "update "+notRecentlyLoggedIn.TableName()+" set created_at = ? where id = ?",
288 time.Now().Add(-24*time.Hour),
289 notRecentlyLoggedIn.ID).Exec(),
290 )
291
292 type expected struct {
293 code int
294 isAuthenticated bool
295 }
296
297 var cases = []struct {
298 desc string
299 newPassword string
300 currentPassword string
301 nonce string
302 requireReauthentication bool
303 requireCurrentPassword bool
304 sessionId *uuid.UUID
305 expected expected
306 }{
307 {
308 desc: "Need reauthentication because outside of recently logged in window",
309 newPassword: "newpassword123",
310 nonce: "",
311 requireReauthentication: true,
312 sessionId: &notRecentlyLoggedIn.ID,
313 expected: expected{code: http.StatusBadRequest, isAuthenticated: false},
314 },
315 {
316 desc: "No nonce provided",
317 newPassword: "newpassword123",
318 nonce: "",
319 sessionId: &notRecentlyLoggedIn.ID,
320 requireReauthentication: true,
321 expected: expected{code: http.StatusBadRequest, isAuthenticated: false},
322 },
323 {
324 desc: "Invalid nonce",
325 newPassword: "newpassword1234",
326 nonce: "123456",
327 sessionId: &notRecentlyLoggedIn.ID,
328 requireReauthentication: true,

Callers

nothing calls this directly

Calls 13

generateTokenMethod · 0.95
GrantAuthenticatedUserFunction · 0.92
FindSessionByIDFunction · 0.92
NowMethod · 0.80
EncodeMethod · 0.80
SetMethod · 0.80
EqualMethod · 0.80
AuthenticateMethod · 0.80
AddMethod · 0.65
RunMethod · 0.65
TableNameMethod · 0.45

Tested by

no test coverage detected