diff --git a/src/controller/cve-id.controller/cve-id.controller.js b/src/controller/cve-id.controller/cve-id.controller.js index d31790710..dd4062ea7 100644 --- a/src/controller/cve-id.controller/cve-id.controller.js +++ b/src/controller/cve-id.controller/cve-id.controller.js @@ -32,28 +32,30 @@ async function getFilteredCveId (req, res, next) { } options.page = req.ctx.query.page ? parseInt(req.ctx.query.page) : CONSTANTS.PAGINATOR_PAGE // if 'page' query parameter is not defined, set 'page' to the default page value const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() - const isSecretariat = await orgRepo.isSecretariat(orgShortName) + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() + const isSecretariat = await orgRepo.isSecretariatByShortName(orgShortName) const isBulkDownload = await orgRepo.isBulkDownload(orgShortName) // Create map of orgUUID to shortnames and users to simplify aggregation later - const orgs = await orgRepo.getAllOrgs() - const users = await userRepo.getAllUsers() + const orgs = await orgRepo.findAll() + const users = await userRepo.findAll() const orgMap = {} const userMap = {} - orgs.forEach(org => { - orgMap[org.UUID] = { shortname: org.short_name, users: {} } - }) - users.forEach(user => { userMap[user.UUID] = user.username - if (!orgMap[user.org_UUID]) { - orgMap[user.org_UUID] = { shortname: `MISSING ORG ${user.org_UUID}`, users: {} } + }) + + orgs.forEach(org => { + orgMap[org.UUID] = { + shortname: org.short_name, + users: org.users.reduce((orgUserMap, userid) => { + orgUserMap[userid] = userMap[userid] + return orgUserMap + }, {}) } - orgMap[user.org_UUID].users[user.UUID] = user.username }) Object.keys(req.ctx.query).forEach(k => { @@ -186,7 +188,7 @@ async function reserveCveId (req, res, next) { let amount let shortName let year - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() try { Object.keys(req.ctx.query).forEach(k => { @@ -203,7 +205,7 @@ async function reserveCveId (req, res, next) { } }) - const isSecretariat = await orgRepo.isSecretariat(orgShortName) + const isSecretariat = await orgRepo.isSecretariatByShortName(orgShortName) if (orgShortName !== shortName && !isSecretariat) { return res.status(403).json(error.orgCannotReserveForOther()) } @@ -239,7 +241,7 @@ async function reserveCveId (req, res, next) { return res.status(403).json(error.overIdQuota(payload)) } - hasLock = await orgRepo.findOneAndUpdate({ short_name: shortName, inUse: false }, { $set: { inUse: true } }, { new: true }) // set lock for org + hasLock = await orgRepo.findOneAndUpdate({ short_name: shortName, $or: [{ inUse: false }, { inUse: { $exists: false } }] }, { $set: { inUse: true } }, { new: true }) // set lock for org if (!hasLock) { return res.status(403).json(error.reservationInProgress()) } @@ -280,7 +282,7 @@ async function getCveId (req, res, next) { const auth = req.ctx.authenticated const id = req.ctx.params.id const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() const agt = setAggregateObj({ cve_id: id }) let result = await cveIdRepo.aggregate(agt) @@ -293,14 +295,12 @@ async function getCveId (req, res, next) { let finalResult = {} let loggerUuid = 'unauthenticated-user' let orgShortName = '' - let orgUUID = null let isSecretariat = false if (auth) { loggerUuid = req.ctx.uuid orgShortName = req.ctx.org - orgUUID = await orgRepo.getOrgUUID(orgShortName) // orgShortName is not null - isSecretariat = await orgRepo.isSecretariatUUID(orgUUID) + isSecretariat = await orgRepo.isSecretariatByShortName(orgShortName) } // Secretariat and owning org are allowed to see complete results @@ -334,15 +334,15 @@ async function modifyCveId (req, res, next) { let state let newOrgShortName let orgUUID - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() const cveRepo = req.ctx.repositories.getCveRepository() const org = await orgRepo.findOneByShortName(req.ctx.org) // Get remaining org quota const totalReserved = await cveIdRepo.countDocuments({ owning_cna: org.UUID, state: 'RESERVED' }) - const remainingQuota = (org.policies.id_quota - totalReserved) + const remainingQuota = (org.hard_quota - totalReserved) // Check for existing record - await only allowed at top level so cannot // move inside of it statement below @@ -408,10 +408,10 @@ async function modifyCveId (req, res, next) { action: 'update_cveid', change: id + ' was successfully updated.', req_UUID: req.ctx.uuid, - org_UUID: await orgRepo.getOrgUUID(req.ctx.org), + org_UUID: org.UUID, cve_id: result } - payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, payload.org_UUID) + payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) logger.info(JSON.stringify(payload)) return res.status(200).json(responseMessage) } catch (err) { @@ -425,8 +425,8 @@ async function createCveIdRange (req, res, next) { const CONSTANTS = getConstants() const year = req.ctx.params.year const cveIdRangeRepo = req.ctx.repositories.getCveIdRangeRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() const result = await cveIdRangeRepo.findOne({ cve_year: year }) if (result) { @@ -443,7 +443,7 @@ async function createCveIdRange (req, res, next) { req_UUID: req.ctx.uuid, org_UUID: await orgRepo.getOrgUUID(req.ctx.org) } - payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, payload.org_UUID) + payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) logger.info(JSON.stringify(payload)) return res.status(200).send() @@ -491,8 +491,8 @@ async function priorityReservation (year, amount, shortName, orgShortName, reque } if (!isFull) { - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() const id = generateSequentialIds(year, result.ranges.priority.top_id, amount) const owningOrgUUID = await orgRepo.getOrgUUID(shortName) @@ -588,8 +588,8 @@ async function sequentialReservation (year, amount, shortName, orgShortName, req } if (!isFull) { - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() const ids = generateSequentialIds(year, result.ranges.general.top_id, amount) const owningOrgUUID = await orgRepo.getOrgUUID(shortName) @@ -698,8 +698,8 @@ async function nonSequentialReservation (year, amount, shortName, orgShortName, } // Case 2: Enough IDs in the 'AVAILABLE' pool - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() let index let counter = 0 const cveIdDocuments = [] @@ -856,7 +856,7 @@ async function reserveNonSequentialCveId (index, available, year, shortName, org async function getPayload (req, org) { const payload = { - id_quota: org.policies.id_quota + id_quota: org.hard_quota } const cveIdRepo = req.ctx.repositories.getCveIdRepository() @@ -906,7 +906,7 @@ function setAggregateObj (query) { }, { $lookup: { - from: 'Org', + from: 'BaseOrg', localField: 'owning_cna', foreignField: 'UUID', as: 'ownerCna' @@ -929,7 +929,7 @@ function setAggregateObj (query) { }, { $lookup: { - from: 'User', + from: 'BaseUser', localField: 'requested_by.user', foreignField: 'UUID', as: 'result' @@ -952,7 +952,7 @@ function setAggregateObj (query) { }, { $lookup: { - from: 'Org', + from: 'BaseOrg', localField: 'requested_by.cna', foreignField: 'UUID', as: 'result' diff --git a/src/controller/cve.controller/cve.controller.js b/src/controller/cve.controller/cve.controller.js index 6f5d9294d..a1ad669d0 100644 --- a/src/controller/cve.controller/cve.controller.js +++ b/src/controller/cve.controller/cve.controller.js @@ -352,7 +352,7 @@ async function submitCve (req, res, next) { const state = newCve.cve.cveMetadata.state const cveRepo = req.ctx.repositories.getCveRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() // the cve id provided in the body must match the cve id provided in the URL params if (id !== cveId) { @@ -395,8 +395,8 @@ async function submitCve (req, res, next) { org_UUID: await orgRepo.getOrgUUID(req.ctx.org), cve: cveId } - const userRepo = req.ctx.repositories.getUserRepository() - payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, payload.org_UUID) + const userRepo = req.ctx.repositories.getBaseUserRepository() + payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) logger.info(JSON.stringify(payload)) return res.status(200).json(responseMessage) } catch (err) { @@ -415,7 +415,7 @@ async function updateCve (req, res, next) { const cveId = req.ctx.params.id const cveRepo = req.ctx.repositories.getCveRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() const newCveMetaData = newCve.cve.cveMetadata const newCveId = newCveMetaData.cveId const newCveState = newCveMetaData.state @@ -459,8 +459,8 @@ async function updateCve (req, res, next) { cve: cveId } - const userRepo = req.ctx.repositories.getUserRepository() - payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, payload.org_UUID) + const userRepo = req.ctx.repositories.getBaseUserRepository() + payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) logger.info(JSON.stringify(payload)) return res.status(200).json(responseMessage) } catch (err) { @@ -476,10 +476,10 @@ async function submitCna (req, res, next) { const id = req.ctx.params.id const cveRepo = req.ctx.repositories.getCveRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() const orgUuid = await orgRepo.getOrgUUID(req.ctx.org) - const userUuid = await userRepo.getUserUUID(req.ctx.user, orgUuid) + const userUuid = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) // To avoid breaking legacy behavior in the "booleanIsTrue" function, we need to check to make sure that undefined is set to false let erlCheck @@ -497,7 +497,7 @@ async function submitCna (req, res, next) { // check that cveId org matches user org const cveId = result - const isSecretariat = await orgRepo.isSecretariat(req.ctx.org) + const isSecretariat = await orgRepo.isSecretariatByShortName(req.ctx.org) if ((cveId.owning_cna !== orgUuid) && !isSecretariat) { return res.status(403).json(error.owningOrgDoesNotMatch()) } @@ -572,10 +572,10 @@ async function updateCna (req, res, next) { const id = req.ctx.params.id const cveRepo = req.ctx.repositories.getCveRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() const orgUuid = await orgRepo.getOrgUUID(req.ctx.org) - const userUuid = await userRepo.getUserUUID(req.ctx.user, orgUuid) + const userUuid = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) // To avoid breaking legacy behavior in the "booleanIsTrue" function, we need to check to make sure that undefined is set to false let erlCheck @@ -593,7 +593,7 @@ async function updateCna (req, res, next) { // check that cveId org matches user org const cveId = result - const isSecretariat = await orgRepo.isSecretariat(req.ctx.org) + const isSecretariat = await orgRepo.isSecretariatByShortName(req.ctx.org) if ((cveId.owning_cna !== orgUuid) && !isSecretariat) { return res.status(403).json(error.owningOrgDoesNotMatch()) } @@ -698,7 +698,7 @@ async function rejectCVE (req, res, next) { } // Both orgs below should exist since they passed validation - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() const providerOrgObj = await orgRepo.findOneByShortName(req.ctx.org) const owningCnaObj = await orgRepo.findOneByUUID(cveIdObj.owning_cna) @@ -738,8 +738,8 @@ async function rejectCVE (req, res, next) { org_UUID: await orgRepo.getOrgUUID(req.ctx.org), cve: id } - const userRepo = req.ctx.repositories.getUserRepository() - payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, payload.org_UUID) + const userRepo = req.ctx.repositories.getBaseUserRepository() + payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) logger.info(JSON.stringify(payload)) return res.status(200).json(responseMessage) } catch (err) { @@ -755,7 +755,7 @@ async function rejectExistingCve (req, res, next) { const id = req.ctx.params.id const cveIdRepo = req.ctx.repositories.getCveIdRepository() const cveRepo = req.ctx.repositories.getCveRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() const providerOrgObj = await orgRepo.findOneByShortName(req.ctx.org) // check that cve id exists @@ -813,8 +813,8 @@ async function rejectExistingCve (req, res, next) { org_UUID: providerOrgObj.UUID, cve: id } - const userRepo = req.ctx.repositories.getUserRepository() - payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, payload.org_UUID) + const userRepo = req.ctx.repositories.getBaseUserRepository() + payload.user_UUID = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) logger.info(JSON.stringify(payload)) return res.status(200).json(responseMessage) } catch (err) { @@ -830,10 +830,10 @@ async function insertAdp (req, res, next) { const id = req.ctx.params.id const cveRepo = req.ctx.repositories.getCveRepository() const cveIdRepo = req.ctx.repositories.getCveIdRepository() - const orgRepo = req.ctx.repositories.getOrgRepository() - const userRepo = req.ctx.repositories.getUserRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const userRepo = req.ctx.repositories.getBaseUserRepository() const orgUuid = await orgRepo.getOrgUUID(req.ctx.org) - const userUuid = await userRepo.getUserUUID(req.ctx.user, orgUuid) + const userUuid = await userRepo.getUserUUID(req.ctx.user, req.ctx.org) // check that cve id exists let result = await cveIdRepo.findOneByCveId(id) diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 03aee444c..eee334d93 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -231,7 +231,7 @@ async function onlySecretariatOrAdmin (req, res, next) { // Checks that the requester belongs to an org that has the 'CNA' role async function onlyCnas (req, res, next) { const shortName = req.ctx.org - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() const CONSTANTS = getConstants() try { @@ -239,10 +239,10 @@ async function onlyCnas (req, res, next) { if (org === null) { logger.info({ uuid: req.ctx.uuid, message: shortName + ' is NOT a ' + CONSTANTS.AUTH_ROLE_ENUM.CNA }) return res.status(404).json(error.cnaDoesNotExist(shortName)) - } else if (org.authority.active_roles.includes(CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT)) { + } else if (org.authority.includes(CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT)) { logger.info({ uuid: req.ctx.uuid, message: org.short_name + ' is a ' + CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT + ' so until Root organizations are implemented this role is allowed.' }) next() - } else if (org.authority.active_roles.includes(CONSTANTS.AUTH_ROLE_ENUM.CNA)) { // the org is a CNA + } else if (org.authority.includes(CONSTANTS.AUTH_ROLE_ENUM.CNA)) { // the org is a CNA logger.info({ uuid: req.ctx.uuid, message: 'Confirmed ' + org.short_name + ' as a ' + CONSTANTS.AUTH_ROLE_ENUM.CNA }) next() } else { @@ -257,7 +257,7 @@ async function onlyCnas (req, res, next) { // Checks that the requester belongs to an org that has the 'ADP' role async function onlyAdps (req, res, next) { const shortName = req.ctx.org - const orgRepo = req.ctx.repositories.getOrgRepository() + const orgRepo = req.ctx.repositories.getBaseOrgRepository() const CONSTANTS = getConstants() try { @@ -265,10 +265,10 @@ async function onlyAdps (req, res, next) { if (org === null) { logger.info({ uuid: req.ctx.uuid, message: shortName + ' is NOT an ' + CONSTANTS.AUTH_ROLE_ENUM.ADP }) return res.status(404).json(error.adpDoesNotExist(shortName)) - } else if (org.authority.active_roles.includes(CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT)) { + } else if (org.authority.includes(CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT)) { logger.info({ uuid: req.ctx.uuid, message: org.short_name + ' is a ' + CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT + ' so until Root organizations are implemented this role is allowed.' }) next() - } else if (org.authority.active_roles.includes(CONSTANTS.AUTH_ROLE_ENUM.ADP)) { // the org is an ADP + } else if (org.authority.includes(CONSTANTS.AUTH_ROLE_ENUM.ADP)) { // the org is an ADP logger.info({ uuid: req.ctx.uuid, message: 'Confirmed ' + org.short_name + ' as an ' + CONSTANTS.AUTH_ROLE_ENUM.ADP }) next() } else { @@ -289,10 +289,10 @@ async function onlyOrgWithPartnerRole (req, res, next) { if (org === null) { logger.info({ uuid: req.ctx.uuid, message: shortName + ' does NOT exist ' }) return res.status(404).json(error.orgDoesNotExist(shortName)) - } else if ((org.authority.length === 1 && org.authority[0] === 'BULK_DOWNLOAD') || (org.authority?.active_roles?.length === 1 && org.authority.active_roles[0] === 'BULK_DOWNLOAD')) { + } else if ((org.authority.length === 1 && org.authority[0] === 'BULK_DOWNLOAD') || (org.authority?.length === 1 && org.authority[0] === 'BULK_DOWNLOAD')) { logger.info({ uuid: req.ctx.uuid, message: org.short_name + 'only has BULK_DOWNLOAD role ' }) return res.status(403).json(error.orgHasNoPartnerRole(shortName)) - } else if (org.authority.length > 0 || org.authority?.active_roles.length > 0) { + } else if (org.authority.length > 0 || org.authority?.length > 0) { logger.info({ uuid: req.ctx.uuid, message: org.short_name + ' has a role ' }) next() } else { @@ -317,8 +317,8 @@ function validateQueryParameterNames (queryParamNames, validNames) { async function cnaMustOwnID (req, res, next) { try { const requestingOrg = req.ctx.org - const orgRepo = req.ctx.repositories.getOrgRepository() - const isSecretariat = await orgRepo.isSecretariat(requestingOrg) + const orgRepo = req.ctx.repositories.getBaseOrgRepository() + const isSecretariat = await orgRepo.isSecretariatByShortName(requestingOrg) const requestingOrgInfo = await orgRepo.findOneByShortName(requestingOrg) const id = req.ctx.params.id const cveIdRepo = req.ctx.repositories.getCveIdRepository() diff --git a/src/repositories/baseOrgRepository.js b/src/repositories/baseOrgRepository.js index 30945fe65..4c65600a0 100644 --- a/src/repositories/baseOrgRepository.js +++ b/src/repositories/baseOrgRepository.js @@ -50,10 +50,16 @@ class BaseOrgRepository extends BaseRepository { super(BaseOrg) } + async findAll (options = {}, returnLegacyFormat = false) { + const OrgRepository = require('./orgRepository') + if (returnLegacyFormat) return await OrgRepository.getAllOrgs() + return await BaseOrgModel.find(options) + } + async findOneByShortNameWithSelect (shortName, select, options = {}, returnLegacyFormat = false) { const OrgRepository = require('./orgRepository') if (returnLegacyFormat) return await OrgRepository.findOneByShortName(shortName, options) - await BaseOrgModel.findOne({ short_name: shortName }, null, options).select(select) + return await BaseOrgModel.findOne({ short_name: shortName }, null, options).select(select) } async findOneByShortName (shortName, options = {}, returnLegacyFormat = false) { diff --git a/src/repositories/baseUserRepository.js b/src/repositories/baseUserRepository.js index 5928a555d..7ac65e532 100644 --- a/src/repositories/baseUserRepository.js +++ b/src/repositories/baseUserRepository.js @@ -79,6 +79,12 @@ class BaseUserRepository extends BaseRepository { return userUUIDs.some(uuid => org.users.includes(uuid)) } + async findAll (options = {}, isLegacyObject = false) { + const legacyUserRepo = new UserRepository() + if (isLegacyObject) return await legacyUserRepo.getAllUsers() + return await BaseUser.find(options) + } + async findOneByUsernameAndOrgShortname (username, orgShortName, options = {}, isLegacyObject = false) { const legacyUserRepo = new UserRepository() const users = await BaseUser.find({ username: username }, null, options) diff --git a/src/scripts/migrate.js b/src/scripts/migrate.js index daf089699..1f6a77673 100644 --- a/src/scripts/migrate.js +++ b/src/scripts/migrate.js @@ -174,7 +174,7 @@ async function orgHelper (db) { // Doc to update existing org record, or to be created let type = 'CNAOrg' - if (doc.short_name.toLowerCase().includes('mitre')) { type = 'SECRETARIAT' } + if (doc.short_name.toLowerCase().includes('mitre')) { type = 'SecretariatOrg' } updateDoc = { $set: { UUID: doc.UUID, diff --git a/test/unit-tests/cve-id/cveIdGetAllTest.js b/test/unit-tests/cve-id/cveIdGetAllTest.js index e30098a7f..549ebd407 100644 --- a/test/unit-tests/cve-id/cveIdGetAllTest.js +++ b/test/unit-tests/cve-id/cveIdGetAllTest.js @@ -5,9 +5,9 @@ const expect = chai.expect const _ = require('lodash') const cveIdController = require('../../../src/controller/cve-id.controller/cve-id.controller.js') -const OrgRepository = require('../../../src/repositories/orgRepository.js') +const OrgRepository = require('../../../src/repositories/baseOrgRepository.js') const CveIdRepository = require('../../../src/repositories/cveIdRepository.js') -const UserRepository = require('../../../src/repositories/userRepository.js') +const UserRepository = require('../../../src/repositories/baseUserRepository.js') const orgUUID = faker.datatype.uuid() const orgUUID2 = faker.datatype.uuid() @@ -22,7 +22,13 @@ const stubOrg = { 'CNA', 'Secretariat' ] - } + }, + users: [ + { + UUID: userUUID, + username: 'testUser' + } + ] } const stubOrg2 = { @@ -33,7 +39,13 @@ const stubOrg2 = { active_roles: [ 'CNA' ] - } + }, + users: [ + { + UUID: userUUID, + username: 'testUser' + } + ] } const stubUser = { @@ -63,9 +75,9 @@ const builtQuery = { } } describe('Testing getFilteredCveId function', () => { - let sandbox, status, json, res, next, getOrgRepository, + let sandbox, status, json, res, next, getBaseOrgRepository, orgRepo, getCveIdRepository, cveIdRepo, - getUserRepository, userRepo, req, cveIdCopy + getBaseUserRepository, userRepo, req, cveIdCopy // Stub out functions called in insertAdp and reset them for each test beforeEach(() => { @@ -91,12 +103,12 @@ describe('Testing getFilteredCveId function', () => { } orgRepo = new OrgRepository() - getOrgRepository = sandbox.stub() - getOrgRepository.returns(orgRepo) + getBaseOrgRepository = sandbox.stub() + getBaseOrgRepository.returns(orgRepo) userRepo = new UserRepository() - getUserRepository = sandbox.stub() - getUserRepository.returns(userRepo) + getBaseUserRepository = sandbox.stub() + getBaseUserRepository.returns(userRepo) cveIdRepo = new CveIdRepository() getCveIdRepository = sandbox.stub() @@ -106,12 +118,12 @@ describe('Testing getFilteredCveId function', () => { sandbox.stub(cveIdRepo, 'aggregatePaginate').returns(aggPagResp) sandbox.stub(orgRepo, 'getOrgUUID').returns(stubOrg.UUID) - sandbox.stub(orgRepo, 'isSecretariat').returns(true) + sandbox.stub(orgRepo, 'isSecretariatByShortName').returns(true) sandbox.stub(orgRepo, 'isBulkDownload').returns(false) - sandbox.stub(orgRepo, 'getAllOrgs').returns([stubOrg, stubOrg2]) + sandbox.stub(orgRepo, 'findAll').returns([stubOrg, stubOrg2]) sandbox.stub(userRepo, 'getUserUUID').returns(stubUser.UUID) - sandbox.stub(userRepo, 'getAllUsers').returns([stubUser]) + sandbox.stub(userRepo, 'findAll').returns([stubUser]) sandbox.spy(cveIdController, 'CVEID_GET_FILTER') @@ -126,8 +138,8 @@ describe('Testing getFilteredCveId function', () => { state: 'RESERVED' }, repositories: { - getOrgRepository, - getUserRepository, + getBaseOrgRepository, + getBaseUserRepository, getCveIdRepository } } diff --git a/test/unit-tests/cve-id/cveIdGetSingleTest.js b/test/unit-tests/cve-id/cveIdGetSingleTest.js index ea80b1ad1..f3d82b7e9 100644 --- a/test/unit-tests/cve-id/cveIdGetSingleTest.js +++ b/test/unit-tests/cve-id/cveIdGetSingleTest.js @@ -45,11 +45,7 @@ class NullOrgRepo { return null } - async isSecretariat () { - return null - } - - async isSecretariatUUID () { + async isSecretariatByShortName () { return null } } @@ -67,8 +63,8 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { .get((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdGetCveIdDoesntExist() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new NullOrgRepo() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new NullOrgRepo() } } req.ctx.repositories = factory next() @@ -102,8 +98,8 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { .get((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdGetCveIdAvailable() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new NullOrgRepo() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new NullOrgRepo() } } req.ctx.repositories = factory next() @@ -138,7 +134,7 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { return cveIdFixtures.org.UUID } - async isSecretariatUUID () { + async isSecretariatByShortName () { return false } } @@ -147,8 +143,8 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { .get((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdGetCveIdNotOwningOrg() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgGetCveIdNotOwnerOrgReserved() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgGetCveIdNotOwnerOrgReserved() } } req.ctx.repositories = factory next() @@ -192,7 +188,7 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { return cveIdFixtures.org.UUID } - async isSecretariatUUID () { + async isSecretariatByShortName () { return false } @@ -205,8 +201,8 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { .get((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdGetCveIdNotOwningOrgNotReserved() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgGetCveIdNotOwnerOrgNotReserved() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgGetCveIdNotOwnerOrgNotReserved() } } req.ctx.repositories = factory next() @@ -248,7 +244,7 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { return cveIdFixtures.owningOrg.UUID } - async isSecretariatUUID () { + async isSecretariatByShortName () { return false } @@ -261,8 +257,8 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { .get((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdGetCveIdOwningOrg() }, - getUserRepository: () => { return new UserGetCveIdOwningOrg() }, - getOrgRepository: () => { return new OrgGetCveIdOwningOrg() } + getBaseUserRepository: () => { return new UserGetCveIdOwningOrg() }, + getBaseOrgRepository: () => { return new OrgGetCveIdOwningOrg() } } req.ctx.repositories = factory req.ctx.authenticated = true @@ -311,7 +307,7 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { return cveIdFixtures.secretariatOrg.UUID } - async isSecretariatUUID () { + async isSecretariatByShortName () { return true } @@ -328,8 +324,8 @@ describe('Testing the GET /cve-id/:id endpoint in CveId Controller', () => { .get((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdGetCveIdOwningOrg() }, - getUserRepository: () => { return new UserGetCveIdRequestorSecretariat() }, - getOrgRepository: () => { return new OrgGetCveIdRequestorSecretariat() } + getBaseUserRepository: () => { return new UserGetCveIdRequestorSecretariat() }, + getBaseOrgRepository: () => { return new OrgGetCveIdRequestorSecretariat() } } req.ctx.repositories = factory req.ctx.authenticated = true diff --git a/test/unit-tests/cve-id/cveIdRangeCreateTest.js b/test/unit-tests/cve-id/cveIdRangeCreateTest.js index 9782333c2..14d31054a 100644 --- a/test/unit-tests/cve-id/cveIdRangeCreateTest.js +++ b/test/unit-tests/cve-id/cveIdRangeCreateTest.js @@ -74,8 +74,8 @@ describe('Testing the POST /cve-id-range/:year endpoint in CveId Controller', () .post((req, res, next) => { const factory = { getCveIdRangeRepository: () => { return new CveIdRange2022Exists() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new NullOrgRepo() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new NullOrgRepo() } } req.ctx.repositories = factory next() @@ -115,8 +115,8 @@ describe('Testing the POST /cve-id-range/:year endpoint in CveId Controller', () .post((req, res, next) => { const factory = { getCveIdRangeRepository: () => { return new CveIdRange2022NotExists() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new NullOrgRepo() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new NullOrgRepo() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/cve-id/cveIdUpdateTest.js b/test/unit-tests/cve-id/cveIdUpdateTest.js index 0330bf317..81b4106db 100644 --- a/test/unit-tests/cve-id/cveIdUpdateTest.js +++ b/test/unit-tests/cve-id/cveIdUpdateTest.js @@ -108,8 +108,8 @@ describe('Testing the PUT /cve-id/:id endpoint in CveId Controller', () => { .put((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdModifyCveIdDoesntExist() }, - getOrgRepository: () => { return new OrgModifyCveIdDoesntExist() }, - getUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgModifyCveIdDoesntExist() }, + getBaseUserRepository: () => { return new NullUserRepo() }, getCveRepository: () => { return new NullCveRepo() } } req.ctx.repositories = factory @@ -148,8 +148,8 @@ describe('Testing the PUT /cve-id/:id endpoint in CveId Controller', () => { .put((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdModifyCveIdOrgAndStateModified() }, - getOrgRepository: () => { return new OrgModifyCveIdOrgDoesntExist() }, - getUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgModifyCveIdOrgDoesntExist() }, + getBaseUserRepository: () => { return new NullUserRepo() }, getCveRepository: () => { return new NullCveRepo() } } req.ctx.repositories = factory @@ -183,8 +183,8 @@ describe('Testing the PUT /cve-id/:id endpoint in CveId Controller', () => { // .put((req, res, next) => { // const factory = { // getCveIdRepository: () => { return new CveIdModifyCveIdOrgAndStateModified() }, - // getOrgRepository: () => { return new NullOrgRepo() }, - // getUserRepository: () => { return new NullUserRepo() }, + // getBaseOrgRepository: () => { return new NullOrgRepo() }, + // getBaseUserRepository: () => { return new NullUserRepo() }, // getCveRepository: () => { return new NullCveRepo() } // } // req.ctx.repositories = factory @@ -215,8 +215,8 @@ describe('Testing the PUT /cve-id/:id endpoint in CveId Controller', () => { .put((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdModifyCveIdOrgAndStateModified() }, - getOrgRepository: () => { return new OrgModifyCveIdOrgAndStateModified() }, - getUserRepository: () => { return new UserModifyCveIdOrgAndStateModified() }, + getBaseOrgRepository: () => { return new OrgModifyCveIdOrgAndStateModified() }, + getBaseUserRepository: () => { return new UserModifyCveIdOrgAndStateModified() }, getCveRepository: () => { return new NullCveRepo() } } req.ctx.repositories = factory @@ -275,8 +275,8 @@ describe('Testing the PUT /cve-id/:id endpoint in CveId Controller', () => { .put((req, res, next) => { const factory = { getCveIdRepository: () => { return new CveIdModifyCveIdNoQuery() }, - getOrgRepository: () => { return new OrgModifyCveIdOrgAndStateModified() }, - getUserRepository: () => { return new UserModifyCveIdOrgAndStateModified() }, + getBaseOrgRepository: () => { return new OrgModifyCveIdOrgAndStateModified() }, + getBaseUserRepository: () => { return new UserModifyCveIdOrgAndStateModified() }, getCveRepository: () => { return new NullCveRepo() } } req.ctx.repositories = factory diff --git a/test/unit-tests/cve-id/mockObjects.cve-id.js b/test/unit-tests/cve-id/mockObjects.cve-id.js index 7c81f6f23..2c096f761 100644 --- a/test/unit-tests/cve-id/mockObjects.cve-id.js +++ b/test/unit-tests/cve-id/mockObjects.cve-id.js @@ -30,9 +30,7 @@ const secretariatOrg = { active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA, CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT] }, name: 'The MITRE Corporation', - policies: { - id_quota: 1000 - }, + hard_quota: 1000, short_name: 'mitre', inUse: false } @@ -58,9 +56,7 @@ const owningOrg = { active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA] }, name: 'Cisco', - policies: { - id_quota: 1000 - }, + hard_quota: 1000, short_name: 'cisco', inUse: false } @@ -87,9 +83,7 @@ const org = { active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA] }, name: 'Siemens', - policies: { - id_quota: 500 - }, + hard_quota: 500, short_name: 'siemens', inUse: false } @@ -116,9 +110,7 @@ const nonExistentOrg = { active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA] }, name: 'The Oval Office', - policies: { - id_quota: 5 - }, + hard_quota: 5, short_name: 'oval', inUse: false } diff --git a/test/unit-tests/cve-id/reserveCveId.non-sequential/mockObjects.non-sequential.js b/test/unit-tests/cve-id/reserveCveId.non-sequential/mockObjects.non-sequential.js index 7fe1279fb..06822a2a0 100644 --- a/test/unit-tests/cve-id/reserveCveId.non-sequential/mockObjects.non-sequential.js +++ b/test/unit-tests/cve-id/reserveCveId.non-sequential/mockObjects.non-sequential.js @@ -29,9 +29,7 @@ const secretariatOrg = { active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA, CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT] }, name: 'The MITRE Corporation', - policies: { - id_quota: 1000 - }, + hard_quota: 1000, short_name: 'mitre', inUse: false } @@ -57,9 +55,7 @@ const orgA = { active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA] }, name: 'Cisco', - policies: { - id_quota: 500 - }, + hard_quota: 500, short_name: 'cisco', inUse: false } @@ -86,9 +82,7 @@ const orgB = { active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA] }, name: 'Siemens', - policies: { - id_quota: 500 - }, + hard_quota: 500, short_name: 'siemens', inUse: false } diff --git a/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.non-sequential.js b/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.non-sequential.js index 7d3c45968..7638c2d17 100644 --- a/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.non-sequential.js +++ b/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.non-sequential.js @@ -139,7 +139,7 @@ describe('Testing the non sequential reservation (Base Case) of POST /cve-id end } class OrgReserveNonSequentialYearDoesntExist { - async isSecretariat () { + async isSecretariatByShortName () { return false } @@ -163,8 +163,8 @@ describe('Testing the non sequential reservation (Base Case) of POST /cve-id end const factory = { getCveIdRepository: () => { return new CveIdReserveNonSequentialIsFull() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveYearDoesntExist() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveNonSequentialYearDoesntExist() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveNonSequentialYearDoesntExist() } } req.ctx.repositories = factory next() @@ -178,7 +178,7 @@ describe('Testing the non sequential reservation (Base Case) of POST /cve-id end done(err) } - const quotaHeader = cveIdNonSeqFixtures.orgA.policies.id_quota.toString() + const quotaHeader = cveIdNonSeqFixtures.orgA.hard_quota.toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(403) @@ -200,7 +200,7 @@ describe('Testing the non sequential reservation (Base Case) of POST /cve-id end } class OrgReserveNonSequentialSuccess { - async isSecretariat () { + async isSecretariatByShortName () { return false } @@ -233,8 +233,8 @@ describe('Testing the non sequential reservation (Base Case) of POST /cve-id end const factory = { getCveIdRepository: () => { return cveIdRepo }, getCveIdRangeRepository: () => { return cveIdRangeRepo }, - getUserRepository: () => { return userRepo }, - getOrgRepository: () => { return orgRepo } + getBaseUserRepository: () => { return userRepo }, + getBaseOrgRepository: () => { return orgRepo } } req.ctx.repositories = factory next() @@ -248,7 +248,7 @@ describe('Testing the non sequential reservation (Base Case) of POST /cve-id end done(err) } - const quotaHeader = (cveIdNonSeqFixtures.orgA.policies.id_quota - 10).toString() + const quotaHeader = (cveIdNonSeqFixtures.orgA.hard_quota - 10).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(200) diff --git a/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.usersA_B.non-sequential.js b/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.usersA_B.non-sequential.js index fee9b72eb..0cdb092a2 100644 --- a/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.usersA_B.non-sequential.js +++ b/test/unit-tests/cve-id/reserveCveId.non-sequential/reserveCveIdTest.usersA_B.non-sequential.js @@ -219,7 +219,7 @@ class UserReserveNonSequentialSuccessCaseAB { } class OrgReserveNonSequentialSuccessCaseAB { - async isSecretariat () { + async isSecretariatByShortName () { return false } @@ -273,8 +273,8 @@ describe('Testing the non sequential reservation (Case AB) of POST /cve-id endpo const factory = { getCveIdRepository: () => { return cveIdRepo }, getCveIdRangeRepository: () => { return cveIdRangeRepo }, - getUserRepository: () => { return userRepo }, - getOrgRepository: () => { return orgRepo } + getBaseUserRepository: () => { return userRepo }, + getBaseOrgRepository: () => { return orgRepo } } req.ctx.repositories = factory next() @@ -288,7 +288,7 @@ describe('Testing the non sequential reservation (Case AB) of POST /cve-id endpo done(err) } - const quotaHeader = (cveIdNonSeqFixtures.orgA.policies.id_quota - 10).toString() + const quotaHeader = (cveIdNonSeqFixtures.orgA.hard_quota - 10).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(200) @@ -372,8 +372,8 @@ describe('Testing the non sequential reservation (Case AB) of POST /cve-id endpo const factory = { getCveIdRepository: () => { return new CveIdReservePoolIncremented10IdsCaseAB2() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveNonSequentialSuccessCaseAB2() }, - getUserRepository: () => { return new UserReserveNonSequentialSuccessCaseAB() }, - getOrgRepository: () => { return new OrgReserveNonSequentialSuccessCaseAB() } + getBaseUserRepository: () => { return new UserReserveNonSequentialSuccessCaseAB() }, + getBaseOrgRepository: () => { return new OrgReserveNonSequentialSuccessCaseAB() } } req.ctx.repositories = factory next() @@ -387,7 +387,7 @@ describe('Testing the non sequential reservation (Case AB) of POST /cve-id endpo done(err) } - const quotaHeader = (cveIdNonSeqFixtures.orgB.policies.id_quota - 10).toString() + const quotaHeader = (cveIdNonSeqFixtures.orgB.hard_quota - 10).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(200) @@ -577,8 +577,8 @@ describe('Testing the non sequential reservation (Case AB) of POST /cve-id endpo const factory = { getCveIdRepository: () => { return new CveIdReservePoolIncremented10IdsCaseAB3() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveNonSequentialSuccessCaseAB3() }, - getUserRepository: () => { return new UserReserveNonSequentialSuccessCaseAB() }, - getOrgRepository: () => { return new OrgReserveNonSequentialSuccessCaseAB() } + getBaseUserRepository: () => { return new UserReserveNonSequentialSuccessCaseAB() }, + getBaseOrgRepository: () => { return new OrgReserveNonSequentialSuccessCaseAB() } } req.ctx.repositories = factory next() @@ -592,7 +592,7 @@ describe('Testing the non sequential reservation (Case AB) of POST /cve-id endpo done(err) } - const quotaHeader = (cveIdNonSeqFixtures.orgA.policies.id_quota - 10).toString() + const quotaHeader = (cveIdNonSeqFixtures.orgA.hard_quota - 10).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(403) diff --git a/test/unit-tests/cve-id/reserveCveId/cveIdReserveGeneralLogicTest.js b/test/unit-tests/cve-id/reserveCveId/cveIdReserveGeneralLogicTest.js index bbc1d27fb..f2641f2f4 100644 --- a/test/unit-tests/cve-id/reserveCveId/cveIdReserveGeneralLogicTest.js +++ b/test/unit-tests/cve-id/reserveCveId/cveIdReserveGeneralLogicTest.js @@ -40,13 +40,13 @@ class NullUserRepo { } class OrgReserveShortNameUndefined { - async isSecretariat () { + async isSecretariatByShortName () { return true } } class OrgReserveAmountLargerThanNonSequential { - async isSecretariat () { + async isSecretariatByShortName () { return true } @@ -69,7 +69,7 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller context('Negative Tests', () => { it('Requester is not a user of the same org or the secretariat', (done) => { class OrgReserveNotOwningOrg { - async isSecretariat () { + async isSecretariatByShortName () { return false } } @@ -78,8 +78,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveNotOwningOrg() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveNotOwningOrg() } } req.ctx.repositories = factory next() @@ -107,8 +107,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveShortNameUndefined() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveShortNameUndefined() } } req.ctx.repositories = factory next() @@ -136,8 +136,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveShortNameUndefined() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveShortNameUndefined() } } req.ctx.repositories = factory next() @@ -165,8 +165,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveShortNameUndefined() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveShortNameUndefined() } } req.ctx.repositories = factory next() @@ -194,8 +194,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveShortNameUndefined() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveShortNameUndefined() } } req.ctx.repositories = factory next() @@ -223,8 +223,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveShortNameUndefined() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveShortNameUndefined() } } req.ctx.repositories = factory next() @@ -249,7 +249,7 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller it('Org does not exist', (done) => { class OrgReserveOrgDoesntExist { - async isSecretariat () { + async isSecretariatByShortName () { return true } @@ -262,8 +262,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveOrgDoesntExist() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveOrgDoesntExist() } } req.ctx.repositories = factory next() @@ -293,8 +293,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveAmountLargerThanNonSequential() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveAmountLargerThanNonSequential() } } req.ctx.repositories = factory next() @@ -319,7 +319,7 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller it('Amount query parameter is > than id_quota', (done) => { class OrgReserveAmountGreaterIdQuota { - async isSecretariat () { + async isSecretariatByShortName () { return true } @@ -332,8 +332,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveAmountGreaterIdQuota() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveAmountGreaterIdQuota() } } req.ctx.repositories = factory next() @@ -362,8 +362,8 @@ describe('Testing the general logic of POST /cve-id endpoint in CveId Controller .post((req, res, next) => { const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveAmountLargerThanNonSequential() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveAmountLargerThanNonSequential() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/cve-id/reserveCveId/cveIdReservePriorityTest.js b/test/unit-tests/cve-id/reserveCveId/cveIdReservePriorityTest.js index 3fa3727e1..6fa1caec5 100644 --- a/test/unit-tests/cve-id/reserveCveId/cveIdReservePriorityTest.js +++ b/test/unit-tests/cve-id/reserveCveId/cveIdReservePriorityTest.js @@ -51,7 +51,7 @@ class UserReserveSequentialPriorityIsFull { } class OrgReserveSequentialPriorityIsFull { - async isSecretariat () { + async isSecretariatByShortName () { return false } @@ -90,7 +90,7 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con } class OrgReserveYear2025RangeDoesntExist { - async isSecretariat () { + async isSecretariatByShortName () { return true } @@ -114,8 +114,8 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con const factory = { getCveIdRepository: () => { return new NullCveIdRepo() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveYearDoesntExist() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveYear2025RangeDoesntExist() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveYear2025RangeDoesntExist() } } req.ctx.repositories = factory next() @@ -129,7 +129,7 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con done(err) } - const quotaHeader = cveIdFixtures.owningOrg.policies.id_quota.toString() + const quotaHeader = cveIdFixtures.owningOrg.hard_quota.toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(403) @@ -163,7 +163,7 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con } class OrgReserveSequentialIsFull { - async isSecretariat () { + async isSecretariatByShortName () { return false } @@ -187,8 +187,8 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con const factory = { getCveIdRepository: () => { return new CveIdReserveSequentialPriorityIsFull() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveSequentialIsFull() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveSequentialIsFull() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveSequentialIsFull() } } req.ctx.repositories = factory next() @@ -202,7 +202,7 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con done(err) } - const quotaHeader = (cveIdFixtures.owningOrg.policies.id_quota).toString() + const quotaHeader = (cveIdFixtures.owningOrg.hard_quota).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(403) @@ -252,8 +252,8 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con const factory = { getCveIdRepository: () => { return new CveIdReserveSequentialPriorityIsFull() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveSequentialPriorityIsFull() }, - getUserRepository: () => { return new UserReserveSequentialPriorityIsFull() }, - getOrgRepository: () => { return new OrgReserveSequentialPriorityIsFull() } + getBaseUserRepository: () => { return new UserReserveSequentialPriorityIsFull() }, + getBaseOrgRepository: () => { return new OrgReserveSequentialPriorityIsFull() } } req.ctx.repositories = factory next() @@ -270,7 +270,7 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con done(err) } - const quotaHeader = (cveIdFixtures.owningOrg.policies.id_quota - 1).toString() + const quotaHeader = (cveIdFixtures.owningOrg.hard_quota - 1).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(200) @@ -323,8 +323,8 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con const factory = { getCveIdRepository: () => { return new CveIdReserveSequentialPriorityIsFull() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveSequentialPriority() }, - getUserRepository: () => { return new UserReserveSequentialPriorityIsFull() }, - getOrgRepository: () => { return new OrgReserveSequentialPriorityIsFull() } + getBaseUserRepository: () => { return new UserReserveSequentialPriorityIsFull() }, + getBaseOrgRepository: () => { return new OrgReserveSequentialPriorityIsFull() } } req.ctx.repositories = factory next() @@ -341,7 +341,7 @@ describe('Testing the priority reservation of POST /cve-id endpoint in CveId Con done(err) } - const quotaHeader = (cveIdFixtures.owningOrg.policies.id_quota - 1).toString() + const quotaHeader = (cveIdFixtures.owningOrg.hard_quota - 1).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(200) diff --git a/test/unit-tests/cve-id/reserveCveId/cveIdReserveSequentialTest.js b/test/unit-tests/cve-id/reserveCveId/cveIdReserveSequentialTest.js index fb5f3385c..8c300fdb8 100644 --- a/test/unit-tests/cve-id/reserveCveId/cveIdReserveSequentialTest.js +++ b/test/unit-tests/cve-id/reserveCveId/cveIdReserveSequentialTest.js @@ -35,7 +35,7 @@ class NullUserRepo { } class OrgReserveYear2025RangeDoesntExistSequential { - async isSecretariat () { + async isSecretariatByShortName () { return true } @@ -74,8 +74,8 @@ describe('Testing the sequential reservation of POST /cve-id endpoint in CveId C const factory = { getCveIdRepository: () => { return new CveIdReserveSequentialYearDoesntExist() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveYearDoesntExist() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveYear2025RangeDoesntExistSequential() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveYear2025RangeDoesntExistSequential() } } req.ctx.repositories = factory next() @@ -89,7 +89,7 @@ describe('Testing the sequential reservation of POST /cve-id endpoint in CveId C done(err) } - const quotaHeader = (cveIdFixtures.owningOrg.policies.id_quota - 2).toString() + const quotaHeader = (cveIdFixtures.owningOrg.hard_quota - 2).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(403) @@ -133,8 +133,8 @@ describe('Testing the sequential reservation of POST /cve-id endpoint in CveId C const factory = { getCveIdRepository: () => { return new CveIdReserveSequentialIsFull() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveSequentialIsFull() }, - getUserRepository: () => { return new NullUserRepo() }, - getOrgRepository: () => { return new OrgReserveYear2025RangeDoesntExistSequential() } + getBaseUserRepository: () => { return new NullUserRepo() }, + getBaseOrgRepository: () => { return new OrgReserveYear2025RangeDoesntExistSequential() } } req.ctx.repositories = factory next() @@ -148,7 +148,7 @@ describe('Testing the sequential reservation of POST /cve-id endpoint in CveId C done(err) } - const quotaHeader = (cveIdFixtures.owningOrg.policies.id_quota - 2).toString() + const quotaHeader = (cveIdFixtures.owningOrg.hard_quota - 2).toString() expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(403) @@ -209,7 +209,7 @@ describe('Testing the sequential reservation of POST /cve-id endpoint in CveId C } class OrgReserveSequentialPriorityIsFull { - async isSecretariat () { + async isSecretariatByShortName () { return false } @@ -237,8 +237,8 @@ describe('Testing the sequential reservation of POST /cve-id endpoint in CveId C const factory = { getCveIdRepository: () => { return new CveIdReserveSequential() }, getCveIdRangeRepository: () => { return new CveIdRangeReserveSequential() }, - getUserRepository: () => { return new UserReserveSequentialPriorityIsFull() }, - getOrgRepository: () => { return new OrgReserveSequentialPriorityIsFull() } + getBaseUserRepository: () => { return new UserReserveSequentialPriorityIsFull() }, + getBaseOrgRepository: () => { return new OrgReserveSequentialPriorityIsFull() } } req.ctx.repositories = factory next() @@ -255,7 +255,7 @@ describe('Testing the sequential reservation of POST /cve-id endpoint in CveId C done(err) } - const quotaHeader = (cveIdFixtures.owningOrg.policies.id_quota - 7).toString() // already has two reserved cve ids + const quotaHeader = (cveIdFixtures.owningOrg.hard_quota - 7).toString() // already has two reserved cve ids expect(res.header).to.have.property('cve-api-remaining-quota').and.to.equal(quotaHeader) expect(res).to.have.status(200) diff --git a/test/unit-tests/cve/cveCnaContainerCreateTest.js b/test/unit-tests/cve/cveCnaContainerCreateTest.js index ebc484eb1..784ec7fb6 100644 --- a/test/unit-tests/cve/cveCnaContainerCreateTest.js +++ b/test/unit-tests/cve/cveCnaContainerCreateTest.js @@ -33,7 +33,7 @@ class MyOrg { return null } - async isSecretariat (org) { + async isSecretariatByShortName (org) { if (org === cveFixtures.secretariatHeader['CVE-API-ORG']) { return true } @@ -117,8 +117,8 @@ app.route('/cve-cna-negative-tests/:id') const factory = { getCveIdRepository: () => { return new MyCveIdNegativeTests() }, getCveRepository: () => { return new MyCveNegativeTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() @@ -129,8 +129,8 @@ app.route('/cve-cna-positive-tests/:id') const factory = { getCveIdRepository: () => { return new MyCveIdPositiveTests() }, getCveRepository: () => { return new MyCvePositiveTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/cve/cveCnaContainerUpdateTest.js b/test/unit-tests/cve/cveCnaContainerUpdateTest.js index 04dd04d26..6cf912a51 100644 --- a/test/unit-tests/cve/cveCnaContainerUpdateTest.js +++ b/test/unit-tests/cve/cveCnaContainerUpdateTest.js @@ -34,7 +34,7 @@ class MyOrg { return null } - async isSecretariat (org) { + async isSecretariatByShortName (org) { if (org === cveFixtures.secretariatHeader['CVE-API-ORG']) { return true } @@ -128,8 +128,8 @@ app.route('/cve-cna-negative-tests/:id') const factory = { getCveIdRepository: () => { return new MyCveIdNegativeTests() }, getCveRepository: () => { return new MyCveNegativeTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() @@ -140,8 +140,8 @@ app.route('/cve-cna-positive-tests/:id') const factory = { getCveIdRepository: () => { return new MyCveIdPositiveTests() }, getCveRepository: () => { return new MyCvePositiveTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/cve/cveCreateTest.js b/test/unit-tests/cve/cveCreateTest.js index 16057e821..fb1dbea36 100644 --- a/test/unit-tests/cve/cveCreateTest.js +++ b/test/unit-tests/cve/cveCreateTest.js @@ -117,8 +117,8 @@ app.route('/cve-create-record-negative-tests/:id') const factory = { getCveRepository: () => { return new MyCveNegativeTests() }, getCveIdRepository: () => { return new MyCveIdNegativeTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() @@ -129,8 +129,8 @@ app.route('/cve-create-record-positive-tests/:id') const factory = { getCveRepository: () => { return new MyCvePositiveTests() }, getCveIdRepository: () => { return new MyCveIdPositiveTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/cve/cveRecordRejectionTest.js b/test/unit-tests/cve/cveRecordRejectionTest.js index 0f3637e46..b36e3346d 100644 --- a/test/unit-tests/cve/cveRecordRejectionTest.js +++ b/test/unit-tests/cve/cveRecordRejectionTest.js @@ -99,8 +99,8 @@ app.route('/cve-reject-negative-tests/:id') const factory = { getCveIdRepository: () => { return new MyCveIdNegativeTests() }, getCveRepository: () => { return new MyCveNegativeTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() @@ -111,8 +111,8 @@ app.route('/cve-reject-positive-tests/:id') const factory = { getCveIdRepository: () => { return new MyCveIdPositiveTests() }, getCveRepository: () => { return new MyCvePositiveTests() }, - getOrgRepository: () => { return new MyOrg() }, - getUserRepository: () => { return new MyUser() } + getBaseOrgRepository: () => { return new MyOrg() }, + getBaseUserRepository: () => { return new MyUser() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/cve/cveUpdateTest.js b/test/unit-tests/cve/cveUpdateTest.js index 06f75adc0..b7c026c55 100644 --- a/test/unit-tests/cve/cveUpdateTest.js +++ b/test/unit-tests/cve/cveUpdateTest.js @@ -62,8 +62,8 @@ describe('Testing the PUT /cve/:id endpoint in Cve Controller', () => { const factory = { getCveIdRepository: () => { return new CveIdRepo() }, getCveRepository: () => { return new CveRepo() }, - getOrgRepository: () => { return new OrgRepo() }, - getUserRepository: () => { return new UserRepo() } + getBaseOrgRepository: () => { return new OrgRepo() }, + getBaseUserRepository: () => { return new UserRepo() } } req.ctx.repositories = factory next() @@ -126,8 +126,8 @@ describe('Testing the PUT /cve/:id endpoint in Cve Controller', () => { const factory = { getCveIdRepository: () => { return new CveIdRepo() }, getCveRepository: () => { return new CveRepo() }, - getOrgRepository: () => { return new OrgRepo() }, - getUserRepository: () => { return new UserRepo() } + getBaseOrgRepository: () => { return new OrgRepo() }, + getBaseUserRepository: () => { return new UserRepo() } } req.ctx.repositories = factory next() @@ -191,8 +191,8 @@ describe('Testing the PUT /cve/:id endpoint in Cve Controller', () => { const factory = { getCveIdRepository: () => { return new CveIdRepo() }, getCveRepository: () => { return new CveRepo() }, - getOrgRepository: () => { return new OrgRepo() }, - getUserRepository: () => { return new UserRepo() } + getBaseOrgRepository: () => { return new OrgRepo() }, + getBaseUserRepository: () => { return new UserRepo() } } req.ctx.repositories = factory next() @@ -242,8 +242,8 @@ describe('Testing the PUT /cve/:id endpoint in Cve Controller', () => { const factory = { getCveIdRepository: () => { return new CveIdRepo() }, getCveRepository: () => { return new CveRepo() }, - getOrgRepository: () => { return new OrgRepo() }, - getUserRepository: () => { return new UserRepo() } + getBaseOrgRepository: () => { return new OrgRepo() }, + getBaseUserRepository: () => { return new UserRepo() } } req.ctx.repositories = factory next() @@ -308,8 +308,8 @@ describe('Testing the PUT /cve/:id endpoint in Cve Controller', () => { const factory = { getCveIdRepository: () => { return new CveIdRepo() }, getCveRepository: () => { return new CveRepo() }, - getOrgRepository: () => { return new OrgRepo() }, - getUserRepository: () => { return new UserRepo() } + getBaseOrgRepository: () => { return new OrgRepo() }, + getBaseUserRepository: () => { return new UserRepo() } } req.ctx.repositories = factory next() @@ -367,8 +367,8 @@ describe('Testing the PUT /cve/:id endpoint in Cve Controller', () => { const factory = { getCveIdRepository: () => { return new CveIdRepo() }, getCveRepository: () => { return new CveRepo() }, - getOrgRepository: () => { return new OrgRepo() }, - getUserRepository: () => { return new UserRepo() } + getBaseOrgRepository: () => { return new OrgRepo() }, + getBaseUserRepository: () => { return new UserRepo() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/cve/insertAdpTest.js b/test/unit-tests/cve/insertAdpTest.js index fd654a247..38ba6a912 100644 --- a/test/unit-tests/cve/insertAdpTest.js +++ b/test/unit-tests/cve/insertAdpTest.js @@ -11,10 +11,10 @@ const errors = require('../../../src/controller/cve.controller/error.js') const error = new errors.CveControllerError() const constants = require('../../../src/constants').getConstants() -const OrgRepository = require('../../../src/repositories/orgRepository.js') +const OrgRepository = require('../../../src/repositories/baseOrgRepository.js') const CveIdRepository = require('../../../src/repositories/cveIdRepository.js') const CveRepository = require('../../../src/repositories/cveRepository.js') -const UserRepository = require('../../../src/repositories/userRepository.js') +const UserRepository = require('../../../src/repositories/baseUserRepository.js') const adpUUID = faker.datatype.uuid() @@ -48,9 +48,9 @@ const stubCveId = { } describe('Testing insertAdp function', () => { - let status, json, res, next, getOrgRepository, + let status, json, res, next, getBaseOrgRepository, orgRepo, getCveRepository, cveRepo, getCveIdRepository, - cveIdRepo, getUserRepository, userRepo, adpContainerCopy, + cveIdRepo, getBaseUserRepository, userRepo, adpContainerCopy, cveCopy, req // Stub out functions called in insertAdp and reset them for each test @@ -61,12 +61,12 @@ describe('Testing insertAdp function', () => { next = sinon.spy() status.returns(res) orgRepo = new OrgRepository() - getOrgRepository = sinon.stub() - getOrgRepository.returns(orgRepo) + getBaseOrgRepository = sinon.stub() + getBaseOrgRepository.returns(orgRepo) userRepo = new UserRepository() - getUserRepository = sinon.stub() - getUserRepository.returns(userRepo) + getBaseUserRepository = sinon.stub() + getBaseUserRepository.returns(userRepo) cveRepo = new CveRepository() getCveRepository = sinon.stub() @@ -94,8 +94,8 @@ describe('Testing insertAdp function', () => { id: cveIdPublished5 }, repositories: { - getOrgRepository, - getUserRepository, + getBaseOrgRepository, + getBaseUserRepository, getCveRepository, getCveIdRepository }, diff --git a/test/unit-tests/cve/updateCnaTest.js b/test/unit-tests/cve/updateCnaTest.js index b72cb009e..b036731ce 100644 --- a/test/unit-tests/cve/updateCnaTest.js +++ b/test/unit-tests/cve/updateCnaTest.js @@ -55,8 +55,8 @@ describe('updateCna function', () => { let userRepo let getCveRepository let getCveIdRepository - let getUserRepository - let getOrgRepository + let getBaseUserRepository + let getBaseOrgRepository let cveCopy let cnaContainerCopy @@ -70,16 +70,16 @@ describe('updateCna function', () => { cnaContainerCopy = _.cloneDeep(cnaContainer) sinon.stub(Cve, 'validateCveRecord').returns({ isValid: true }) - orgRepo = { getOrgUUID: sinon.stub(), isSecretariat: sinon.stub() } + orgRepo = { getOrgUUID: sinon.stub(), isSecretariatByShortName: sinon.stub() } orgRepo.getOrgUUID.returns(stubCnaOrg.UUID) - orgRepo.isSecretariat.returns(false) - getOrgRepository = sinon.stub() - getOrgRepository.returns(orgRepo) + orgRepo.isSecretariatByShortName.returns(false) + getBaseOrgRepository = sinon.stub() + getBaseOrgRepository.returns(orgRepo) userRepo = { getUserUUID: sinon.stub() } userRepo.getUserUUID.returns(stubCnaUser.UUID) - getUserRepository = sinon.stub() - getUserRepository.returns(userRepo) + getBaseUserRepository = sinon.stub() + getBaseUserRepository.returns(userRepo) cveRepo = { findOneByCveId: sinon.stub(), updateByCveId: sinon.stub() } cveRepo.findOneByCveId.returns({ cve: cveCopy }) @@ -100,8 +100,8 @@ describe('updateCna function', () => { id: cveIdPublished5 }, repositories: { - getOrgRepository, - getUserRepository, + getBaseOrgRepository, + getBaseUserRepository, getCveRepository, getCveIdRepository }, diff --git a/test/unit-tests/middleware/cnaMustOwnIdTestMiddlewareTest.js b/test/unit-tests/middleware/cnaMustOwnIdTestMiddlewareTest.js index 73eeb6e08..3055e2073 100644 --- a/test/unit-tests/middleware/cnaMustOwnIdTestMiddlewareTest.js +++ b/test/unit-tests/middleware/cnaMustOwnIdTestMiddlewareTest.js @@ -23,7 +23,7 @@ describe('Test cna must own Id middleware', () => { return mwCnaFixtures.owningOrg } - async isSecretariat () { + async isSecretariatByShortName () { return false } } @@ -36,7 +36,7 @@ describe('Test cna must own Id middleware', () => { app.route('/requester-owns-cveid-and-is-a-cna') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new RequesterOrg() }, + getBaseOrgRepository: () => { return new RequesterOrg() }, getCveIdRepository: () => { return new RequesterCveId() } } req.ctx.repositories = factory @@ -70,7 +70,7 @@ describe('Test cna must own Id middleware', () => { return mwCnaFixtures.owningOrg } - async isSecretariat () { + async isSecretariatByShortName () { return false } } @@ -83,7 +83,7 @@ describe('Test cna must own Id middleware', () => { app.route('/requester-does-not-own-cve-id') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new RequesterOrg() }, + getBaseOrgRepository: () => { return new RequesterOrg() }, getCveIdRepository: () => { return new RequesterCveId() } } req.ctx.repositories = factory @@ -116,7 +116,7 @@ describe('Test cna must own Id middleware', () => { return mwCnaFixtures.owningOrg } - async isSecretariat () { + async isSecretariatByShortName () { return false } } @@ -129,7 +129,7 @@ describe('Test cna must own Id middleware', () => { app.route('/requester-did-not-provide-a-cve-id') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new RequesterOrg() }, + getBaseOrgRepository: () => { return new RequesterOrg() }, getCveIdRepository: () => { return new RequesterCveId() } } req.ctx.repositories = factory diff --git a/test/unit-tests/middleware/onlyAdpsTest.js b/test/unit-tests/middleware/onlyAdpsTest.js index 8b2cd30d4..59a82caa1 100644 --- a/test/unit-tests/middleware/onlyAdpsTest.js +++ b/test/unit-tests/middleware/onlyAdpsTest.js @@ -5,7 +5,7 @@ const sinon = require('sinon') const { faker } = require('@faker-js/faker') const expect = chai.expect -const OrgRepository = require('../../../src/repositories/orgRepository.js') +const OrgRepository = require('../../../src/repositories/baseOrgRepository.js') const { onlyAdps } = require('../../../src/middleware/middleware.js') const errors = require('../../../src/middleware/error.js') const error = new errors.MiddlewareError() @@ -14,37 +14,25 @@ const stubAdpOrg = { short_name: 'adpOrg', name: 'test_adp', UUID: faker.datatype.uuid(), - authority: { - active_roles: [ - 'ADP' - ] - } + authority: ['ADP'] } const stubCnaOrg = { short_name: 'cnaOrg', name: 'test_cna', UUID: faker.datatype.uuid(), - authority: { - active_roles: [ - 'CNA' - ] - } + authority: ['CNA'] } const stubSecretariat = { short_name: 'secOrg', name: 'test_sec', UUID: faker.datatype.uuid(), - authority: { - active_roles: [ - 'SECRETARIAT' - ] - } + authority: ['SECRETARIAT'] } describe('Testing onlyAdps middleware', () => { - let status, json, res, next, getOrgRepository, orgRepo + let status, json, res, next, getBaseOrgRepository, orgRepo beforeEach(() => { status = sinon.stub() json = sinon.spy() @@ -52,8 +40,8 @@ describe('Testing onlyAdps middleware', () => { next = sinon.spy() status.returns(res) orgRepo = new OrgRepository() - getOrgRepository = sinon.stub() - getOrgRepository.returns(orgRepo) + getBaseOrgRepository = sinon.stub() + getBaseOrgRepository.returns(orgRepo) }) context('Negative Tests', () => { it('Should return 403 for users from orgs without the ADP role ', async () => { @@ -62,7 +50,7 @@ describe('Testing onlyAdps middleware', () => { org: stubCnaOrg.short_name, uuid: stubCnaOrg.UUID, repositories: { - getOrgRepository + getBaseOrgRepository } } } @@ -81,7 +69,7 @@ describe('Testing onlyAdps middleware', () => { org: stubCnaOrg.short_name, uuid: stubCnaOrg.UUID, repositories: { - getOrgRepository + getBaseOrgRepository } } } @@ -102,7 +90,7 @@ describe('Testing onlyAdps middleware', () => { org: stubAdpOrg.short_name, uuid: stubAdpOrg.UUID, repositories: { - getOrgRepository + getBaseOrgRepository } } } @@ -119,7 +107,7 @@ describe('Testing onlyAdps middleware', () => { org: stubSecretariat.short_name, uuid: stubSecretariat.UUID, repositories: { - getOrgRepository + getBaseOrgRepository } } } diff --git a/test/unit-tests/middleware/onlyCnas.fixtures.js b/test/unit-tests/middleware/onlyCnas.fixtures.js index 0ca3e04b5..285e9a937 100644 --- a/test/unit-tests/middleware/onlyCnas.fixtures.js +++ b/test/unit-tests/middleware/onlyCnas.fixtures.js @@ -10,9 +10,7 @@ const secretariatHeaders = { const secretariatOrg = { UUID: '11kd129f-af00-4d8c-8f7b-e19b0587223f', - authority: { - active_roles: [CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT] - }, + authority: [CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT], name: 'The Sec', policies: { id_quota: 5 @@ -44,9 +42,7 @@ const secretariatAndCnaHeaders = { const secretariatAndCnaOrg = { UUID: '15fd129f-af00-4d8c-8f7b-e19b0587223f', - authority: { - active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA, CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT] - }, + authority: [CONSTANTS.AUTH_ROLE_ENUM.CNA, CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT], name: 'The Sec and CNA', policies: { id_quota: 5 @@ -78,9 +74,7 @@ const notCnaHeaders = { const notCnaOrg = { UUID: '25bd129f-af00-4d8c-8f7b-e19b0587223f', - authority: { - active_roles: [''] - }, + authority: [''], name: 'Not a CNA', policies: { id_quota: 5 @@ -112,9 +106,7 @@ const cnaHeaders = { const cnaOrg = { UUID: '87yd129f-af00-4d8c-8f7b-e19b0587223f', - authority: { - active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA] - }, + authority: [CONSTANTS.AUTH_ROLE_ENUM.CNA], name: 'CNA', policies: { id_quota: 5 diff --git a/test/unit-tests/middleware/onlyCnasMiddlewareTest.js b/test/unit-tests/middleware/onlyCnasMiddlewareTest.js index 8a4542f0e..3c8b77393 100644 --- a/test/unit-tests/middleware/onlyCnasMiddlewareTest.js +++ b/test/unit-tests/middleware/onlyCnasMiddlewareTest.js @@ -26,7 +26,7 @@ describe('Test only CNA middleware', () => { app.route('/only-cnas-org-cna-passes') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new OrgOnlyCnasOrgCnaPass() } + getBaseOrgRepository: () => { return new OrgOnlyCnasOrgCnaPass() } } req.ctx.repositories = factory next() @@ -61,7 +61,7 @@ describe('Test only CNA middleware', () => { app.route('/only-cnas-org-cna-and-secretariat-passes') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new OrgOnlyCnasOrgCnaSecretariatPass() } + getBaseOrgRepository: () => { return new OrgOnlyCnasOrgCnaSecretariatPass() } } req.ctx.repositories = factory next() @@ -98,7 +98,7 @@ describe('Test only CNA middleware', () => { app.route('/only-cnas-org-secretariat-passes') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new OrgOnlyCnasOrgSecretariatPass() } + getBaseOrgRepository: () => { return new OrgOnlyCnasOrgSecretariatPass() } } req.ctx.repositories = factory next() @@ -135,7 +135,7 @@ describe('Test only CNA middleware', () => { app.route('/only-cnas-org-not-cna-rejected') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new OrgOnlyCnasOrgNotCnaReject() } + getBaseOrgRepository: () => { return new OrgOnlyCnasOrgNotCnaReject() } } req.ctx.repositories = factory next() @@ -171,7 +171,7 @@ describe('Test only CNA middleware', () => { app.route('/only-cnas-org-equals-null') .post((req, res, next) => { const factory = { - getOrgRepository: () => { return new OrgOnlyCnasOrgNull() } + getBaseOrgRepository: () => { return new OrgOnlyCnasOrgNull() } } req.ctx.repositories = factory next() diff --git a/test/unit-tests/middleware/onlyOrgWithPartnerRoleTest.js b/test/unit-tests/middleware/onlyOrgWithPartnerRoleTest.js index 34013b54c..e270c9dee 100644 --- a/test/unit-tests/middleware/onlyOrgWithPartnerRoleTest.js +++ b/test/unit-tests/middleware/onlyOrgWithPartnerRoleTest.js @@ -16,53 +16,35 @@ const stubAdpOrg = { short_name: 'adpOrg', name: 'test_adp', UUID: faker.datatype.uuid(), - authority: { - active_roles: [ - 'ADP' - ] - } + authority: ['ADP'] } const stubCnaOrg = { short_name: 'cnaOrg', name: 'test_cna', UUID: faker.datatype.uuid(), - authority: { - active_roles: [ - 'CNA' - ] - } + authority: ['CNA'] } const stubBulkDownloadOrg = { short_name: 'bdOrg', name: 'test_bd', UUID: faker.datatype.uuid(), - authority: { - active_roles: [ - 'BULK_DOWNLOAD' - ] - } + authority: ['BULK_DOWNLOAD'] } const stubOrgNoRole = { short_name: 'NoRole', name: 'test_org', UUID: faker.datatype.uuid(), - authority: { - active_roles: [] - } + authority: [] } const stubSecretariat = { short_name: 'secOrg', name: 'test_sec', UUID: faker.datatype.uuid(), - authority: { - active_roles: [ - 'SECRETARIAT' - ] - } + authority: ['SECRETARIAT'] } describe('Testing onlyOrgWithPartnerRole middleware', () => {