Skip to content

Commit 9c53af8

Browse files
committed
fixed return type and added test for default validator
1 parent 0e897c7 commit 9c53af8

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

recipe/emailpassword/ep_userIdMapping_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func TestCreateUserIdMappingUpdateEmailPassword(t *testing.T) {
188188

189189
newEmail := "email@example.com"
190190
newPass := "newpass123"
191-
updateResp, err := UpdateEmailOrPassword(externalUserId, &newEmail, &newPass)
191+
updateResp, err := UpdateEmailOrPassword(externalUserId, &newEmail, &newPass, nil)
192192
assert.NoError(t, err)
193193
assert.NotNil(t, updateResp.OK)
194194

recipe/emailpassword/epmodels/recipeInterface.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@ type UpdateEmailOrPasswordResponse struct {
5959
OK *struct{}
6060
UnknownUserIdError *struct{}
6161
EmailAlreadyExistsError *struct{}
62-
PasswordPolicyViolatedError *struct{}
62+
PasswordPolicyViolatedError *PasswordPolicyViolatedError
63+
}
64+
65+
type PasswordPolicyViolatedError struct {
66+
FailureReason *string
6367
}

recipe/emailpassword/recipeImplementation.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package emailpassword
1717

1818
import (
19-
"errors"
2019
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
2120
"github.com/supertokens/supertokens-golang/supertokens"
2221
)
@@ -171,9 +170,12 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
171170
formFields := getEmailPasswordConfig().SignUpFeature.FormFields
172171
for i := range formFields {
173172
if formFields[i].ID == "password" {
174-
err := formFields[i].Validate(password)
175-
if err == nil {
176-
return epmodels.UpdateEmailOrPasswordResponse{PasswordPolicyViolatedError: &struct{}{}}, errors.New(*err)
173+
err := formFields[i].Validate(*password)
174+
if err != nil {
175+
errResponse := epmodels.PasswordPolicyViolatedError{
176+
FailureReason: err,
177+
}
178+
return epmodels.UpdateEmailOrPasswordResponse{PasswordPolicyViolatedError: &errResponse}, nil
177179
}
178180
}
179181
}

recipe/emailpassword/updateEmailPass_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ func TestUpdateEmailPass(t *testing.T) {
9898
}
9999

100100
email := "test2@gmail.com"
101-
password := "testPass"
101+
password := "testPass1"
102102

103103
UpdateEmailOrPassword(data["user"].(map[string]interface{})["id"].(string), &email, &password, nil)
104-
105104
res1, err := unittesting.SignInRequest("testrandom@gmail.com", "validpass123", testServer.URL)
106105

107106
if err != nil {
@@ -140,6 +139,12 @@ func TestUpdateEmailPass(t *testing.T) {
140139

141140
assert.Equal(t, "OK", data2["status"])
142141
assert.Equal(t, email, data2["user"].(map[string]interface{})["email"])
142+
143+
password = "test"
144+
applyPasswordPolicy := true
145+
res3, err := UpdateEmailOrPassword(data["user"].(map[string]interface{})["id"].(string), &email, &password, &applyPasswordPolicy)
146+
assert.NotNil(t, res3.PasswordPolicyViolatedError)
147+
assert.Equal(t, "Password must contain at least 8 characters, including a number", *res3.PasswordPolicyViolatedError.FailureReason)
143148
}
144149

145150
func TestAPICustomResponse(t *testing.T) {

0 commit comments

Comments
 (0)