-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attestation apply test for overlay results (#3287)
* updating attestation apply test to include an overlay Signed-off-by: Emily Rodriguez <[email protected]> * refactor test file Signed-off-by: Emily Rodriguez <[email protected]> --------- Signed-off-by: Emily Rodriguez <[email protected]> Co-authored-by: Amndeep Singh Mann <[email protected]>
- Loading branch information
Showing
5 changed files
with
2,645 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,103 @@ | ||
/* eslint-disable array-bracket-newline */ | ||
/* eslint-disable array-element-newline */ | ||
import {expect} from 'chai' | ||
import {runCommand} from '@oclif/test' | ||
import tmp from 'tmp' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import {omitHDFChangingFields} from '../utils' | ||
import { expect } from 'chai'; | ||
import { runCommand } from '@oclif/test'; | ||
import tmp from 'tmp'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { omitHDFChangingFields } from '../utils'; | ||
|
||
describe('Test attest apply', () => { | ||
const tmpobj = tmp.dirSync({unsafeCleanup: true}) | ||
let tmpobj; | ||
|
||
// NOTE: replacing all CR from the files being generated to ensure proper comparison. | ||
it('Successfully applies a JSON attestations file', async () => { | ||
await runCommand<{name: string}>(['attest apply', | ||
'-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), | ||
path.resolve('./test/sample_data/attestations/attestations_jsonFormat.json'), | ||
'-o', `${tmpobj.name}/rhel8_attestations_jsonOutput.json`, | ||
]) | ||
const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_jsonOutput.json`, 'utf8').replaceAll(/\r/gi, '')) | ||
const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) | ||
before(() => { | ||
tmpobj = tmp.dirSync({ unsafeCleanup: true }); | ||
}); | ||
|
||
expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) | ||
}) | ||
after(() => { | ||
tmpobj.removeCallback(); | ||
}); | ||
|
||
it('Successfully applies an XLSX attestations file', async () => { | ||
await runCommand<{name: string}>(['attest apply', '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), path.resolve('./test/sample_data/attestations/attestations_xlsxFormat.xlsx'), '-o', `${tmpobj.name}/rhel8_attestations_xlsxOutput.json`]) | ||
const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_xlsxOutput.json`, 'utf8').replaceAll(/\r/gi, '')) | ||
const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) | ||
const captureOpts = { | ||
print: true, | ||
stripAnsi: false, | ||
}; | ||
|
||
const readAndParseJSON = (filePath) => { | ||
return JSON.parse(fs.readFileSync(filePath, 'utf8').replaceAll(/\r/gi, '')); | ||
}; | ||
|
||
expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) | ||
}) | ||
const runAndValidate = async (commandArgs, outputFilePath, expectedFilePath) => { | ||
const { stderr } = await runCommand(commandArgs, undefined, captureOpts); | ||
const output = readAndParseJSON(outputFilePath); | ||
const expected = readAndParseJSON(expectedFilePath); | ||
|
||
expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)); | ||
expect(stderr).to.be.empty; | ||
}; | ||
|
||
it('Successfully applies a JSON attestations file', async () => { | ||
await runAndValidate( | ||
[ | ||
'attest apply', | ||
'-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), | ||
path.resolve('./test/sample_data/attestations/attestations_jsonFormat.json'), | ||
'-o', `${tmpobj.name}/rhel8_attestations_jsonOutput.json`, | ||
], | ||
`${tmpobj.name}/rhel8_attestations_jsonOutput.json`, | ||
path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json') | ||
); | ||
}); | ||
|
||
it('Successfully applies an XLSX attestations file', async () => { | ||
await runAndValidate( | ||
[ | ||
'attest apply', | ||
'-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), | ||
path.resolve('./test/sample_data/attestations/attestations_xlsxFormat.xlsx'), | ||
'-o', `${tmpobj.name}/rhel8_attestations_xlsxOutput.json`, | ||
], | ||
`${tmpobj.name}/rhel8_attestations_xlsxOutput.json`, | ||
path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json') | ||
); | ||
}); | ||
|
||
it('Successfully applies a YAML attestations file', async () => { | ||
await runCommand<{name: string}>(['attest apply', '-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), path.resolve('./test/sample_data/attestations/attestations_yamlFormat.yaml'), '-o', `${tmpobj.name}/rhel8_attestations_yamlOutput.json`]) | ||
const output = JSON.parse(fs.readFileSync(`${tmpobj.name}/rhel8_attestations_yamlOutput.json`, 'utf8').replaceAll(/\r/gi, '')) | ||
const expected = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json'), 'utf8').replaceAll(/\r/gi, '')) | ||
await runAndValidate( | ||
[ | ||
'attest apply', | ||
'-i', path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus.json'), | ||
path.resolve('./test/sample_data/attestations/attestations_yamlFormat.yaml'), | ||
'-o', `${tmpobj.name}/rhel8_attestations_yamlOutput.json`, | ||
], | ||
`${tmpobj.name}/rhel8_attestations_yamlOutput.json`, | ||
path.resolve('./test/sample_data/attestations/rhel8_sample_oneOfEachControlStatus_output.json') | ||
); | ||
}); | ||
|
||
it('Successfully applies JSON attestations file to an overlay profile', async () => { | ||
await runAndValidate( | ||
[ | ||
'attest apply', | ||
'-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_sample.json'), | ||
path.resolve('./test/sample_data/attestations/triple_overlay_example-attestations.json'), | ||
'-o', `${tmpobj.name}/triple_overlay_attested.json`, | ||
], | ||
`${tmpobj.name}/triple_overlay_attested.json`, | ||
path.resolve('./test/sample_data/attestations/triple_overlay_attested.json') | ||
); | ||
}); | ||
|
||
expect(omitHDFChangingFields(output)).to.eql(omitHDFChangingFields(expected)) | ||
}) | ||
}) | ||
it('Successfully applies a YAML attestations file to an overlay profile', async () => { | ||
await runAndValidate( | ||
[ | ||
'attest apply', | ||
'-i', path.resolve('./test/sample_data/HDF/input/triple_overlay_profile_sample.json'), | ||
path.resolve('./test/sample_data/attestations/triple_overlay_example-attestations.yml'), | ||
'-o', `${tmpobj.name}/triple_overlay_attested_with_yml.json`, | ||
], | ||
`${tmpobj.name}/triple_overlay_attested_with_yml.json`, | ||
path.resolve('./test/sample_data/attestations/triple_overlay_attested.json') | ||
); | ||
}); | ||
}); |
Oops, something went wrong.