Skip to content

Commit 03a6a72

Browse files
authored
Merge pull request #26 from screwdriver-cd/security
fix(858): Enable auth for artifact reads
2 parents 803f9cd + 1dfac62 commit 03a6a72

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

plugins/builds.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ exports.register = (server, options, next) => {
3131
description: 'Read build artifacts',
3232
notes: 'Get an artifact from a specific build',
3333
tags: ['api', 'builds'],
34+
auth: {
35+
strategies: ['token'],
36+
scope: ['user']
37+
},
38+
plugins: {
39+
'hapi-swagger': {
40+
security: [{ token: [] }]
41+
}
42+
},
3443
handler: (request, reply) => {
3544
const buildId = request.params.id;
3645
const artifact = request.params.artifact;

test/plugins/builds.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ describe('builds plugin test', () => {
7171
describe('GET /builds/:id/:artifact', () => {
7272
it('returns 404 if not found', () => (
7373
server.inject({
74+
headers: {
75+
'x-foo': 'bar'
76+
},
77+
credentials: {
78+
username: mockBuildID,
79+
scope: ['user']
80+
},
7481
url: `/builds/${mockBuildID}/foo`
7582
}).then((reply) => {
7683
assert.equal(reply.statusCode, 404);
@@ -109,6 +116,13 @@ describe('builds plugin test', () => {
109116

110117
it('returns 500 if caching fails', () => (
111118
badServer.inject({
119+
headers: {
120+
'x-foo': 'bar'
121+
},
122+
credentials: {
123+
username: mockBuildID,
124+
scope: ['user']
125+
},
112126
url: `/builds/${mockBuildID}/foo`
113127
}).then((reply) => {
114128
assert.equal(reply.statusCode, 500);
@@ -162,7 +176,14 @@ describe('builds plugin test', () => {
162176
assert.equal(reply.statusCode, 202);
163177

164178
return server.inject({
165-
url: `/builds/${mockBuildID}/foo`
179+
url: `/builds/${mockBuildID}/foo`,
180+
headers: {
181+
'x-foo': 'bar'
182+
},
183+
credentials: {
184+
username: mockBuildID,
185+
scope: ['user']
186+
}
166187
}).then((reply2) => {
167188
assert.equal(reply2.statusCode, 200);
168189
assert.equal(reply2.headers['x-foo'], 'bar');

0 commit comments

Comments
 (0)