Skip to content

Commit

Permalink
feat: add platform metadata to human-readable output
Browse files Browse the repository at this point in the history
  • Loading branch information
dkontorovskyy committed Oct 15, 2020
1 parent e30142b commit ab2ddc5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cli/commands/test/formatters/format-test-meta.ts
Expand Up @@ -43,6 +43,13 @@ export function formatTestMeta(
chalk.bold(rightPadWithSpaces('Docker image: ', padToLength)) +
options.path,
);

if (res.platform) {
meta.push(
chalk.bold(rightPadWithSpaces('Platform: ', padToLength)) +
res.platform,
);
}
} else {
meta.push(
chalk.bold(rightPadWithSpaces('Open source: ', padToLength)) + openSource,
Expand Down
1 change: 1 addition & 0 deletions src/lib/snyk-test/legacy.ts
Expand Up @@ -146,6 +146,7 @@ export interface BasicResultData {
summary: string;
packageManager?: SupportedProjectTypes;
severityThreshold?: string;
platform?: string;
}

export interface LegacyVulnApiResult extends BasicResultData {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/snyk-test/run-test.ts
Expand Up @@ -109,6 +109,8 @@ function prepareEcosystemResponseForParsing(
const projectName = payloadBody?.name || depGraph?.rootPkg.name;
const packageManager = payloadBody?.identity?.type as SupportedProjectTypes;
const targetFile = payloadBody?.identity?.targetFile || options.file;
const platform = payloadBody?.identity?.args?.platform;

return {
depGraph,
dockerfilePackages,
Expand All @@ -118,6 +120,7 @@ function prepareEcosystemResponseForParsing(
displayTargetFile: targetFile,
foundProjectCount: undefined,
payloadPolicy: payloadBody?.policy,
platform,
};
}

Expand Down Expand Up @@ -248,6 +251,7 @@ async function sendAndParseResults(
foundProjectCount,
displayTargetFile,
dockerfilePackages,
platform,
} = prepareResponseForParsing(
payloadCopy,
res as TestDependenciesResponse,
Expand Down Expand Up @@ -279,6 +283,7 @@ async function sendAndParseResults(
projectName,
foundProjectCount,
displayTargetFile,
platform,
});
}
}
Expand Down
77 changes: 77 additions & 0 deletions test/acceptance/cli-test/cli-test.docker.spec.ts
Expand Up @@ -76,6 +76,83 @@ export const DockerTests: AcceptanceTests = {
);
},

'`test foo:latest --docker --platform=linux/amd64`': (params) => async (
t,
) => {
const spyPlugin = stubDockerPluginResponse(
params.ecoSystemPlugins,
{
scanResults: [
{
facts: [
{ type: 'depGraph', data: {} },
{ type: 'dockerfileAnalysis', data: {} },
],
identity: {
type: 'deb',
args: {
platform: 'linux/amd64',
},
},
target: {
image: 'docker-image|ubuntu',
},
},
],
},
t,
);

await params.cli.test('foo:latest', {
docker: true,
org: 'explicit-org',
});
const req = params.server.popRequest();
t.equal(req.method, 'POST', 'makes POST request');
t.equal(
req.headers['x-snyk-cli-version'],
params.versionNumber,
'sends version number',
);
t.match(req.url, '/test-dependencies', 'posts to correct url');
t.deepEqual(
req.body,
{
scanResult: {
facts: [
{ type: 'depGraph', data: {} },
{ type: 'dockerfileAnalysis', data: {} },
],
identity: {
type: 'deb',
args: {
platform: 'linux/amd64',
},
},
target: {
image: 'docker-image|ubuntu',
},
},
},
'sends correct payload',
);
t.same(
spyPlugin.getCall(0).args,
[
{
docker: true,
org: 'explicit-org',
projectName: null,
packageManager: null,
pinningSupported: null,
path: 'foo:latest',
showVulnPaths: 'some',
},
],
'calls docker plugin with expected arguments',
);
},

'`test foo:latest --docker vulnerable paths`': (params) => async (t) => {
stubDockerPluginResponse(
params.ecoSystemPlugins,
Expand Down

0 comments on commit ab2ddc5

Please sign in to comment.