MCPcopy Index your code
hub / github.com/coder/coder / TestUserForgotPassword

Function TestUserForgotPassword

coderd/userauth_test.go:2736–3051  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2734}
2735
2736func TestUserForgotPassword(t *testing.T) {
2737 t.Parallel()
2738
2739 const oldPassword = "SomeSecurePassword!"
2740 const newPassword = "SomeNewSecurePassword!"
2741
2742 requireOneTimePasscodeNotification := func(t *testing.T, notif *notificationstest.FakeNotification, userID uuid.UUID) {
2743 require.Equal(t, notifications.TemplateUserRequestedOneTimePasscode, notif.TemplateID)
2744 require.Equal(t, userID, notif.UserID)
2745 require.Equal(t, 1, len(notif.Targets))
2746 require.Equal(t, userID, notif.Targets[0])
2747 }
2748
2749 requireCanLogin := func(t *testing.T, ctx context.Context, client *codersdk.Client, email string, password string) {
2750 _, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{
2751 Email: email,
2752 Password: password,
2753 })
2754 require.NoError(t, err)
2755 }
2756
2757 requireCannotLogin := func(t *testing.T, ctx context.Context, client *codersdk.Client, email string, password string) {
2758 _, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{
2759 Email: email,
2760 Password: password,
2761 })
2762 var apiErr *codersdk.Error
2763 require.ErrorAs(t, err, &apiErr)
2764 require.Equal(t, http.StatusUnauthorized, apiErr.StatusCode())
2765 require.Contains(t, apiErr.Message, "Incorrect email or password.")
2766 }
2767
2768 requireRequestOneTimePasscode := func(t *testing.T, ctx context.Context, client *codersdk.Client, notifyEnq *notificationstest.FakeEnqueuer, email string, userID uuid.UUID) string {
2769 notifyEnq.Clear()
2770 err := client.RequestOneTimePasscode(ctx, codersdk.RequestOneTimePasscodeRequest{Email: email})
2771 require.NoError(t, err)
2772 sent := notifyEnq.Sent()
2773 require.Len(t, sent, 1)
2774
2775 requireOneTimePasscodeNotification(t, sent[0], userID)
2776 return sent[0].Labels["one_time_passcode"]
2777 }
2778
2779 requireChangePasswordWithOneTimePasscode := func(t *testing.T, ctx context.Context, client *codersdk.Client, email string, passcode string, password string) {
2780 err := client.ChangePasswordWithOneTimePasscode(ctx, codersdk.ChangePasswordWithOneTimePasscodeRequest{
2781 Email: email,
2782 OneTimePasscode: passcode,
2783 Password: password,
2784 })
2785 require.NoError(t, err)
2786 }
2787
2788 t.Run("CanChangePassword", func(t *testing.T) {
2789 t.Parallel()
2790
2791 notifyEnq := &notificationstest.FakeEnqueuer{}
2792
2793 client := coderdtest.New(t, &coderdtest.Options{

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
ClearMethod · 0.95
SentMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
LoginWithPasswordMethod · 0.80
RunMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected