Skip to content

Commit

Permalink
Adds handler for bad response returned from registry
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-sandhu committed Feb 5, 2025
1 parent 2bf11cd commit db9db2a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docker/lib/dependabot/docker/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ def fetch_digest_of(tag)
rescue DockerRegistry2::RegistryAuthenticationException,
RestClient::Forbidden
raise PrivateSourceAuthenticationFailure, registry_hostname
rescue RestClient::ServerBrokeConnection,
RestClient::TooManyRequests
raise PrivateSourceBadResponse, registry_hostname
end

def transient_docker_errors
Expand Down
36 changes: 36 additions & 0 deletions docker/spec/dependabot/docker/update_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,42 @@ def stub_tag_with_no_digest(tag)

it { is_expected.to eq("17.10") }

context "when it returns a bad response (TooManyRequests) error" do
before do
stub_request(:get, repo_url + "tags/list")
.to_raise(RestClient::TooManyRequests)
end

it "raises" do
expect { checker.latest_version }
.to raise_error(Dependabot::PrivateSourceBadResponse)
end

context "when using a private registry" do
let(:dependency_name) { "ubuntu" }
let(:dependency) do
Dependabot::Dependency.new(
name: dependency_name,
version: version,
requirements: [{
requirement: nil,
groups: [],
file: "Dockerfile",
source: { registry: "registry-host.io:5000" }
}],
package_manager: "docker"
)
end
let(:repo_url) { "https://registry-host.io:5000/v2/ubuntu/" }
let(:tags_fixture_name) { "ubuntu_no_latest.json" }

it "raises" do
expect { checker.latest_version }
.to raise_error(Dependabot::PrivateSourceBadResponse)
end
end
end

context "when the time out occurs every time" do
before do
stub_request(:get, repo_url + "tags/list")
Expand Down

0 comments on commit db9db2a

Please sign in to comment.