text:
const express = require('express')
const app = express()
const chai = require('chai')
const expect = chai.expect
chai.use(require('chai-http'))

// Body Parser Middleware
app.use(express.json()) // Allows us to handle raw JSON data
app.use(express.urlencoded({ extended: false })) // Allows us to handle url encoded data
const middleware = require('../../../src/middleware/middleware')
app.use(middleware.createCtxAndReqUUID)

const orgFixtures = require('./mockObjects.org')
const orgController = require('../../../src/controller/org.controller/org.controller')
const orgParams = require('../../../src/controller/org.controller/org.middleware')

describe('Testing the GET /org endpoint in Org Controller', () => {
  context('Positive Tests', () => {
    it('Page query param not provided: should list non-paginated orgs because orgs fit in one page', async () => {
      const itemsPerPage = 500

      class GetAllOrgs {
        async aggregatePaginate () {
          const res = {
            itemsList: orgFixtures.allOrgs,
            itemCount: orgFixtures.allOrgs.length,
            itemsPerPage: itemsPerPage,
            currentPage: 1,
            pageCount: 1,
            pagingCounter: 1,
            hasPrevPage: false,
            hasNextPage: false,
            prevPage: null,
            nextPage: null
          }
          return res
        }
      }

      app.route('/org-all-cnas-non-paginated')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new GetAllOrgs() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ALL)

      const testSecretariatHeader = Object.assign({}, orgFixtures.secretariatHeader)
      const res = await chai.request(app)
        .get('/org-all-cnas-non-paginated')
        .set(testSecretariatHeader)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('organizations').and.to.be.a('array').and.to.have.lengthOf(orgFixtures.allOrgs.length)
      expect(res.body).to.not.have.property('totalCount')
      expect(res.body).to.not.have.property('itemsPerPage')
      expect(res.body).to.not.have.property('pageCount')
      expect(res.body).to.not.have.property('currentPage')
      expect(res.body).to.not.have.property('prevPage')
      expect(res.body).to.not.have.property('nextPage')
    })

    it('Page query param not provided: should list the users in two pages (page 1/2)', async () => {
      const itemsPerPage = 5

      class GetAllOrgs {
        async aggregatePaginate () {
          const res = {
            itemsList: [orgFixtures.allOrgs[0], orgFixtures.allOrgs[1], orgFixtures.allOrgs[3], orgFixtures.allOrgs[3], orgFixtures.allOrgs[4]],
            itemCount: orgFixtures.allOrgs.length,
            itemsPerPage: itemsPerPage,
            currentPage: 1,
            pageCount: 2,
            pagingCounter: 1,
            hasPrevPage: false,
            hasNextPage: true,
            prevPage: null,
            nextPage: 2
          }
          return res
        }
      }

      app.route('/org-all-cnas-paginated')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new GetAllOrgs() }
          }
          req.ctx.repositories = factory
          // temporary fix for #920: force pagnation
          req.TEST_PAGINATOR_LIMIT = itemsPerPage
          next()
        }, orgParams.parseGetParams, orgController.ORG_ALL)

      const testSecretariatHeader = Object.assign({}, orgFixtures.secretariatHeader)
      const res = await chai.request(app)
        .get('/org-all-cnas-paginated')
        .set(testSecretariatHeader)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('organizations').and.to.be.a('array').and.to.have.lengthOf(5)
      expect(res.body).to.have.property('totalCount').and.to.equal(orgFixtures.allOrgs.length)
      expect(res.body).to.have.property('itemsPerPage').and.to.equal(itemsPerPage)
      expect(res.body).to.have.property('pageCount').and.to.equal(2)
      expect(res.body).to.have.property('currentPage').and.to.equal(1)
      expect(res.body).to.have.property('prevPage').and.to.equal(null)
      expect(res.body).to.have.property('nextPage').and.to.equal(2)
    })

    it('Page query param provided: should list the users in two pages (page 2/2)', async () => {
      const itemsPerPage = 5

      class GetAllOrgs {
        async aggregatePaginate () {
          const res = {
            itemsList: [orgFixtures.allOrgs[5], orgFixtures.allOrgs[6], orgFixtures.allOrgs[7], orgFixtures.allOrgs[8]],
            itemCount: orgFixtures.allOrgs.length,
            itemsPerPage: itemsPerPage,
            currentPage: 2,
            pageCount: 2,
            pagingCounter: 1,
            hasPrevPage: true,
            hasNextPage: false,
            prevPage: 1,
            nextPage: null
          }
          return res
        }
      }

      app.route('/org-all-cnas-paginated-2')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new GetAllOrgs() }
          }
          req.ctx.repositories = factory
          // temporary fix for #920: force pagnation
          req.TEST_PAGINATOR_LIMIT = itemsPerPage
          next()
        }, orgParams.parseGetParams, orgController.ORG_ALL)

      const testSecretariatHeader = Object.assign({}, orgFixtures.secretariatHeader)
      const res = await chai.request(app)
        .get('/org-all-cnas-paginated-2?page=2')
        .set(testSecretariatHeader)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('organizations').and.to.be.a('array').and.to.have.lengthOf(4)
      expect(res.body).to.have.property('totalCount').and.to.equal(orgFixtures.allOrgs.length)
      expect(res.body).to.have.property('itemsPerPage').and.to.equal(itemsPerPage)
      expect(res.body).to.have.property('pageCount').and.to.equal(2)
      expect(res.body).to.have.property('currentPage').and.to.equal(2)
      expect(res.body).to.have.property('prevPage').and.to.equal(1)
      expect(res.body).to.have.property('nextPage').and.to.equal(null)
    })

    it('Page query param provided: should return an empty list because no org exists', async () => {
      const itemsPerPage = 5

      class GetAllOrgs {
        async aggregatePaginate () {
          const res = {
            itemsList: [],
            itemCount: 0,
            itemsPerPage: itemsPerPage,
            currentPage: 1,
            pageCount: 1,
            pagingCounter: 1,
            hasPrevPage: false,
            hasNextPage: false,
            prevPage: null,
            nextPage: null
          }
          return res
        }
      }

      app.route('/org-all-cnas-empty')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new GetAllOrgs() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ALL)

      const res = await chai.request(app)
        .get('/org-all-cnas-empty?page=1')
        .set(orgFixtures.secretariatHeader)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('organizations').and.to.be.a('array').and.to.have.lengthOf(0)
      expect(res.body).to.not.have.property('totalCount')
      expect(res.body).to.not.have.property('itemsPerPage')
      expect(res.body).to.not.have.property('pageCount')
      expect(res.body).to.not.have.property('currentPage')
      expect(res.body).to.not.have.property('prevPage')
      expect(res.body).to.not.have.property('nextPage')
    })
  })
})


text:
const getConstants = require('../../../src/constants').getConstants
const CONSTANTS = getConstants()

const secretariatHeader = {
  'content-type': 'application/json',
  'CVE-API-ORG': 'mitre',
  'CVE-API-USER': 'cpadro',
  'CVE-API-KEY': 'S96E4QT-SMT4YE3-KX03X6K-4615CED'
}

const owningOrgHeader = {
  'content-type': 'application/json',
  'CVE-API-ORG': 'cisco',
  'CVE-API-USER': 'alopez',
  'CVE-API-KEY': 'SVXPHM9-1VXM0A8-QMG8WN0-29MASSE'
}

const orgHeader = {
  'content-type': 'application/json',
  'CVE-API-ORG': 'apple',
  'CVE-API-USER': 'rgonz',
  'CVE-API-KEY': 'NKWE9PE-42B472A-M5A9W3G-80C31B7'
}

const userAHeader = {
  'content-type': 'application/json',
  'CVE-API-ORG': 'google',
  'CVE-API-USER': 'abaker',
  'CVE-API-KEY': 'TCF25YM-39C4H6D-KA32EGF-V5XSHN3'
}

// admin user header
const userDHeader = {
  'content-type': 'application/json',
  'CVE-API-ORG': 'google',
  'CVE-API-USER': 'gsmith',
  'CVE-API-KEY': 'TCF25YM-39C4H6D-KA32EGF-V5XSHN3'
}

const existentOrg = {
  UUID: '15fd129f-af00-4d8c-8f7b-e19b0587223f',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA, CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT]
  },
  name: 'The MITRE Corporation',
  policies: {
    id_quota: 1000
  },
  short_name: 'mitre'
}

const owningOrg = {
  UUID: '88c02595-c8f7-4864-a0e7-e09b3e1da691',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA]
  },
  name: 'Cisco',
  policies: {
    id_quota: 5
  },
  short_name: 'cisco'
}

const existentOrgDummy = {
  UUID: 'ec7fc4ef-a63e-4ac9-b0f4-ac3e57725b4e',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA, CONSTANTS.AUTH_ROLE_ENUM.ADP]
  },
  name: 'Google',
  policies: {
    id_quota: 10
  },
  short_name: 'google'
}

const existentOrgDummy2 = {
  UUID: 'eckuc4ef-a63e-89c9-b0f4-ac3erhf5v5be',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA, CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT]
  },
  name: 'Oracle',
  policies: {
    id_quota: 15
  },
  short_name: 'oracle'
}

const nonExistentOrg = {
  UUID: '794715e2-ded9-4a16-8dfd-9a062a63e1d5',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA]
  },
  name: 'The Oval Office',
  policies: {
    id_quota: 1000
  },
  short_name: 'oval'
}

const toBeDeactivatedOrg = {
  UUID: '345715e2-ded9-4a16-8dfd-9a062a63e1d5',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA]
  },
  name: 'OffOn',
  policies: {
    id_quota: 50
  },
  short_name: 'offon'
}

const toBeActivatedOrg = {
  UUID: '543715e2-ded9-4a16-8dfd-9a062a63e1d5',
  authority: {
    active_roles: []
  },
  name: 'OnOff',
  policies: {
    id_quota: 75
  },
  short_name: 'OnOff'
}

// For validating policies.id_quota below minimum
const orgWithNegativeIdQuota = {
  UUID: '0zoiz5ht-meym-9pj7-95de-ub4ge22rfazn',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA]
  },
  name: 'Stark Industries',
  policies: {
    id_quota: -1
  },
  short_name: 'stark'
}

// For validating policies.id_quota above maximum
const orgExceedingMaxIdQuota = {
  UUID: '0zoir4ht-meym-90j7-95de-ub4ge77rfaz8n',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA]
  },
  name: 'E.E.A.',
  policies: {
    id_quota: 100500
  },
  short_name: 'eea'
}

const orgWithZeroIdQuota = {
  UUID: 'eq3ecuob-yqbf-eheo-piaq-j9zfna86agw4',
  authority: {
    active_roles: [CONSTANTS.AUTH_ROLE_ENUM.CNA]
  },
  name: 'Wayne Enterprises',
  policies: {
    id_quota: 0
  },
  short_name: 'wayne'
}

const existentUser = {
  UUID: 'e13186d5-ce3d-4fd9-aecd-8698c26897f2',
  org_UUID: existentOrg.UUID,
  name: {
    first: 'Cristina',
    last: 'Padro'
  },
  authority: {
    active_roles: []
  },
  secret: '$argon2i$v=19$m=4096,t=3,p=1$+qGHEfH5h4/tk404iWBxFw$xV96/b4NvQVvlZIq57wTS8s7gfKzsfMXRiOyf3ffgcw',
  username: 'cpadro',
  active: true
}

const existentUserDummy = {
  UUID: 'e13556d5-ce3d-4fd9-aecd-8698c26898g5',
  org_UUID: owningOrg.UUID,
  name: {
    first: 'Luis',
    last: 'Ramirez'
  },
  authority: {
    active_roles: []
  },
  secret: '$argon2i$v=19$m=4096,t=3,p=1$yHw6o9QK1Fe3Zn/bzCMejw$A44O4TueJT12iKu1NlhZpIoTYPIOV5KERoJiwAWUPYk',
  username: 'lramirez',
  active: true
}

const existentUserDummy2 = {
  UUID: 'e13gfvh6d5-783d-4fd9-a90d-869yjvjgk8g5',
  org_UUID: existentOrgDummy2.UUID,
  name: {
    first: 'Jose',
    last: 'Alamo',
    middle: 'Natalicio',
    suffix: 'Jr.'
  },
  authority: {
    active_roles: []
  },
  secret: '$argon2i$v=19$m=4096,t=3,p=1$QAwCe7bO5FYsroeiAM+FWw$f3nJRqhYxScf+2eBfBOu18OkIlexFsgOVJW/++8n9l0',
  username: 'natalm',
  active: false
}

const nonExistentUser = {
  UUID: '7d277951-53cb-45c5-82a0-9f1f9c8d29c7',
  org_UUID: existentOrg.UUID,
  name: {
    first: 'David',
    last: 'Smith',
    suffix: 'Sr.'
  },
  authority: {
    active_roles: []
  },
  secret: '$argon2i$v=19$m=4096,t=3,p=1$HQuqVd6W5rxX0VvXtI178Q$kPKWWjIq1czpJFfYZBvpq04SupCfAR/dReDQvgVS+P0',
  username: 'dsmith',
  active: false
}

const userA = {
  username: 'abaker',
  active: true,
  name: {
    first: 'Ashley',
    last: 'Baker',
    middle: 'N',
    suffix: 'I'
  },
  authority: {
    active_roles: []
  },
  org_UUID: existentOrgDummy.UUID,
  UUID: '33394284-4acf-424f-b199-9e57656ee451',
  secret: '$argon2i$v=19$m=4096,t=3,p=1$meXeqZas6Ba2eQrIb3xbiA$x8KRFqYVuvlvsyMiUA2/hSaFbd2mxaKhEM5rXUfx9sw'
}

const userB = { // same username as userA but different org_UUID
  username: 'abaker',
  active: true,
  name: {
    first: 'Ashley',
    last: 'Baker',
    middle: 'N',
    suffix: 'I'
  },
  authority: {
    active_roles: []
  },
  org_UUID: owningOrg.UUID,
  UUID: '33394284-4acf-424f-b199-9e57656ff451',
  secret: '$argon2i$v=19$m=4096,t=3,p=1$meXeqZas6Ba2eQrIb3xbiA$x8KRFqYVuvlvsyMiUA2/hSaFbd2mxaKhEM5rXUfx9sw'
}

const userC = { // same org_UUID as userA but different username
  username: 'wbalck',
  active: true,
  name: {
    first: 'William',
    last: 'Black'
  },
  authority: {
    active_roles: []
  },
  org_UUID: existentOrgDummy.UUID,
  UUID: '33394284-4acf-423b-b199-9e57656ee451',
  secret: '$argon2i$v=19$m=4096,t=3,p=1$meXeqZas6Ba2eQrIb3xbiA$x8KRFqYVuvlvsyMiUA2/hSaFbd2mxaKhEM5rXUfx9sw'
}

const userD = { // same org_UUID as userA but org admin
  username: 'gsmith',
  active: true,
  name: {
    first: 'Gregory',
    last: 'Smith'
  },
  authority: {
    active_roles: [CONSTANTS.USER_ROLE_ENUM.ADMIN]
  },
  org_UUID: existentOrgDummy.UUID,
  UUID: '33394284-4acf-423b-b199-9e57656ee451',
  secret: '$argon2i$v=19$m=4096,t=3,p=1$meXeqZas6Ba2eQrIb3xbiA$x8KRFqYVuvlvsyMiUA2/hSaFbd2mxaKhEM5rXUfx9sw'
}

const allOrgs = [existentOrg, owningOrg, existentOrgDummy, existentOrgDummy2, toBeDeactivatedOrg, toBeActivatedOrg, orgWithNegativeIdQuota, orgExceedingMaxIdQuota, orgWithZeroIdQuota]

const allOwningOrgUsers = [
  existentUserDummy,
  {
    org_UUID: owningOrg.UUID,
    username: 'travispost',
    UUID: '48e89261-5797-4614-81ae-4bf0595b0689',
    active: true,
    name: {
      first: 'Travis',
      last: 'Post',
      middle: 'A.'
    },
    authority: {
      active_roles: []
    },
    secret: '$argon2i$v=19$m=4096,t=3,p=1$+oG246Lm4fOnSTFJZdAfPA$PQIHmY1LgzJn0IYSTlaNqGr00K9f2F0uZQgboQnqRjw'
  },
  {
    org_UUID: owningOrg.UUID,
    username: 'duaspade',
    UUID: 'cd35c708-c6c9-4c52-89e3-c053c2b8cbf5',
    active: true,
    name: {
      first: 'Dua',
      last: 'Spade'
    },
    authority: {
      active_roles: []
    },
    secret: '$argon2i$v=19$m=4096,t=3,p=1$VHsBUuc2pGTYL9seHOJ8Vw$hQXRlzUIJklxYhRoMmwSNScyulMdR4IGmxxyALe6jsw'
  },
  {
    org_UUID: owningOrg.UUID,
    username: 'colewhite',
    UUID: '9624d11f-28c5-4717-8039-3752bf9b03e0',
    active: true,
    name: {
      first: 'Cole',
      last: 'White',
      suffix: 'IV'
    },
    authority: {
      active_roles: []
    },
    secret: '$argon2i$v=19$m=4096,t=3,p=1$NDA1tIslsvipxuOI8raZZQ$FJk57PhH2C+h/L4snN5gRqRsPF2VNHO1Wm+pLo+ACqo'
  },
  {
    org_UUID: owningOrg.UUID,
    username: 'adamlux',
    UUID: '8a6ecd6a-7f7e-48c1-b0d6-8691a388eb66',
    active: true,
    name: {
      first: 'Adam',
      last: 'Lux'
    },
    authority: {
      active_roles: []
    },
    secret: '$argon2i$v=19$m=4096,t=3,p=1$QY6juc/rjf1XOUpIjRJ1/w$KyDUmzLRHymH0HXO70/pgUrkkLTJ4EUs508b517ama4'
  }
]

module.exports = {
  userA,
  userB,
  userC,
  userD,
  allOrgs,
  allOwningOrgUsers,
  secretariatHeader,
  owningOrgHeader,
  userAHeader,
  userDHeader,
  orgHeader,
  owningOrg,
  existentOrg,
  existentOrgDummy,
  existentUserDummy2,
  nonExistentOrg,
  existentUser,
  existentUserDummy,
  existentOrgDummy2,
  nonExistentUser,
  orgWithNegativeIdQuota,
  orgExceedingMaxIdQuota,
  orgWithZeroIdQuota,
  toBeDeactivatedOrg,
  toBeActivatedOrg
}

repo_name: CVEProject/cve-services

repo_language: JavaScript

file_name: Dockerfile

mime_type: text/plain


text:
const express = require('express')
const app = express()
const chai = require('chai')
const expect = chai.expect
chai.use(require('chai-http'))

// Body Parser Middleware
app.use(express.json()) // Allows us to handle raw JSON data
app.use(express.urlencoded({ extended: false })) // Allows us to handle url encoded data
const middleware = require('../../../src/middleware/middleware')
app.use(middleware.createCtxAndReqUUID)

const errors = require('../../../src/controller/org.controller/error')
const error = new errors.OrgControllerError()

const orgFixtures = require('./mockObjects.org')
const orgController = require('../../../src/controller/org.controller/org.controller')
const orgParams = require('../../../src/controller/org.controller/org.middleware')

class OrgGet {
  async aggregate (aggregation) {
    if (aggregation[0].$match.short_name === orgFixtures.existentOrg.short_name) {
      return [orgFixtures.existentOrg]
    } else if (aggregation[0].$match.short_name === orgFixtures.owningOrg.short_name) {
      return [orgFixtures.owningOrg]
    } else if (aggregation[0].$match.UUID === orgFixtures.owningOrg.UUID) {
      return [orgFixtures.owningOrg]
    }

    return []
  }

  async isSecretariat (shortname) {
    if (shortname === orgFixtures.secretariatHeader['CVE-API-ORG']) {
      return true
    } else {
      return false
    }
  }

  async findOneByShortName (shortname) {
    return orgFixtures.owningOrg
  }
}

describe('Testing the GET /org/:identifier endpoint in Org Controller', () => {
  context('Negative Tests', () => {
    it('Org does not exists', async () => {
      app.route('/org-cant-get-doesnt-exist/:identifier')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgGet() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_SINGLE)

      const res = await chai.request(app)
        .get(`/org-cant-get-doesnt-exist/${orgFixtures.nonExistentOrg.short_name}`)
        .set(orgFixtures.secretariatHeader)

      expect(res).to.have.status(404)
      expect(res).to.have.property('body').and.to.be.a('object')
      const errObj = error.orgDne(orgFixtures.nonExistentOrg.short_name, 'identifier', 'path')
      expect(res.body.error).to.equal(errObj.error)
      expect(res.body.message).to.equal(errObj.message)
    })

    it('Org exists and requester is not a user of the same org or is secretariat', (done) => {
      app.route('/org-cant-get-user-not-secretariat-or-same-org/:identifier')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgGet() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_SINGLE)

      chai.request(app)
        .get(`/org-cant-get-user-not-secretariat-or-same-org/${orgFixtures.owningOrg.short_name}`)
        .set(orgFixtures.orgHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

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

    it('Invalid UUID requesting an org', (done) => {
      app.route('/org-get-org-by-invalid-uuid/:identifier')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgGet() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_SINGLE)

      chai.request(app)
        .get(`/org-get-org-by-uuid/${'nonexistent123'}`)
        .set(orgFixtures.owningOrgHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }
          expect(res).to.have.status(404)
          expect(res).to.have.property('body').and.to.be.a('object')
          done()
        })
    })
  })

  context('Positive Tests', () => {
    it('Org exists and requester is secretariat', (done) => {
      app.route('/org-get-does-exist/:identifier')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgGet() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_SINGLE)

      chai.request(app)
        .get(`/org-get-does-exist/${orgFixtures.existentOrg.short_name}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('short_name').and.to.equal(orgFixtures.existentOrg.short_name)
          done()
        })
    })

    it('Org exists and requester is a user of the same org', (done) => {
      app.route('/org-get-does-exist-user-same-org/:identifier')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgGet() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_SINGLE)

      chai.request(app)
        .get(`/org-get-does-exist-user-same-org/${orgFixtures.owningOrg.short_name}`)
        .set(orgFixtures.owningOrgHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('short_name').and.to.equal(orgFixtures.owningOrg.short_name)
          done()
        })
    })

    it('Valid UUID requesting an org', (done) => {
      app.route('/org-get-org-by-uuid/:identifier')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgGet() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_SINGLE)

      chai.request(app)
        .get(`/org-get-org-by-uuid/${orgFixtures.owningOrg.UUID}`)
        .set(orgFixtures.owningOrgHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('UUID').and.to.equal(orgFixtures.owningOrg.UUID)
          done()
        })
    })
  })
})


text:
const express = require('express')
const app = express()
const chai = require('chai')
const expect = chai.expect
chai.use(require('chai-http'))

// Body Parser Middleware
app.use(express.json()) // Allows us to handle raw JSON data
app.use(express.urlencoded({ extended: false })) // Allows us to handle url encoded data
const middleware = require('../../../src/middleware/middleware')
app.use(middleware.createCtxAndReqUUID)

const Org = require('../../../src/model/org')
const getConstants = require('../../../src/constants').getConstants
const errors = require('../../../src/controller/org.controller/error')
const error = new errors.OrgControllerError()

const orgFixtures = require('./mockObjects.org')
const orgController = require('../../../src/controller/org.controller/org.controller')
const orgParams = require('../../../src/controller/org.controller/org.middleware')

describe('Testing the GET /org/:shortname/id_quota endpoint in Org Controller', () => {
  context('Negative Tests', () => {
    it('Org with a negative id_quota was not saved', (done) => {
      const org = new Org(orgFixtures.orgWithNegativeIdQuota)

      org.validate((err) => {
        const CONSTANTS = getConstants()

        expect(err.errors['policies.id_quota'].message).to.equal(CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_min_message)
        done()
      })
    })

    it('Org with an id_quota greater than the max was not saved', (done) => {
      const org = new Org(orgFixtures.orgExceedingMaxIdQuota)

      org.validate((err) => {
        const CONSTANTS = getConstants()

        expect(err.errors['policies.id_quota'].message).to.equal(CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_max_message)
        done()
      })
    })

    it('Requestor is not secretariat or a user of the same org', (done) => {
      class OrgNotOwnerOrSecretariatIdQuota {
        async isSecretariat () {
          return false
        }
      }

      app.route('/org-id_quota-not-owning-secretariat-org/:shortname')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgNotOwnerOrSecretariatIdQuota() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ID_QUOTA)

      chai.request(app)
        .get(`/org-id_quota-not-owning-secretariat-org/${orgFixtures.owningOrg.short_name}`)
        .set(orgFixtures.orgHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

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

    it('Org does not exist', (done) => {
      class OrgDoesNotExistIdQuota {
        async isSecretariat () {
          return true
        }

        async findOneByShortName () {
          return null
        }
      }

      app.route('/org-id_quota-org-does-not-exist/:shortname')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgDoesNotExistIdQuota() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ID_QUOTA)

      chai.request(app)
        .get(`/org-id_quota-org-does-not-exist/${orgFixtures.nonExistentOrg.short_name}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(404)
          expect(res).to.have.property('body').and.to.be.a('object')
          const errObj = error.orgDnePathParam(orgFixtures.nonExistentOrg.short_name)
          expect(res.body.error).to.equal(errObj.error)
          expect(res.body.message).to.equal(errObj.message)
          done()
        })
    })
  })

  context('Positive Tests', () => {
    it('Requestor is secretariat', (done) => {
      class OrgSecretariatIdQuota {
        async isSecretariat () {
          return true
        }

        async findOneByShortName () {
          return orgFixtures.existentOrg
        }

        async getOrgUUID () {
          return orgFixtures.existentOrg.UUID
        }
      }

      class CveIdSecretariatIdQuota {
        async countDocuments () {
          return 0
        }
      }

      app.route('/org-id_quota-secretariat/:shortname')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgSecretariatIdQuota() },
            getCveIdRepository: () => { return new CveIdSecretariatIdQuota() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ID_QUOTA)

      chai.request(app)
        .get(`/org-id_quota-secretariat/${orgFixtures.existentOrg.short_name}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body.id_quota).to.equal(1000)
          expect(res.body.total_reserved).to.equal(0)
          expect(res.body.available).to.equal(1000)
          done()
        })
    })

    it('Requestor is a user of the same org', (done) => {
      class OrgOwnerIdQuota {
        async isSecretariat () {
          return false
        }

        async findOneByShortName () {
          return orgFixtures.owningOrg
        }

        async getOrgUUID () {
          return orgFixtures.owningOrg.UUID
        }
      }

      class CveIdOwnerIdQuota {
        async countDocuments () {
          return 0
        }
      }

      app.route('/org-id_quota-owning-org/:shortname')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgOwnerIdQuota() },
            getCveIdRepository: () => { return new CveIdOwnerIdQuota() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ID_QUOTA)

      chai.request(app)
        .get(`/org-id_quota-owning-org/${orgFixtures.owningOrg.short_name}`)
        .set(orgFixtures.owningOrgHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body.id_quota).to.equal(5)
          expect(res.body.total_reserved).to.equal(0)
          expect(res.body.available).to.equal(5)
          done()
        })
    })

    it('Org id_quota exceeds min quota limit', (done) => {
      class OrgExceedsMinIdQuota {
        async isSecretariat () {
          return true
        }

        async findOneByShortName () {
          return orgFixtures.orgWithNegativeIdQuota
        }

        async getOrgUUID () {
          return orgFixtures.orgWithNegativeIdQuota.UUID
        }
      }

      class CveIdExceedsMinQuota {
        async countDocuments () {
          return 0
        }
      }

      app.route('/org-id_quota-exceeds-min-quota-limit/:shortname')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgExceedsMinIdQuota() },
            getCveIdRepository: () => { return new CveIdExceedsMinQuota() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ID_QUOTA)

      chai.request(app)
        .get(`/org-id_quota-exceeds-min-quota-limit/${orgFixtures.orgWithNegativeIdQuota.short_name}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('id_quota').to.equal(-1)
          expect(res.body).to.have.property('total_reserved').to.equal(0)
          expect(res.body).to.have.property('available').to.equal(-1)
          done()
        })
    })

    it('Org id_quota exceeds max quota limit', (done) => {
      class OrgExceedsMaxIdQuota {
        async isSecretariat () {
          return true
        }

        async findOneByShortName () {
          return orgFixtures.orgExceedingMaxIdQuota
        }

        async getOrgUUID () {
          return orgFixtures.orgExceedingMaxIdQuota.UUID
        }
      }

      class CveIdExceedsMaxQuota {
        async countDocuments () {
          return 0
        }
      }

      app.route('/org-id_quota-exceeds-max-quota-limit/:shortname')
        .get((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgExceedsMaxIdQuota() },
            getCveIdRepository: () => { return new CveIdExceedsMaxQuota() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parseGetParams, orgController.ORG_ID_QUOTA)

      chai.request(app)
        .get(`/org-id_quota-exceeds-max-quota-limit/${orgFixtures.orgExceedingMaxIdQuota.short_name}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('id_quota').to.equal(100500)
          expect(res.body).to.have.property('total_reserved').to.equal(0)
          expect(res.body).to.have.property('available').to.equal(100500)
          done()
        })
    })
  })
})


text:
const express = require('express')
const app = express()
const chai = require('chai')
const expect = chai.expect
chai.use(require('chai-http'))

// Body Parser Middleware
app.use(express.json()) // Allows us to handle raw JSON data
app.use(express.urlencoded({ extended: false })) // Allows us to handle url encoded data
const middleware = require('../../../src/middleware/middleware')
app.use(middleware.createCtxAndReqUUID)

const getConstants = require('../../../src/constants').getConstants
const errors = require('../../../src/controller/org.controller/error')
const error = new errors.OrgControllerError()

const orgFixtures = require('./mockObjects.org')
const orgController = require('../../../src/controller/org.controller/org.controller')
const orgParams = require('../../../src/controller/org.controller/org.middleware')

class NullUserRepo {
  async getUserUUID () {
    return null
  }

  async findOneByUserNameAndOrgUUID () {
    return null
  }

  async isAdmin () {
    return null
  }
}

class OrgUpdatedAddingRole {
  async findOneByShortName () {
    return orgFixtures.owningOrg
  }

  async aggregate () {
    return [orgFixtures.owningOrg]
  }

  async updateByOrgUUID () {
    return { n: 1 }
  }

  async getOrgUUID () {
    return null
  }
}

class OrgUpdatedRemovingRole {
  async findOneByShortName () {
    return orgFixtures.owningOrg
  }

  async aggregate () {
    return [orgFixtures.owningOrg]
  }

  async updateByOrgUUID () {
    return { n: 1 }
  }

  async getOrgUUID () {
    return null
  }
}

describe('Testing the PUT /org/:shortname endpoint in Org Controller', () => {
  context('Negative Tests', () => {
    it('Org is not updated because it does not exists', async () => {
      class OrgNotUpdatedDoesNotExist {
        async findOneByShortName () {
          return null
        }
      }

      app.route('/org-not-updated-doesnt-exists/:shortname')
        .put((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgNotUpdatedDoesNotExist() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)

      const res = await chai.request(app)
        .put(`/org-not-updated-doesnt-exists/${orgFixtures.nonExistentOrg.short_name}`)
        .set(orgFixtures.secretariatHeader)

      expect(res).to.have.status(404)
      expect(res).to.have.property('body').and.to.be.a('object')
      const errObj = error.orgDnePathParam(orgFixtures.nonExistentOrg.short_name)
      expect(res.body.error).to.equal(errObj.error)
      expect(res.body.message).to.equal(errObj.message)
    })

    it('Org is not updated because the new shortname already exists', (done) => {
      class OrgNotUpdatedShortNameExists {
        async findOneByShortName () {
          return orgFixtures.existentOrg
        }
      }

      app.route('/org-not-updated-shortname-exists/:shortname')
        .put((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgNotUpdatedShortNameExists() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)

      chai.request(app)
        .put(`/org-not-updated-shortname-exists/${orgFixtures.existentOrg.short_name}?new_short_name=cisco`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(403)
          expect(res).to.have.property('body').and.to.be.a('object')
          const errObj = error.duplicateShortname('cisco')
          expect(res.body.error).to.equal(errObj.error)
          expect(res.body.message).to.equal(errObj.message)
          done()
        })
    })
  })

  context('Positive Tests', () => {
    it('Org is updated: Adding a role', (done) => {
      const CONSTANTS = getConstants()

      app.route('/org-updated-adding-role-1/:shortname')
        .put((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgUpdatedAddingRole() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)

      chai.request(app)
        .put(`/org-updated-adding-role-1/${orgFixtures.owningOrg.short_name}?active_roles.add=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}&active_roles.add=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('updated').and.to.be.a('object')
          expect(res.body.updated.authority.active_roles).to.have.lengthOf(2)
          expect(res.body.updated.authority.active_roles[0]).to.equal(CONSTANTS.AUTH_ROLE_ENUM.CNA)
          expect(res.body.updated.authority.active_roles[1]).to.equal(CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA)
          expect(res.body.updated.short_name).to.equal(orgFixtures.owningOrg.short_name)
          expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
          expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
          expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
          done()
        })
    })

    it('Org is unchanged: Adding a role that the org already have', (done) => {
      const CONSTANTS = getConstants()

      app.route('/org-updated-adding-role-2/:shortname')
        .put((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgUpdatedAddingRole() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)

      chai.request(app)
        .put(`/org-updated-adding-role-2/${orgFixtures.owningOrg.short_name}?active_roles.add=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}&active_roles.add=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('updated').and.to.be.a('object')
          expect(res.body.updated.authority.active_roles).to.have.lengthOf(2)
          expect(res.body.updated.authority.active_roles[0]).to.equal(CONSTANTS.AUTH_ROLE_ENUM.CNA)
          expect(res.body.updated.authority.active_roles[1]).to.equal(CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA)
          expect(res.body.updated.short_name).to.equal(orgFixtures.owningOrg.short_name)
          expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
          expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
          expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
          done()
        })
    })

    it('Org is updated: Removing a role', (done) => {
      const CONSTANTS = getConstants()

      app.route('/org-updated-removing-role-1/:shortname')
        .put((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgUpdatedRemovingRole() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)

      chai.request(app)
        .put(`/org-updated-removing-role-1/${orgFixtures.owningOrg.short_name}?active_roles.remove=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}&active_roles.remove=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('updated').and.to.be.a('object')
          expect(res.body.updated.authority.active_roles).to.have.lengthOf(1)
          expect(res.body.updated.authority.active_roles[0]).to.equal(CONSTANTS.AUTH_ROLE_ENUM.CNA)
          expect(res.body.updated.short_name).to.equal(orgFixtures.owningOrg.short_name)
          expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
          expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
          expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
          done()
        })
    })

    it('Org is unchanged: Removing a role that the org does not have', (done) => {
      const CONSTANTS = getConstants()

      app.route('/org-updated-removing-role-2/:shortname')
        .put((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgUpdatedRemovingRole() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)

      chai.request(app)
        .put(`/org-updated-removing-role-2/${orgFixtures.owningOrg.short_name}?active_roles.remove=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}&active_roles.remove=${CONSTANTS.AUTH_ROLE_ENUM.ROOT_CNA}`)
        .set(orgFixtures.secretariatHeader)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('updated').and.to.be.a('object')
          expect(res.body.updated.authority.active_roles).to.have.lengthOf(1)
          expect(res.body.updated.authority.active_roles[0]).to.equal(CONSTANTS.AUTH_ROLE_ENUM.CNA)
          expect(res.body.updated.short_name).to.equal(orgFixtures.owningOrg.short_name)
          expect(res.body.updated.name).to.equal(orgFixtures.owningOrg.name)
          expect(res.body.updated.UUID).to.equal(orgFixtures.owningOrg.UUID)
          expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.owningOrg.policies.id_quota)
          done()
        })
    })

    // check that the org is unchanged
    it('No query parameters are provided', async () => {
      class OrgNotUpdatedNoQueryParameters {
        async findOneByShortName () {
          return orgFixtures.existentOrg
        }

        async updateByOrgUUID () {
          return { n: 1 }
        }

        async getOrgUUID () {
          return null
        }

        async aggregate () {
          return [orgFixtures.existentOrg]
        }
      }

      app.route('/org-not-updated-no-query-parameters/:shortname')
        .put((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgNotUpdatedNoQueryParameters() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_UPDATE_SINGLE)

      const res = await chai.request(app)
        .put(`/org-not-updated-no-query-parameters/${orgFixtures.existentOrg.short_name}`)
        .set(orgFixtures.secretariatHeader)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('updated').and.to.be.a('object')
      expect(res.body.updated.authority.active_roles[0]).to.equal(orgFixtures.existentOrg.authority.active_roles[0])
      expect(res.body.updated.authority.active_roles[1]).to.equal(orgFixtures.existentOrg.authority.active_roles[1])
      expect(res.body.updated.authority.active_roles).to.have.lengthOf(2)
      expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.existentOrg.policies.id_quota)
      expect(res.body.updated.policies.id_quota).to.equal(orgFixtures.existentOrg.policies.id_quota)
      expect(res.body.updated.name).to.equal(orgFixtures.existentOrg.name)
      expect(res.body.updated.short_name).to.equal(orgFixtures.existentOrg.short_name)
      expect(res.body.updated.UUID).to.equal(orgFixtures.existentOrg.UUID)
    })
  })
})


text:
const express = require('express')
const app = express()
const chai = require('chai')
const expect = chai.expect
chai.use(require('chai-http'))

// Body Parser Middleware
app.use(express.json()) // Allows us to handle raw JSON data
app.use(express.urlencoded({ extended: false })) // Allows us to handle url encoded data
const middleware = require('../../../src/middleware/middleware')
app.use(middleware.createCtxAndReqUUID)

const getConstants = require('../../../src/constants').getConstants
const errors = require('../../../src/controller/org.controller/error')
const error = new errors.OrgControllerError()

const orgFixtures = require('./mockObjects.org')
const orgController = require('../../../src/controller/org.controller/org.controller')
const orgParams = require('../../../src/controller/org.controller/org.middleware')

class OrgNotCreatedAlreadyExists {
  async findOneByShortName () {
    return orgFixtures.existentOrg
  }
}

class OrgCreated {
  async findOneByShortName () {
    return null
  }

  async updateByOrgUUID () {
    return null
  }

  async getOrgUUID () {
    return null
  }

  async aggregate (aggregation) {
    if (aggregation[0].$match.short_name === orgFixtures.existentOrg.short_name) {
      return [orgFixtures.existentOrg]
    } else if (aggregation[0].$match.short_name === orgFixtures.nonExistentOrg.short_name) {
      return [orgFixtures.nonExistentOrg]
    }

    return []
  }
}

class NullUserRepo {
  async getUserUUID () {
    return null
  }

  async findOneByUserNameAndOrgUUID () {
    return null
  }

  async isAdmin () {
    return null
  }
}

class OrgCreatedWhenRolesDefined {
  async findOneByShortName () {
    return null
  }

  async updateByOrgUUID () {
    return null
  }

  async getOrgUUID () {
    return null
  }

  async aggregate () {
    return [orgFixtures.existentOrg]
  }
}

class OrgCreatedIdQuotaNullUndefined {
  async findOneByShortName () {
    return null
  }

  async updateByOrgUUID () {
    return null
  }

  async getOrgUUID () {
    return null
  }

  async aggregate () {
    const CONSTANTS = getConstants()

    this.testRes1 = JSON.parse(JSON.stringify(orgFixtures.nonExistentOrg))
    this.testRes1.policies.id_quota = CONSTANTS.DEFAULT_ID_QUOTA

    return [this.testRes1]
  }
}

describe('Testing the POST /org endpoint in Org Controller', () => {
  context('Negative Tests', () => {
    it('Org is not created because the UUID is provided', (done) => {
      app.route('/org-created-when-uuid-undefined')
        .post((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgCreated() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_CREATE_SINGLE)

      chai.request(app)
        .post('/org-created-when-uuid-undefined')
        .set(orgFixtures.secretariatHeader)
        .send(orgFixtures.existentOrg)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(400)
          expect(res).to.have.property('body').and.to.be.a('object')
          const errObj = error.uuidProvided('org')
          expect(res.body.error).to.equal(errObj.error)
          expect(res.body.message).to.equal(errObj.message)
          done()
        })

      // check that it really didn't create the org
      // https://github.com/CVEProject/cve-services/issues/887

      chai.request(app)
        .get('/')
    })

    it('Org is not created because it already exists', (done) => {
      app.route('/org-not-created-already-exists')
        .post((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgNotCreatedAlreadyExists() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_CREATE_SINGLE)

      const testOrg = JSON.parse(JSON.stringify(orgFixtures.existentOrg))
      delete testOrg.UUID

      chai.request(app)
        .post('/org-not-created-already-exists')
        .set(orgFixtures.secretariatHeader)
        .send(testOrg)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(400)
          expect(res).to.have.property('body').and.to.be.a('object')
          const errObj = error.orgExists(orgFixtures.existentOrg.short_name)
          expect(res.body.error).to.equal(errObj.error)
          expect(res.body.message).to.equal(errObj.message)
          done()
        })
    })
  })

  context('Positive Tests', () => {
    it('Org is created', async () => {
      app.route('/org-created-when-uuid-not-provided')
        .post((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgCreated() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_CREATE_SINGLE)

      const testOrg = JSON.parse(JSON.stringify(orgFixtures.existentOrg))
      delete testOrg.UUID

      const res = await chai.request(app)
        .post('/org-created-when-uuid-not-provided')
        .set(orgFixtures.secretariatHeader)
        .send(testOrg)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('message').and.to.be.a('string')
      expect(res.body.message).to.equal(orgFixtures.existentOrg.short_name + ' organization was successfully created.')
      expect(res.body).to.have.property('created').and.to.be.a('object')
      expect(res.body.created).to.have.property('short_name').to.equal(orgFixtures.existentOrg.short_name)
    })

    it('Org is Secretariat and is created when roles are defined', async () => {
      app.route('/org-created-when-roles-defined')
        .post((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgCreatedWhenRolesDefined() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_CREATE_SINGLE)

      const CONSTANTS = getConstants()
      const testOrg = JSON.parse(JSON.stringify(orgFixtures.existentOrg))
      delete testOrg.UUID

      const res = await chai.request(app)
        .post('/org-created-when-roles-defined')
        .set(orgFixtures.secretariatHeader)
        .send(testOrg)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('message').and.to.be.a('string')
      expect(res.body.message).to.equal(orgFixtures.existentOrg.short_name + ' organization was successfully created.')
      expect(res.body).to.have.property('created').and.to.be.a('object')
      expect(res.body.created).to.have.property('short_name').to.equal(orgFixtures.existentOrg.short_name)
      expect(res.body.created).to.have.nested.property('policies.id_quota').to.equal(orgFixtures.existentOrg.policies.id_quota)
      expect(res.body.created).to.have.nested.property('authority.active_roles').to.include(CONSTANTS.AUTH_ROLE_ENUM.CNA).and.to.include(CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT)
      expect(res.body.created).to.have.nested.property('authority.active_roles').to.have.lengthOf(2)
    })

    it('Org is not secretariat and is created when roles are undefined and id_quota is defined', (done) => {
      app.route('/org-created-when-roles-undefined-id_quota-defined')
        .post((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgCreated() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_CREATE_SINGLE)

      const CONSTANTS = getConstants()
      const testOrg = JSON.parse(JSON.stringify(orgFixtures.nonExistentOrg))
      delete testOrg.UUID
      delete testOrg.authority.active_roles

      chai.request(app)
        .post('/org-created-when-roles-undefined-id_quota-defined')
        .set(orgFixtures.secretariatHeader)
        .send(testOrg)
        .end((err, res) => {
          if (err) {
            done(err)
          }

          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('message').and.to.be.a('string')
          expect(res.body.message).to.equal(testOrg.short_name + ' organization was successfully created.')
          expect(res.body).to.have.property('created').and.to.be.a('object')
          expect(res.body.created).to.have.property('short_name').to.equal(testOrg.short_name)
          expect(res.body.created).to.have.nested.property('policies.id_quota').to.equal(testOrg.policies.id_quota)
          expect(res.body.created).to.have.nested.property('authority.active_roles').to.include(CONSTANTS.AUTH_ROLE_ENUM.CNA)
          expect(res.body.created).to.have.nested.property('authority.active_roles').to.have.lengthOf(1)
          done()
        })
    })

    it('Org is created when id_quota is undefined', async () => {
      app.route('/org-created-when-id_quota-undefined')
        .post((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgCreatedIdQuotaNullUndefined() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_CREATE_SINGLE)

      const CONSTANTS = getConstants()
      const testOrg = JSON.parse(JSON.stringify(orgFixtures.nonExistentOrg))
      delete testOrg.UUID
      delete testOrg.policies.id_quota

      const res = await chai.request(app)
        .post('/org-created-when-id_quota-undefined')
        .set(orgFixtures.secretariatHeader)
        .send(testOrg)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('message').and.to.be.a('string')
      expect(res.body.message).to.equal(testOrg.short_name + ' organization was successfully created.')
      expect(res.body).to.have.property('created').and.to.be.a('object')
      expect(res.body.created).to.have.property('short_name').to.equal(testOrg.short_name)
      expect(res.body.created).to.have.nested.property('policies.id_quota').to.equal(CONSTANTS.DEFAULT_ID_QUOTA)
      expect(res.body.created).to.have.nested.property('authority.active_roles').to.include(CONSTANTS.AUTH_ROLE_ENUM.CNA)
      expect(res.body.created).to.have.nested.property('authority.active_roles').to.have.lengthOf(1)
    })

    it('Org is created when id_quota is null', async () => {
      app.route('/org-created-when-id_quota-null')
        .post((req, res, next) => {
          const factory = {
            getOrgRepository: () => { return new OrgCreatedIdQuotaNullUndefined() },
            getUserRepository: () => { return new NullUserRepo() }
          }
          req.ctx.repositories = factory
          next()
        }, orgParams.parsePostParams, orgController.ORG_CREATE_SINGLE)

      const CONSTANTS = getConstants()
      const testOrg = JSON.parse(JSON.stringify(orgFixtures.nonExistentOrg))
      delete testOrg.UUID
      testOrg.policies.id_quota = null

      const res = await chai.request(app)
        .post('/org-created-when-id_quota-null')
        .set(orgFixtures.secretariatHeader)
        .send(testOrg)

      expect(res).to.have.status(200)
      expect(res).to.have.property('body').and.to.be.a('object')
      expect(res.body).to.have.property('message').and.to.be.a('string')
      expect(res.body.message).to.equal(testOrg.short_name + ' organization was successfully created.')
      expect(res.body).to.have.property('created').and.to.be.a('object')
      expect(res.body.created).to.have.property('short_name').to.equal(testOrg.short_name)
      expect(res.body.created).to.have.nested.property('policies.id_quota').to.equal(CONSTANTS.DEFAULT_ID_QUOTA)
      expect(res.body.created).to.have.nested.property('authority.active_roles').to.include(CONSTANTS.AUTH_ROLE_ENUM.CNA)
      expect(res.body.created).to.have.nested.property('authority.active_roles').to.have.lengthOf(1)
    })
  })
})


dataType: CVE

dataFormat: MITRE

assignerShortname: cisco

state: DUPLICATE

format: uyi

scenario: kjk

type: oio

kjgk: kjgkhg

hi: i

vendorName: u

productName: yuyi

versionValue: uuy

packageName: kgkug

shortName: cisco

value: y

description: y

type: u

capecId: y

discoverer: Tom Smith

description: y


state: PUBLISHED

description: y

description: y


STATE: PUBLIC

TITLE: D'live AP command injection vulnerability

product_name: D'live set-top box AP(WF2429TB)

platform: Linux

vendor_name: Netis Korea

data_format: MITRE

data_type: CVE

value: Improper Input validation vulnerability exists in Netis Korea D'live AP which could cause arbitrary command injection and execution when the time setting (using ntpServerlp1 parameter) for the users.

engine: Vulnogram 0.0.9

attackComplexity: HIGH

availabilityImpact: HIGH

baseSeverity: MEDIUM

confidentialityImpact: HIGH

integrityImpact: HIGH

privilegesRequired: HIGH

scope: UNCHANGED

value: CWE-20 Improper Input Validation

refsource: CONFIRM

discovery: UNKNOWN

STATE: REJECT

value: ** REJECT ** DO NOT USE THIS CANDIDATE NUMBER.  ConsultIDs: none.  Reason: This candidate was withdrawn by its CNA.  Further investigation showed that it was not a security issue.  Notes: none.

product_name: Moodle

refsource: MISC

value: A vulnerability was found in Moodle affecting 3.7 to 3.7.1, 3.6 to 3.6.5, 3.5 to 3.5.7 and earlier unsupported versions, where users with the capability to create courses were assigned as a teacher in those courses, regardless of whether they had the capability to be automatically assigned that role.


STATE: DISPUTED

value: Cross-site scripting (XSS) vulnerability in Revive Adserver before 4.0.1 allows remote authenticated users to inject arbitrary web script or HTML via the user's email address.

name: [oss-security] 20170202 Re: CVE request: multiples vulnerabilities in Revive Adserver

refsource: MLIST

refsource: BID


product_name: Revive Adserver


text:
const headers = {
  'CVE-API-ORG': 'mitre',
  'content-type': 'application/json',
  'CVE-API-USER': 'test_secretariat_0@mitre.org',
  'CVE-API-KEY': 'TCF25YM-39C4H6D-KA32EGF-V5XSHN3'
}

const nonSecretariatUserHeaders = {
  'CVE-API-ORG': 'win_5',
  'CVE-API-Key': 'TCF25YM-39C4H6D-KA32EGF-V5XSHN3',
  'CVE-API-USER': 'jasminesmith@win_5.com'
}

const nonSecretariatUserHeadersWithAdp2 = {
  'CVE-API-ORG': 'range_4',
  'CVE-API-Key': 'TCF25YM-39C4H6D-KA32EGF-V5XSHN3',
  'CVE-API-USER': 'scottmitchell@range_4.com'
}

const badNonSecretariatUserHeaders = {
  'CVE-API-ORG': 'activity_6',
  'CVE-API-Key': 'TCF25YM-39C4H6D-KA32EGF-V5XSHN3',
  'CVE-API-USER': 'benjaminsimmons@activity_6.com'
}

const testCve = {
  cnaContainer: {
    affected: [
      {
        vendor: 'n/a',
        product: 'n/a',
        versions: [
          {
            version: 'n/a',
            status: 'unknown'
          }
        ]
      }
    ],
    descriptions: [
      {
        lang: 'en',
        value: 'Cross-site scripting (XSS) vulnerability in Revive Adserver before 4.0.1 allows remote authenticated users to inject arbitrary web script or HTML via the user\'s email address.'
      }
    ],
    problemTypes: [
      {
        descriptions: [
          {
            description: 'n/a',
            lang: 'eng',
            type: 'text'
          }
        ]
      }
    ],
    providerMetadata: {
      orgId: '9cbfeea8-dea2-4923-b772-1ab41730e742'
    },
    references: [
      {
        name: '[oss-security] 20170202 Re: CVE request: multiples vulnerabilities in Revive Adserver',
        refsource: 'MLIST',
        url: 'http://www.openwall.com/lists/oss-security/2017/02/02/3'
      },
      {
        name: 'https://www.revive-adserver.com/security/revive-sa-2017-001/',
        refsource: 'CONFIRM',
        url: 'https://www.revive-adserver.com/security/revive-sa-2017-001/'
      },
      {
        name: '95875',
        refsource: 'BID',
        url: 'http://www.securityfocus.com/bid/95875'
      }
    ]
  }
}

const testCveEdited = {
  cnaContainer: {
    affected: [
      {
        vendor: 'n/a',
        product: 'n/a',
        versions: [
          {
            version: 'n/a',
            status: 'unknown'
          }
        ]
      }
    ],
    descriptions: [
      {
        lang: 'en',
        value: 'Cross-site scripting 2 (XSS) vulnerability in Revive Adserver before 4.0.1 allows remote authenticated users to inject arbitrary web script or HTML via the user\'s email address.'
      }
    ],
    problemTypes: [
      {
        descriptions: [
          {
            description: 'n/a',
            lang: 'eng',
            type: 'text'
          }
        ]
      }
    ],
    providerMetadata: {
      orgId: '9cbfeea8-dea2-4923-b772-1ab41730e742'
    },
    references: [
      {
        name: '[oss-security] 20170202 Re: CVE request: multiples vulnerabilities in Revive Adserver',
        refsource: 'MLIST',
        url: 'http://www.openwall.com/lists/oss-security/2017/02/02/3'
      },
      {
        name: 'https://www.revive-adserver.com/security/revive-sa-2017-001/',
        refsource: 'CONFIRM',
        url: 'https://www.revive-adserver.com/security/revive-sa-2017-001/'
      },
      {
        name: '95875',
        refsource: 'BID',
        url: 'http://www.securityfocus.com/bid/95875'
      }
    ]
  }

}

const testAdp = {

  adpContainer: {
    affected: [
      {
        vendor: 'n/a',
        product: 'n/a',
        versions: [
          {
            version: 'n/a',
            status: 'unknown'
          }
        ]
      }
    ],
    descriptions: [
      {
        lang: 'en',
        value: "Cross-site scripting (XSS) vulnerability in Revive Adserver before 4.0.1 allows remote authenticated users to inject arbitrary web script or HTML via the user's email address."
      }
    ],
    problemTypes: [
      {
        descriptions: [
          {
            description: 'n/a',
            lang: 'eng',
            type: 'text'
          }
        ]
      }
    ],
    providerMetadata: {
      orgId: '9cbfeea8-dea2-4923-b772-1ab41730e742'
    },
    references: [
      {
        name: '[oss-security] 20170202 Re: CVE request: multiples vulnerabilities in Revive Adserver',
        refsource: 'MLIST',
        url: 'http://www.openwall.com/lists/oss-security/2017/02/02/3'
      },
      {
        name: 'https://www.revive-adserver.com/security/revive-sa-2017-001/',
        refsource: 'CONFIRM',
        url: 'https://www.revive-adserver.com/security/revive-sa-2017-001/'
      },
      {
        name: '95875',
        refsource: 'BID',
        url: 'http://www.securityfocus.com/bid/95875'
      }
    ]
  }
}

const testAdp2 = {

  adpContainer: {
    affected: [
      {
        vendor: 'n/a',
        product: 'n/a',
        versions: [
          {
            version: 'n/a',
            status: 'unknown'
          }
        ]
      }
    ],
    descriptions: [
      {
        lang: 'en',
        value: "Cross-site scripting2 (XSS) vulnerability in Revive Adserver before 4.0.1 allows remote authenticated users to inject arbitrary web script or HTML via the user's email address."
      }
    ],
    problemTypes: [
      {
        descriptions: [
          {
            description: 'n/a',
            lang: 'eng',
            type: 'text'
          }
        ]
      }
    ],
    providerMetadata: {
    },
    references: [
      {
        name: '[oss-security] 20170202 Re: CVE request: multiples vulnerabilities in Revive Adserver',
        refsource: 'MLIST',
        url: 'http://www.openwall.com/lists/oss-security/2017/02/02/3'
      },
      {
        name: 'https://www.revive-adserver.com/security/revive-sa-2017-001/',
        refsource: 'CONFIRM',
        url: 'https://www.revive-adserver.com/security/revive-sa-2017-001/'
      },
      {
        name: '95875',
        refsource: 'BID',
        url: 'http://www.securityfocus.com/bid/95875'
      }
    ]
  }
}

module.exports = {
  headers, nonSecretariatUserHeaders, badNonSecretariatUserHeaders, nonSecretariatUserHeadersWithAdp2, testCve, testCveEdited, testAdp, testAdp2
}


text:
const chai = require('chai')
chai.use(require('chai-http'))

const expect = chai.expect

const constants = require('./constants.js')
const app = require('../../src/index.js')

// Helper function to reserve a CVE-ID
async function cveIdReserveHelper (requestLength, year, shortName, batchType) {
  return await chai.request(app)
    .post(`/api/cve-id?amount=${requestLength}&cve_year=${year}&short_name=${shortName}&batch_type=${batchType}`)
    .set(constants.nonSecretariatUserHeaders)
    .then((res, err) => {
      return res.body.cve_ids[0].cve_id
    })
}

// Helper function to bulk reserve CVE-ID
async function cveIdBulkReserveHelper (requestLength, year, shortName, batchType) {
  return await chai.request(app)
    .post(`/api/cve-id?amount=${requestLength}&cve_year=${year}&short_name=${shortName}&batch_type=${batchType}`)
    .set(constants.headers)
    .then((res, err) => {
      const ids = res.body.cve_ids.map(cveId => {
        return cveId.cve_id
      })
      return ids
    })
}

// Helper function to publish a CVE
async function cveRequestAsCnaHelper (cveId) {
  await chai.request(app)
    .post(`/api/cve/${cveId}/cna`)
    .set(constants.nonSecretariatUserHeaders)
    .send(constants.testCve)
    .then((res, err) => {
      // Safety Expect
      expect(res).to.have.status(200)
    })
}

async function cveRequestAsSecHelper (cveId) {
  await chai.request(app)
    .post(`/api/cve/${cveId}/cna`)
    .set(constants.headers)
    .send(constants.testCve)
    .then((res, err) => {
      // Safety Expect
      expect(res).to.have.status(200)
    })
}

async function cveRequestAsCnaHelperWithCnaContainer (cveId, cnaContainer) {
  await chai.request(app)
    .post(`/api/cve/${cveId}/cna`)
    .set(constants.nonSecretariatUserHeaders)
    .send(cnaContainer)
    .then((res, err) => {
      // Safety Expect
      expect(res).to.have.status(200)
    })
}

async function cveUpdatetAsCnaHelperWithCnaContainer (cveId, cnaContainer) {
  await chai.request(app)
    .put(`/api/cve/${cveId}/cna`)
    .set(constants.nonSecretariatUserHeaders)
    .send(cnaContainer)
    .then((res, err) => {
      // Safety Expect
      expect(res).to.have.status(200)
    })
}

async function cveUpdateAsSecHelper (cveId, cnaContainer) {
  await chai.request(app)
    .put(`/api/cve/${cveId}/cna`)
    .set(constants.headers)
    .send(cnaContainer)
    .then((res, err) => {
      // Safety Expect
      expect(res).to.have.status(200)
    })
}

async function cveUpdateAsCnaHelperWithAdpContainer (cveId, adpContainer) {
  await chai.request(app)
    .put(`/api/cve/${cveId}/adp`)
    .set(constants.nonSecretariatUserHeaders)
    .send(adpContainer)
    .then((res, err) => {
      expect(res).to.have.status(200)
    })
}

module.exports = {
  cveIdReserveHelper,
  cveIdBulkReserveHelper,
  cveRequestAsCnaHelper,
  cveRequestAsCnaHelperWithCnaContainer,
  cveRequestAsSecHelper,
  cveUpdatetAsCnaHelperWithCnaContainer,
  cveUpdateAsSecHelper,
  cveUpdateAsCnaHelperWithAdpContainer
}


text:
/* eslint-disable no-unused-expressions */

const chai = require('chai')
chai.use(require('chai-http'))
const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')

describe('Test time_modified for get CVE', () => {
  context('Negative Tests', () => {
    it('Get CVE should fail if time_modified.gt is given a date with an invalid month', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.gt=2022-13-01T00:00:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.lt is given a date with an invalid month', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.lt=2022-13-01T00:00:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.lt is given a date with an invalid day', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.lt=2022-01-32T00:00:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.gt is given a date with an invalid day', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.gt=2022-01-32T00:00:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.gt is given a date with invalid hours', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.gt=2022-01-01T25:00:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.lt is given a date with invalid hours', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.lt=2022-01-01T25:00:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.gt is given a date with invalid minutes', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.gt=2022-01-01T00:61:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.lt is given a date with invalid minutes', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.lt=2022-01-01T00:61:00Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.gt is given a date with invalid seconds', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.gt=2022-01-01T00:00:61Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
    it('Get CVE should fail if time_modified.lt is given a date with invalid seconds', async () => {
      await chai.request(app)
        .get('/api/cve?time_modified.lt=2022-01-01T00:00:61Z')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('Parameters were invalid')
        })
    })
  })
})


text:
/* eslint-disable no-unused-expressions */
const chai = require('chai')
chai.use(require('chai-http'))
const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')

describe('Testing that a user maintains their quota if the cna role is removed', () => {
  context('Positive Test', () => {
    it('User should still have quota after cna role removal', async () => {
      // Get the org ID since it is remade every run
      let orgUuid, quota
      await chai.request(app)
        .get('/api/org/win_5/users')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          orgUuid = res.body.users[0].org_UUID
        })
      // Check to make sure ORG has the role.
      await chai.request(app)
        .get(`/api/org/${orgUuid}`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(res.body.authority.active_roles).to.include('ADP')
          expect(res.body.policies.id_quota).to.exist
          quota = res.body.policies.id_quota
        })
      // Remove the role from the user. & check the quota and active roles
      await chai.request(app)
        .put('/api/org/win_5?active_roles.remove=CNA')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(res.body.updated.authority.active_roles).to.not.include('CNA')
          expect(res.body.updated.policies.id_quota).to.be.equal(quota)
        })
    })
  })
  // Give the user the role back incase it is used by another test
  afterEach(async () => {
    await chai.request(app)
      .put('/api/org/win_5?active_roles.add=CNA')
      .set(constants.headers)
      .then((res, err) => {
        expect(err).to.be.undefined
        expect(res).to.have.status(200)
        expect(res.body.updated.authority.active_roles).to.include('CNA')
      })
  })
})


text:
/* eslint-disable no-unused-expressions */

const chai = require('chai')
chai.use(require('chai-http'))
const helpers = require('../helpers.js')

const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')
const currentDate = new Date().toISOString()

describe('Testing Get cve_cursor endpoint', () => {
  let cveIds = []
  before(async () => {
    cveIds = await helpers.cveIdBulkReserveHelper(5, '2023', constants.headers['CVE-API-ORG'], 'sequential')
    for (const cveId of cveIds) {
      await helpers.cveRequestAsSecHelper(cveId)
    }
  })
  const TOTAL_COUNT = 119

  context('Positive Tests', () => {
    it('Get cve_cursor should return all records when no parameters are specifed', async () => {
      await chai.request(app)
        .get('/api/cve_cursor')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(res.body.cveRecords.length).to.equal(TOTAL_COUNT)
        })
    })
    it('Get cve_cursor should return 2 records when limit parameter is set to 2', async () => {
      const limit = 2
      await chai.request(app)
        .get('/api/cve_cursor?limit=2')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(res.body.cveRecords.length).to.equal(limit)
        })
    })
    it('Get cve_cursor should not return duplicate records when records are modified between page calls with time_modified.gt ', async () => {
      let next = null
      let prev = null
      let pageOneRec1 = null
      let pageOneRec2 = null
      let pageTwoRec1 = null
      let pageTwoRec2 = null

      const requester = chai.request(app).keepOpen()

      // Request page 1
      await requester.get('/api/cve_cursor?limit=2&time_modified.gt=' + currentDate)
        .set(constants.headers)
        .then(async (res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          // Check that we're on the first page
          expect(res.body.hasNext).to.be.true
          expect(res.body.hasPrevious).to.be.false

          // Save both records from page 1
          pageOneRec1 = res.body.cveRecords[0]
          pageOneRec2 = res.body.cveRecords[1]
          next = res.body.next
        })

      // Request page 2
      await requester.get('/api/cve_cursor?limit=2&next_page=' + next + '&time_modified.gt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          // Check that we're not on the first page
          expect(res.body.hasNext).to.be.true
          expect(res.body.hasPrevious).to.be.true

          // Store records from page 2
          pageTwoRec1 = res.body.cveRecords[0]
          pageTwoRec2 = res.body.cveRecords[1]
          prev = res.body.previous
        })

      // Create new CVE record, which would appear at the beginning, but data should not be moved
      const newcveId = await helpers.cveIdBulkReserveHelper(1, '2023', constants.headers['CVE-API-ORG'], 'sequential')
      await helpers.cveRequestAsSecHelper(newcveId)

      // Request page 2 again using same next_page string, should see no change in results
      await requester.get('/api/cve_cursor?limit=2&next_page=' + next + '&time_modified.gt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          expect(res.body.cveRecords[0]).to.deep.equal(pageTwoRec1)
          expect(res.body.cveRecords[1]).to.deep.equal(pageTwoRec2)
        })

      // Request page 1 again using prev_page string from first page 2 request, should see no change in results
      await requester.get('/api/cve_cursor?limit=2&previous_page=' + prev + '&time_modified.gt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          expect(res.body.cveRecords[0]).to.deep.equal(pageOneRec1)
          expect(res.body.cveRecords[1]).to.deep.equal(pageOneRec2)
        })

      // Request page 1 again without next/prev, should see new record
      await requester.get('/api/cve_cursor?limit=2&time_modified.gt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          // Newly created record appears at the front, shifting other records
          expect(res.body.cveRecords[0]).to.not.deep.equal(pageOneRec1)
          expect(res.body.cveRecords[1]).to.deep.equal(pageOneRec1)
        })

      requester.close()
    }).timeout(1000000)
    it('Get cve_cursor should not miss records when records are modified between page calls with time_modified.lt ', async () => {
      let next = null
      let prev = null
      let pageOneRec1 = null
      let pageOneRec2 = null
      let pageTwoRec1 = null
      let pageTwoRec2 = null

      const requester = chai.request(app).keepOpen()

      // Request page 1
      await requester.get('/api/cve_cursor?limit=2&time_modified.lt=' + currentDate)
        .set(constants.headers)
        .then(async (res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          // Check that we're on the first page
          expect(res.body.hasNext).to.be.true
          expect(res.body.hasPrevious).to.be.false

          // Save both records from page 1
          pageOneRec1 = res.body.cveRecords[0]
          pageOneRec2 = res.body.cveRecords[1]
          next = res.body.next
        })

      // Request page 2
      await requester.get('/api/cve_cursor?limit=2&next_page=' + next + '&time_modified.lt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          // Check that we're not on the first page
          expect(res.body.hasNext).to.be.true
          expect(res.body.hasPrevious).to.be.true

          // Store records from page 2
          pageTwoRec1 = res.body.cveRecords[0]
          pageTwoRec2 = res.body.cveRecords[1]
          prev = res.body.previous
        })

      // Modify page 1 CVE record, which would remove it, but data should not be moved
      await helpers.cveUpdateAsSecHelper(pageOneRec1.cveMetadata.cveId, constants.testCve)

      // Request page 2 again using same next_page string, should see no change in results
      await requester.get('/api/cve_cursor?limit=2&next_page=' + next + '&time_modified.lt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          expect(res.body.cveRecords[0]).to.deep.equal(pageTwoRec1)
          expect(res.body.cveRecords[1]).to.deep.equal(pageTwoRec2)
        })

      // Request page 1 again using prev_page string from first page 2 request, should have 1 record because modified one is filtered out
      await requester.get('/api/cve_cursor?limit=2&previous_page=' + prev + '&time_modified.lt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)

          expect(res.body.cveRecords.length).to.equal(1)
          expect(res.body.cveRecords[0]).to.deep.equal(pageOneRec2)
        })

      // Request page 1 again without next/prev, should see 2 records, record from page 2 shifted over
      await requester.get('/api/cve_cursor?limit=2&time_modified.lt=' + currentDate)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(res.body.cveRecords.length).to.equal(2)

          // Newly created record appears at the front, shifting other records
          expect(res.body.cveRecords[0]).to.deep.equal(pageOneRec2)
          expect(res.body.cveRecords[1]).to.deep.equal(pageTwoRec1)
        })

      requester.close()
    }).timeout(1000000)
  })
})


text:
/* eslint-disable no-unused-expressions */

const chai = require('chai')
chai.use(require('chai-http'))

const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')

const helpers = require('../helpers.js')

const requestLength = 1
const shortName = 'win_5'
const cveYear = '2023'
const batchType = 'non-sequential'

describe('Testing Reserve CVE Endpoint', () => {
  let cveId, cveIdDollar
  beforeEach(async () => {
    cveId = await helpers.cveIdReserveHelper(requestLength, cveYear, shortName, batchType)
    cveIdDollar = await helpers.cveIdReserveHelper(requestLength, cveYear, shortName, batchType)
  })
  context('Negative Tests', () => {
    it('Should not allow null byte ', async () => {
      // Publish the CVE
      await chai.request(app)
        .post(`/api/cve/${cveId}/cna`)
        .set(constants.nonSecretariatUserHeaders)
        .send({
          cnaContainer: {
            'x_\u0000': true,
            affected: [{
              product: 'p',
              vendor: 'v',
              versions: [
                {
                  version: '1.2',
                  status: 'affected'
                }
              ]
            }],
            descriptions: [{
              lang: 'en',
              value: 'v p 1.2 is insecure.'
            }],
            problemTypes: [{
              descriptions: [{ description: 'insecurity', lang: 'en' }]
            }],
            references: [{ url: 'https://example.com' }]
          }
        })
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('A problem occurred while saving the CVE Record, ensure field names in x_ objects do not start with $ or include a null byte.')
        })
    })
    it('Should not allow $ in start of x_ parameters ', async () => {
      // Publish the CVE
      await chai.request(app)
        .post(`/api/cve/${cveIdDollar}/cna`)
        .set(constants.nonSecretariatUserHeaders)
        .send({
          cnaContainer: {
            $test: true,
            affected: [{
              product: 'p',
              vendor: 'v',
              versions: [
                {
                  version: '1.2',
                  status: 'affected'
                }
              ]
            }],
            descriptions: [{
              lang: 'en',
              value: 'v p 1.2 is insecure.'
            }],
            problemTypes: [{
              descriptions: [{ description: 'insecurity', lang: 'en' }]
            }],
            references: [{ url: 'https://example.com' }]
          }
        })
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
          expect(res.body.message).to.contain('CVE cnaContainer JSON schema validation FAILED.')
        })
    })
  })
})


text:
/* eslint-disable no-unused-expressions */

const chai = require('chai')
chai.use(require('chai-http'))

const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')

const helpers = require('../helpers.js')

const requestLength = 1
const shortName = 'win_5'
const cveYear = '2023'
const batchType = 'non-sequential'

describe('Testing Reserve CVE Endpoint', () => {
  let cveId
  beforeEach(async () => {
    cveId = await helpers.cveIdReserveHelper(requestLength, cveYear, shortName, batchType)
  })
  context('Positive Tests', () => {
    it('Testing Reservation of CVE ', async () => {
      // Publish the CVE
      await chai.request(app)
        .post(`/api/cve/${cveId}/cna`)
        .set(constants.nonSecretariatUserHeaders)
        .send(constants.testCve)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(res).to.have.property('body').and.to.be.a('object')
          expect(res.body).to.have.property('created').and.to.be.a('object')
          expect(res.body.created).to.have.nested.property('cveMetadata.cveId')
          expect(res.body.created).to.have.nested.property('cveMetadata.state')
        })
    })
  })
})


text:
/* eslint-disable no-unused-expressions */
const chai = require('chai')
chai.use(require('chai-http'))
const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')
const helpers = require('../helpers.js')
const _ = require('lodash')

const shortName = 'win_5'

describe('Test cna_modified parameter for get CVE', () => {
  let cveId
  before(async () => {
    cveId = await helpers.cveIdReserveHelper(1, '2023', shortName, 'non-sequential')
    await helpers.cveRequestAsCnaHelper(cveId)
    await helpers.cveUpdateAsCnaHelperWithAdpContainer(cveId, constants.testAdp)
  })
  context('Positive Test', () => {
    it('CVE should not be returned with adp_short_name set to fake_org as it does not exist', async () => {
      await chai.request(app)
        .get('/api/cve/?adp_short_name=fake_org')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.false
        })
    })
    it(`CVE should be returned with adp_short_name set to ${shortName} as it has been created`, async () => {
      await chai.request(app)
        .get(`/api/cve/?adp_short_name=${shortName}`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
        })
    })
    it(`Get CVE with adp_short_name set to ${shortName} AND date.gt should return when searched with a known earlier than date`, async () => {
      await chai.request(app)
        .get(`/api/cve/?time_modified.gt=2022-01-01T00:00:00&adp_short_name=${shortName}`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
        })
    })
    it(`Get CVE with with adp_short_name set to ${shortName} AND date.gt should return and empty list when searched with a known bad earlier than date`, async () => {
      await chai.request(app)
        .get(`/api/cve/?time_modified.gt=2100-01-01T00:00:00&adp_short_name=${shortName}`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.false
        })
    })

    it(`Get CVE with adp_short_name set to ${shortName} AND date.lt should return when searched with a known later than date`, async () => {
      await chai.request(app)
        .get(`/api/cve/?time_modified.lt=2100-01-01T00:00:00&adp_short_name=${shortName}`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
        })
    })
    it(`Get CVE with adp_short_name set to ${shortName} AND date.lt should return and empty list when searched with a known bad later than date`, async () => {
      await chai.request(app)
        .get(`/api/cve/?time_modified.lt=2022-01-01T00:00:00&adp_short_name=${shortName}`)
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.false
        })
    })
  })
})


text:
/* eslint-disable no-unused-expressions */

const chai = require('chai')
chai.use(require('chai-http'))
const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')
const helpers = require('../helpers.js')
const _ = require('lodash')

const shortName = 'win_5'

describe('Test cna_modified parameter for get CVE', () => {
  let cveId
  before(async () => {
    cveId = await helpers.cveIdReserveHelper(1, '2023', shortName, 'non-sequential')
    await helpers.cveRequestAsCnaHelper(cveId)
  })
  context('Positive Test', () => {
    it('Get CVE with cna_modified set to true AND date.gt should return when searched with a known earlier than date', async () => {
      await chai.request(app)
        .get('/api/cve/?time_modified.gt=2022-01-01T00:00:00&cna_modified=true')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
        })
    })
    it('Get CVE with cna_modified set to true AND date.gt should return and empty list when searched with a known bad earlier than date', async () => {
      await chai.request(app)
        .get('/api/cve/?time_modified.gt=2100-01-01T00:00:00&cna_modified=true')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.false
        })
    })

    it('Get CVE with cna_modified set to true AND date.lt should return when searched with a known later than date', async () => {
      await chai.request(app)
        .get('/api/cve/?time_modified.lt=2100-01-01T00:00:00&cna_modified=true')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
        })
    })
    it('Get CVE with cna_modified set to true AND date.lt should return and empty list when searched with a known bad later than date', async () => {
      await chai.request(app)
        .get('/api/cve/?time_modified.lt=2022-01-01T00:00:00&cna_modified=true')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.false
        })
    })
  })
  context('Negative Tests', () => {
    it('CVE should NOT be returned with cna_modified true as it has been created', async () => {
      await chai.request(app)
        .get('/api/cve/?cna_modified=true')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
        })
    })
    it('Get CVE with cna_modified set to true should NOT be returned after being edited', async () => {
      // Edit the CNA container
      await helpers.cveUpdatetAsCnaHelperWithCnaContainer(cveId, constants.testCveEdited)
      await chai.request(app)
        .get('/api/cve/?cna_modified=true')
        .set(constants.headers)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(400)
        })
    })
  })
})


text:
/* eslint-disable no-unused-expressions */

const chai = require('chai')
chai.use(require('chai-http'))

const expect = chai.expect

const constants = require('../constants.js')
const app = require('../../../src/index.js')
const helpers = require('../helpers.js')

const _ = require('lodash')

const adpContainer = require('../../schemas/5.0/adpContainerExample.json').adpContainer

// Parameters for the CVE-ID reservation helper
const requestLength = 1
const shortName = 'win_5'
const cveYear = '2023'
const batchType = 'non-sequential'

const adpLength = 1

async function reserveAdp (cveId, headers, body) {
  return await chai.request(app)
    .put(`/api/cve/${cveId}/adp`)
    .set(headers)
    .send(body)
}

describe('Testing ADP insert Endpoint', () => {
  let cveId, adpContainerCopy
  beforeEach(async () => {
    // Reserve a custom CVE-ID
    cveId = await helpers.cveIdReserveHelper(requestLength, cveYear, shortName, batchType)
    // Publish the CVE
    await helpers.cveRequestAsCnaHelper(cveId)
    adpContainerCopy = _.cloneDeep(adpContainer)
  })
  context('Positive Tests', () => {
    it('Reserve ADP ', async () => {
      await reserveAdp(cveId, constants.nonSecretariatUserHeaders, constants.testAdp).then((res, err) => {
        expect(err).to.be.undefined
        const resMessage = cveId + ' record had new ADP container for org ' + shortName + ' successfully inserted'
        expect(res.body.message).to.include(resMessage)
        expect(res.body.updated.containers.adp).to.have.length(adpLength)

        adpContainerCopy.providerMetadata = res.body.updated.containers.adp[0].providerMetadata
        expect(res.body.updated.containers.adp[0]).to.deep.equal(adpContainerCopy)
        expect(res).to.have.status(200)
      })
    })
  })
  context('Negative Tests', () => {
    it('Reserve ADP should fail if the org does not have ADP', async () => {
      await reserveAdp(cveId, constants.badNonSecretariatUserHeaders, constants.testAdp)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(403)
          expect(res.body.error).to.include('ADP_ONLY')
        })
    })

    it('A user should not be able to edit someone elses ADP container', async () => {
      // First make the ADP container
      await reserveAdp(cveId, constants.nonSecretariatUserHeaders, constants.testAdp)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
        })

      // Add a second Container
      await reserveAdp(cveId, constants.nonSecretariatUserHeadersWithAdp2, constants.testAdp)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
        })

      await reserveAdp(cveId, constants.nonSecretariatUserHeadersWithAdp2, constants.testAdp2)
        .then((res, err) => {
          expect(err).to.be.undefined
          expect(res).to.have.status(200)
          expect(res.body.updated.containers.adp[0].descriptions[0].value).to.include('Cross-site scripting')
          expect(res.body.updated.containers.adp[1].descriptions[0].value).to.include('Cross-site scripting2')
        })
    })
  })
})