@@ -910,6 +910,88 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
910
910
} ) ;
911
911
} ) ;
912
912
913
+ it ( 'should programmatically reset password on ajax request' , done => {
914
+ const user = new Parse . User ( ) ;
915
+ const emailAdapter = {
916
+ sendVerificationEmail : ( ) => Promise . resolve ( ) ,
917
+ sendPasswordResetEmail : options => {
918
+ request ( {
919
+ url : options . link ,
920
+ followRedirects : false ,
921
+ } ) . then ( response => {
922
+ expect ( response . status ) . toEqual ( 302 ) ;
923
+ const re = / h t t p : \/ \/ l o c a l h o s t : 8 3 7 8 \/ 1 \/ a p p s \/ c h o o s e _ p a s s w o r d \? t o k e n = ( [ a - z A - Z 0 - 9 ] + ) \& i d = t e s t \& u s e r n a m e = z x c v / ;
924
+ const match = response . text . match ( re ) ;
925
+ if ( ! match ) {
926
+ fail ( 'should have a token' ) ;
927
+ done ( ) ;
928
+ return ;
929
+ }
930
+ const token = match [ 1 ] ;
931
+
932
+ request ( {
933
+ url : 'http://localhost:8378/1/apps/test/request_password_reset' ,
934
+ method : 'POST' ,
935
+ body : { new_password : 'hello' , token, username : 'zxcv' } ,
936
+ headers : {
937
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
938
+ 'X-Requested-With' : 'XMLHttpRequest' ,
939
+ } ,
940
+ followRedirects : false ,
941
+ } ) . then ( response => {
942
+ console . log ( 'REQUEST RESPONSE' ) ;
943
+ expect ( response . status ) . toEqual ( 200 ) ;
944
+ expect ( response . text ) . toEqual ( '"Password successfully reset"' ) ;
945
+
946
+ Parse . User . logIn ( 'zxcv' , 'hello' ) . then (
947
+ function ( ) {
948
+ const config = Config . get ( 'test' ) ;
949
+ config . database . adapter
950
+ . find (
951
+ '_User' ,
952
+ { fields : { } } ,
953
+ { username : 'zxcv' } ,
954
+ { limit : 1 }
955
+ )
956
+ . then ( results => {
957
+ // _perishable_token should be unset after reset password
958
+ expect ( results . length ) . toEqual ( 1 ) ;
959
+ expect ( results [ 0 ] [ '_perishable_token' ] ) . toEqual ( undefined ) ;
960
+ done ( ) ;
961
+ } ) ;
962
+ } ,
963
+ err => {
964
+ jfail ( err ) ;
965
+ fail ( 'should login with new password' ) ;
966
+ done ( ) ;
967
+ }
968
+ ) ;
969
+ } ) ;
970
+ } ) ;
971
+ } ,
972
+ sendMail : ( ) => { } ,
973
+ } ;
974
+ reconfigureServer ( {
975
+ appName : 'emailing app' ,
976
+ verifyUserEmails : true ,
977
+ emailAdapter : emailAdapter ,
978
+ publicServerURL : 'http://localhost:8378/1' ,
979
+ } ) . then ( ( ) => {
980
+ user . setPassword ( 'asdf' ) ;
981
+ user . setUsername ( 'zxcv' ) ;
982
+ user . set ( 'email' , '[email protected] ' ) ;
983
+ user . signUp ( ) . then ( ( ) => {
984
+ Parse . User . requestPasswordReset ( '[email protected] ' , {
985
+ error : err => {
986
+ jfail ( err ) ;
987
+ fail ( 'Should not fail' ) ;
988
+ done ( ) ;
989
+ } ,
990
+ } ) ;
991
+ } ) ;
992
+ } ) ;
993
+ } ) ;
994
+
913
995
it ( 'deletes password reset token on email address change' , done => {
914
996
reconfigureServer ( {
915
997
appName : 'coolapp' ,
0 commit comments