Skip to content

Commit

Permalink
Fixes #37705 - 404 v1 search with v2 container clients
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Aug 8, 2024
1 parent d74a50f commit 28fcc52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/smart_proxy_container_gateway/container_gateway_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ class Api < ::Sinatra::Base
end

get '/v1/search/?' do
# Checks for podman client and issues a 404 in that case. Podman
# Checks for v2 client and issues a 404 in that case. Podman
# examines the response from a /v1/search request. If the result
# is a 4XX, it will then proceed with a request to /_catalog
if !request.env['HTTP_USER_AGENT'].nil? && request.env['HTTP_USER_AGENT'].downcase.include?('libpod')
if request.env['HTTP_DOCKER_DISTRIBUTION_API_VERSION'] == 'registry/2.0'
halt 404, "not found"
end

Expand Down
10 changes: 8 additions & 2 deletions test/container_gateway_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ def test_put_repository_list
assert last_response.ok?
end

def test_v1_search_v2_client
header 'DOCKER_DISTRIBUTION_API_VERSION', 'registry/2.0'
get '/v1/search'
assert last_response.status == 404
end

def test_v1_search_with_user
user_id = @database.connection[:users].insert(name: 'test_user')
catalog = ["test_repo"]
Expand All @@ -210,7 +216,7 @@ def test_v1_search_with_user
}
).to_return(:body => foreman_auth_response.to_json)

header 'HTTP_USER_AGENT', 'notpodman'
header 'DOCKER_DISTRIBUTION_API_VERSION', 'registry/1.0'
# Basic test_user:test_password
header "AUTHORIZATION", "Basic dGVzdF91c2VyOnRlc3RfcGFzc3dvcmQ="

Expand All @@ -224,7 +230,7 @@ def test_v1_search_with_no_user
@container_gateway_main.expects(:catalog).with(nil).returns(catalog)
catalog.expects(:limit).returns(catalog)
catalog.expects(:select_map).returns(catalog)
header 'HTTP_USER_AGENT', 'notpodman'
header 'DOCKER_DISTRIBUTION_API_VERSION', 'registry/1.0'
get '/v1/search'
assert last_response.ok?
assert_equal [{ "description" => "", "name" => "test_repo" }].sort, JSON.parse(last_response.body)["results"].sort
Expand Down

0 comments on commit 28fcc52

Please sign in to comment.