mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
fix(digest): check container image info for nil (#1027)
This commit is contained in:
parent
7221704638
commit
9bb8991a76
3 changed files with 17 additions and 1 deletions
|
|
@ -22,6 +22,10 @@ const ContentDigestHeader = "Docker-Content-Digest"
|
|||
|
||||
// CompareDigest ...
|
||||
func CompareDigest(container types.Container, registryAuth string) (bool, error) {
|
||||
if !container.HasImageInfo() {
|
||||
return false, errors.New("container image info missing")
|
||||
}
|
||||
|
||||
var digest string
|
||||
|
||||
registryAuth = TransformAuth(registryAuth)
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ var _ = Describe("Digests", func() {
|
|||
mockCreated,
|
||||
mockDigest)
|
||||
|
||||
mockContainerNoImage := mocks.CreateMockContainerWithImageInfoP(mockId, mockName, mockImage, mockCreated, nil)
|
||||
|
||||
When("a digest comparison is done", func() {
|
||||
It("should return true if digests match",
|
||||
SkipIfCredentialsEmpty(GHCRCredentials, func() {
|
||||
|
|
@ -75,6 +77,11 @@ var _ = Describe("Digests", func() {
|
|||
It("should return an error if the registry isn't available", func() {
|
||||
|
||||
})
|
||||
It("should return an error when container contains no image info", func() {
|
||||
matches, err := digest.CompareDigest(mockContainerNoImage, `user:pass`)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(matches).To(Equal(false))
|
||||
})
|
||||
})
|
||||
When("using different registries", func() {
|
||||
It("should work with DockerHub",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue