Skip to content

Commit aa51806

Browse files
authored
Merge pull request #1859 from CVEProject/af-1856
Resolves Issue #1856 and #1857: Return authority validation errors for invalid registry org roles
2 parents 007f895 + 45f8668 commit aa51806

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/repositories/baseOrgRepository.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,23 @@ class BaseOrgRepository extends BaseRepository {
10421042
return { isValid: false, errors: [{ instancePath: '/authority', message: 'authority is required' }] }
10431043
}
10441044

1045+
const validAuthorityRoles = getConstants().ORG_ROLES
1046+
const authorityRoleError = instancePath => ({
1047+
isValid: false,
1048+
errors: [{
1049+
instancePath,
1050+
message: 'must be equal to one of the allowed values',
1051+
params: { allowedValues: validAuthorityRoles }
1052+
}]
1053+
})
1054+
10451055
let validateObject = {}
10461056
if (Array.isArray(org.authority)) {
1057+
const invalidAuthorityIndex = org.authority.findIndex(role => !validAuthorityRoles.includes(role))
1058+
if (invalidAuthorityIndex !== -1) {
1059+
return authorityRoleError(`/authority/${invalidAuthorityIndex}`)
1060+
}
1061+
10471062
// User passed in an array, we need to decide how we handle this.
10481063
if (org.authority.includes('SECRETARIAT')) {
10491064
org.authority = ['SECRETARIAT']
@@ -1068,6 +1083,10 @@ class BaseOrgRepository extends BaseRepository {
10681083
}
10691084
}
10701085
} else {
1086+
if (!validAuthorityRoles.includes(org.authority)) {
1087+
return authorityRoleError('/authority')
1088+
}
1089+
10711090
if (org.authority === 'ADP') {
10721091
validateObject = ADPOrgModel.validateOrg(org)
10731092
}

test/integration-tests/registry-org/registryOrgCRUDTest.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,23 @@ describe('Testing /registryOrg endpoints', () => {
748748
expect(res.body.message).to.equal('Parameters were invalid')
749749
})
750750
})
751+
it('Fails to update a registry organization with lowercase authority and returns authority errors', async () => {
752+
await chai.request(app)
753+
.put('/api/registry/org/registry_org_test')
754+
.set(secretariatHeaders)
755+
.send({
756+
...createdOrg,
757+
authority: ['cna']
758+
})
759+
.then((res) => {
760+
expect(res).to.have.status(400)
761+
expect(res.body.message).to.equal('Parameters were invalid')
762+
expect(res.body.errors).to.be.an('array')
763+
expect(res.body.errors[0].instancePath).to.equal('/authority/0')
764+
expect(res.body.errors[0].message).to.equal('must be equal to one of the allowed values')
765+
expect(res.body.errors[0].params.allowedValues).to.include('CNA')
766+
})
767+
})
751768
it('Fails to update a registry organization providing an invalid partner_role_type enum value', async () => {
752769
await chai.request(app)
753770
.put('/api/registry/org/registry_org_test')

0 commit comments

Comments
 (0)