Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delta fuzzy matching testing #3166

Merged
merged 12 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jobs:
run: |
cd dist/macos
for file in saf-*.pkg; do
prefix=${file%-*-*.pkg}
suffix=${file#saf-*-*-*}
mv "$file" "$prefix-$suffix"
prefix=${file%-*-*.pkg}
suffix=${file#saf-*-*-*}
mv "$file" "$prefix-$suffix"
done

- name: Upload SAF-CLI macOS Installer Artifact
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/build-windows-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ jobs:
run: |
cd saf/dist/win32
for file in saf-*.exe; do
prefix=${file%-*-*} # get prefix by removing frome end
suffix=${file#saf-*-*-} # get suffix by removing from start
mv "$file" "$prefix-$suffix"
prefix=${file%-*-*} # get prefix by removing from end
suffix=${file#saf-*-*-} # get suffix by removing from start
mv "$file" "$prefix-$suffix"
done

- name: Rename Debian Installers
run: |
cd saf/dist/deb
for file in saf_*.deb; do
prefix=${file%.*-*.deb}
prefix_ver=${prefix#saf_}
suffix=${file#*_*_}
sudo mv "$file" "saf-$prefix_ver-$suffix"
prefix=${file%.*-*.deb}
prefix_ver=${prefix#saf_}
suffix=${file#*_*_}
sudo mv "$file" "saf-$prefix_ver-$suffix"
done

- name: Upload SAF-CLI Windows Build x64 Artifact
Expand Down
48 changes: 33 additions & 15 deletions .github/workflows/e2e-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,41 @@ jobs:
strategy:
fail-fast: true
matrix:
platform: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
platform: [ ubuntu, macos, windows ]
runs-on: ${{ matrix.platform }}-latest
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: Install cinc-auditor/Compile/Run Tests on ${{ matrix.platform }}
if: ${{ matrix.platform == 'windows-latest' }}
shell: pwsh
run: |
Start-Process powershell -Verb RunAs
. { iwr -useb https://omnitruck.cinc.sh/install.ps1 } | iex; install -project cinc-auditor
$env:Path = $env:Path + ';C:\cinc-project\cinc-auditor\bin' + ';C:\cinc-project\cinc-auditor\embedded\bin'
cinc-auditor -v
npm run prepack
npm run test

- name: Prepack (compile) on ${{ matrix.platform }}
run: npm run prepack
- name: Install cinc-auditor/Compile/Run Tests 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
npm run prepack
npm run test

- 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"]'))
})
})
Loading