This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforgot_password_test.go
56 lines (47 loc) · 1.62 KB
/
forgot_password_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package auth_test
import (
"context"
"fmt"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types"
"github.com/stretchr/testify/require"
auth "github.com/gofor-little/aws-auth"
)
func TestForgotPassword(t *testing.T) {
setup(t)
defer teardown(t)
testCases := []struct {
emailAddress string
password string
}{
{"[email protected]", "test-Password1234!!"},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("TestForgotPassword%d", i), func(t *testing.T) {
_, err := auth.SignUp(context.Background(), tc.emailAddress, tc.password)
require.NoError(t, err)
// Confirm the user without the use of a confirmation code so we can test the sign in.
_, err = auth.CognitoClient.AdminConfirmSignUp(context.Background(), &cognitoidentityprovider.AdminConfirmSignUpInput{
UserPoolId: aws.String(auth.CognitoUserPoolID),
Username: aws.String(tc.emailAddress),
})
require.NoError(t, err)
// Set the email verified to true so we can use it in the forgot password request.
_, err = auth.CognitoClient.AdminUpdateUserAttributes(context.Background(), &cognitoidentityprovider.AdminUpdateUserAttributesInput{
UserAttributes: []types.AttributeType{
{
Name: aws.String("email_verified"),
Value: aws.String("true"),
},
},
UserPoolId: aws.String(auth.CognitoUserPoolID),
Username: aws.String(tc.emailAddress),
})
require.NoError(t, err)
_, err = auth.ForgotPassword(context.Background(), tc.emailAddress)
require.NoError(t, err)
})
}
}