Skip to content
Draft
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
24 changes: 23 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/lib/plugins/sast/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { analysisProgressUpdate } from './utils';
import { FeatureNotSupportedBySnykCodeError } from './errors';
import { getProxyForUrl } from 'proxy-from-env';
import { generateTags } from '../../../cli/commands/monitor';
import { bootstrap } from 'global-agent';
import chalk from 'chalk';
import * as debugLib from 'debug';
Expand Down Expand Up @@ -210,6 +211,7 @@ async function getCodeAnalysis(
targetName: options['target-name'],
targetRef: options['target-reference'],
remoteRepoUrl: options['remote-repo-url'],
tags: generateTags(options),
},
}),
analysisContext,
Expand Down
74 changes: 74 additions & 0 deletions test/jest/unit/snyk-code/snyk-code-test-report.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,80 @@ describe('Test snyk code with --report', () => {

expect(actual?.reportResults).toEqual(expectedReportResults);
});

it('should pass project-tags to reportOptions when provided', async () => {
const tags = [
{ key: 'env', value: 'prod' },
{ key: 'team', value: 'security' },
];

const reportOptions = {
enabled: true,
projectName: 'test-project-name',
targetName: 'test-target-name',
targetRef: 'test-target-ref',
remoteRepoUrl: 'https://github.com/owner/repo',
tags,
};

analyzeFoldersMock.mockResolvedValue(
sampleAnalyzeFoldersWithReportAndIgnoresResponse,
);

await getCodeTestResults(
'.',
{
path: '',
code: true,
report: true,
'project-name': reportOptions.projectName,
'target-name': reportOptions.targetName,
'target-reference': reportOptions.targetRef,
'remote-repo-url': reportOptions.remoteRepoUrl,
'project-tags': 'env=prod,team=security',
},
sastSettings,
'test-id',
);

expect(analyzeFoldersMock).toHaveBeenCalledWith(
expect.objectContaining({
reportOptions: expect.objectContaining({
enabled: true,
projectName: reportOptions.projectName,
tags,
}),
}),
);
});

it('should not include tags in reportOptions when project-tags is not provided', async () => {
analyzeFoldersMock.mockResolvedValue(
sampleAnalyzeFoldersWithReportAndIgnoresResponse,
);

await getCodeTestResults(
'.',
{
path: '',
code: true,
report: true,
'project-name': 'test-project',
},
sastSettings,
'test-id',
);

expect(analyzeFoldersMock).toHaveBeenCalledWith(
expect.objectContaining({
reportOptions: expect.objectContaining({
enabled: true,
projectName: 'test-project',
tags: undefined,
}),
}),
);
});
});

describe('SCM-based report flow - analyzeScmProject', () => {
Expand Down