mirror of
https://github.com/containrrr/watchtower.git
synced 2025-02-01 19:14:37 +02:00
fix(digest): check container image info for nil (#1027)
This commit is contained in:
parent
7221704638
commit
9bb8991a76
@ -43,6 +43,11 @@ func CreateMockContainer(id string, name string, image string, created time.Time
|
|||||||
|
|
||||||
// CreateMockContainerWithImageInfo should only be used for testing
|
// CreateMockContainerWithImageInfo should only be used for testing
|
||||||
func CreateMockContainerWithImageInfo(id string, name string, image string, created time.Time, imageInfo types.ImageInspect) container.Container {
|
func CreateMockContainerWithImageInfo(id string, name string, image string, created time.Time, imageInfo types.ImageInspect) container.Container {
|
||||||
|
return CreateMockContainerWithImageInfoP(id, name, image, created, &imageInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateMockContainerWithImageInfoP should only be used for testing
|
||||||
|
func CreateMockContainerWithImageInfoP(id string, name string, image string, created time.Time, imageInfo *types.ImageInspect) container.Container {
|
||||||
content := types.ContainerJSON{
|
content := types.ContainerJSON{
|
||||||
ContainerJSONBase: &types.ContainerJSONBase{
|
ContainerJSONBase: &types.ContainerJSONBase{
|
||||||
ID: id,
|
ID: id,
|
||||||
@ -57,7 +62,7 @@ func CreateMockContainerWithImageInfo(id string, name string, image string, crea
|
|||||||
}
|
}
|
||||||
return *container.NewContainer(
|
return *container.NewContainer(
|
||||||
&content,
|
&content,
|
||||||
&imageInfo,
|
imageInfo,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,10 @@ const ContentDigestHeader = "Docker-Content-Digest"
|
|||||||
|
|
||||||
// CompareDigest ...
|
// CompareDigest ...
|
||||||
func CompareDigest(container types.Container, registryAuth string) (bool, error) {
|
func CompareDigest(container types.Container, registryAuth string) (bool, error) {
|
||||||
|
if !container.HasImageInfo() {
|
||||||
|
return false, errors.New("container image info missing")
|
||||||
|
}
|
||||||
|
|
||||||
var digest string
|
var digest string
|
||||||
|
|
||||||
registryAuth = TransformAuth(registryAuth)
|
registryAuth = TransformAuth(registryAuth)
|
||||||
|
@ -59,6 +59,8 @@ var _ = Describe("Digests", func() {
|
|||||||
mockCreated,
|
mockCreated,
|
||||||
mockDigest)
|
mockDigest)
|
||||||
|
|
||||||
|
mockContainerNoImage := mocks.CreateMockContainerWithImageInfoP(mockId, mockName, mockImage, mockCreated, nil)
|
||||||
|
|
||||||
When("a digest comparison is done", func() {
|
When("a digest comparison is done", func() {
|
||||||
It("should return true if digests match",
|
It("should return true if digests match",
|
||||||
SkipIfCredentialsEmpty(GHCRCredentials, func() {
|
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 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() {
|
When("using different registries", func() {
|
||||||
It("should work with DockerHub",
|
It("should work with DockerHub",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user