Skip to content

Commit

Permalink
Merge pull request #3867 from snyk/feat/update-iac-cloud-integrated-ff
Browse files Browse the repository at this point in the history
feat: Update feature gating for new IaC Integrated experience [CFG-2163, CFG-2168]
  • Loading branch information
ofekatr committed Sep 29, 2022
2 parents 9e2d5f1 + 72bed38 commit 14996c2
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/cli/commands/test/iac/v2/assert-iac-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const keys: (keyof IaCTestFlags)[] = [
'json-file-output',
'sarif-file-output',
'scan',
'experimental',
'var-file',
'detectionDepth',
'cloud-context',
Expand Down
5 changes: 5 additions & 0 deletions src/cli/commands/test/iac/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getFlag } from '../index';
import { IaCTestFlags } from '../local-execution/types';
import { findAndLoadPolicy } from '../../../../../lib/policy';
import { assertIacV2Options } from './assert-iac-options';
import { UnsupportedEntitlementError } from '../../../../../lib/errors/unsupported-entitlement-error';

export async function test(
paths: string[],
Expand All @@ -23,6 +24,10 @@ export async function test(
const testConfig = await prepareTestConfig(paths, options);
const { orgSettings } = testConfig;

if (!orgSettings.entitlements?.infrastructureAsCode) {
throw new UnsupportedEntitlementError('infrastructureAsCode');
}

const testSpinner = buildSpinner(options);

printHeader(options);
Expand Down
5 changes: 1 addition & 4 deletions src/cli/commands/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ export default async function test(
const options = setDefaultTestOptions(originalOptions);
if (originalOptions.iac) {
// temporary placeholder for the "new" flow that integrates with UPE
if (
(await hasFeatureFlag('iacCliUnifiedEngine', options)) &&
options.experimental
) {
if (await hasFeatureFlag('iacIntegratedExperience', options)) {
return await iacTestCommandV2.test(paths, originalOptions);
} else {
return await iacTestCommand(...args);
Expand Down
5 changes: 4 additions & 1 deletion test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import * as path from 'path';
import { getFixturePath } from '../jest/util/getFixturePath';

const featureFlagDefaults = (): Map<string, boolean> => {
return new Map([['cliFailFast', false]]);
return new Map([
['cliFailFast', false],
['iacIntegratedExperience', false],
]);
};

export type FakeServer = {
Expand Down
3 changes: 3 additions & 0 deletions test/jest/unit/cli/commands/test/iac/v2/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ describe('test', () => {
isLicensesEnabled: false,
isPrivate: false,
},
entitlements: {
infrastructureAsCode: true,
},
};

const scanFixture = JSON.parse(fs.readFileSync(scanFixturePath, 'utf-8'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ console.log(JSON.stringify(scanResult, null, 2));
```
3. scan the directory by running the following command:
```
snyk-dev iac test --experimental vpc_group.tf plan.json invalid_file.txt
snyk-dev iac test vpc_group.tf plan.json invalid_file.txt
```
4. save the scan results in the [primary fixture file](../snyk-iac-test-results.json)
5. start regenerating fixtures like a mad (wo)man!!!
14 changes: 7 additions & 7 deletions test/jest/unit/lib/iac/test/v2/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('convertEngineToJsonResults', () => {
return isError ? new SnykIacTestError(item) : item;
});

const experimentalJsonOutputFixtureContent = fs.readFileSync(
const integratedJsonOutputFixtureContent = fs.readFileSync(
path.join(
__dirname,
'..',
Expand All @@ -40,15 +40,15 @@ describe('convertEngineToJsonResults', () => {
'iac',
'process-results',
'fixtures',
'experimental-json-output.json',
'integrated-json-output.json',
),
'utf-8',
);
let experimentalJsonOutputFixture: Array<Result | ScanError> = JSON.parse(
experimentalJsonOutputFixtureContent,
let integratedJsonOutputFixture: Array<Result | ScanError> = JSON.parse(
integratedJsonOutputFixtureContent,
);

experimentalJsonOutputFixture = experimentalJsonOutputFixture.map((item) =>
integratedJsonOutputFixture = integratedJsonOutputFixture.map((item) =>
!('error' in item) ? { ...item, path: process.cwd() } : item,
);

Expand All @@ -75,12 +75,12 @@ describe('convertEngineToJsonResults', () => {
orgSettings,
});

experimentalJsonOutputFixture.forEach((item) => {
integratedJsonOutputFixture.forEach((item) => {
if ('targetFilePath' in item) {
item.targetFilePath = path.resolve(item.targetFile);
}
});

expect(result).toEqual(experimentalJsonOutputFixture);
expect(result).toEqual(integratedJsonOutputFixture);
});
});
12 changes: 6 additions & 6 deletions test/jest/unit/lib/iac/test/v2/sarif.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('convertEngineToSarifResults', () => {
);
const snykIacTestFixture: TestOutput = JSON.parse(snykIacTestFixtureContent);

const experimentalSarifOutputFixtureContent = fs.readFileSync(
const integratedSarifOutputFixtureContent = fs.readFileSync(
path.join(
__dirname,
'..',
Expand All @@ -32,21 +32,21 @@ describe('convertEngineToSarifResults', () => {
'iac',
'process-results',
'fixtures',
'experimental-sarif-output.json',
'integrated-sarif-output.json',
),
'utf-8',
);
const experimentalSarifOutputFixture: sarif.Log = JSON.parse(
experimentalSarifOutputFixtureContent,
const integratedSarifOutputFixture: sarif.Log = JSON.parse(
integratedSarifOutputFixtureContent,
);

experimentalSarifOutputFixture.runs[0].originalUriBaseIds!.PROJECTROOT.uri = pathToFileURL(
integratedSarifOutputFixture.runs[0].originalUriBaseIds!.PROJECTROOT.uri = pathToFileURL(
process.cwd() + '/',
).href;

it('returns expected SARIF result', () => {
const result = convertEngineToSarifResults(snykIacTestFixture);

expect(result).toEqual(experimentalSarifOutputFixture);
expect(result).toEqual(integratedSarifOutputFixture);
});
});
6 changes: 2 additions & 4 deletions test/smoke/iac/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { run } from '../../jest/acceptance/iac/helpers';

jest.setTimeout(1_000 * 90);

describe('snyk iac test --experimental', () => {
describe('snyk iac test', () => {
beforeAll(async () => {
await login();
});
Expand All @@ -12,9 +12,7 @@ describe('snyk iac test --experimental', () => {
const filePath = 'iac/depth_detection/root.tf';

// Act
const { stderr, stdout, exitCode } = await run(
`snyk iac test --experimental ${filePath}`,
);
const { stderr, stdout, exitCode } = await run(`snyk iac test ${filePath}`);

// Assert
expect(stdout).toContain('Infrastructure as Code');
Expand Down

0 comments on commit 14996c2

Please sign in to comment.