From 5c11c02530cb5f6e9adcb67c694c0a479ff96ca1 Mon Sep 17 00:00:00 2001 From: William Bradford Clark Date: Fri, 16 Jun 2023 11:51:24 -0400 Subject: [PATCH] Fixes #36482 - Use string keys for accessing 'arch' and 'minor' in repo hash --- app/lib/katello/resources/cdn/katello_cdn.rb | 12 ++++--- test/lib/resources/katello_cdn_test.rb | 34 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/lib/katello/resources/cdn/katello_cdn.rb b/app/lib/katello/resources/cdn/katello_cdn.rb index af196839448..4e9116a5abc 100644 --- a/app/lib/katello/resources/cdn/katello_cdn.rb +++ b/app/lib/katello/resources/cdn/katello_cdn.rb @@ -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? @@ -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 diff --git a/test/lib/resources/katello_cdn_test.rb b/test/lib/resources/katello_cdn_test.rb index ff2968d039a..23a5a6d1ee0 100644 --- a/test/lib/resources/katello_cdn_test.rb +++ b/test/lib/resources/katello_cdn_test.rb @@ -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