Skip to content

Commit

Permalink
fix: check iacNewEngine FF and pass it to snyk-iac-test [IAC-3059]
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-snyk committed Oct 2, 2024
1 parent 2d2c348 commit 978c8b1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/cli/commands/test/iac/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { assertIacV2Options } from './assert-iac-options';
export async function test(
paths: string[],
options: IaCTestFlags,
iacNewEngine?: boolean,
): Promise<TestCommandResult> {
assertIacV2Options(options);
const testConfig = await prepareTestConfig(paths, options);
const testConfig = await prepareTestConfig(paths, options, iacNewEngine);

const testSpinner = buildSpinner(options);

Expand All @@ -41,6 +42,7 @@ export async function test(
async function prepareTestConfig(
paths: string[],
options: IaCTestFlags,
iacNewEngine?: boolean,
): Promise<TestConfig> {
const iacCachePath = pathLib.join(systemCachePath, 'iac');

Expand Down Expand Up @@ -86,5 +88,6 @@ async function prepareTestConfig(
org,
customRules,
experimental,
iacNewEngine,
};
}
10 changes: 8 additions & 2 deletions src/cli/commands/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ export default async function test(
const { options: originalOptions, paths } = processCommandArgs(...args);

const options = setDefaultTestOptions(originalOptions);

if (originalOptions.iac) {
const iacNewEngine = await hasFeatureFlag('iacNewEngine', options);
const iacIntegratedExperience = await hasFeatureFlag(
'iacIntegratedExperience',
options,
);
// temporary placeholder for the "new" flow that integrates with UPE
if (await hasFeatureFlag('iacIntegratedExperience', options)) {
return await iacTestCommandV2.test(paths, originalOptions);
if (iacIntegratedExperience || iacNewEngine) {
return await iacTestCommandV2.test(paths, originalOptions, iacNewEngine);
} else {
return await iacTestCommand(...args);
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/iac/test/v2/local-cache/policy-engine/constants/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as os from 'os';

const policyEngineChecksums = `
64d72e61b1b39ae74c069667b9ada4edfe6343df1fceeef49fbee54b60d8013d snyk-iac-test_0.55.1_Darwin_arm64
86b1db19a733afdf623ac5dfcb4f59f29a534997673efc94b9a0b4c14aa6abff snyk-iac-test_0.55.1_Darwin_x86_64
a4e30ef1e973a323a2fce72ba8dc7d507b74fd7c524b2a4e7617958980146860 snyk-iac-test_0.55.1_Linux_arm64
e0ecebc81e619b4e7f6616c720f30150cb373548937e78f8eb42878516a087f5 snyk-iac-test_0.55.1_Linux_x86_64
f8a8c2aa8081027baceae917dbecfacdb06c1fc8710b4d17d71ace96704112ce snyk-iac-test_0.55.1_Windows_x86_64.exe
020098c4dce6a7412e7aaffc379f5b668886ce1dfbcb584241985ac4de6be7f4 snyk-iac-test_0.56.0_Darwin_arm64
07a682745d31048a1d279da53cdda2ddf75607bc90348d18d9c6b86cbeff6b81 snyk-iac-test_0.56.0_Windows_x86_64.exe
1f46cc456e5261bf7b789a44621dfc1e1676b48679e9e89478107f40636011e6 snyk-iac-test_0.56.0_Darwin_x86_64
4f58f39a93119a8acd74469d54f3bee53c4fb0e22a161b3311ccb9ac4cef4dad snyk-iac-test_0.56.0_Linux_arm64
e29ace0c3d2ac60b2aec2ed50a93c8e6ba839cecb75dc6f057d02dc21a090e96 snyk-iac-test_0.56.0_Linux_x86_64
`;

export const policyEngineVersion = getPolicyEngineVersion();
Expand Down
4 changes: 4 additions & 0 deletions src/lib/iac/test/v2/scan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ function processFlags(
flags.push('-rulesClientURL', rulesClientURL);
}

if (options.iacNewEngine) {
flags.push('-iac-new-engine');
}

return flags;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/iac/test/v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface TestConfig {
org?: string;
customRules?: boolean;
experimental?: boolean;
iacNewEngine?: boolean;
}
6 changes: 4 additions & 2 deletions test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as bodyParser from 'body-parser';
import * as express from 'express';
import * as fs from 'fs';
import * as http from 'http';
import * as http from 'http';
import * as https from 'https';
import * as path from 'path';
import * as net from 'net';
Expand All @@ -12,6 +12,8 @@ const featureFlagDefaults = (): Map<string, boolean> => {
return new Map([
['cliFailFast', false],
['iacIntegratedExperience', false],
['iacCliShareResults', false],
['iacNewEngine', false],
['containerCliAppVulnsEnabled', true],
['enablePnpmCli', false],
]);
Expand All @@ -24,7 +26,7 @@ export function getFirstIPv4Address(): string {
for (const [, group] of Object.entries(interfaces)) {
if (group) {
for (const inter of group) {
if (inter && inter.family == 'IPv4' && inter.address != '127.0.0.1') {
if (inter && inter.family == 'IPv4' && inter.address != '127.0.0.1' ) {
ipaddress = inter.address;
break;
}
Expand Down
27 changes: 20 additions & 7 deletions test/jest/acceptance/iac/cli-share-results.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ describe('CLI Share Results', () => {

afterAll(async () => teardown());

describe('feature flag is not enabled', () => {
beforeAll(() => {
server.setFeatureFlag('iacCliShareResults', false);
});

describe('feature flag iacCliShareResults is not enabled', () => {
it('the output includes an error', async () => {
const { stdout, exitCode } = await run(
`snyk iac test ./iac/arm/rule_test.json --report`,
Expand All @@ -40,8 +36,8 @@ describe('CLI Share Results', () => {
});
});

describe('feature flag is enabled', () => {
beforeAll(() => {
describe('feature flag iacCliShareResults is enabled', () => {
beforeEach(() => {
server.setFeatureFlag('iacCliShareResults', true);
});

Expand Down Expand Up @@ -252,4 +248,21 @@ describe('CLI Share Results', () => {
});
});
});

describe('feature flag iacNewEngine is enabled', () => {
beforeEach(() => {
server.setFeatureFlag('iacNewEngine', true);
});

it('the output includes an error', async () => {
const { stdout, exitCode } = await run(
`snyk iac test ./iac/arm/rule_test.json --report`,
);

expect(stdout).toMatch(
'flag --report is not yet supported when iacNewEngine flag is enabled',
);
expect(exitCode).toBe(2);
});
});
});

0 comments on commit 978c8b1

Please sign in to comment.