Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
fix: npm >= v5.5.0 login need not email (#1275) (#1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmzy authored and fengmk2 committed Mar 14, 2018
1 parent 4210b7b commit 1b30146
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
32 changes: 21 additions & 11 deletions controllers/registry/user/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,8 @@ var config = require('../../../config');
module.exports = function* addUser() {
var name = this.params.name;
var body = this.request.body || {};
var user = {
name: body.name,
// salt: body.salt,
// password_sha: body.password_sha,
email: body.email,
ip: this.ip || '0.0.0.0',
// roles: body.roles || [],
};

ensurePasswordSalt(user, body);

if (!body.password || !user.name || !user.salt || !user.password_sha || !user.email) {
if (!body.password || !body.name) {
this.status = 422;
this.body = {
error: 'paramError',
Expand Down Expand Up @@ -91,6 +81,26 @@ module.exports = function* addUser() {
return;
}

var user = {
name: body.name,
// salt: body.salt,
// password_sha: body.password_sha,
email: body.email,
ip: this.ip || '0.0.0.0',
// roles: body.roles || [],
};

ensurePasswordSalt(user, body);

if (!user.salt || !user.password_sha || !user.email) {
this.status = 422;
this.body = {
error: 'paramError',
reason: 'params missing, name, email or password missing.'
};
return;
}

var existUser = yield userService.get(name);
if (existUser) {
this.status = 409;
Expand Down
29 changes: 29 additions & 0 deletions test/controllers/registry/user/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,35 @@ describe('controllers/registry/user/add.test.js', function () {
})
.expect(201, done);
});

it('should 422 add user without email', function (done) {
mm(userService, 'get', function* () {
return null;
});
mm(userService, 'add', function* () {
return {rev: '1-123'};
});
request(app)
.put('/-/user/org.couchdb.user:name')
.send({
name: 'name',
password: 'password'
})
.expect(422, done);
});

it('should login without email ok', function (done) {
mm(userService, 'authAndSave', function* () {
return {login: 'name'};
});
request(app)
.put('/-/user/org.couchdb.user:name')
.send({
name: 'name',
password: 'password'
})
.expect(201, done);
});
});

describe('config.customUserSerivce = true', function () {
Expand Down

0 comments on commit 1b30146

Please sign in to comment.