2021-12-23 05:01:52 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
2021-12-23 05:01:52 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/db"
|
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
func resetPasswordTest(t *testing.T, s TestSetup) {
|
|
|
|
t.Helper()
|
2021-12-24 00:57:39 +00:00
|
|
|
t.Run(`should reset password`, func(t *testing.T) {
|
|
|
|
email := "reset_password." + s.TestInfo.Email
|
|
|
|
_, ctx := createContext(s)
|
2022-01-17 06:02:13 +00:00
|
|
|
_, err := resolvers.SignupResolver(ctx, model.SignUpInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Email: email,
|
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password,
|
|
|
|
})
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
_, err = resolvers.ForgotPasswordResolver(ctx, model.ForgotPasswordInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Email: email,
|
|
|
|
})
|
|
|
|
assert.Nil(t, err, "no errors for forgot password")
|
|
|
|
|
2022-07-10 16:19:33 +00:00
|
|
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeForgotPassword)
|
2021-12-24 00:57:39 +00:00
|
|
|
assert.Nil(t, err, "should get forgot password request")
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Token: verificationRequest.Token,
|
|
|
|
Password: "test1",
|
|
|
|
ConfirmPassword: "test",
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NotNil(t, err, "passowrds don't match")
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Token: verificationRequest.Token,
|
|
|
|
Password: "test1",
|
|
|
|
ConfirmPassword: "test1",
|
|
|
|
})
|
|
|
|
|
2022-03-17 10:05:07 +00:00
|
|
|
assert.NotNil(t, err, "invalid password")
|
|
|
|
|
|
|
|
_, err = resolvers.ResetPasswordResolver(ctx, model.ResetPasswordInput{
|
|
|
|
Token: verificationRequest.Token,
|
|
|
|
Password: "Test@1234",
|
|
|
|
ConfirmPassword: "Test@1234",
|
|
|
|
})
|
|
|
|
|
2021-12-24 00:57:39 +00:00
|
|
|
assert.Nil(t, err, "password changed successfully")
|
|
|
|
|
|
|
|
cleanData(email)
|
2021-12-23 05:01:52 +00:00
|
|
|
})
|
|
|
|
}
|