Skip to content

Commit

Permalink
removing appdata calls for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Matte22 committed Sep 16, 2024
1 parent fb1eccf commit 90e8c23
Show file tree
Hide file tree
Showing 14 changed files with 711 additions and 707 deletions.
1 change: 1 addition & 0 deletions test/api/mocha/data/collection/collectionGet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ describe('GET - Collection', function () {
}
expect(res).to.have.status(200)
expect(res.body).to.be.an('array').of.length(0)
utils.deleteCollection(collectionNoMetadata.data.collectionId)
})
})

Expand Down
13 changes: 13 additions & 0 deletions test/api/mocha/data/review/requestBodies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//This data contains expected response data that varies by iteration "scenario" or "iteration" for each test case. These expectations are relative to the "referenceData.js" data used to construct the API requests.
const reference = require('../../referenceData.js')
const requestBodies = {
resetRule: {
autoResult: false,
comment: "",
detail: "test\nvisible to lvl1\nhas history",
metadata: {},
result: 'notapplicable',
status: 'submitted',
}
}
module.exports = requestBodies
22 changes: 15 additions & 7 deletions test/api/mocha/data/review/reviewDelete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const expectations = require('./expectations.js')
const reference = require('../../referenceData.js')

describe('DELETE - Review', () => {

before(async function () {
// this.timeout(4000)
// await utils.loadAppData()
await utils.loadAppData()
await utils.uploadTestStigs()
})

Expand All @@ -22,12 +23,12 @@ describe('DELETE - Review', () => {
}
describe(`iteration:${iteration.name}`, () => {
const distinct = expectations[iteration.name]

describe('DELETE - deleteReviewByAssetRule - /collections/{collectionId}/reviews/{assetId}/{ruleId}', () => {

let review = null
beforeEach(async function () {
this.timeout(4000)
await utils.loadAppData()
// await utils.uploadTestStigs()
review = await utils.importReview(reference.testCollection.collectionId, reference.testAsset.assetId, reference.testAsset.testRuleId)
})

it('Delete a Review', async () => {
Expand All @@ -39,7 +40,6 @@ describe('DELETE - Review', () => {

expect(res.body.assetId).to.equal(reference.testAsset.assetId)
expect(res.body.rule.ruleId).to.equal(reference.testAsset.testRuleId)
expect(res.body.history).to.be.an('array').of.length(reference.testAsset.testRuleIdHistoryCount)
expect(res.body.stigs).to.be.an('array').of.length(reference.testAsset.testRuleIdStigCount)

for(const history of res.body.history) {
Expand All @@ -57,10 +57,18 @@ describe('DELETE - Review', () => {

before(async function () {
this.timeout(4000)
await utils.loadAppData()
// await utils.uploadTestStigs()
review = await utils.importReview(reference.testCollection.collectionId, reference.testAsset.assetId, reference.testAsset.testRuleId)
})

it('should create metadata to be deleted', async () => {
const res = await chai.request(config.baseUrl)
.put(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}/metadata`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({[reference.reviewMetadataKey]: reference.reviewMetadataValue})
expect(res).to.have.status(200)
expect(res.body).to.eql({[reference.reviewMetadataKey]: reference.reviewMetadataValue})

})
it('Delete one metadata key/value of a Review', async () => {
const res = await chai.request(config.baseUrl)
.delete(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testAsset.testRuleId}/metadata/keys/${reference.reviewMetadataKey}`)
Expand Down
23 changes: 3 additions & 20 deletions test/api/mocha/data/review/reviewGet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const reference = require('../../referenceData.js')
const iterations = require('../../iterations.js')

describe('GET - Review', () => {

before(async function () {
this.timeout(4000)
await utils.uploadTestStigs()
//await utils.uploadTestStigs()
await utils.loadAppData()
await utils.createDisabledCollectionsandAssets()
//await utils.createDisabledCollectionsandAssets()
})

for(const iteration of iterations){
Expand Down Expand Up @@ -490,24 +491,6 @@ describe('GET - Review', () => {
expect(res.body).to.be.lengthOf(1)
expect(res.body).to.include(reference.reviewMetadataKey)
})
it("should return empty 200 response, no metadata", async () => {

// using scrap rule id for windows cuz lvl1 cannot access
const res = await chai.request(config.baseUrl)
.get(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.scrapRuleIdWindows10}/metadata/keys`)
.set('Authorization', `Bearer ${iteration.token}`)
if(distinct.canPatchReview){
expect(res).to.have.status(200)
return
}
expect(res).to.have.status(200)
})
it("should return empty 200 response if metadata key isnt found. ", async () => {
const res = await chai.request(config.baseUrl)
.get(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testRuleNoMetadata.ruleId}/metadata/keys`)
.set('Authorization', `Bearer ${iteration.token}`)
expect(res).to.have.status(200)
})
})
describe('GET - getReviewMetadataValue - /collections/{collectionId}/reviews/{assetId}/{ruleId}/metadata/keys/{key}', () => {

Expand Down
21 changes: 7 additions & 14 deletions test/api/mocha/data/review/reviewPatch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const utils = require('../../utils/testUtils')
const reference = require('../../referenceData.js')
const iterations = require('../../iterations.js')
const expectations = require('./expectations.js')
const requestBodies = require('./requestBodies.js')

describe('PATCH - Review', () => {

Expand All @@ -26,14 +27,12 @@ describe('PATCH - Review', () => {
describe('PATCH - patchReviewByAssetRule - /collections/{collectionId}/reviews/{assetId}/{ruleId}', () => {

beforeEach(async function () {
this.timeout(4000)
await utils.loadAppData()
// await utils.uploadTestStigs()
await utils.putReviewByAssetRule(reference.testCollection.collectionId, reference.testAsset.assetId, reference.testCollection.ruleId, requestBodies.resetRule)
})

it('PATCH Review with new details, expect status to remain', async () => {
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${'SV-106181r1_rule'}`)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({detail:"these details have changed, but the status remains"})

Expand All @@ -42,7 +41,7 @@ describe('PATCH - Review', () => {
})
it('PATCH Review with new result, expect status to reset to saved', async () => {
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${'SV-106181r1_rule'}`)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({result: "pass"})

Expand All @@ -52,7 +51,7 @@ describe('PATCH - Review', () => {
})
it('PATCH Review to submitted status', async () => {
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${'SV-106181r1_rule'}`)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({status: "submitted"})

Expand All @@ -61,7 +60,7 @@ describe('PATCH - Review', () => {
})
it('PATCH Review patched and no longer meets Collection Requirements', async () => {
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${'SV-106181r1_rule'}`)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({result: "fail"})

Expand All @@ -81,7 +80,6 @@ describe('PATCH - Review', () => {
}
expect(res).to.have.status(200)
expect(res.body).to.have.property("touchTs").to.eql(res.body.status.ts)
expect(res.body.status).to.have.property("ts").to.not.eql(res.body.ts)
})
it('Merge provided properties with a Review', async () => {
const res = await chai
Expand All @@ -105,11 +103,6 @@ describe('PATCH - Review', () => {
})
describe('PATCH - patchReviewMetadata - /collections/{collectionId}/reviews/{assetId}/{ruleId}/metadata', () => {

// before(async function () {
// this.timeout(4000)
// await utils.loadAppData()
// await utils.uploadTestStigs()
// })
it('Merge metadata property/value into a Review', async () => {
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}/metadata`)
Expand Down
13 changes: 4 additions & 9 deletions test/api/mocha/data/review/reviewPost.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const utils = require('../../utils/testUtils')
const iterations = require('../../iterations.js')
const expectations = require('./expectations.js')
const reference = require('../../referenceData.js')

const requestBodies = require('./requestBodies.js')
const checkReviews = (reviews, postreview, iteration) => {
for(let review of reviews){
if(review.ruleId == reference.testCollection.ruleId && review.assetId == reference.testAsset.assetId){
Expand Down Expand Up @@ -55,6 +55,7 @@ const checkReviews = (reviews, postreview, iteration) => {
}

describe('POST - Review', () => {

before(async function () {
await utils.uploadTestStigs()
})
Expand Down Expand Up @@ -791,7 +792,6 @@ describe('POST - Review', () => {

beforeEach(async function () {
this.timeout(4000)
// await utils.uploadTestStigs()
await utils.loadAppData("batch-test-data.json")
})
it(`POST batch Review: target by assets, and one rule, expect validation failure - invalid result for status`, async () => {
Expand Down Expand Up @@ -1012,7 +1012,6 @@ describe('POST - Review', () => {
let tempCollectionCanAcceptFalse
before(async function () {
this.timeout(4000)
await utils.loadAppData()
tempCollectionCanAcceptFalse = await utils.createTempCollection({
name: 'temoCollection',
description: 'Collection TEST description',
Expand Down Expand Up @@ -1087,7 +1086,6 @@ describe('POST - Review', () => {
.send(postreview)

expect(res).to.have.status(403)
expect(res.body.details).to.eql('"Reviews cannot be accepted/rejected in this Collection"')
})
it(`should throw SmError.PriviledgeError`, async () => {

Expand All @@ -1105,12 +1103,10 @@ describe('POST - Review', () => {
}
}
const res = await chai.request(config.baseUrl)
.post(`/collections/${tempCollection.data.collectionId}/reviews`)
.post(`/collections/${tempCollectionCanAcceptFalse.data.collectionId}/reviews`)
.set('Authorization', `Bearer ${iteration.token}`)
.send(postreview)

expect(res).to.have.status(403)
expect(res.body.details).to.eql('"Reviews cannot be accepted/rejected in this Collection"')
})
})
})
Expand All @@ -1119,8 +1115,7 @@ describe('POST - Review', () => {
let deletedCollection, deletedAsset
before(async function () {
this.timeout(4000)
await utils.loadAppData()
// await utils.uploadTestStigs()
await utils.putReviewByAssetRule(reference.testCollection.collectionId, reference.testAsset.assetId, reference.testCollection.ruleId, requestBodies.requestBodies)
const deletedItems = await utils.createDisabledCollectionsandAssets()
deletedCollection = deletedItems.collection
deletedAsset = deletedItems.asset
Expand Down
53 changes: 25 additions & 28 deletions test/api/mocha/data/review/reviewPut.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const xml2js = require('xml2js');
const iterations = require('../../iterations.js')
const expectations = require('./expectations.js')
const reference = require('../../referenceData.js')
const requestBodies = require('./requestBodies.js')

describe('PUT - Review', () => {

Expand Down Expand Up @@ -243,7 +244,7 @@ describe('PUT - Review', () => {

expect(res).to.have.status(403)
})
it('Test all projections are returned and contain accurate data. ', async () => {
it('Test all projections are returned and contain accurate data. (besides history that is tested better elsewhere)', async () => {

const putBody = {
result: 'pass',
Expand All @@ -254,7 +255,7 @@ describe('PUT - Review', () => {
}

const res = await chai.request(config.baseUrl)
.put(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}?projection=rule&projection=history&projection=stigs&projection=metadata`)
.put(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}?projection=rule&projection=stigs&projection=metadata`)
.set('Authorization', `Bearer ${iteration.token}`)
.send(putBody)

Expand All @@ -269,14 +270,11 @@ describe('PUT - Review', () => {
expect(res.body.metadata[reference.reviewMetadataKey]).to.be.equal(reference.reviewMetadataValue)

//projections

expect(res.body).to.have.property("rule")
expect(res.body).to.have.property("history")
expect(res.body).to.have.property("stigs")
expect(res.body).to.have.property("metadata")

expect(res.body.rule.ruleId).to.be.eql(reference.testCollection.ruleId)
expect(res.body.history).to.have.lengthOf(6)
expect(res.body.stigs).to.have.lengthOf(1)
expect(res.body.metadata).to.have.property(reference.reviewMetadataKey)
expect(res.body.metadata[reference.reviewMetadataKey]).to.be.equal(reference.reviewMetadataValue)
Expand Down Expand Up @@ -338,38 +336,37 @@ describe('PUT - Review', () => {

before(async function () {
this.timeout(4000)
// await utils.uploadTestStigs()
await utils.loadAppData()
await utils.putReviewByAssetRule(reference.testCollection.collectionId, reference.testAsset.assetId, reference.testCollection.ruleId, requestBodies.resetRule)
})

it('Set all metadata of a Review', async () => {
const res = await chai.request(config.baseUrl)
.put(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}/metadata`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({[reference.reviewMetadataKey]: reference.reviewMetadataValue})

expect(res).to.have.status(200)
expect(res.body).to.eql({[reference.reviewMetadataKey]: reference.reviewMetadataValue})

})
it('Set all metadata of a Review', async () => {
const res = await chai.request(config.baseUrl)
.put(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.testCollection.ruleId}/metadata`)
it("should return SmError.PrivilegeError if user cannot put review", async () => {
const res = await chai.request(config.baseUrl)
.get(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.scrapRuleIdWindows10}/metadata`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({[reference.reviewMetadataKey]: reference.reviewMetadataValue})

if(distinct.canPatchReview){
expect(res).to.have.status(200)
expect(res.body).to.eql({[reference.reviewMetadataKey]: reference.reviewMetadataValue})

})
it("should return SmError.PrivilegeError if user cannot put review", async () => {
const res = await chai.request(config.baseUrl)
.get(`/collections/${reference.testCollection.collectionId}/reviews/${reference.testAsset.assetId}/${reference.scrapRuleIdWindows10}/metadata`)
.set('Authorization', `Bearer ${iteration.token}`)
if(distinct.canPatchReview){
expect(res).to.have.status(200)
return
}
expect(res).to.have.status(403)
expect(res.body.error).to.be.equal("User has insufficient privilege to complete this request.")
})
return
}
expect(res).to.have.status(403)
expect(res.body.error).to.be.equal("User has insufficient privilege to complete this request.")
})
})

describe('PUT - putReviewMetadataValue - /collections/{collectionId}/reviews/{assetId}/{ruleId}/metadata/keys/{key}', () => {

before(async function () {
this.timeout(4000)
// await utils.uploadTestStigs()
await utils.loadAppData()
await utils.putReviewByAssetRule(reference.testCollection.collectionId, reference.testAsset.assetId, reference.testCollection.ruleId, requestBodies.resetRule)
})
it('Set one metadata key/value of a Review', async () => {
const res = await chai.request(config.baseUrl)
Expand Down
Loading

0 comments on commit 90e8c23

Please sign in to comment.