Skip to content

Commit d782008

Browse files
committed
test: skipPasswordHash test for reset-pwd-short
1 parent 70e0939 commit d782008

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

test/methods/reset-pwd-short.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,89 @@ const withAction = (
443443
});
444444
});
445445
});
446+
447+
describe('with skipPasswordHash', () => {
448+
let app: Application;
449+
let usersService: MemoryService;
450+
let authLocalMgntService: AuthenticationManagementService;
451+
452+
beforeEach(async () => {
453+
app = feathers();
454+
app.use('authentication', authService(app));
455+
456+
const optionsUsers: Partial<MemoryServiceOptions> = {
457+
multi: true,
458+
id: idType
459+
};
460+
if (pagination === "paginated") {
461+
optionsUsers.paginate = { default: 10, max: 50 };
462+
}
463+
app.use("users", new MemoryService(optionsUsers))
464+
465+
app.setup();
466+
467+
usersService = app.service('users');
468+
await usersService.remove(null);
469+
await usersService.create(clone(users));
470+
});
471+
472+
it("hashes password when skipPasswordHash is false", async () => {
473+
app.configure(
474+
authLocalMgnt({
475+
skipPasswordHash: false,
476+
})
477+
);
478+
app.use("authManagement/reset-password-short", new ResetPwdShortService(app, {
479+
skipPasswordHash: false,
480+
}));
481+
authLocalMgntService = app.service('authManagement');
482+
483+
484+
const result = await callMethod(app, {
485+
token: '00099',
486+
password: '123456',
487+
user: {
488+
email: users[0].email
489+
},
490+
notifierOptions: {transport: 'sms'},
491+
}) as User;
492+
const user = await usersService.get(result[idType]);
493+
494+
assert.notStrictEqual(
495+
user.password,
496+
'123456',
497+
'password was not hashed'
498+
);
499+
});
500+
501+
it("does not hash password when skipPasswordHash is true", async () => {
502+
app.configure(
503+
authLocalMgnt({
504+
skipPasswordHash: true,
505+
})
506+
);
507+
app.use("authManagement/reset-password-short", new ResetPwdShortService(app, {
508+
skipPasswordHash: true,
509+
}));
510+
authLocalMgntService = app.service('authManagement');
511+
512+
const result = await callMethod(app, {
513+
token: '00099',
514+
password: '123456',
515+
user: {
516+
email: users[0].email
517+
},
518+
notifierOptions: {transport: 'sms'},
519+
}) as User;
520+
const user = await usersService.get(result[idType]);
521+
522+
assert.strictEqual(
523+
user.password,
524+
'123456',
525+
'password was hashed'
526+
);
527+
});
528+
});
446529
});
447530
});
448531
});

0 commit comments

Comments
 (0)