Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37705 - 404 v1 search with v2 container clients #42

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading