Skip to content

Commit

Permalink
Fixes #38014 - Add safe navigation for empty capsule content counts
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1984 committed Nov 20, 2024
1 parent f96ac21 commit ff599e1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/hammer_cli_katello/capsule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,16 @@ class InfoCommand < HammerCLIKatello::InfoCommand

private

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def extend_data(data)
data["lifecycle_environments"].each do |lce|
lce["content_views"].each do |cv|
cv["repositories"].each do |repo|
data["lifecycle_environments"]&.each do |lce|
lce["content_views"]&.each do |cv|
cv["repositories"]&.each do |repo|
if cv["up_to_date"] && !data.dig("content_counts").nil?
cvv_count_repos = data.dig("content_counts", "content_view_versions",
cv["cvv_id"].to_s, "repositories")
cvv_count_repos.each do |_repo_id, counts_and_metadata|
cvv_count_repos&.each do |_repo_id, counts_and_metadata|
if counts_and_metadata.
dig("metadata", "library_instance_id") == repo["library_id"] &&
counts_and_metadata.dig("metadata", "env_id") == lce["id"]
Expand All @@ -272,7 +274,8 @@ def extend_data(data)
end
data
end

# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
build_options
end

Expand Down
7 changes: 7 additions & 0 deletions test/functional/capsule/content/data/empty_counts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"last_sync_time": "2016-01-10 00:27:51 +0100",
"active_sync_tasks": [],
"last_failed_sync_tasks": [],
"lifecycle_environments": [],
"content_counts": {}
}
31 changes: 31 additions & 0 deletions test/functional/capsule/content/info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@
assert_cmd(expected_result, result)
end

it "works with content counts being an empty hash" do
@sync_status = load_json('./data/sync_status_no_counts.json', __FILE__)
@sync_status['lifecycle_environments'] = [
load_json('./data/library_env.json', __FILE__),
load_json('./data/empty_counts.json', __FILE__)
]

ex = api_expects(:capsule_content, :sync_status, 'Get sync info') do |par|
par['id'] == 3
end
ex.returns(@sync_status)

output = OutputMatcher.new([
"Lifecycle Environments:",
" 1) Name: Library",
" Organization: Default Organization",
" Content Views:",
" 1) Name: Zoo View",
" Composite: no",
" Last Published: 2023/10/09 19:18:15",
" Repositories:",
" 1) Repository ID: 2",
" Repository Name: Zoo",
" Content Counts:"
])
expected_result = success_result(output)

result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end

it "works with no content counts" do
@sync_status = load_json('./data/sync_status_no_counts.json', __FILE__)
@sync_status['lifecycle_environments'] = [
Expand Down

0 comments on commit ff599e1

Please sign in to comment.