@@ -135,4 +135,71 @@ describe('auth handlers', () => {
135135 assertContains ( html , 'Invalid email or password' )
136136 assertContains ( html , 'returnTo=' + encodeURIComponent ( '/checkout' ) )
137137 } )
138+
139+ it ( 'POST /reset-password with mismatched passwords redirects back with error' , async ( ) => {
140+ // First, request a password reset to get a token
141+ let forgotPasswordResponse = await router . fetch ( 'https://remix.run/forgot-password' , {
142+ method : 'POST' ,
143+ body : new URLSearchParams ( {
144+ 145+ } ) ,
146+ } )
147+
148+ let html = await forgotPasswordResponse . text ( )
149+ // Extract token from the reset link in the demo response
150+ let tokenMatch = html . match ( / \/ r e s e t - p a s s w o r d \/ ( [ ^ " ] + ) / )
151+ assert . ok ( tokenMatch , 'Expected to find reset token in response' )
152+ let token = tokenMatch [ 1 ]
153+
154+ // Try to reset password with mismatched passwords
155+ let response = await router . fetch ( `https://remix.run/reset-password/${ token } ` , {
156+ method : 'POST' ,
157+ body : new URLSearchParams ( {
158+ password : 'newpassword123' ,
159+ confirmPassword : 'differentpassword' ,
160+ } ) ,
161+ redirect : 'manual' ,
162+ } )
163+
164+ assert . equal ( response . status , 302 )
165+ assert . equal ( response . headers . get ( 'Location' ) , `/reset-password/${ token } ` )
166+
167+ // Follow redirect to see the error message
168+ let sessionCookie = getSessionCookie ( response )
169+ let followUpResponse = await router . fetch ( `https://remix.run/reset-password/${ token } ` , {
170+ headers : {
171+ Cookie : `session=${ sessionCookie } ` ,
172+ } ,
173+ } )
174+
175+ let errorHtml = await followUpResponse . text ( )
176+ assertContains ( errorHtml , 'Passwords do not match' )
177+ } )
178+
179+ it ( 'POST /reset-password with invalid token redirects back with error' , async ( ) => {
180+ let invalidToken = 'invalid-token-12345'
181+
182+ let response = await router . fetch ( `https://remix.run/reset-password/${ invalidToken } ` , {
183+ method : 'POST' ,
184+ body : new URLSearchParams ( {
185+ password : 'newpassword123' ,
186+ confirmPassword : 'newpassword123' ,
187+ } ) ,
188+ redirect : 'manual' ,
189+ } )
190+
191+ assert . equal ( response . status , 302 )
192+ assert . equal ( response . headers . get ( 'Location' ) , `/reset-password/${ invalidToken } ` )
193+
194+ // Follow redirect to see the error message
195+ let sessionCookie = getSessionCookie ( response )
196+ let followUpResponse = await router . fetch ( `https://remix.run/reset-password/${ invalidToken } ` , {
197+ headers : {
198+ Cookie : `session=${ sessionCookie } ` ,
199+ } ,
200+ } )
201+
202+ let errorHtml = await followUpResponse . text ( )
203+ assertContains ( errorHtml , 'Invalid or expired reset token' )
204+ } )
138205} )
0 commit comments