Skip to content

Commit 64969f7

Browse files
authored
Merge pull request #1429 from CVEProject/cb_org_registry_integration_tests
Resolves issue #1410 - registry tests for postOrgTest, and issue #1426 - improper handling of contact_info for registry org
2 parents 2e354ff + a27c9d9 commit 64969f7

File tree

3 files changed

+94
-13
lines changed

3 files changed

+94
-13
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,11 @@ async function createOrg (req, res, next) {
321321
handlers.reports_to = () => {
322322
regOrg.reports_to = body.reports_to
323323
}
324-
325-
handlers['contact_info.poc'] = () => {
324+
handlers.contact_info = () => {
326325
regOrg.contact_info.poc = body.contact_info.poc
327-
}
328-
handlers['contact_info.poc_email'] = () => {
329326
regOrg.contact_info.poc_email = body.contact_info.poc_email
330-
}
331-
handlers['contact_info.poc_phone'] = () => {
332327
regOrg.contact_info.poc_phone = body.contact_info.poc_phone
333-
}
334-
handlers['contact_info.org_email'] = () => {
335328
regOrg.contact_info.org_email = body.contact_info.org_email
336-
}
337-
handlers['contact_info.website'] = () => {
338329
regOrg.contact_info.website = body.contact_info.website
339330
}
340331
} else {

test/integration-tests/constants.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,23 @@ const testOrg = {
363363
}
364364
}
365365

366+
const testRegistryOrg = {
367+
short_name: 'test_registry_org',
368+
long_name: 'Test Registry Organization',
369+
cve_program_org_function: 'CNA',
370+
contact_info: {
371+
poc: 'Dave',
372+
poc_email: 'dave@test.org',
373+
poc_phone: '555-1234',
374+
org_email: 'contact@test.org',
375+
website: 'test.org'
376+
},
377+
authority: {
378+
active_roles: ['CNA']
379+
},
380+
hard_quota: 100000
381+
}
382+
366383
const existingOrg = {
367384

368385
short_name: 'win_5',
@@ -377,6 +394,23 @@ const existingOrg = {
377394
}
378395
}
379396

397+
const existingRegistryOrg = {
398+
short_name: 'win_5',
399+
long_name: 'Test Registry Organization',
400+
cve_program_org_function: 'CNA',
401+
contact_info: {
402+
poc: 'Dave',
403+
poc_email: 'dave@test.org',
404+
poc_phone: '555-1234',
405+
org_email: 'contact@test.org',
406+
website: 'test.org'
407+
},
408+
authority: {
409+
active_roles: ['CNA']
410+
},
411+
hard_quota: 100000
412+
}
413+
380414
module.exports = {
381415
headers,
382416
nonSecretariatUserHeaders,
@@ -390,5 +424,7 @@ module.exports = {
390424
testAdp,
391425
testAdp2,
392426
testOrg,
393-
existingOrg
427+
testRegistryOrg,
428+
existingOrg,
429+
existingRegistryOrg
394430
}

test/integration-tests/org/postOrgTest.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const expect = chai.expect
66
const constants = require('../constants.js')
77
const app = require('../../../src/index.js')
88

9+
const registryFlag = {
10+
registry: true
11+
}
12+
913
describe('Testing Org post endpoint', () => {
1014
context('Positive Tests', () => {
1115
it('Allows creation of org', async () => {
@@ -37,9 +41,45 @@ describe('Testing Org post endpoint', () => {
3741
expect(res.body.created.authority).to.deep.equal(constants.testOrg.authority)
3842
})
3943
})
44+
it('Allows creation of an org with registry enabled', async () => {
45+
await chai.request(app)
46+
.post('/api/org')
47+
.set(constants.headers)
48+
.query(registryFlag)
49+
.send(constants.testRegistryOrg)
50+
.then((res, err) => {
51+
expect(err).to.be.undefined
52+
expect(res).to.have.status(200)
53+
54+
expect(res.body).to.haveOwnProperty('message')
55+
expect(res.body.message).to.equal(constants.testRegistryOrg.short_name + ' organization was successfully created.')
56+
57+
expect(res.body).to.haveOwnProperty('created')
58+
59+
expect(res.body.created).to.haveOwnProperty('UUID')
60+
61+
expect(res.body.created).to.haveOwnProperty('short_name')
62+
expect(res.body.created.short_name).to.equal(constants.testRegistryOrg.short_name)
63+
64+
expect(res.body.created).to.haveOwnProperty('long_name')
65+
expect(res.body.created.long_name).to.equal(constants.testRegistryOrg.long_name)
66+
67+
expect(res.body.created).to.haveOwnProperty('cve_program_org_function')
68+
expect(res.body.created.cve_program_org_function).to.equal(constants.testRegistryOrg.cve_program_org_function)
69+
70+
expect(res.body.created).to.haveOwnProperty('contact_info')
71+
expect(res.body.created.contact_info).to.include(constants.testRegistryOrg.contact_info)
72+
73+
expect(res.body.created).to.haveOwnProperty('authority')
74+
expect(res.body.created.authority).to.deep.equal(constants.testRegistryOrg.authority)
75+
76+
expect(res.body.created).to.haveOwnProperty('hard_quota')
77+
expect(res.body.created.hard_quota).to.equal(constants.testRegistryOrg.hard_quota)
78+
})
79+
})
4080
})
41-
context('Negitive Test', () => {
42-
it('Should fail to create an org that already exists ', async () => {
81+
context('Negative Tests', () => {
82+
it('Should fail to create an org that already exists', async () => {
4383
await chai.request(app)
4484
.post('/api/org')
4585
.set({ ...constants.headers })
@@ -48,6 +88,20 @@ describe('Testing Org post endpoint', () => {
4888
expect(err).to.be.undefined
4989
expect(res).to.have.status(400)
5090

91+
expect(res.body).to.haveOwnProperty('error')
92+
expect(res.body.error).to.equal('ORG_EXISTS')
93+
})
94+
})
95+
it('Should fail to create an org that already exists with registry enabled', async () => {
96+
await chai.request(app)
97+
.post('/api/org')
98+
.set({ ...constants.headers })
99+
.query(registryFlag)
100+
.send(constants.existingRegistryOrg)
101+
.then((res, err) => {
102+
expect(err).to.be.undefined
103+
expect(res).to.have.status(400)
104+
51105
expect(res.body).to.haveOwnProperty('error')
52106
expect(res.body.error).to.equal('ORG_EXISTS')
53107
})

0 commit comments

Comments
 (0)