Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate pipeline stage ownership on update #3823

Merged
merged 3 commits into from
May 7, 2024
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
7 changes: 3 additions & 4 deletions forge/ee/db/controllers/Pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ module.exports = {
* @param {String} [options.deviceGroupId] The ID of the device group to deploy to
* @param {Boolean} [options.deployToDevices] Whether to deploy to devices of the source stage
*/
updatePipelineStage: async function (app, stageId, options) {
updatePipelineStage: async function (app, pipeline, stageId, options) {
const stage = await app.db.models.PipelineStage.byId(stageId)
if (!stage) {
throw new PipelineControllerError('not_found', 'Pipeline stage not found', 404)
}
const pipeline = await app.db.models.Pipeline.byId(stage.PipelineId)
if (!pipeline) {
throw new PipelineControllerError('not_found', 'Pipeline not found', 404)
if (stage.PipelineId !== pipeline.id) {
throw new PipelineControllerError('not_found', 'Pipeline stage not found', 404)
}

if (options.name) {
Expand Down
1 change: 1 addition & 0 deletions forge/ee/routes/pipeline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ module.exports = async function (app) {
}

const stage = await app.db.controllers.Pipeline.updatePipelineStage(
request.pipeline,
request.params.stageId,
options
)
Expand Down
18 changes: 18 additions & 0 deletions test/unit/forge/ee/routes/api/pipeline_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,24 @@ describe('Pipelines API', function () {

response.statusCode.should.equal(200)
})
it('Should fail if the pipeline does not contain the request stage', async function () {
const pipelineId = TestObjects.pipelineDevices.hashid
const stageId = TestObjects.stageOne.hashid

const response = await app.inject({
method: 'PUT',
url: `/api/v1/pipelines/${pipelineId}/stages/${stageId}`,
payload: {
name: 'New Name'
},
cookies: { sid: TestObjects.tokens.alice }

})

const body = await response.json()
body.should.have.property('code', 'not_found')
response.statusCode.should.equal(404)
})
})

describe('With a new instance', function () {
Expand Down
Loading