@@ -271,6 +271,101 @@ describe('password-change.ts', function () {
271271 } ) ;
272272 } )
273273 } ) ;
274+
275+ [ {
276+ name : "authManagement.create" ,
277+ callMethod : ( app : Application , data : DataPasswordChange , params ?: ParamsTest ) => {
278+ return app . service ( "authManagement" ) . create ( withAction ( data ) , params ) ;
279+ }
280+ } , {
281+ name : "authManagement.passwordChange" ,
282+ callMethod : ( app : Application , data : DataPasswordChange , params ?: ParamsTest ) => {
283+ return app . service ( "authManagement" ) . passwordChange ( data , params ) ;
284+ }
285+ } , {
286+ name : "authManagement/password-change" ,
287+ callMethod : ( app : Application , data : DataPasswordChange , params ?: ParamsTest ) => {
288+ return app . service ( "authManagement/password-change" ) . create ( data , params ) ;
289+ }
290+ } ] . forEach ( ( { name, callMethod } ) => {
291+ describe ( `password-change.test.ts ${ idType } skipPasswordHash ${ name } ` , ( ) => {
292+ describe ( 'standard' , ( ) => {
293+ let app : Application ;
294+ let usersService : MemoryService ;
295+
296+ beforeEach ( async ( ) => {
297+ app = feathers ( ) ;
298+ app . use ( 'authentication' , authService ( app ) ) ;
299+
300+ const optionsUsers : Partial < MemoryServiceOptions > = {
301+ multi : true ,
302+ id : idType
303+ } ;
304+
305+ app . use ( "users" , new MemoryService ( optionsUsers ) )
306+
307+ app . setup ( ) ;
308+
309+ usersService = app . service ( 'users' ) ;
310+ await usersService . remove ( null ) ;
311+ await usersService . create ( clone ( users ) ) ;
312+ } ) ;
313+
314+ it ( 'with skipPasswordHash false' , async ( ) => {
315+ app . configure ( authLocalMgnt ( {
316+ passParams : params => params ,
317+ skipPasswordHash : false ,
318+ } ) ) ;
319+ app . use ( "authManagement/password-change" , new PasswordChangeService ( app , {
320+ passParams : params => params ,
321+ skipPasswordHash : false ,
322+ } ) )
323+
324+
325+ const userRec = clone ( users [ 1 ] ) ;
326+
327+ const result = await callMethod ( app , {
328+ user : {
329+ email : userRec . email
330+ } ,
331+ oldPassword : userRec . plainPassword ,
332+ password : userRec . plainNewPassword
333+ } ) as User ;
334+ const user = await usersService . get ( result [ idType ] ) ;
335+
336+ assert . strictEqual ( result . isVerified , true , 'isVerified not true' ) ;
337+ assert . notStrictEqual ( user . password , result . plainNewPassword , 'password was not hashed' ) ;
338+ } ) ;
339+
340+ it ( 'with skipPasswordHash true' , async ( ) => {
341+ app . configure ( authLocalMgnt ( {
342+ passParams : params => params ,
343+ skipPasswordHash : true ,
344+ } ) ) ;
345+ app . use ( "authManagement/password-change" , new PasswordChangeService ( app , {
346+ passParams : params => params ,
347+ skipPasswordHash : true ,
348+ } ) )
349+
350+
351+ const userRec = clone ( users [ 1 ] ) ;
352+
353+ const result = await callMethod ( app , {
354+ user : {
355+ email : userRec . email
356+ } ,
357+ oldPassword : userRec . plainPassword ,
358+ password : userRec . plainNewPassword
359+ } ) as User ;
360+ const user = await usersService . get ( result [ idType ] ) ;
361+
362+ assert . strictEqual ( result . isVerified , true , 'isVerified not true' ) ;
363+ assert . strictEqual ( user . password , result . plainNewPassword , 'password was hashed' ) ;
364+ } ) ;
365+
366+ } ) ;
367+ } ) ;
368+ } )
274369 } ) ;
275370} ) ;
276371
0 commit comments