Skip to content

Commit f2b96f1

Browse files
authored
Merge pull request #1288 from CVEProject/dev
Updating Int with Dev
2 parents e89a368 + 7748d46 commit f2b96f1

File tree

22 files changed

+8535
-7244
lines changed

22 files changed

+8535
-7244
lines changed

.github/workflows/test-http.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
docker compose --file test-http/docker/docker-compose.yml exec -T demon pytest src/ | tee test-http/src/testOutput.txt
3333
- name: Archive Test Results
34-
uses: actions/upload-artifact@v2
34+
uses: actions/upload-artifact@v4
3535
with:
3636
name: test-results
3737
path: test-http/src/testOutput.txt

api-docs/openapi.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@
20992099
"Organization"
21002100
],
21012101
"summary": "Updates information about the organization specified by short name (accessible to Secretariat)",
2102-
"description": " <h2>Access Control</h2> <p>User must belong to an organization with the <b>Secretariat</b> role, or user must belong to the organization specified by short name</p> <h2>Expected Behavior</h2> <p><b>Secretariat:</b> Updates any organization's information</p> <p><b>Non-secretariat:</b> Updates 'last_active' timestamp to show that an org is still active</p>",
2102+
"description": " <h2>Access Control</h2> <p>User must belong to an organization with the <b>Secretariat</b> role</p> <h2>Expected Behavior</h2> <p><b>Secretariat:</b> Updates any organization's information</p>",
21032103
"operationId": "orgUpdateSingle",
21042104
"parameters": [
21052105
{
@@ -2142,14 +2142,7 @@
21422142
"content": {
21432143
"application/json": {
21442144
"schema": {
2145-
"oneOf": [
2146-
{
2147-
"$ref": "../schemas/org/update-org-response.json"
2148-
},
2149-
{
2150-
"$ref": "../schemas/org/am-i-alive-response.json"
2151-
}
2152-
]
2145+
"$ref": "../schemas/org/update-org-response.json"
21532146
}
21542147
}
21552148
}

package-lock.json

Lines changed: 1614 additions & 978 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"chai-string": "^1.5.0",
1414
"chai-things": "^0.2.0",
1515
"chai-uuid": "^1.0.6",
16-
"depcheck": "^0.9.2",
16+
"depcheck": "^1.4.7",
1717
"eslint": "^8.20.0",
1818
"eslint-config-standard": "^14.1.1",
1919
"eslint-plugin-import": "^2.26.0",
@@ -34,7 +34,7 @@
3434
"cors": "^2.8.5",
3535
"crypto-random-string": "^3.3.1",
3636
"dotenv": "^5.0.1",
37-
"express": "^4.19.2",
37+
"express": "^4.21.0",
3838
"express-jsonschema": "^1.1.6",
3939
"express-rate-limit": "^6.5.2",
4040
"express-validator": "^6.14.2",

schemas/org/am-i-alive-response.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/constants/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fs = require('fs')
2-
const cveSchemaV5 = JSON.parse(fs.readFileSync('src/middleware/schemas/CVE_JSON_5.1_bundled.json'))
2+
const cveSchemaV5 = JSON.parse(fs.readFileSync('src/middleware/schemas/CVE_JSON_5.1.1_bundled.json'))
33

44
/**
55
* Return default values.
@@ -16,7 +16,7 @@ function getConstants () {
1616
* @lends defaults
1717
*/
1818
const defaults = {
19-
SCHEMA_VERSION: '5.1',
19+
SCHEMA_VERSION: '5.1.1',
2020
MONGOOSE_VALIDATION: {
2121
Org_policies_id_quota_min: 0,
2222
Org_policies_id_quota_min_message: 'Org.policies.id_quota cannot be a negative number.',

src/controller/cve.controller/cve.middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const errors = require('./error')
33
const error = new errors.CveControllerError()
44
const utils = require('../../utils/utils')
55
const fs = require('fs')
6-
const RejectedSchema = JSON.parse(fs.readFileSync('src/middleware/schemas/5.1_rejected_cna_container.json'))
7-
const cnaContainerSchema = JSON.parse(fs.readFileSync('src/middleware/schemas/5.1_published_cna_container.json'))
6+
const RejectedSchema = JSON.parse(fs.readFileSync('src/middleware/schemas/5.1.1_rejected_cna_container.json'))
7+
const cnaContainerSchema = JSON.parse(fs.readFileSync('src/middleware/schemas/5.1.1_published_cna_container.json'))
88
const logger = require('../../middleware/logger')
99
const Ajv = require('ajv')
1010
const addFormats = require('ajv-formats')

src/controller/org.controller/index.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,9 @@ router.put('/org/:shortname',
245245
#swagger.summary = "Updates information about the organization specified by short name (accessible to Secretariat)"
246246
#swagger.description = "
247247
<h2>Access Control</h2>
248-
<p>User must belong to an organization with the <b>Secretariat</b> role, or user must belong to the organization specified by short name</p>
248+
<p>User must belong to an organization with the <b>Secretariat</b> role</p>
249249
<h2>Expected Behavior</h2>
250-
<p><b>Secretariat:</b> Updates any organization's information</p>
251-
<p><b>Non-secretariat:</b> Updates 'last_active' timestamp to show that an org is still active</p>"
250+
<p><b>Secretariat:</b> Updates any organization's information</p>"
252251
#swagger.parameters['shortname'] = { description: 'The shortname of the organization' }
253252
#swagger.parameters['$ref'] = [
254253
'#/components/parameters/id_quota',
@@ -264,12 +263,7 @@ router.put('/org/:shortname',
264263
description: 'Returns information about the organization updated',
265264
content: {
266265
"application/json": {
267-
schema: {
268-
oneOf: [
269-
{ $ref: '../schemas/org/update-org-response.json' },
270-
{ $ref: '../schemas/org/am-i-alive-response.json' }
271-
]
272-
}
266+
schema: { $ref: '../schemas/org/update-org-response.json' }
273267
}
274268
}
275269
}
@@ -315,10 +309,10 @@ router.put('/org/:shortname',
315309
}
316310
*/
317311
mw.validateUser,
318-
param(['shortname']).isString().trim().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),
319-
mw.validateOrg,
312+
mw.onlySecretariat,
320313
query().custom((query) => { return mw.validateQueryParameterNames(query, ['new_short_name', 'id_quota', 'name', 'active_roles.add', 'active_roles.remove']) }),
321314
query(['new_short_name', 'id_quota', 'name', 'active_roles.add', 'active_roles.remove']).custom((val) => { return mw.containsNoInvalidCharacters(val) }),
315+
param(['shortname']).isString().trim().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),
322316
query(['new_short_name']).optional().isString().trim().notEmpty().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),
323317
query(['id_quota']).optional().not().isArray().isInt({ min: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_min, max: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_max }).withMessage(errorMsgs.ID_QUOTA),
324318
query(['name']).optional().isString().trim().notEmpty(),

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

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ async function updateOrg (req, res, next) {
329329
const addRoles = []
330330
const orgRepo = req.ctx.repositories.getOrgRepository()
331331
const org = await orgRepo.findOneByShortName(shortName)
332-
const orgMakingChanges = req.ctx.org
333332
let agt = setAggregateOrgObj({ short_name: shortName })
334333

335334
// org doesn't exist
@@ -338,38 +337,30 @@ async function updateOrg (req, res, next) {
338337
return res.status(404).json(error.orgDnePathParam(shortName))
339338
}
340339

341-
const isSec = await orgRepo.isSecretariat(orgMakingChanges)
342-
343-
if (isSec) {
344-
Object.keys(req.ctx.query).forEach(k => {
345-
const key = k.toLowerCase()
346-
347-
if (key === 'new_short_name') {
348-
newOrg.short_name = req.ctx.query.new_short_name
349-
agt = setAggregateOrgObj({ short_name: newOrg.short_name })
350-
} else if (key === 'name') {
351-
newOrg.name = req.ctx.query.name
352-
} else if (key === 'id_quota') {
353-
newOrg.policies.id_quota = req.ctx.query.id_quota
354-
} else if (key === 'active_roles.add') {
355-
if (Array.isArray(req.ctx.query['active_roles.add'])) {
356-
req.ctx.query['active_roles.add'].forEach(r => {
357-
addRoles.push(r)
358-
})
359-
}
360-
} else if (key === 'active_roles.remove') {
361-
if (Array.isArray(req.ctx.query['active_roles.remove'])) {
362-
req.ctx.query['active_roles.remove'].forEach(r => {
363-
removeRoles.push(r)
364-
})
365-
}
366-
}
367-
})
368-
}
340+
Object.keys(req.ctx.query).forEach(k => {
341+
const key = k.toLowerCase()
369342

370-
if (shortName === orgMakingChanges) {
371-
newOrg.last_active = Date.now()
372-
}
343+
if (key === 'new_short_name') {
344+
newOrg.short_name = req.ctx.query.new_short_name
345+
agt = setAggregateOrgObj({ short_name: newOrg.short_name })
346+
} else if (key === 'name') {
347+
newOrg.name = req.ctx.query.name
348+
} else if (key === 'id_quota') {
349+
newOrg.policies.id_quota = req.ctx.query.id_quota
350+
} else if (key === 'active_roles.add') {
351+
if (Array.isArray(req.ctx.query['active_roles.add'])) {
352+
req.ctx.query['active_roles.add'].forEach(r => {
353+
addRoles.push(r)
354+
})
355+
}
356+
} else if (key === 'active_roles.remove') {
357+
if (Array.isArray(req.ctx.query['active_roles.remove'])) {
358+
req.ctx.query['active_roles.remove'].forEach(r => {
359+
removeRoles.push(r)
360+
})
361+
}
362+
}
363+
})
373364

374365
// updating the org's roles
375366
if (org) {
@@ -412,13 +403,6 @@ async function updateOrg (req, res, next) {
412403
result = await orgRepo.aggregate(agt)
413404
result = result.length > 0 ? result[0] : null
414405

415-
if (!isSec) {
416-
if (!result || !result.last_active) {
417-
return res.status(500).json(error.serverError())
418-
}
419-
result = { last_active: result.last_active }
420-
}
421-
422406
const responseMessage = {
423407
message: shortName + ' organization was successfully updated.',
424408
updated: result
@@ -835,8 +819,7 @@ function setAggregateOrgObj (query) {
835819
name: true,
836820
'authority.active_roles': true,
837821
'policies.id_quota': true,
838-
time: true,
839-
last_active: true
822+
time: true
840823
}
841824
}
842825
]

src/middleware/middleware.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const getConstants = require('../constants').getConstants
22
const fs = require('fs')
3-
const cveSchemaV5 = JSON.parse(fs.readFileSync('src/middleware/schemas/CVE_JSON_5.1_bundled.json'))
3+
const cveSchemaV5 = JSON.parse(fs.readFileSync('src/middleware/schemas/CVE_JSON_5.1.1_bundled.json'))
44
const argon2 = require('argon2')
55
const logger = require('./logger')
66
const Ajv = require('ajv')
@@ -135,32 +135,6 @@ async function validateUser (req, res, next) {
135135
}
136136
}
137137

138-
async function validateOrg (req, res, next) {
139-
const org = req.ctx.org
140-
const reqOrg = req.params.shortname
141-
const orgRepo = req.ctx.repositories.getOrgRepository()
142-
const CONSTANTS = getConstants()
143-
144-
try {
145-
logger.info({ uuid: req.ctx.uuid, message: 'Authenticating org: ' + org })
146-
147-
const isSec = await orgRepo.isSecretariat(org)
148-
if (!isSec) {
149-
if (org !== reqOrg) {
150-
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(403).json(error.secretariatOnly())
152-
} else if (Object.keys(req.query).length > 0) {
153-
return res.status(403).json(error.secretariatOnly())
154-
}
155-
}
156-
157-
logger.info({ uuid: req.ctx.uuid, message: 'Confirmed ' + org + ' has the authority to make changes to ' + reqOrg })
158-
next()
159-
} catch (err) {
160-
next(err)
161-
}
162-
}
163-
164138
// Checks that the requester belongs to an org that has the 'BULK_DOWNLOAD' role
165139
async function onlySecretariatOrBulkDownload (req, res, next) {
166140
const org = req.ctx.org
@@ -509,7 +483,6 @@ module.exports = {
509483
setCacheControl,
510484
optionallyValidateUser,
511485
validateUser,
512-
validateOrg,
513486
onlySecretariat,
514487
onlySecretariatOrBulkDownload,
515488
onlySecretariatOrAdmin,

0 commit comments

Comments
 (0)