From dffbb75e8a6127be5c228bd2cbcd1417c4bb20fa Mon Sep 17 00:00:00 2001 From: ghe Date: Wed, 19 Aug 2020 09:00:30 +0100 Subject: [PATCH] fix: try to find the ruby lock & ruby custom gemfile test --- .../plugins/rubygems/inspectors/gemfile.ts | 2 +- .../acceptance/cli-test/cli-test.ruby.spec.ts | 54 +++++++++++++++++++ .../gemfiles/Gemfile.lock.rails-2.3.6 | 26 +++++++++ .../gemfiles/Gemfile.rails-2.3.6 | 26 +++++++++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.lock.rails-2.3.6 create mode 100644 test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.rails-2.3.6 diff --git a/src/lib/plugins/rubygems/inspectors/gemfile.ts b/src/lib/plugins/rubygems/inspectors/gemfile.ts index 194f529c885..9319c62f71f 100644 --- a/src/lib/plugins/rubygems/inspectors/gemfile.ts +++ b/src/lib/plugins/rubygems/inspectors/gemfile.ts @@ -24,7 +24,7 @@ export async function gatherSpecs(root: string, target: string): Promise { // if the target is a Gemfile we treat is as the lockfile const gemfileLock = await tryGetSpec( root, - isGemfileLock ? target : path.join(dir, name + '.lock'), + isGemfileLock ? target : path.join(target + '.lock'), ); if (gemfileLock) { diff --git a/test/acceptance/cli-test/cli-test.ruby.spec.ts b/test/acceptance/cli-test/cli-test.ruby.spec.ts index c054b7c82ea..1cd8fb7e511 100644 --- a/test/acceptance/cli-test/cli-test.ruby.spec.ts +++ b/test/acceptance/cli-test/cli-test.ruby.spec.ts @@ -77,6 +77,60 @@ export const RubyTests: AcceptanceTests = { 'depGraph looks fine', ); }, + '`test ruby-app-custom-names --file=123.gemfile --package-manager=rubygems`': ( + params, + utils, + ) => async (t) => { + utils.chdirWorkspaces(); + await params.cli.test('ruby-app-custom-names', { + file: '123.gemfile', + packageManager: 'rubygems', + }); + + 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-dep-graph', 'posts to correct url'); + + const depGraph = req.body.depGraph; + t.equal(depGraph.pkgManager.name, 'rubygems'); + t.same( + depGraph.pkgs.map((p) => p.id).sort(), + [ + 'crass@1.0.4', + 'lynx@0.4.0', + 'mini_portile2@2.3.0', + 'nokogiri@1.8.5', + 'nokogumbo@1.5.0', + 'ruby-app-custom-names@', + 'sanitize@4.6.2', + 'yard@0.8.0', + ].sort(), + 'depGraph looks fine', + ); + }, + + '`test ruby-app-custom-names --file=gemfiles/Gemfile.rails-2.3.6 --package-manager=rubygems`': ( + params, + utils, + ) => async (t) => { + utils.chdirWorkspaces(); + try { + await params.cli.test('ruby-app-custom-names', { + file: 'gemfiles/Gemfile.rails-2.3.6', + packageManager: 'rubygems', + }); + } catch (e) { + t.match( + e.message, + 'if this is a custom file name re-run with --file=path/to/custom.gemfile.lock --package-manager=rubygems', + ); + } + }, '`test ruby-app-custom-names --file=gemfiles/Gemfile.rails-2.4.5.lock --package-manager=rubygems`': ( params, diff --git a/test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.lock.rails-2.3.6 b/test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.lock.rails-2.3.6 new file mode 100644 index 00000000000..1471006e88e --- /dev/null +++ b/test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.lock.rails-2.3.6 @@ -0,0 +1,26 @@ +GEM + remote: http://rubygems.org/ + specs: + crass (1.0.4) + lynx (0.4.0) + mini_portile2 (2.3.0) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + nokogumbo (1.5.0) + nokogiri + sanitize (4.6.2) + crass (~> 1.0.2) + nokogiri (>= 1.4.4) + nokogumbo (~> 1.4) + yard (0.8.0) + +PLATFORMS + ruby + +DEPENDENCIES + lynx (= 0.4.0) + sanitize (= 4.6.2) + yard (= 0.8.0) + +BUNDLED WITH + 1.16.5 diff --git a/test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.rails-2.3.6 b/test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.rails-2.3.6 new file mode 100644 index 00000000000..1471006e88e --- /dev/null +++ b/test/acceptance/workspaces/ruby-app-custom-names/gemfiles/Gemfile.rails-2.3.6 @@ -0,0 +1,26 @@ +GEM + remote: http://rubygems.org/ + specs: + crass (1.0.4) + lynx (0.4.0) + mini_portile2 (2.3.0) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + nokogumbo (1.5.0) + nokogiri + sanitize (4.6.2) + crass (~> 1.0.2) + nokogiri (>= 1.4.4) + nokogumbo (~> 1.4) + yard (0.8.0) + +PLATFORMS + ruby + +DEPENDENCIES + lynx (= 0.4.0) + sanitize (= 4.6.2) + yard (= 0.8.0) + +BUNDLED WITH + 1.16.5