From 107d16ba792689c3cdba119a0ff0961e7d265088 Mon Sep 17 00:00:00 2001 From: Michael Gokhman Date: Thu, 28 Sep 2017 13:20:15 +0300 Subject: [PATCH] feat: dep & govendor as separate pkg managers --- cli/commands/protect/index.js | 3 ++- cli/commands/protect/wizard.js | 3 ++- lib/detect.js | 4 ++-- lib/plugins/index.js | 3 ++- lib/snyk-test/index.js | 12 +++++++++-- test/acceptance/cli.acceptance.test.js | 28 +++++++++++++------------- 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/cli/commands/protect/index.js b/cli/commands/protect/index.js index efc1907212..a150a883a3 100644 --- a/cli/commands/protect/index.js +++ b/cli/commands/protect/index.js @@ -13,7 +13,8 @@ var unsupportedPackageManagers = { pip: 'Python', sbt: 'SBT', gradle: 'Gradle', - golang: 'Golang', + golangdep: 'Golang/Dep', + govendor: 'Govendor', nuget: 'NuGet', composer: 'Composer', }; diff --git a/cli/commands/protect/wizard.js b/cli/commands/protect/wizard.js index 85af467eb3..8cc3a88285 100644 --- a/cli/commands/protect/wizard.js +++ b/cli/commands/protect/wizard.js @@ -39,7 +39,8 @@ var unsupportedPackageManagers = { pip: 'Python', sbt: 'SBT', gradle: 'Gradle', - golang: 'Golang', + golangdep: 'Golang/Dep', + govendor: 'Govendor', nuget: 'NuGet', composer: 'Composer', }; diff --git a/lib/detect.js b/lib/detect.js index 6c7cbcc78a..e60c65307e 100644 --- a/lib/detect.js +++ b/lib/detect.js @@ -28,8 +28,8 @@ var DETECTABLE_PACKAGE_MANAGERS = { 'build.sbt': 'sbt', 'yarn.lock': 'yarn', 'requirements.txt': 'pip', - 'Gopkg.lock': 'golang', - 'vendor.json': 'golang', + 'Gopkg.lock': 'golangdep', + 'vendor.json': 'govendor', 'project.json': 'nuget', 'project.assets.json': 'nuget', 'packages.config': 'nuget', diff --git a/lib/plugins/index.js b/lib/plugins/index.js index 5a256cc4d3..1260bc69cf 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -25,7 +25,8 @@ function loadPlugin(packageManager) { case 'pip': { return require('snyk-python-plugin'); } - case 'golang': { + case 'golangdep': + case 'govendor': { return require('snyk-go-plugin'); } case 'nuget': { diff --git a/lib/snyk-test/index.js b/lib/snyk-test/index.js index f4409de254..abefd2e2cd 100644 --- a/lib/snyk-test/index.js +++ b/lib/snyk-test/index.js @@ -43,8 +43,16 @@ function run(root, options) { if (['npm', 'yarn'].indexOf(packageManager) >= 0) { return require('./npm')(root, options); } - if (['rubygems', 'maven', 'gradle', 'sbt', 'pip', - 'golang', 'nuget', 'composer',].indexOf(packageManager) === -1) { + if (['rubygems', + 'maven', + 'gradle', + 'sbt', + 'pip', + 'golangdep', + 'govendor', + 'nuget', + 'composer', + ].indexOf(packageManager) === -1) { throw new Error('Unsupported package manager: ' + packageManager); } return runTest(packageManager, root, options); diff --git a/test/acceptance/cli.acceptance.test.js b/test/acceptance/cli.acceptance.test.js index cdb5a05836..81b0d92ae7 100644 --- a/test/acceptance/cli.acceptance.test.js +++ b/test/acceptance/cli.acceptance.test.js @@ -460,7 +460,7 @@ function (t) { sinon.stub(plugins, 'loadPlugin'); t.teardown(plugins.loadPlugin.restore); plugins.loadPlugin - .withArgs('golang') + .withArgs('golangdep') .returns(plugin); return cli.test('golang-app', { @@ -469,12 +469,12 @@ function (t) { .then(function () { var req = server.popRequest(); t.equal(req.method, 'POST', 'makes POST request'); - t.match(req.url, '/vuln/golang', 'posts to correct url'); + t.match(req.url, '/vuln/golangdep', 'posts to correct url'); t.same(plugin.inspect.getCall(0).args, ['golang-app', 'Gopkg.lock', { args: null, file: 'Gopkg.lock', - packageManager: 'golang', + packageManager: 'golangdep', },], 'calls golang plugin'); }); }); @@ -524,7 +524,7 @@ function (t) { sinon.stub(plugins, 'loadPlugin'); t.teardown(plugins.loadPlugin.restore); plugins.loadPlugin - .withArgs('golang') + .withArgs('govendor') .returns(plugin); return cli.test('golang-app', { @@ -533,12 +533,12 @@ function (t) { .then(function () { var req = server.popRequest(); t.equal(req.method, 'POST', 'makes POST request'); - t.match(req.url, '/vuln/golang', 'posts to correct url'); + t.match(req.url, '/vuln/govendor', 'posts to correct url'); t.same(plugin.inspect.getCall(0).args, ['golang-app', 'vendor/vendor.json', { args: null, file: 'vendor/vendor.json', - packageManager: 'golang', + packageManager: 'govendor', },], 'calls golang plugin'); }); }); @@ -855,7 +855,7 @@ function (t) { sinon.stub(plugins, 'loadPlugin'); t.teardown(plugins.loadPlugin.restore); plugins.loadPlugin - .withArgs('golang') + .withArgs('golangdep') .returns(plugin); return cli.monitor('golang-app', { @@ -864,7 +864,7 @@ function (t) { .then(function () { var req = server.popRequest(); t.equal(req.method, 'PUT', 'makes PUT request'); - t.match(req.url, '/monitor/golang', 'puts at correct url'); + t.match(req.url, '/monitor/golangdep', 'puts at correct url'); t.equal(req.body.targetFile, 'Gopkg.lock', 'sends the targetFile'); t.same(plugin.inspect.getCall(0).args, ['golang-app', 'Gopkg.lock', { @@ -892,7 +892,7 @@ function (t) { sinon.stub(plugins, 'loadPlugin'); t.teardown(plugins.loadPlugin.restore); plugins.loadPlugin - .withArgs('golang') + .withArgs('govendor') .returns(plugin); return cli.monitor('golang-app', { @@ -901,7 +901,7 @@ function (t) { .then(function () { var req = server.popRequest(); t.equal(req.method, 'PUT', 'makes PUT request'); - t.match(req.url, '/monitor/golang', 'puts at correct url'); + t.match(req.url, '/monitor/govendor', 'puts at correct url'); t.equal(req.body.targetFile, 'vendor/vendor.json', 'sends the targetFile'); t.same(plugin.inspect.getCall(0).args, ['golang-app', 'vendor/vendor.json', { @@ -928,8 +928,8 @@ test('`wizard` for unsupported package managers', function (t) { { file: 'pip-app/requirements.txt', type: 'Python' }, { file: 'sbt-app/build.sbt', type: 'SBT' }, { file: 'gradle-app/build.gradle', type: 'Gradle' }, - { file: 'golang-app/Gopkg.lock', type: 'Golang' }, - { file: 'golang-app/vendor/vendor.json', type: 'Golang' }, + { file: 'golang-app/Gopkg.lock', type: 'Golang/Dep' }, + { file: 'golang-app/vendor/vendor.json', type: 'Govendor' }, { file: 'composer-app/composer.lock', type: 'Composer' }, ]; return Promise.all(cases.map(testUnsupported)) @@ -958,8 +958,8 @@ test('`protect` for unsupported package managers', function (t) { { file: 'pip-app/requirements.txt', type: 'Python' }, { file: 'sbt-app/build.sbt', type: 'SBT' }, { file: 'gradle-app/build.gradle', type: 'Gradle' }, - { file: 'golang-app/Gopkg.lock', type: 'Golang' }, - { file: 'golang-app/vendor/vendor.json', type: 'Golang' }, + { file: 'golang-app/Gopkg.lock', type: 'Golang/Dep' }, + { file: 'golang-app/vendor/vendor.json', type: 'Govendor' }, { file: 'composer-app/composer.lock', type: 'Composer' }, ]; return Promise.all(cases.map(testUnsupported))