Skip to content

Commit

Permalink
Merge pull request snyk#275 from snyk/feat/docker-monitor-sends-docke…
Browse files Browse the repository at this point in the history
…rfile

feat: send the base image when running `snyk monitor`
  • Loading branch information
Dar Malovani committed Nov 19, 2018
2 parents 88ec98d + b2d4863 commit e014a67
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ ignore:
'npm:mem:20180117':
- nyc > yargs > os-locale > mem:
reason: DoS vulnerability is not valid for CLI tool
expires: '2018-11-19T10:35:25.346Z'
expires: '2018-12-19T10:35:25.346Z'
- tap > nyc > yargs > os-locale > mem:
reason: DoS vulnerability is not valid for CLI tool
expires: '2018-11-19T10:35:25.346Z'
expires: '2018-12-19T10:35:25.346Z'
patch: {}
2 changes: 1 addition & 1 deletion src/cli/commands/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function monitor() {

var packageManager = detect.detectPackageManager(path, options);

var targetFile = options.docker
var targetFile = options.docker && !options.file // snyk monitor --docker (without --file)
? undefined
: (options.file || detect.detectPackageFile(path));

Expand Down
44 changes: 44 additions & 0 deletions test/acceptance/cli.acceptance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,50 @@ function (t) {
});
});

test('`monitor foo:latest --docker --file=Dockerfile`',
function (t) {
var dockerImageId = 'sha256:' +
'578c3e61a98cb5720e7c8fc152017be1dff373ebd72a32bbe6e328234efc8d1a';
var plugin = {
inspect: function () {
return Promise.resolve({
plugin: {
packageManager: 'rpm',
dockerImageId: dockerImageId,
},
package: {docker: 'base-image-name'},
});
},
};
sinon.spy(plugin, 'inspect');

sinon.stub(plugins, 'loadPlugin')
.withArgs(sinon.match.any, sinon.match({docker: true}))
.returns(plugin);
t.teardown(plugins.loadPlugin.restore);

return cli.monitor('foo:latest', {
docker: true,
org: 'explicit-org',
file: 'Dockerfile',
})
.then(function () {
var req = server.popRequest();
t.equal(req.method, 'PUT', 'makes PUT request');
t.match(req.url, '/monitor/rpm',
'puts at correct url (uses package manager from plugin response)');
t.equal(req.body.meta.dockerImageId, dockerImageId, 'sends dockerImageId');
t.equal(req.body.package.docker, 'base-image-name', 'sends base image');
t.same(plugin.inspect.getCall(0).args,
['foo:latest', 'Dockerfile', {
args: null,
docker: true,
file: 'Dockerfile',
org: 'explicit-org',
}], 'calls docker plugin with expected arguments');
});
});

test('`monitor foo:latest --docker` doesnt send policy from cwd',
function (t) {
chdirWorkspaces('npm-package-policy');
Expand Down

0 comments on commit e014a67

Please sign in to comment.