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

Updating Test from Int #1270

Merged
merged 29 commits into from
Aug 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
664aea5
1258 first draft, one test failing
Jul 24, 2024
a85cbb9
all tests passing, more tests to write
Jul 26, 2024
f967daa
#1258 all tests passing
Jul 29, 2024
f98b83d
#1258 all tests passing
Jul 29, 2024
a660d97
#1258 small changes to negative tests
Jul 29, 2024
b94e2c2
#1258 fixes for pr pipeline
Jul 31, 2024
53c9fb1
quieting bad eslint error
Jul 31, 2024
403b3bf
#1258 now rejects non-sec requests with params
Jul 31, 2024
03cc618
#1258 updated swagger documentation
Aug 2, 2024
c082fb5
test to see if my username shows up
jack-flores Aug 2, 2024
cfb8911
#1258 added schema for am-i-alive
jack-flores Aug 5, 2024
fcc7fc4
Updated github actions to use docker compose instead of docker-compose
jdaigneau5 Aug 5, 2024
45db2a8
More docker-compose fixes
jdaigneau5 Aug 5, 2024
8fc52ad
Merge pull request #1265 from CVEProject/jd-dc-fix
david-rocca Aug 5, 2024
afa5db0
Merge branch 'dev' into jf-1258
jack-flores Aug 5, 2024
a45d63a
#1258 more unit tests
jack-flores Aug 8, 2024
278065c
#1258 secretariat update to another org no longer updates last_active
jack-flores Aug 15, 2024
20c1596
Update swagger.js to reflect changes from https://github.com/CVEProje…
M-nj Aug 16, 2024
0efc8aa
#1258 addressing comments from team
jack-flores Aug 19, 2024
9d1e931
#1258 update openapi.json
jack-flores Aug 19, 2024
13cc2b2
reverting openapi.json to most recent correct ver
jack-flores Aug 20, 2024
85a4076
#1258 addressing comments from team
jack-flores Aug 20, 2024
3300b06
Merge pull request #1262 from CVEProject/jf-1258
jdaigneau5 Aug 21, 2024
59e72b7
Merge branch 'dev' into api-docs-redirect-correction
jdaigneau5 Aug 26, 2024
d6acf27
Merge pull request #1263 from M-nj/api-docs-redirect-correction
jdaigneau5 Aug 26, 2024
f4a125b
updated version number to 2.4.0
jdaigneau5 Aug 26, 2024
17f8d7b
Merge pull request #1268 from CVEProject/jd-2.4.0
athu-tran Aug 26, 2024
416d2ab
Merge branch 'int' into dev
jdaigneau5 Aug 26, 2024
e89a368
Merge pull request #1269 from CVEProject/dev
athu-tran Aug 26, 2024
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
Prev Previous commit
Next Next commit
#1258 now rejects non-sec requests with params
  • Loading branch information
jack-flores committed Jul 31, 2024
commit 403b3bf417cbad7f950e7860b0c4ee659b5c8284
4 changes: 4 additions & 0 deletions src/controller/org.controller/org.controller.js
Original file line number Diff line number Diff line change
@@ -409,6 +409,10 @@ async function updateOrg (req, res, next) {
result = await orgRepo.aggregate(agt)
result = result.length > 0 ? result[0] : null

if (!isSec) {
result = { last_active: result.last_active }
}

const responseMessage = {
message: shortName + ' organization was successfully updated.',
updated: result
6 changes: 4 additions & 2 deletions src/middleware/middleware.js
Original file line number Diff line number Diff line change
@@ -146,9 +146,11 @@ async function validateOrg (req, res, next) {

const isSec = await orgRepo.isSecretariat(org)
if (!isSec) {
if (!(org === reqOrg)) {
if (org !== reqOrg) {
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.' })
return res.status(401).json(error.unauthorized())
return res.status(403).json(error.secretariatOnly())
} else if (Object.keys(req.query).length > 0) {
return res.status(403).json(error.secretariatOnly())
}
}

27 changes: 20 additions & 7 deletions test/integration-tests/org/putOrgTest.js
Original file line number Diff line number Diff line change
@@ -65,7 +65,6 @@ describe('Testing org put endpoint', () => {
await chai.request(app)
.put('/api/org/win_5')
.set({ ...constants.nonSecretariatUserHeaders })
.query(params)
.send()
.then((res, err) => {
// Assert that that the last_active field was updated under 2 seconds ago
@@ -75,8 +74,9 @@ describe('Testing org put endpoint', () => {
expect(withinTwoSeconds).to.be.true
// Assert no other fields were changed
expect(res).to.have.status(200)
expect(res.body.updated.name).to.equal(cnaParams.name)
expect(res.body.updated.policies.id_quota).to.equal(cnaParams.id_quota)
expect(res.body.updated.active_roles).to.be.undefined
expect(res.body.updated.name).to.be.undefined
expect(res.body.updated.policies).to.be.undefined
expect(err).to.be.undefined
})
})
@@ -88,10 +88,23 @@ describe('Testing org put endpoint', () => {
.set({ ...constants.nonSecretariatUserHeaders })
.send()
.then((res, err) => {
expect(res).to.have.status(401)
expect(res).to.have.status(403)
expect(err).to.be.undefined
expect(res.body).to.haveOwnProperty('error')
expect(res.body.error).to.equal('SECRETARIAT_ONLY')
})
})
it('Fails update to fields made by a non-secretariat org to itself', async () => {
await chai.request(app)
.put('/api/org/win_5')
.set({ ...constants.nonSecretariatUserHeaders })
.query(params)
.send()
.then((res, err) => {
expect(res).to.have.status(403)
expect(err).to.be.undefined
expect(res.body).to.haveOwnProperty('error')
expect(res.body.error).to.equal('UNAUTHORIZED')
expect(res.body.error).to.equal('SECRETARIAT_ONLY')
})
})
it('Fails update made by a non-secretariat org to a secretariat', async () => {
@@ -100,10 +113,10 @@ describe('Testing org put endpoint', () => {
.set({ ...constants.nonSecretariatUserHeaders })
.send()
.then((res, err) => {
expect(res).to.have.status(401)
expect(res).to.have.status(403)
expect(err).to.be.undefined
expect(res.body).to.haveOwnProperty('error')
expect(res.body.error).to.equal('UNAUTHORIZED')
expect(res.body.error).to.equal('SECRETARIAT_ONLY')
})
})
})