Skip to content

Commit 403b3bf

Browse files
author
jack-flores
committed
#1258 now rejects non-sec requests with params
1 parent 53c9fb1 commit 403b3bf

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/controller/org.controller/org.controller.js

+4
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ async function updateOrg (req, res, next) {
409409
result = await orgRepo.aggregate(agt)
410410
result = result.length > 0 ? result[0] : null
411411

412+
if (!isSec) {
413+
result = { last_active: result.last_active }
414+
}
415+
412416
const responseMessage = {
413417
message: shortName + ' organization was successfully updated.',
414418
updated: result

src/middleware/middleware.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ async function validateOrg (req, res, next) {
146146

147147
const isSec = await orgRepo.isSecretariat(org)
148148
if (!isSec) {
149-
if (!(org === reqOrg)) {
149+
if (org !== reqOrg) {
150150
logger.info({ uuid: req.ctx.uuid, message: org + ' is not a ' + CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT + ' or the same as ' + reqOrg + ' and is not allowed to make these changes.' })
151-
return res.status(401).json(error.unauthorized())
151+
return res.status(403).json(error.secretariatOnly())
152+
} else if (Object.keys(req.query).length > 0) {
153+
return res.status(403).json(error.secretariatOnly())
152154
}
153155
}
154156

test/integration-tests/org/putOrgTest.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe('Testing org put endpoint', () => {
6565
await chai.request(app)
6666
.put('/api/org/win_5')
6767
.set({ ...constants.nonSecretariatUserHeaders })
68-
.query(params)
6968
.send()
7069
.then((res, err) => {
7170
// Assert that that the last_active field was updated under 2 seconds ago
@@ -75,8 +74,9 @@ describe('Testing org put endpoint', () => {
7574
expect(withinTwoSeconds).to.be.true
7675
// Assert no other fields were changed
7776
expect(res).to.have.status(200)
78-
expect(res.body.updated.name).to.equal(cnaParams.name)
79-
expect(res.body.updated.policies.id_quota).to.equal(cnaParams.id_quota)
77+
expect(res.body.updated.active_roles).to.be.undefined
78+
expect(res.body.updated.name).to.be.undefined
79+
expect(res.body.updated.policies).to.be.undefined
8080
expect(err).to.be.undefined
8181
})
8282
})
@@ -88,10 +88,23 @@ describe('Testing org put endpoint', () => {
8888
.set({ ...constants.nonSecretariatUserHeaders })
8989
.send()
9090
.then((res, err) => {
91-
expect(res).to.have.status(401)
91+
expect(res).to.have.status(403)
92+
expect(err).to.be.undefined
93+
expect(res.body).to.haveOwnProperty('error')
94+
expect(res.body.error).to.equal('SECRETARIAT_ONLY')
95+
})
96+
})
97+
it('Fails update to fields made by a non-secretariat org to itself', async () => {
98+
await chai.request(app)
99+
.put('/api/org/win_5')
100+
.set({ ...constants.nonSecretariatUserHeaders })
101+
.query(params)
102+
.send()
103+
.then((res, err) => {
104+
expect(res).to.have.status(403)
92105
expect(err).to.be.undefined
93106
expect(res.body).to.haveOwnProperty('error')
94-
expect(res.body.error).to.equal('UNAUTHORIZED')
107+
expect(res.body.error).to.equal('SECRETARIAT_ONLY')
95108
})
96109
})
97110
it('Fails update made by a non-secretariat org to a secretariat', async () => {
@@ -100,10 +113,10 @@ describe('Testing org put endpoint', () => {
100113
.set({ ...constants.nonSecretariatUserHeaders })
101114
.send()
102115
.then((res, err) => {
103-
expect(res).to.have.status(401)
116+
expect(res).to.have.status(403)
104117
expect(err).to.be.undefined
105118
expect(res.body).to.haveOwnProperty('error')
106-
expect(res.body.error).to.equal('UNAUTHORIZED')
119+
expect(res.body.error).to.equal('SECRETARIAT_ONLY')
107120
})
108121
})
109122
})

0 commit comments

Comments
 (0)