Skip to content

Commit

Permalink
Merge pull request #598 from CVEProject/dev
Browse files Browse the repository at this point in the history
#564, #574 Update INT from DEV
  • Loading branch information
slubar authored Mar 21, 2022
2 parents c4b1456 + 718b712 commit 62dc6f3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/controller/org.controller/org.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ async function updateUser (req, res, next) {
return res.status(404).json(error.orgDneParam(shortName))
}

if (shortName !== requesterShortName && !isSecretariat) {
logger.info({ uuid: req.ctx.uuid, message: shortName + ' organization can only be viewed by the users of the same organization or the Secretariat.' })
return res.status(403).json(error.notSameOrgOrSecretariat())
}

const user = await userRepo.findOneByUserNameAndOrgUUID(username, orgUUID)
if (!user) {
logger.info({ uuid: req.ctx.uuid, message: 'The user could not be updated because ' + username + ' does not exist for ' + shortName + ' organization.' })
Expand Down Expand Up @@ -636,19 +641,24 @@ async function resetSecret (req, res, next) {
const orgShortName = req.ctx.params.shortname
const userRepo = req.ctx.repositories.getUserRepository()
const orgRepo = req.ctx.repositories.getOrgRepository()
const isSecretariat = await orgRepo.isSecretariat(requesterShortName)
const orgUUID = await orgRepo.getOrgUUID(orgShortName) // userUUID may be null if user does not exist
if (!orgUUID) {
logger.info({ uuid: req.ctx.uuid, messsage: orgShortName + ' organization does not exist.' })
return res.status(404).json(error.orgDneParam(orgShortName))
}

if (orgShortName !== requesterShortName && !isSecretariat) {
logger.info({ uuid: req.ctx.uuid, message: orgShortName + ' organization can only be viewed by the users of the same organization or the Secretariat.' })
return res.status(403).json(error.notSameOrgOrSecretariat())
}

const oldUser = await userRepo.findOneByUserNameAndOrgUUID(username, orgUUID)
if (!oldUser) {
logger.info({ uuid: req.ctx.uuid, messsage: username + ' user does not exist.' })
return res.status(404).json(error.userDne(username))
}

const isSecretariat = await orgRepo.isSecretariat(requesterShortName)
const isAdmin = await userRepo.isAdmin(requesterUsername, requesterShortName)
// check if the user is not the requester or if the requester is not a secretariat
if ((orgShortName !== requesterShortName || username !== requesterUsername) && !isSecretariat) {
Expand Down
4 changes: 2 additions & 2 deletions test-http/src/test/org_user_tests/org_as_org_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def test_org_admin_cannot_update_user_for_another_org(org_admin_headers):
headers=org_admin_headers
)
assert res.status_code == 403
response_contains_json(res, 'error', 'NOT_SAME_USER_OR_SECRETARIAT')
response_contains_json(res, 'error', 'NOT_SAME_ORG_OR_SECRETARIAT')


def test_org_admin_cannot_update_user_new_shortname_dne(org_admin_headers):
Expand Down Expand Up @@ -455,7 +455,7 @@ def test_org_admin_reset_diff_org_secret(org_admin_headers):
headers=org_admin_headers
)
assert res.status_code == 403
response_contains_json(res, 'error', 'NOT_SAME_USER_OR_SECRETARIAT')
response_contains_json(res, 'error', 'NOT_SAME_ORG_OR_SECRETARIAT')


def test_org_admin_reset_same_org_secret(org_admin_headers):
Expand Down
6 changes: 3 additions & 3 deletions test/unit-tests/user/userResetSecretTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('Testing the PUT /org/:shortname/user/:username/reset_secret endpoint i

expect(res).to.have.status(403)
expect(res).to.have.property('body').and.to.be.a('object')
const errObj = error.notSameUserOrSecretariat()
const errObj = error.notSameOrgOrSecretariat()
expect(res.body.error).to.equal(errObj.error)
expect(res.body.message).to.equal(errObj.message)
done()
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('Testing the PUT /org/:shortname/user/:username/reset_secret endpoint i

expect(res).to.have.status(403)
expect(res).to.have.property('body').and.to.be.a('object')
const errObj = error.notSameUserOrSecretariat()
const errObj = error.notSameOrgOrSecretariat()
expect(res.body.error).to.equal(errObj.error)
expect(res.body.message).to.equal(errObj.message)
done()
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('Testing the PUT /org/:shortname/user/:username/reset_secret endpoint i

expect(res).to.have.status(403)
expect(res).to.have.property('body').and.to.be.a('object')
const errObj = error.notSameUserOrSecretariat()
const errObj = error.notSameOrgOrSecretariat()
expect(res.body.error).to.equal(errObj.error)
expect(res.body.message).to.equal(errObj.message)
done()
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/user/userUpdateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe('Testing the PUT /org/:shortname/user/:username endpoint in Org Control

expect(res).to.have.status(403)
expect(res).to.have.property('body').and.to.be.a('object')
const errObj = error.notSameUserOrSecretariat()
const errObj = error.notSameOrgOrSecretariat()
expect(res.body.error).to.equal(errObj.error)
expect(res.body.message).to.equal(errObj.message)
done()
Expand Down Expand Up @@ -320,7 +320,7 @@ describe('Testing the PUT /org/:shortname/user/:username endpoint in Org Control

expect(res).to.have.status(403)
expect(res).to.have.property('body').and.to.be.a('object')
const errObj = error.notSameUserOrSecretariat()
const errObj = error.notSameOrgOrSecretariat()
expect(res.body.error).to.equal(errObj.error)
expect(res.body.message).to.equal(errObj.message)
done()
Expand Down

0 comments on commit 62dc6f3

Please sign in to comment.