Commit 2c354c1d authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Don't crash when listing helm chart images

- Adds fixtures for helm charts
- Fix crash when trying to parse nil date due to helm chart
  missing the field
parent 79959871
---
title: Fix crash registry contains helm charts
merge_request: 21381
author:
type: fixed
...@@ -82,7 +82,7 @@ module ContainerRegistry ...@@ -82,7 +82,7 @@ module ContainerRegistry
return unless config return unless config
strong_memoize(:created_at) do strong_memoize(:created_at) do
DateTime.rfc3339(config['created']) DateTime.rfc3339(config['created']) if config['created']
end end
end end
......
{
"name": "mychart",
"version": "0.1.0",
"description": "A Helm chart for Kubernetes",
"apiVersion": "v2",
"appVersion": "1.16.0",
"type": "application"
}
{
"schemaVersion": 2,
"config": {
"mediaType": "application/vnd.cncf.helm.config.v1+json",
"digest": "sha256:65a07b841ece031e6d0ec5eb948eacb17aa6d7294cdeb01d5348e86242951487",
"size": 141
},
"layers": [
{
"mediaType": "application/tar+gzip",
"digest": "sha256:896935a875c8fe8f8b9b81e5862413de316f8da3d6d9a7e0f6f1e90f6204f551",
"size": 2801
}
]
}
...@@ -97,6 +97,29 @@ describe ContainerRegistry::Tag do ...@@ -97,6 +97,29 @@ describe ContainerRegistry::Tag do
end end
end end
context 'image is a helm chart' do
before do
stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag')
.with(headers: headers)
.to_return(
status: 200,
body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest_helm.json'),
headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v2+json' })
stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:65a07b841ece031e6d0ec5eb948eacb17aa6d7294cdeb01d5348e86242951487')
.with(headers: { 'Accept' => 'application/vnd.cncf.helm.config.v1+json' })
.to_return(
status: 200,
body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob_helm.json'))
end
context '#created_at' do
subject { tag.created_at }
it { is_expected.to be_nil }
end
end
context 'schema v2' do context 'schema v2' do
before do before do
stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag') stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment