Skip to content

Commit b761ade

Browse files
authored
Delta fuzzy matching testing (#3166)
* fix delta test Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * fix e2e to install cinc-auditor when running on windows platform Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Removed installing cinc-auditor installation for windows Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Testing installion of cinc-auditor on windows Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Testing installion of cinc-auditor on windows Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Testing installion of cinc-auditor on windows - modified path Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Testing installion of cinc-auditor on windows - modified path-2 Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Testing installion of cinc-auditor on windows - modified path-3 Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Testing installion of cinc-auditor on windows - modified path-3 Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Testing installion of cinc-auditor on windows - modified path-4 Signed-off-by: George M Dias <GDIAS@MITRE.ORG> * Updated github runners Signed-off-by: George M Dias <GDIAS@MITRE.ORG> --------- Signed-off-by: George M Dias <GDIAS@MITRE.ORG>
1 parent 0e3707d commit b761ade

File tree

5 files changed

+63
-48
lines changed

5 files changed

+63
-48
lines changed

.github/workflows/build-macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ jobs:
3232
run: |
3333
cd dist/macos
3434
for file in saf-*.pkg; do
35-
prefix=${file%-*-*.pkg}
36-
suffix=${file#saf-*-*-*}
37-
mv "$file" "$prefix-$suffix"
35+
prefix=${file%-*-*.pkg}
36+
suffix=${file#saf-*-*-*}
37+
mv "$file" "$prefix-$suffix"
3838
done
3939
4040
- name: Upload SAF-CLI macOS Installer Artifact

.github/workflows/build-windows-linux.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ jobs:
4444
run: |
4545
cd saf/dist/win32
4646
for file in saf-*.exe; do
47-
prefix=${file%-*-*} # get prefix by removing frome end
48-
suffix=${file#saf-*-*-} # get suffix by removing from start
49-
mv "$file" "$prefix-$suffix"
47+
prefix=${file%-*-*} # get prefix by removing from end
48+
suffix=${file#saf-*-*-} # get suffix by removing from start
49+
mv "$file" "$prefix-$suffix"
5050
done
5151
5252
- name: Rename Debian Installers
5353
run: |
5454
cd saf/dist/deb
5555
for file in saf_*.deb; do
56-
prefix=${file%.*-*.deb}
57-
prefix_ver=${prefix#saf_}
58-
suffix=${file#*_*_}
59-
sudo mv "$file" "saf-$prefix_ver-$suffix"
56+
prefix=${file%.*-*.deb}
57+
prefix_ver=${prefix#saf_}
58+
suffix=${file#*_*_}
59+
sudo mv "$file" "saf-$prefix_ver-$suffix"
6060
done
6161
6262
- name: Upload SAF-CLI Windows Build x64 Artifact

.github/workflows/e2e-ci.yml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,41 @@ jobs:
1212
strategy:
1313
fail-fast: true
1414
matrix:
15-
platform: [ ubuntu-latest, macos-latest, windows-latest ]
16-
runs-on: ${{ matrix.platform }}
15+
platform: [ ubuntu, macos, windows ]
16+
runs-on: ${{ matrix.platform }}-latest
1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v4
1919

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

27-
- name: Install dependencies on ${{ matrix.platform }}
28-
run: npm ci
27+
- name: Install dependencies on ${{ matrix.platform }}
28+
run: npm ci
29+
30+
- name: Install cinc-auditor/Compile/Run Tests on ${{ matrix.platform }}
31+
if: ${{ matrix.platform == 'windows-latest' }}
32+
shell: pwsh
33+
run: |
34+
Start-Process powershell -Verb RunAs
35+
. { iwr -useb https://omnitruck.cinc.sh/install.ps1 } | iex; install -project cinc-auditor
36+
$env:Path = $env:Path + ';C:\cinc-project\cinc-auditor\bin' + ';C:\cinc-project\cinc-auditor\embedded\bin'
37+
cinc-auditor -v
38+
npm run prepack
39+
npm run test
2940
30-
- name: Prepack (compile) on ${{ matrix.platform }}
31-
run: npm run prepack
41+
- name: Install cinc-auditor/Compile/Run Tests on ${{ matrix.platform }}
42+
if: ${{ matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest' }}
43+
run: |
44+
curl -L https://omnitruck.cinc.sh/install.sh | sudo bash -s -- -P cinc-auditor
45+
npm run prepack
46+
npm run test
3247
33-
- name: Run e2e tests on ${{ matrix.platform }}
34-
run: npm run test
48+
# - name: Prepack (compile) on ${{ matrix.platform }}
49+
# run: npm run prepack
50+
51+
# - name: Run e2e tests on ${{ matrix.platform }}
52+
# run: npm run test

src/commands/generate/delta.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,7 @@ export default class GenerateDelta extends BaseCommand<typeof GenerateDelta> {
378378
// Get the directory name without the trailing "controls" directory
379379
// Here we are using the newly updated (mapped) controls
380380
// const profileDir = path.dirname(controlsDir)
381-
// eslint-disable-next-line no-warning-comments
382-
// TODO: normally it's 'inspec json ...' but vscode doesn't recognize my alias?
383-
const inspecJsonFileNew = execSync(`inspec json '${mappedDir}'`, {encoding: 'utf8', maxBuffer: 50 * 1024 * 1024})
381+
const inspecJsonFileNew = execSync(`cinc-auditor json '${mappedDir}'`, {encoding: 'utf8', maxBuffer: 50 * 1024 * 1024})
384382

385383
// Replace existing profile (inputted JSON of source profile to be mapped)
386384
// Allow delta to take care of the rest

test/commands/generate/delta.test.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,24 @@ describe('Test generate delta command', () => {
9292
expect(fs.lstatSync((`${tmpobj.name}/delta.md`)).isFile()).to.be.true // skipcq: JS-0354
9393
})
9494

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

106-
// const output = stdout.split('\n')
107-
// expect(output.includes('Total Controls Found on Delta Directory: 5'))
108-
// expect(output.includes('Total Controls Found on XCCDF: 5'))
109-
// expect(output.includes('Match Controls: 5'))
110-
// expect(output.includes('["+","SV-254238"]'))
111-
// expect(output.includes('["+","SV-254239"]'))
112-
// expect(output.includes('["+","SV-254240"]'))
113-
// expect(output.includes('["+","SV-254241"]'))
114-
// expect(output.includes('["+","SV-254242"]'))
115-
// })
105+
const output = stdout.split('\n')
106+
expect(output.includes('Total Controls Found on Delta Directory: 5'))
107+
expect(output.includes('Total Controls Found on XCCDF: 5'))
108+
expect(output.includes('Match Controls: 5'))
109+
expect(output.includes('["+","SV-254238"]'))
110+
expect(output.includes('["+","SV-254239"]'))
111+
expect(output.includes('["+","SV-254240"]'))
112+
expect(output.includes('["+","SV-254241"]'))
113+
expect(output.includes('["+","SV-254242"]'))
114+
})
116115
})

0 commit comments

Comments
 (0)