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

Commit

Permalink
Merge pull request #334 from cnpm/fix-permission
Browse files Browse the repository at this point in the history
add permission check to /:name/:tag
  • Loading branch information
fengmk2 committed Apr 18, 2014
2 parents 6aae538 + b74cccd commit e5a77a4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions controllers/registry/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,16 @@ exports.updateTag = function *() {
return;
}

// check permission
if (!common.isMaintainer(this.user, mod.package.maintainers)) {
this.status = 403;
this.body = {
error: 'forbidden',
reason: 'no permission to modify ' + name
};
return;
}

yield Module.addTag(name, tag, version);
this.status = 201;
this.body = {
Expand Down
2 changes: 1 addition & 1 deletion routes/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function routes(app) {
app.put('/:name/sync', sync.sync);
app.get('/:name/sync/log/:id', sync.getSyncLog);

app.put('/:name/:tag', mod.updateTag);
app.put('/:name/:tag', login, mod.updateTag);

// need limit by ip
app.get('/:name/download/:filename', limit, mod.download);
Expand Down
17 changes: 17 additions & 0 deletions test/controllers/registry/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ describe('controllers/registry/module.test.js', function () {
request(app)
.put('/testputmodule/newtag')
.set('content-type', 'application/json')
.set('authorization', baseauth)
.send('"0.1.9"')
.expect(201, done);
});
Expand All @@ -698,6 +699,7 @@ describe('controllers/registry/module.test.js', function () {
request(app)
.put('/testputmodule/newtag')
.set('content-type', 'application/json')
.set('authorization', baseauth)
.send('"0.1.9"')
.expect(201, done);
});
Expand All @@ -706,6 +708,7 @@ describe('controllers/registry/module.test.js', function () {
request(app)
.put('/testputmodule/newtag')
.set('content-type', 'application/json')
.set('authorization', baseauth)
.send('"hello"')
.expect(403)
.expect({
Expand All @@ -718,13 +721,27 @@ describe('controllers/registry/module.test.js', function () {
request(app)
.put('/testputmodule/newtag')
.set('content-type', 'application/json')
.set('authorization', baseauth)
.send('"5.0.0"')
.expect(403)
.expect({
error: 'forbidden',
reason: 'setting tag newtag to unknown version: 5.0.0: testputmodule/newtag'
}, done);
});

it('should tag permission 403', function (done) {
request(app)
.put('/testputmodule/newtag')
.set('content-type', 'application/json')
.set('authorization', baseauthOther)
.send('"0.1.9"')
.expect(403)
.expect({
error: 'forbidden',
reason: 'no permission to modify testputmodule'
}, done);
});
});

describe('DELETE /:name/-rev/:rev', function () {
Expand Down

0 comments on commit e5a77a4

Please sign in to comment.