Skip to content

Commit

Permalink
fix: add missing status error code, fix flow issue
Browse files Browse the repository at this point in the history
  • Loading branch information
@jotadeveloper authored and griffithtp committed Jul 20, 2019
1 parent b2d54ee commit e3ad550
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugins/verdaccio-htpasswd/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function lockAndRead(name: string, cb: Function): void {
if (err) {
return cb(err);
}

return cb(null, res);
});
}
Expand Down Expand Up @@ -68,8 +69,10 @@ export function addUserToHTPasswd(
passwd: string
): string {
if (user !== encodeURIComponent(user)) {
let err = Error('username should not contain non-uri-safe characters');
// err.status = 409;
const err = Error('username should not contain non-uri-safe characters');

// $FlowFixMe
err.status = 409;
throw err;
}

Expand All @@ -84,8 +87,8 @@ export function addUserToHTPasswd(
.digest('base64');
}
let comment = 'autocreated ' + new Date().toJSON();

let newline = `${user}:${passwd}:${comment}\n`;

if (body.length && body[body.length - 1] !== '\n') {
newline = '\n' + newline;
}
Expand All @@ -106,8 +109,10 @@ export function sanityCheck(user: string, users: {}, maxUsers: number) {
} else if (Object.keys(users).length >= maxUsers) {
err = Error('maximum amount of users reached');
}

if (err) {
// err.status = 403;
// $FlowFixMe
err.status = 403;
}
return err;
}

0 comments on commit e3ad550

Please sign in to comment.