@@ -98,10 +98,9 @@ func TestUpdateEmailPass(t *testing.T) {
9898 }
9999
100100 email := "test2@gmail.com"
101- password := "testPass"
102-
103- UpdateEmailOrPassword (data ["user" ].(map [string ]interface {})["id" ].(string ), & email , & password )
101+ password := "testPass1"
104102
103+ UpdateEmailOrPassword (data ["user" ].(map [string ]interface {})["id" ].(string ), & email , & password , nil )
105104 res1 , err := unittesting .SignInRequest ("testrandom@gmail.com" , "validpass123" , testServer .URL )
106105
107106 if err != nil {
@@ -140,6 +139,96 @@ 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 )
148+ }
149+
150+ func TestUpdateEmailPassWithCustomValidator (t * testing.T ) {
151+ configValue := supertokens.TypeInput {
152+ Supertokens : & supertokens.ConnectionInfo {
153+ ConnectionURI : "http://localhost:8080" ,
154+ },
155+ AppInfo : supertokens.AppInfo {
156+ APIDomain : "api.supertokens.io" ,
157+ AppName : "SuperTokens" ,
158+ WebsiteDomain : "supertokens.io" ,
159+ },
160+ RecipeList : []supertokens.Recipe {
161+ Init (& epmodels.TypeInput {SignUpFeature : & epmodels.TypeInputSignUp {FormFields : []epmodels.TypeInputFormField {
162+ {
163+ ID : "password" ,
164+ Validate : func (value interface {}) * string {
165+ if len (value .(string )) > 5 {
166+ return nil
167+ }
168+ err := "Password length must be more than 5 characters"
169+ return & err
170+ },
171+ },
172+ }}}),
173+ session .Init (& sessmodels.TypeInput {
174+ GetTokenTransferMethod : func (req * http.Request , forCreateNewSession bool , userContext supertokens.UserContext ) sessmodels.TokenTransferMethod {
175+ return sessmodels .CookieTransferMethod
176+ },
177+ }),
178+ },
179+ }
180+
181+ BeforeEach ()
182+ unittesting .StartUpST ("localhost" , "8080" )
183+ defer AfterEach ()
184+ err := supertokens .Init (configValue )
185+ if err != nil {
186+ t .Error (err .Error ())
187+ }
188+ querier , err := supertokens .GetNewQuerierInstanceOrThrowError ("" )
189+ if err != nil {
190+ t .Error (err .Error ())
191+ }
192+ cdiVersion , err := querier .GetQuerierAPIVersion ()
193+ if err != nil {
194+ t .Error (err .Error ())
195+ }
196+ if unittesting .MaxVersion ("2.7" , cdiVersion ) == "2.7" {
197+ return
198+ }
199+ mux := http .NewServeMux ()
200+ testServer := httptest .NewServer (supertokens .Middleware (mux ))
201+ defer testServer .Close ()
202+
203+ _ , err = unittesting .SignupRequest ("testrandom@gmail.com" , "validpass123" , testServer .URL )
204+ if err != nil {
205+ t .Error (err .Error ())
206+ }
207+
208+ res , err := unittesting .SignInRequest ("testrandom@gmail.com" , "validpass123" , testServer .URL )
209+
210+ if err != nil {
211+ t .Error (err .Error ())
212+ }
213+ dataInBytes , err := io .ReadAll (res .Body )
214+ if err != nil {
215+ t .Error (err .Error ())
216+ }
217+ res .Body .Close ()
218+
219+ var data map [string ]interface {}
220+ err = json .Unmarshal (dataInBytes , & data )
221+ if err != nil {
222+ t .Error (err .Error ())
223+ }
224+
225+ email := "testrandom@gmail.com"
226+ password := "test"
227+
228+ res1 , err := UpdateEmailOrPassword (data ["user" ].(map [string ]interface {})["id" ].(string ), & email , & password , nil )
229+ assert .NotNil (t , res1 .PasswordPolicyViolatedError )
230+ assert .Equal (t , "Password length must be more than 5 characters" , res1 .PasswordPolicyViolatedError .FailureReason )
231+
143232}
144233
145234func TestAPICustomResponse (t * testing.T ) {
0 commit comments