Skip to content

Commit 1048652

Browse files
committed
test: add test for skipPasswordHash for verify signup set password
1 parent afcce7c commit 1048652

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test/methods/verify-signup-set-password-short.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,76 @@ const withAction = (
345345
]);
346346
});
347347
});
348+
349+
describe('with skipPasswordHash', () => {
350+
let app: Application;
351+
let usersService: MemoryService;
352+
353+
beforeEach(async () => {
354+
355+
app = feathers();
356+
app.use('authentication', authService(app));
357+
358+
const optionsUsers: Partial<MemoryServiceOptions> = {
359+
multi: true,
360+
id: idType
361+
};
362+
if (pagination === "paginated") {
363+
optionsUsers.paginate = { default: 10, max: 50 };
364+
}
365+
app.use("users", new MemoryService(optionsUsers))
366+
367+
app.setup();
368+
369+
usersService = app.service('users');
370+
await usersService.remove(null);
371+
await usersService.create(clone(users));
372+
});
373+
374+
it('doesnt hash password when skipPasswordHash is true', async () => {
375+
app.configure(
376+
authLocalMgnt({
377+
skipPasswordHash: true,
378+
})
379+
);
380+
app.use("authManagement/verify-signup-set-password-short", new VerifySignupSetPasswordShortService(app, {
381+
skipPasswordHash: true,
382+
}));
383+
384+
const password = '123456';
385+
const result = await callMethod(app, {
386+
token: '00099',
387+
user: { email: users[0].email },
388+
password,
389+
notifierOptions: { transport: 'sms' },
390+
}) as User;
391+
const user = await usersService.get(result.id || result._id);
392+
393+
assert.deepStrictEqual(password, user.password, 'password is hashed value');
394+
});
395+
396+
it('hashes password when skipPasswordHash is false', async () => {
397+
app.configure(
398+
authLocalMgnt({
399+
skipPasswordHash: false,
400+
})
401+
);
402+
app.use("authManagement/verify-signup-set-password-short", new VerifySignupSetPasswordShortService(app, {
403+
skipPasswordHash: false,
404+
}));
405+
406+
const password = '123456';
407+
const result = await callMethod(app, {
408+
token: '00099',
409+
user: { email: users[0].email },
410+
password,
411+
notifierOptions: { transport: 'sms' },
412+
}) as User;
413+
const user = await usersService.get(result.id || result._id);
414+
415+
assert.notDeepStrictEqual(password, user.password, 'password is not hashed value');
416+
});
417+
});
348418
});
349419
});
350420
});

0 commit comments

Comments
 (0)