Skip to content

Commit

Permalink
Fixes #36482 - Use string keys for accessing 'arch' and 'minor' in re…
Browse files Browse the repository at this point in the history
…po hash
  • Loading branch information
wbclark committed Jun 20, 2023
1 parent 7efc0cb commit f1f7f58
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/lib/katello/resources/cdn/katello_cdn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ def initialize(url, options)
super
end

def fetch_paths(content_path)
def fetch_repo_set(content_path)
url = "/katello/api/v2/repository_sets?organization_id=#{organization['id']}&search=#{CGI.escape("path = #{content_path}")}"
response = get(url)
repo_set = JSON.parse(response)['results'].first
JSON.parse(response)['results'].first
end

def fetch_paths(content_path)
repo_set = fetch_repo_set(content_path)

fail _("Upstream organization %s does not provide this content path") % @organization_label if repo_set.nil?

Expand All @@ -33,8 +37,8 @@ def fetch_paths(content_path)
results = json_body['results']

results.map do |repo|
Katello::Content.substitute_content_path(arch: repo[:arch],
releasever: repo[:minor],
Katello::Content.substitute_content_path(arch: repo['arch'],
releasever: repo['minor'],
content_path: content_path)
end
end
Expand Down
34 changes: 34 additions & 0 deletions test/lib/resources/katello_cdn_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,38 @@ def test_katello_cdn_repository_url_throws_error_when_repo_not_found
end
assert_equal(exception.message, "Repository with content label: 'test', arch: 'noarch', version: '8server' was not found in upstream organization 'test', content view 'test' and lifecycle environment 'test'")
end

def test_fetch_paths
katello_cdn = ::Katello::Resources::CDN::KatelloCdn.new('https://test.com', {
organization_label: 'test',
content_view_label: 'test',
lifecycle_environment_label: 'test'
})

content_path = 'rhel-6-server-els-rpms'
repo_set = {
'label' => content_path
}

response_body = {
'results' => [
{
'arch' => 'i386',
'minor' => '6Server'
}
]
}

expected_url = "/katello/api/v2/repositories?full_result=true&organization_id=#{@organization['id']}&content_view_id=2&environment_id=2&search=#{CGI.escape('content_label = #{content_path}')}"

::Katello::Resources::CDN::KatelloCdn.any_instance.expects(:fetch_repo_set).with(content_path).returns(repo_set)
::Katello::Resources::CDN::KatelloCdn.any_instance.expects(:get).with(expected_url).returns(response_body.to_json)
::Katello::Resources::CDN::KatelloCdn.any_instance.expects(:organization).returns(@organization)
::Katello::Resources::CDN::KatelloCdn.any_instance.expects(:content_view_id).returns(2)
::Katello::Resources::CDN::KatelloCdn.any_instance.expects(:lifecycle_environment_id).returns(2)
Katello::Content.expects(:substitute_content_path).with(arch: 'i386', releasever: '6Server', content_path: content_path).returns("/test/path")

paths = katello_cdn.fetch_paths(content_path)
assert_equal paths, ["/test/path"]
end
end

0 comments on commit f1f7f58

Please sign in to comment.