Skip to content

Commit

Permalink
fix: fixes tests to use uuid (NUWCDIVNPT#1431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matte22 authored Nov 13, 2024
1 parent ca2828d commit 3dddb9f
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 49 deletions.
4 changes: 2 additions & 2 deletions test/api/mocha/data/asset/assetGet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ describe(`GET - Asset`, function () {

it(`should return assets accessible to the requester, testing metadata query. (issue 1357)`, async function () {
const assetWithMetadata = await utils.createTempAsset({
name: 'tempAsset' + Math.floor(Math.random() * 10000),
name: 'tempAsset' + utils.getUUIDSubString(40),
collectionId: reference.scrapCollection.collectionId,
description: 'temp',
ip: '1.1.1.1',
Expand Down Expand Up @@ -728,7 +728,7 @@ describe(`GET - Asset`, function () {
.post(`/assets`)
.set(`Authorization`, `Bearer ` + iteration.token)
.send({
name: `assetNoChecklists` + Math.floor(Math.random() * 10000),
name: `assetNoChecklists` + utils.getUUIDSubString(40),
collectionId: reference.testCollection.collectionId,
description: `test`,
ip: `1.1.1.1`,
Expand Down
4 changes: 2 additions & 2 deletions test/api/mocha/data/asset/assetPost.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('POST - Asset', function () {
.post('/assets?projection=statusStats&projection=stigs')
.set('Authorization', 'Bearer ' + iteration.token)
.send({
name: 'TestAsset' + Date.now(),
name: 'TestAsset' + utils.getUUIDSubString(),
collectionId: reference.testCollection.collectionId,
description: 'test',
ip: '1.1.1.1',
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('POST - Asset', function () {
.post('/assets?projection=stigGrants')
.set('Authorization', 'Bearer ' + iteration.token)
.send({
name: 'TestAsset' + Date.now(),
name: 'TestAsset' + utils.getUUIDSubString(),
collectionId: reference.testCollection.collectionId,
description: 'test',
ip: '1.1.1.1',
Expand Down
10 changes: 5 additions & 5 deletions test/api/mocha/data/asset/assetPut.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('PUT - Asset', function () {
.put(`/assets/${reference.scrapAsset.assetId}?projection=statusStats&projection=stigs&projection=stigGrants`)
.set('Authorization', 'Bearer ' + iteration.token)
.send({
"name": 'TestAsset' + Math.floor(Math.random() * 1000),
"name": 'TestAsset' + utils.getUUIDSubString(),
"collectionId": reference.scrapCollection.collectionId,
"description": "test desc",
"ip": "1.1.1.1",
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('PUT - Asset', function () {
.put(`/assets/${reference.testAsset.assetId}?projection=statusStats&projection=stigs&projection=stigGrants`)
.set('Authorization', 'Bearer ' + iteration.token)
.send({
"name": 'TestAsset' + Math.floor(Math.random() * 1000),
"name": 'TestAsset' + utils.getUUIDSubString(),
"collectionId": reference.testCollection.collectionId,
"description": "test desc",
"ip": "1.1.1.1",
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('PUT - Asset', function () {
.put(`/assets/${reference.scrapAsset.assetId}`)
.set('Authorization', 'Bearer ' + iteration.token)
.send({
"name":'TestAsset' + Math.floor(Math.random() * 1000),
"name":'TestAsset' + utils.getUUIDSubString(),
"collectionId": reference.scrapCollection.collectionId,
"description": "test desc",
"ip": "1.1.1.1",
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('PUT - Asset', function () {
.put(`/assets/${reference.scrapAsset.assetId}`)
.set('Authorization', 'Bearer ' + iteration.token)
.send({
"name": 'TestAsset' + Math.floor(Math.random() * 1000),
"name": 'TestAsset' + utils.getUUIDSubString(),
"collectionId": reference.scrapLvl1User.userId,
"description": "test desc",
"ip": "1.1.1.1",
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('PUT - Asset', function () {
const res = await chai.request(config.baseUrl)
.put(`/collections/${reference.scrapCollection.collectionId}/stigs/${reference.scrapAsset.scrapBenchmark}/assets?projection=restrictedUserAccess`)
.set('Authorization', 'Bearer ' + iteration.token)
.send([`${Math.floor(Math.random() * 123456)}`])
.send([`12321`])
expect(res).to.have.status(403)
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/api/mocha/data/collection/collectionDelete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('DELETE - Collection ', function () {

before(async function () {
const testCollectionClone = JSON.parse(JSON.stringify(requestBodies.resetTestCollection))
testCollectionClone.name = `Collection ` + Math.floor(Math.random() * 1000000)
testCollectionClone.name = `Collection ` + utils.getUUIDSubString()
tempCollection = await utils.createTempCollection(testCollectionClone)
})

Expand Down Expand Up @@ -63,7 +63,7 @@ describe('DELETE - Collection ', function () {
let tempLabel = null
beforeEach(async function () {
const labelPost = JSON.parse(JSON.stringify(requestBodies.recreateCollectionLabel))
labelPost.name = `Label ` + Math.floor(Math.random() * 1000000)
labelPost.name = `Label ` + utils.getUUIDSubString(8)
tempLabel = await utils.createCollectionLabel(reference.testCollection.collectionId, labelPost)
})
it('Delete a scrap collection scrap Label',async function () {
Expand Down
8 changes: 3 additions & 5 deletions test/api/mocha/data/collection/collectionGet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('GET - Collection', function () {
it('Return a list of Collections accessible to the requester METADATA param but with a colon character (see issue 1357)',async function () {
const tempCollectionWithMetadata = await utils.createTempCollection(
{
name: 'tempCollection' + Math.floor(Math.random() * 1000),
name: 'tempCollection' + utils.getUUIDSubString(),
description: 'Collection TEST description',
settings: {
fields: {
Expand Down Expand Up @@ -452,10 +452,8 @@ describe('GET - Collection', function () {
})
it("should return SmError.NotFoundError because the label does not exist",async function () {

const randomUUID = uuidv4()

const res = await chai.request(config.baseUrl)
.get(`/collections/${reference.testCollection.collectionId}/labels/${randomUUID}`)
.get(`/collections/${reference.testCollection.collectionId}/labels/${uuidv4()}`)
.set('Authorization', `Bearer ${iteration.token}`)
if (distinct.grant === "none"){
expect(res).to.have.status(403)
Expand Down Expand Up @@ -509,7 +507,7 @@ describe('GET - Collection', function () {
it('should return empty 200 reponse, collection does not have metadata',async function () {

const collectionNoMetadata = await utils.createTempCollection( {
name: 'temoCollection' + Math.floor(Math.random() * 1000),
name: 'temoCollection' + utils.getUUIDSubString(),
description: 'Collection TEST description',
settings: {
fields: {
Expand Down
2 changes: 1 addition & 1 deletion test/api/mocha/data/collection/collectionPatch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('PATCH - Collection', function () {

const patchRequest = JSON.parse(JSON.stringify(requestBodies.updateCollection))
patchRequest.grants.push(patchRequest.grants[0])
patchRequest.name = "TEST" + Math.floor(Math.random() * 100) + "-" + Math.floor(Math.random() * 100)
patchRequest.name = "TEST" + utils.getUUIDSubString()
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.testCollection.collectionId}`)
.set('Authorization', `Bearer ${iteration.token}`)
Expand Down
6 changes: 3 additions & 3 deletions test/api/mocha/data/collection/collectionPost.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('POST - Collection - not all tests run for all iterations', function ()

describe("createCollection - /collections", function () {

const random = Math.floor(Math.random() * 100) + "-" + Math.floor(Math.random() * 100)
const random = utils.getUUIDSubString()

it("Create a Collection and test projections",async function () {
const post = JSON.parse(JSON.stringify(requestBodies.createCollection))
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('POST - Collection - not all tests run for all iterations', function ()

const post = JSON.parse(JSON.stringify(requestBodies.createCollection))
post.grants.push(post.grants[0])
post.name = "TEST" + Math.floor(Math.random() * 100) + "-" + Math.floor(Math.random() * 100)
post.name = "TEST" + utils.getUUIDSubString()
const res = await chai
.request(config.baseUrl)
.post(`/collections?elevate=${distinct.canElevate}`)
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('POST - Collection - not all tests run for all iterations', function ()
.post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`)
.set("Authorization", `Bearer ${iteration.token}`)
.send({
name:"Clone_" + Math.floor(Math.random() * 100) + "-" + Math.floor(Math.random() * 100) + "_X",
name:"Clone_" + utils.getUUIDSubString(),
description: "clone of test collection x",
options: {
grants: true,
Expand Down
5 changes: 2 additions & 3 deletions test/api/mocha/data/collection/collectionPut.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('PUT - Collection', function () {

const putRequest = JSON.parse(JSON.stringify(requestBodies.replaceCollection))
putRequest.grants.push(putRequest.grants[0])
putRequest.name = "TEST" + Math.floor(Math.random() * 100) + "-" + Math.floor(Math.random() * 100)
putRequest.name = "TEST" + utils.getUUIDSubString()
const res = await chai.request(config.baseUrl)
.put(`/collections/${reference.testCollection.collectionId}`)
.set('Authorization', `Bearer ${iteration.token}`)
Expand Down Expand Up @@ -214,9 +214,8 @@ describe('PUT - Collection', function () {
}
})
it("should throw SmError.NotFoundError when attempting to set asset stig for a user that does not exist with access level 1",async function () {
const randomUserId = Math.floor(Math.random() * 1002230)
const res = await chai.request(config.baseUrl)
.put(`/collections/${reference.scrapCollection.collectionId}/grants/${randomUserId}/access`)
.put(`/collections/${reference.scrapCollection.collectionId}/grants/${"123432"}/access`)
.set('Authorization', `Bearer ${iteration.token}`)
.send([{
"benchmarkId": reference.scrapAsset.scrapBenchmark,
Expand Down
2 changes: 1 addition & 1 deletion test/api/mocha/data/review/reviewGet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('GET - Review', () => {
it('Return a list of reviews accessible to the requester, metadata Projection. issue 1357', async () => {
const tempCollectionWithMetadata = await utils.createTempCollection(
{
name: 'tempCollection' + Math.floor(Math.random() * 1000),
name: 'tempCollection' + utils.getUUIDSubString(),
description: 'Collection TEST description',
settings: {
fields: {
Expand Down
10 changes: 5 additions & 5 deletions test/api/mocha/data/user/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const reference = require('../../referenceData.js')
const requestBodies = require('./requestBodies.js')

let testUser = null
const randomValue = Math.floor(Math.random() * 10000)
const randomValue = utils.getUUIDSubString(8)

describe('user', () => {

Expand All @@ -26,7 +26,7 @@ describe('user', () => {
// this is here because after we do the gets we need to create a temp user to do all posts, patches, and puts etc on.
// as a result we will have an extra user in the gets to consider
const create = JSON.parse(JSON.stringify(requestBodies.scrapUser))
create.username = create.username + Math.floor(Math.random() * 1000) + Date.now()
create.username = create.username + utils.getUUIDSubString()
testUser = await utils.createUser(create)
})

Expand Down Expand Up @@ -273,7 +273,7 @@ describe('user', () => {
"username": "TEST_USER" + randomValue,
"collectionGrants": [
{
"collectionId": `${randomValue}`,
"collectionId": `${"987654"}`,
"accessLevel": 1
}
]
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('user', () => {
"username": "PatchTest",
"collectionGrants": [
{
"collectionId": `${Math.floor(Math.random() * 100022)}`,
"collectionId": `1234321`,
"accessLevel": 1
}
]
Expand Down Expand Up @@ -429,7 +429,7 @@ describe('user', () => {
"username": "putTesting",
"collectionGrants": [
{
"collectionId": `${Math.floor(Math.random() * 100022)}`,
"collectionId": `1234321`,
"accessLevel": 1
}
]
Expand Down
Loading

0 comments on commit 3dddb9f

Please sign in to comment.