Skip to content

Commit

Permalink
adds exception handler on invalid deps in manifest file
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu committed Jan 23, 2025
1 parent 1f66768 commit 0dc3e0f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions npm_and_yarn/lib/dependabot/npm_and_yarn/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,15 @@ def path_dependency_details_from_manifest(file)

resolution_deps = resolution_objects.flat_map(&:to_a)
.map do |path, value|
# skip dependencies that contain invalid values such as inline comments, null, etc.

unless value.is_a?(String)
Dependabot.logger.warn("File fetcher: Skipping dependency \"#{path}\" " \
"with value: \"#{value}\"")

next
end

convert_dependency_path_to_name(path, value)
end

Expand Down
22 changes: 22 additions & 0 deletions npm_and_yarn/spec/dependabot/npm_and_yarn/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,28 @@
end
end
end

context "when package dep contains verbose data but are fetchable" do
before do
file_url = File.join(url, "mocks/sprintf-js/package.json?ref=sha")
stub_request(:get, file_url)
.with(headers: { "Authorization" => "token token" })
.to_return(
status: 200,
body: fixture("github", "package_json_verbose_content.json"),
headers: json_header
)
end

it "fetches package.json from path dependency" do
expect(file_fetcher_instance.files.count).to eq(3)
expect(file_fetcher_instance.files.map(&:name))
.to include("mocks/sprintf-js/package.json")
path_file = file_fetcher_instance.files
.find { |f| f.name == "mocks/sprintf-js/package.json" }
expect(path_file.support_file?).to be(true)
end
end
end

context "with a lerna.json file" do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "package.json",
"path": "package.json",
"sha": "5c7b3419e0056515122b981f1566ebe22c208251",
"size": 594,
"url": "https://api.github.com/repos/gocardless/bump/contents/package.json?ref=master",
"html_url": "https://github.com/gocardless/bump/blob/master/package.json",
"git_url": "https://api.github.com/repos/gocardless/bump/git/blobs/5c7b3419e0056515122b981f1566ebe22c208251",
"download_url": "https://raw.githubusercontent.com/gocardless/bump/master/package.json?token=ABMwe0apDiKCctWHnEHnszRBAebVHjQnks5WJWD9wA%3D%3D",
"type": "file",
"content": "ewogICJuYW1lIjogImJ1bXAtdGVzdCIsCiAgInZlcnNpb24iOiAiMC4wLjEi\nLAogICJkZXNjcmlwdGlvbiI6ICIiLAogICJtYWluIjogImluZGV4LmpzIiwK\nICAic2NyaXB0cyI6IHsKICAgICJ0ZXN0IjogImVjaG8gXCJFcnJvcjogbm8g\ndGVzdCBzcGVjaWZpZWRcIiAmJiBleGl0IDEiCiAgfSwKICAicmVwb3NpdG9y\neSI6IHsKICAgICJ0eXBlIjogImdpdCIsCiAgICAidXJsIjogImdpdCtodHRw\nczovL2dpdGh1Yi5jb20vZ29jYXJkbGVzcy9idW1wLXRlc3QuZ2l0IgogIH0s\nCiAgImF1dGhvciI6ICIiLAogICJsaWNlbnNlIjogIklTQyIsCiAgImJ1Z3Mi\nOiB7CiAgICAidXJsIjogImh0dHBzOi8vZ2l0aHViLmNvbS9nb2NhcmRsZXNz\nL2J1bXAtdGVzdC9pc3N1ZXMiCiAgfSwKICAiaG9tZXBhZ2UiOiAiaHR0cHM6\nLy9naXRodWIuY29tL2dvY2FyZGxlc3MvYnVtcC10ZXN0I3JlYWRtZSIsCiAg\nImRlcGVuZGVuY2llcyI6IHsKICAgICJsb2Rhc2giOiAiXjEuMy4xIiwKICAg\nICJjaGFsayI6ICIwLjQuMCIsCiAgICAic3RvcHdvcmRzIjogIjAuMC4xIgog\nIH0sCiAgImRldkRlcGVuZGVuY2llcyI6IHsKICAgICJldGFnIjogIl4xLjAu\nMCIKICB9Cn0K\n",
"encoding": "base64",
"_links": {
"self": "https://api.github.com/repos/gocardless/bump/contents/package.json?ref=master",
"git": "https://api.github.com/repos/gocardless/bump/git/blobs/5c7b3419e0056515122b981f1566ebe22c208251",
"html": "https://github.com/gocardless/bump/blob/master/package.json"
}
}

0 comments on commit 0dc3e0f

Please sign in to comment.