From bcdb78d119378c6735c35b1b970d35213ca27dd7 Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Fri, 23 Jun 2023 12:04:33 -0500 Subject: [PATCH] NPM: fix GitHub registry not working when path is specified (#7468) --- .../dependabot/npm_and_yarn/file_parser.rb | 2 +- .../npm_and_yarn/file_parser_spec.rb | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb index dbe2c2711e9..83066aaa26c 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_parser.rb @@ -303,7 +303,7 @@ def url_for_relevant_cred(resolved_url) else URI("https://#{details['registry']}") end - resolved_url_host == uri.host + resolved_url_host == uri.host && resolved_url.include?(details["registry"]) end return unless credential_matching_url diff --git a/npm_and_yarn/spec/dependabot/npm_and_yarn/file_parser_spec.rb b/npm_and_yarn/spec/dependabot/npm_and_yarn/file_parser_spec.rb index d905fd567b4..0bc8ec6f9d4 100644 --- a/npm_and_yarn/spec/dependabot/npm_and_yarn/file_parser_spec.rb +++ b/npm_and_yarn/spec/dependabot/npm_and_yarn/file_parser_spec.rb @@ -251,6 +251,31 @@ }] ) end + + context "with a credential that matches the hostname, but not the path" do + let(:credentials) do + [{ + "type" => "npm_registry", + "registry" => "npm.pkg.github.com/dependabot", + "username" => "x-access-token", + "password" => "token" + }] + end + + its(:requirements) do + is_expected.to eq( + [{ + requirement: "^2.0.1", + file: "package.json", + groups: ["devDependencies"], + source: { + type: "registry", + url: "https://npm.pkg.github.com" + } + }] + ) + end + end end describe "the scoped gitlab dependency" do