diff --git a/nuget/lib/dependabot/nuget/update_checker/version_finder.rb b/nuget/lib/dependabot/nuget/update_checker/version_finder.rb index 118de0b3a1..3147dac038 100644 --- a/nuget/lib/dependabot/nuget/update_checker/version_finder.rb +++ b/nuget/lib/dependabot/nuget/update_checker/version_finder.rb @@ -106,17 +106,16 @@ def available_v3_versions listing. fetch("versions", []). map do |v| - nuspec_url = - listing.fetch("listing_details"). - fetch(:versions_url). + listing_details = listing.fetch("listing_details") + nuspec_url = listing_details. + fetch(:versions_url, nil)&. gsub(/index\.json$/, "#{v}/#{sanitized_name}.nuspec") { version: version_class.new(v), nuspec_url: nuspec_url, source_url: nil, - repo_url: - listing.fetch("listing_details").fetch(:repository_url) + repo_url: listing_details.fetch(:repository_url) } end end diff --git a/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb b/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb index 9f29395200..da7dc7de9d 100644 --- a/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb +++ b/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb @@ -309,6 +309,10 @@ let(:custom_repo_url) do "https://www.myget.org/F/exceptionless/api/v3/index.json" end + let(:custom_nuget_search_url) do + "https://www.myget.org/F/exceptionless/api/v3/"\ + "query?q=microsoft.extensions.dependencymodel&prerelease=true" + end before do stub_request(:get, nuget_versions_url).to_return(status: 404) stub_request(:get, nuget_search_url).to_return(status: 404) @@ -323,9 +327,6 @@ custom_nuget_versions_url = "https://www.myget.org/F/exceptionless/api/v3/flatcontainer/"\ "microsoft.extensions.dependencymodel/index.json" - custom_nuget_search_url = - "https://www.myget.org/F/exceptionless/api/v3/"\ - "query?q=microsoft.extensions.dependencymodel&prerelease=true" stub_request(:get, custom_nuget_versions_url).to_return(status: 404) stub_request(:get, custom_nuget_versions_url). with(basic_auth: %w(my passw0rd)). @@ -337,6 +338,23 @@ end its([:version]) { is_expected.to eq(version_class.new("2.1.0")) } + + context "that does not return PackageBaseAddress" do + let(:custom_repo_url) { "http://localhost:8082/artifactory/api/nuget/v3/nuget-local" } + let(:custom_nuget_search_url) do + "http://localhost:8082/artifactory/api/nuget/v3/nuget-local/"\ + "query?prerelease=true&q=microsoft.extensions.dependencymodel" + end + before do + stub_request(:get, custom_repo_url). + to_return( + status: 200, + body: fixture("nuget_responses", "artifactory_base.json") + ) + end + + its([:version]) { is_expected.to eq(version_class.new("2.1.0")) } + end end context "with a version range specified" do