diff --git a/test/api/mocha/data/asset/assetGet.test.js b/test/api/mocha/data/asset/assetGet.test.js index 1997a6b1..333d8c5c 100644 --- a/test/api/mocha/data/asset/assetGet.test.js +++ b/test/api/mocha/data/asset/assetGet.test.js @@ -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', @@ -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`, diff --git a/test/api/mocha/data/asset/assetPost.test.js b/test/api/mocha/data/asset/assetPost.test.js index 2208fc07..2b11ee1a 100644 --- a/test/api/mocha/data/asset/assetPost.test.js +++ b/test/api/mocha/data/asset/assetPost.test.js @@ -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', @@ -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', diff --git a/test/api/mocha/data/asset/assetPut.test.js b/test/api/mocha/data/asset/assetPut.test.js index 0ea925d0..c3c86426 100644 --- a/test/api/mocha/data/asset/assetPut.test.js +++ b/test/api/mocha/data/asset/assetPut.test.js @@ -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", @@ -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", @@ -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", @@ -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", @@ -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) }) }) diff --git a/test/api/mocha/data/collection/collectionDelete.test.js b/test/api/mocha/data/collection/collectionDelete.test.js index e61b154b..d1b9bbce 100644 --- a/test/api/mocha/data/collection/collectionDelete.test.js +++ b/test/api/mocha/data/collection/collectionDelete.test.js @@ -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) }) @@ -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 () { diff --git a/test/api/mocha/data/collection/collectionGet.test.js b/test/api/mocha/data/collection/collectionGet.test.js index ee489736..c2f5ea46 100644 --- a/test/api/mocha/data/collection/collectionGet.test.js +++ b/test/api/mocha/data/collection/collectionGet.test.js @@ -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: { @@ -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) @@ -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: { diff --git a/test/api/mocha/data/collection/collectionPatch.test.js b/test/api/mocha/data/collection/collectionPatch.test.js index d05d1348..65a14d90 100644 --- a/test/api/mocha/data/collection/collectionPatch.test.js +++ b/test/api/mocha/data/collection/collectionPatch.test.js @@ -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}`) diff --git a/test/api/mocha/data/collection/collectionPost.test.js b/test/api/mocha/data/collection/collectionPost.test.js index 0db9ee9e..3bae4a9b 100644 --- a/test/api/mocha/data/collection/collectionPost.test.js +++ b/test/api/mocha/data/collection/collectionPost.test.js @@ -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)) @@ -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}`) @@ -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, diff --git a/test/api/mocha/data/collection/collectionPut.test.js b/test/api/mocha/data/collection/collectionPut.test.js index d20e4ae6..831c5dc5 100644 --- a/test/api/mocha/data/collection/collectionPut.test.js +++ b/test/api/mocha/data/collection/collectionPut.test.js @@ -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}`) @@ -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, diff --git a/test/api/mocha/data/review/reviewGet.test.js b/test/api/mocha/data/review/reviewGet.test.js index 9a9beb4a..816503a2 100644 --- a/test/api/mocha/data/review/reviewGet.test.js +++ b/test/api/mocha/data/review/reviewGet.test.js @@ -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: { diff --git a/test/api/mocha/data/user/user.test.js b/test/api/mocha/data/user/user.test.js index d2a2c564..bc570802 100644 --- a/test/api/mocha/data/user/user.test.js +++ b/test/api/mocha/data/user/user.test.js @@ -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', () => { @@ -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) }) @@ -273,7 +273,7 @@ describe('user', () => { "username": "TEST_USER" + randomValue, "collectionGrants": [ { - "collectionId": `${randomValue}`, + "collectionId": `${"987654"}`, "accessLevel": 1 } ] @@ -363,7 +363,7 @@ describe('user', () => { "username": "PatchTest", "collectionGrants": [ { - "collectionId": `${Math.floor(Math.random() * 100022)}`, + "collectionId": `1234321`, "accessLevel": 1 } ] @@ -429,7 +429,7 @@ describe('user', () => { "username": "putTesting", "collectionGrants": [ { - "collectionId": `${Math.floor(Math.random() * 100022)}`, + "collectionId": `1234321`, "accessLevel": 1 } ] diff --git a/test/api/mocha/integration/collection.test.js b/test/api/mocha/integration/collection.test.js index e481908b..65d0d738 100644 --- a/test/api/mocha/integration/collection.test.js +++ b/test/api/mocha/integration/collection.test.js @@ -201,7 +201,7 @@ describe('POST - createCollection - /collections', () => { it('Invalid fields.detail.required value', async () => { const postRequest = { - "name": "TEST_" + Math.random().toString(36).substring(7), + "name": "TEST_" + utils.getUUIDSubString(), "description": "Collection TEST description", "settings": { "fields": { @@ -369,7 +369,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -436,7 +436,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": false, @@ -523,7 +523,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -592,7 +592,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -676,7 +676,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -746,7 +746,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -813,7 +813,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -888,7 +888,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${user.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -931,7 +931,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${lvl4.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -949,7 +949,7 @@ describe('POST - cloneCollection - /collections/{collectionId}/clone - test vari .post(`/collections/${reference.testCollection.collectionId}/clone?projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs&projection=labels`) .set('Authorization', `Bearer ${collectioncreator.token}`) .send({ - "name": "Clone_X" + Math.random().toString(36).substring(7), + "name": "Clone_X" + utils.getUUIDSubString(), "description": "clone of test collection x", "options": { "grants": true, @@ -1559,7 +1559,7 @@ describe('GET - putAssetsByCollectionLabelId - /collections/{collectionId}/label .post(`/assets?projection=stigs`) .set('Authorization', `Bearer ${user.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", @@ -1592,7 +1592,7 @@ describe('GET - putAssetsByCollectionLabelId - /collections/{collectionId}/label .put(`/assets/${reference.scrapAsset.assetId}?projection=statusStats&projection=stigs&projection=stigGrants`) .set('Authorization', `Bearer ${user.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", diff --git a/test/api/mocha/integration/deleteHandling.test.js b/test/api/mocha/integration/deleteHandling.test.js index ed6c86e5..a0538f95 100644 --- a/test/api/mocha/integration/deleteHandling.test.js +++ b/test/api/mocha/integration/deleteHandling.test.js @@ -31,7 +31,7 @@ describe('DELETE - deleteAsset - /assets/{assetId} - DELETE - deleteCollection - .post("/collections?elevate=true&projection=grants&projection=labels") .set("Authorization", `Bearer ${user.token}`) .send({ - "name": "TEST_" + Math.floor(Math.random() * 1000), + "name": "TEST_" + utils.getUUIDSubString(), "description": "Collection TEST description", "settings": { "fields": { @@ -87,7 +87,7 @@ describe('DELETE - deleteAsset - /assets/{assetId} - DELETE - deleteCollection - .post(`/assets?projection=stigs`) .set("Authorization", `Bearer ${user.token}`) .send({ - "name": "TEST_" + Math.floor(Math.random() * 1000), + "name": "TEST_" + utils.getUUIDSubString(), "collectionId": collectionToDelete, "description": "test desc", "ip": "1.1.1.1", @@ -225,7 +225,7 @@ describe('DELETE - deleteAsset - /assets/{assetId} - DELETE - deleteCollection - .post(`/assets?projection=stigs`) .set("Authorization", `Bearer ${user.token}`) .send({ - "name": "TEST_" + Math.floor(Math.random() * 1000), + "name": "TEST_" + utils.getUUIDSubString(), "collectionId": deletedCollection, "description": "test desc", "ip": "1.1.1.1", diff --git a/test/api/mocha/utils/testUtils.js b/test/api/mocha/utils/testUtils.js index 94af472e..28a89cf0 100644 --- a/test/api/mocha/utils/testUtils.js +++ b/test/api/mocha/utils/testUtils.js @@ -3,7 +3,7 @@ const config = require('../testConfig.json') const FormData = require('form-data') const fs = require('fs') const path = require('path') - +const { v4: uuidv4 } = require('uuid') const adminToken = config.adminToken // canidate for a function? (used to store responses for a test (metrics)) @@ -17,6 +17,11 @@ const metricsOutputToJSON = (testCaseName, username, responseData, outputJsonFil fs.writeFileSync(metricsFilePath, JSON.stringify(metricsData, null, 2), 'utf8') } +const getUUIDSubString = (length = 20) => { + return uuidv4().substring(0, length) +} + + const loadAppData = (appdataFileName = 'appdata.jsonl') => { return axios({ method: 'post', @@ -35,7 +40,7 @@ const createTempCollection = async (collectionPost) => { if (!collectionPost) { collectionPost = { - name: 'temoCollection' + Math.floor(Math.random() * 1000) + Date.now(), + name: 'temoCollection' + getUUIDSubString(), description: 'Collection TEST description', settings: { fields: { @@ -119,7 +124,7 @@ const deleteCollection = async (collectionId) => { const createTempAsset = async asset => { if (!asset) { asset = { - name: 'tempAsset' + Date.now(), + name: 'tempAsset' + getUUIDSubString(), collectionId: "21", description: 'temp', ip: '1.1.1.1', @@ -720,5 +725,6 @@ module.exports = { getStigByBenchmarkId, getCollection, uploadTestStig, - deleteStigByRevision + deleteStigByRevision, + getUUIDSubString }