Skip to content
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
12 changes: 0 additions & 12 deletions src/cli/commands/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import {
import {
PNPM_FEATURE_FLAG,
UV_FEATURE_FLAG,
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
MAVEN_DVERBOSE_EXHAUSTIVE_DEPS_FF,
} from '../../../lib/package-managers';
import { normalizeTargetFile } from '../../../lib/normalize-target-file';
Expand Down Expand Up @@ -204,19 +203,12 @@ export default async function monitor(...args0: MethodArgs): Promise<any> {
}

let hasPnpmSupport = false;
let hasImprovedDotnetWithoutPublish = false;
let enableMavenDverboseExhaustiveDeps = false;
try {
hasPnpmSupport = (await hasFeatureFlag(
PNPM_FEATURE_FLAG,
options,
)) as boolean;
if (options['dotnet-runtime-resolution']) {
hasImprovedDotnetWithoutPublish = (await hasFeatureFlag(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
)) as boolean;
}
} catch (err) {
hasPnpmSupport = false;
}
Expand Down Expand Up @@ -253,10 +245,6 @@ export default async function monitor(...args0: MethodArgs): Promise<any> {
featureFlags.add(UV_FEATURE_FLAG);
}

if (hasImprovedDotnetWithoutPublish) {
options.useImprovedDotnetWithoutPublish = true;
}

const showMavenScope = await isFeatureFlagSupportedForOrg(
SHOW_MAVEN_BUILD_SCOPE,
getOrganizationID(),
Expand Down
2 changes: 0 additions & 2 deletions src/lib/package-managers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export const PNPM_FEATURE_FLAG = 'enablePnpmCli';
export const UV_FEATURE_FLAG = 'enableUvCLI';
export const DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG =
'useImprovedDotnetWithoutPublish';
export const MAVEN_DVERBOSE_EXHAUSTIVE_DEPS_FF =
'enableMavenDverboseExhaustiveDeps';

Expand Down
11 changes: 0 additions & 11 deletions src/lib/snyk-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {
} = require('../feature-flags');
const {
PNPM_FEATURE_FLAG,
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
MAVEN_DVERBOSE_EXHAUSTIVE_DEPS_FF,
} = require('../package-managers');
const { getOrganizationID } = require('../organization');
Expand All @@ -39,19 +38,9 @@ async function test(root, options, callback) {

async function executeTest(root, options) {
let hasPnpmSupport = false;
let hasImprovedDotnetWithoutPublish = false;
let enableMavenDverboseExhaustiveDeps = false;
try {
hasPnpmSupport = await hasFeatureFlag(PNPM_FEATURE_FLAG, options);
if (options['dotnet-runtime-resolution']) {
hasImprovedDotnetWithoutPublish = await hasFeatureFlag(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
);
if (hasImprovedDotnetWithoutPublish) {
options.useImprovedDotnetWithoutPublish = true;
}
}
} catch (err) {
hasPnpmSupport = false;
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export interface Options {
'exclude-unmanaged'?: boolean;

// Feature Flags
useImprovedDotnetWithoutPublish?: boolean;
disableContainerMonitorProjectNameFix?: boolean;

// Plugin configuration options
Expand Down
1 change: 0 additions & 1 deletion test/acceptance/fake-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const featureFlagDefaults = (): Map<string, boolean> => {
['enablePnpmCli', false],
['enableUvCLI', false],
['sbomMonitorBeta', false],
['useImprovedDotnetWithoutPublish', false],
['scanUsrLibJars', false],
['disableContainerMonitorProjectNameFix', false],
['show-maven-build-scope', false],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,6 @@ describe.each(userJourneyWorkflows)(
])(
'run `snyk test` on a $description',
async ({ fixture, projectFile }) => {
server.setFeatureFlag('useImprovedDotnetWithoutPublish', true);

let prerequisite = await runCommand('dotnet', ['--version']).catch(
function () {
return { code: 1, stderr: '', stdout: '' };
Expand Down
167 changes: 12 additions & 155 deletions test/jest/unit/cli-commands/test-and-monitor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import monitor from '../../../../src/cli/commands/monitor';
import { DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG } from '../../../../src/lib/package-managers';
import * as featureFlags from '../../../../src/lib/feature-flags';
import {
SCAN_USR_LIB_JARS_FEATURE_FLAG,
Expand All @@ -9,7 +8,6 @@ import {
} from '../../../../src/cli/commands/constants';
import * as ecosystems from '../../../../src/lib/ecosystems';
import * as analytics from '../../../../src/lib/analytics';
import * as snykMonitor from '../../../../src/lib/monitor';
import config from '../../../../src/lib/config';
import { apiOrOAuthTokenExists } from '../../../../src/lib/api-token';
import { runTest } from '../../../../src/lib/snyk-test/run-test';
Expand All @@ -23,6 +21,8 @@ jest.mock('../../../../src/lib/formatters');
jest.mock('../../../../src/lib/plugins/get-deps-from-plugin');
jest.mock('../../../../src/lib/spinner');
jest.mock('../../../../src/lib/snyk-test/run-test');
jest.mock('../../../../src/lib/analytics');
jest.mock('../../../../src/lib/monitor');
jest.mock('../../../../src/lib/feature-flags');
jest.mock('../../../../src/lib/protect-update-notification', () => ({
getPackageJsonPathsContainingSnykDependency: jest.fn(() => []),
Expand All @@ -42,20 +42,13 @@ jest.mock('../../../../src/lib/snyk-test/legacy', () => ({
test: jest.fn(() => Promise.resolve({})),
}));

const snykTest = require('../../../../src/lib/snyk-test');

describe('monitor & test', () => {
let getEcosystemSpy: jest.SpyInstance;
let analyticsSpy: jest.SpyInstance;
let snykMonitorSpy: jest.SpyInstance;
let detectSpy: jest.SpyInstance;

beforeEach(() => {
getEcosystemSpy = jest.spyOn(ecosystems, 'getEcosystem');
analyticsSpy = jest.spyOn(analytics, 'allowAnalytics');
snykMonitorSpy = jest.spyOn(snykMonitor, 'monitor');
(apiOrOAuthTokenExists as jest.Mock).mockReturnValue(true);
(featureFlags.hasFeatureFlag as jest.Mock).mockResolvedValue(false);
(featureFlags.isFeatureFlagSupportedForOrg as jest.Mock).mockResolvedValue({
ok: false,
});

// mock config values
Object.defineProperty(config, 'PROJECT_NAME', {
Expand All @@ -64,164 +57,28 @@ describe('monitor & test', () => {
});

afterEach(() => {
getEcosystemSpy.mockRestore();
analyticsSpy.mockRestore();
snykMonitorSpy.mockRestore();
detectSpy?.mockRestore();
(featureFlags.hasFeatureFlag as jest.Mock).mockResolvedValue(false);
});

describe('monitor', () => {
it('should set useImprovedDotnetWithoutPublish on options when the feature flag is enabled', async () => {
getEcosystemSpy.mockReturnValue(undefined);
analyticsSpy.mockReturnValue(false);
const options: any = {
'dotnet-runtime-resolution': true,
};
(featureFlags.hasFeatureFlag as jest.Mock).mockResolvedValue(true);
(
featureFlags.isFeatureFlagSupportedForOrg as jest.Mock
).mockResolvedValue({ ok: true });

try {
await monitor('path/to/project', options);
} catch (error) {
// We expect this to fail since we are not mocking all dependencies.
// We only care about the options being set correctly.
}

expect(featureFlags.hasFeatureFlag).toHaveBeenCalledWith(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
);
expect(options.useImprovedDotnetWithoutPublish).toBe(true);
});

it('should not set useImprovedDotnetWithoutPublish on options when the feature flag is disabled', async () => {
getEcosystemSpy.mockReturnValue(undefined);
analyticsSpy.mockReturnValue(false);
const options: any = {
'dotnet-runtime-resolution': true,
};
(featureFlags.hasFeatureFlag as jest.Mock).mockResolvedValue(false);

try {
await monitor('path/to/project', options);
} catch (error) {
// We expect this to fail since we are not mocking all dependencies.
// We only care about the options being set correctly.
}

expect(featureFlags.hasFeatureFlag).toHaveBeenCalledWith(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
);
expect(options.useImprovedDotnetWithoutPublish).toBeUndefined();
});

it('should not check the feature flag if dotnet-runtime-resolution is not enabled', async () => {
getEcosystemSpy.mockReturnValue(undefined);
analyticsSpy.mockReturnValue(false);
const options: any = {};

try {
await monitor('path/to/project', options);
} catch (error) {
// We expect this to fail since we are not mocking all dependencies.
// We only care about the options being set correctly.
}

expect(featureFlags.hasFeatureFlag).not.toHaveBeenCalledWith(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
);
expect(options.useImprovedDotnetWithoutPublish).toBeUndefined();
});
});

describe('test', () => {
beforeEach(() => {
(runTest as jest.Mock).mockResolvedValue([]);
detectSpy = jest
.spyOn(detect, 'detectPackageManager')
.mockReturnValue('nuget');
});

it('should set useImprovedDotnetWithoutPublish on options when the feature flag is enabled', async () => {
const options: any = {
'dotnet-runtime-resolution': true,
};
(featureFlags.hasFeatureFlag as jest.Mock).mockResolvedValue(true);
(
featureFlags.isFeatureFlagSupportedForOrg as jest.Mock
).mockResolvedValue({ ok: true });
await snykTest('path/to/project', options);

expect(featureFlags.hasFeatureFlag).toHaveBeenCalledWith(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
);
expect(options.useImprovedDotnetWithoutPublish).toBe(true);

expect(detectSpy).toHaveBeenCalled();
const [, , featureFlagsArg] = detectSpy.mock.calls[0];
expect([...featureFlagsArg]).toEqual(
expect.arrayContaining([
'enablePnpmCli',
'show-maven-build-scope',
'show-npm-scope',
]),
);
});

it('should not set useImprovedDotnetWithoutPublish on options when the feature flag is disabled', async () => {
const options: any = {
'dotnet-runtime-resolution': true,
};
(featureFlags.hasFeatureFlag as jest.Mock).mockResolvedValue(false);
await snykTest('path/to/project', options);

expect(featureFlags.hasFeatureFlag).toHaveBeenCalledWith(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
);
expect(options.useImprovedDotnetWithoutPublish).toBeUndefined();
});

it('should not check the feature flag if dotnet-runtime-resolution is not enabled', async () => {
const options: any = {};
await snykTest('path/to/project', options);

expect(featureFlags.hasFeatureFlag).not.toHaveBeenCalledWith(
DOTNET_WITHOUT_PUBLISH_FEATURE_FLAG,
options,
);
expect(options.useImprovedDotnetWithoutPublish).toBeUndefined();
});
jest.restoreAllMocks();
});

describe('docker scanUsrLibJars feature flag', () => {
beforeEach(() => {
getEcosystemSpy.mockReturnValue(undefined); // Don't use ecosystem for these tests
analyticsSpy.mockReturnValue(false);
(ecosystems.getEcosystem as jest.Mock).mockReturnValue(undefined);
(analytics.allowAnalytics as jest.Mock).mockReturnValue(false);
});

describe('test command', () => {
let capturedOptions: any = null;

beforeEach(() => {
// Mock the ecosystem detection to return null so it uses the legacy path
jest.spyOn(ecosystems, 'getEcosystemForTest').mockReturnValue(null);
// Mock runTest to return empty array and capture the options
(ecosystems.getEcosystemForTest as jest.Mock).mockReturnValue(null);
capturedOptions = null;
(runTest as jest.Mock).mockImplementation(
(projectType, root, options) => {
capturedOptions = options;
return Promise.resolve([]);
},
);
// Mock detectPackageManager
jest.spyOn(detect, 'detectPackageManager').mockReturnValue('docker');
(detect.detectPackageManager as jest.Mock).mockReturnValue('docker');
});

it('should set include-system-jars when scanUsrLibJars feature flag is enabled', async () => {
Expand Down Expand Up @@ -427,8 +284,8 @@ describe('monitor & test', () => {

describe('docker disableContainerMonitorProjectNameFix feature flag', () => {
beforeEach(() => {
getEcosystemSpy.mockReturnValue(undefined);
analyticsSpy.mockReturnValue(false);
(ecosystems.getEcosystem as jest.Mock).mockReturnValue(undefined);
(analytics.allowAnalytics as jest.Mock).mockReturnValue(false);
});

describe('monitor command', () => {
Expand Down