Skip to content

Commit

Permalink
fix delta test
Browse files Browse the repository at this point in the history
Signed-off-by: George M Dias <[email protected]>
  • Loading branch information
georgedias committed Dec 30, 2024
1 parent 9d0fbbd commit 38919be
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
38 changes: 25 additions & 13 deletions .github/workflows/e2e-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,32 @@ jobs:
platform: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup Node.js on ${{ matrix.platform }}
uses: actions/setup-node@v4
with:
node-version: "22"
check-latest: true
cache: 'npm'
- name: Setup Node.js on ${{ matrix.platform }}
uses: actions/setup-node@v4
with:
node-version: "22"
check-latest: true
cache: 'npm'

- name: Install dependencies on ${{ matrix.platform }}
run: npm ci
- name: Install dependencies on ${{ matrix.platform }}
run: npm ci

- name: Prepack (compile) on ${{ matrix.platform }}
run: npm run prepack
- name: Install cinc-auditor on ${{ matrix.platform }}
if: matrix.platform == 'windows-latest'
run: |
. { iwr -useb https://omnitruck.cinc.sh/install.ps1 } | iex; install -project cinc-auditor
cinc-auditor -v
- name: Install cinc-auditor on ${{ matrix.platform }}
if: matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest'
run: |
curl -L https://omnitruck.cinc.sh/install.sh | sudo bash -s -- -P cinc-auditor
cinc-auditor -v
- name: Run e2e tests on ${{ matrix.platform }}
run: npm run test
- name: Prepack (compile) on ${{ matrix.platform }}
run: npm run prepack

- name: Run e2e tests on ${{ matrix.platform }}
run: npm run test
4 changes: 1 addition & 3 deletions src/commands/generate/delta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,7 @@ export default class GenerateDelta extends BaseCommand<typeof GenerateDelta> {
// Get the directory name without the trailing "controls" directory
// Here we are using the newly updated (mapped) controls
// const profileDir = path.dirname(controlsDir)
// eslint-disable-next-line no-warning-comments
// TODO: normally it's 'inspec json ...' but vscode doesn't recognize my alias?
const inspecJsonFileNew = execSync(`inspec json '${mappedDir}'`, {encoding: 'utf8', maxBuffer: 50 * 1024 * 1024})
const inspecJsonFileNew = execSync(`cinc-auditor json '${mappedDir}'`, {encoding: 'utf8', maxBuffer: 50 * 1024 * 1024})

// Replace existing profile (inputted JSON of source profile to be mapped)
// Allow delta to take care of the rest
Expand Down
39 changes: 19 additions & 20 deletions test/commands/generate/delta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,24 @@ describe('Test generate delta command', () => {
expect(fs.lstatSync((`${tmpobj.name}/delta.md`)).isFile()).to.be.true // skipcq: JS-0354
})

// // NOTE: This test is failing in GitHub, but passes locally, commenting out for now
// // should process delta using the fuzzy logic
// it('should generate the correct number of controls using fuzzy logic to match and map controls', async () => {
// const {stdout} = await runCommand<{name: string}>(['generate delta',
// '-J', path.resolve('./test/sample_data/inspec/json/profile_and_controls/Windows_Server_2022_v1r3_mini-profile.json'),
// '-X', path.resolve('./test/sample_data/xccdf/stigs/Windows_Server_2022_V2R1_mini-sample-xccdf.xml'),
// '-o', `${tmpobj.name}`,
// '-M',
// '-c', path.resolve('./test/sample_data/inspec/json/profile_and_controls/windows_server_2022_v1r3_mini_controls/'),
// ])
// should process delta using the fuzzy logic
it('should generate the correct number of controls using fuzzy logic to match and map controls', async () => {
const {stdout} = await runCommand<{name: string}>(['generate delta',
'-J', path.resolve('./test/sample_data/inspec/json/profile_and_controls/Windows_Server_2022_v1r3_mini-profile.json'),
'-X', path.resolve('./test/sample_data/xccdf/stigs/Windows_Server_2022_V2R1_mini-sample-xccdf.xml'),
'-o', `${tmpobj.name}`,
'-M',
'-c', path.resolve('./test/sample_data/inspec/json/profile_and_controls/windows_server_2022_v1r3_mini_controls/'),
])

// const output = stdout.split('\n')
// expect(output.includes('Total Controls Found on Delta Directory: 5'))
// expect(output.includes('Total Controls Found on XCCDF: 5'))
// expect(output.includes('Match Controls: 5'))
// expect(output.includes('["+","SV-254238"]'))
// expect(output.includes('["+","SV-254239"]'))
// expect(output.includes('["+","SV-254240"]'))
// expect(output.includes('["+","SV-254241"]'))
// expect(output.includes('["+","SV-254242"]'))
// })
const output = stdout.split('\n')
expect(output.includes('Total Controls Found on Delta Directory: 5'))
expect(output.includes('Total Controls Found on XCCDF: 5'))
expect(output.includes('Match Controls: 5'))
expect(output.includes('["+","SV-254238"]'))
expect(output.includes('["+","SV-254239"]'))
expect(output.includes('["+","SV-254240"]'))
expect(output.includes('["+","SV-254241"]'))
expect(output.includes('["+","SV-254242"]'))
})
})

0 comments on commit 38919be

Please sign in to comment.