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

add permission check to /:name/:tag #334

Merged
merged 1 commit into from
Apr 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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