Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.

Commit

Permalink
fix: adds error message for user registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush Sharma authored and ayusharma committed Sep 21, 2018
1 parent 345aef7 commit 0bab945
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/___tests___/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,15 @@ describe('sanityCheck', () => {
expect(input.message).toEqual('unauthorized access');
expect(verifyFn).toHaveBeenCalled();
});
it('should throw error max number of users', () => {
it('should throw error for registration disabled of users', () => {
const verifyFn = () => {};
const input = sanityCheck('username', users.test, verifyFn, users, -1);
expect(input.status).toEqual(409);
expect(input.message).toEqual('user registration disabled');
});
it('should throw error max number of users', () => {
const verifyFn = () => {};
const input = sanityCheck('username', users.test, verifyFn, users, 1);
expect(input.status).toEqual(403);
expect(input.message).toEqual('maximum amount of users reached');
});
Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ export function sanityCheck(

hash = users[user];

if (maxUsers < 0) {
err = Error('user registration disabled');
// $FlowFixMe
err.status = 409;
return err;
}

if (hash) {
const auth = verifyFn(password, users[user]);
if (auth) {
Expand Down

0 comments on commit 0bab945

Please sign in to comment.