Skip to content

Commit

Permalink
pks/validate: add test for invalid registry and bad signature error c…
Browse files Browse the repository at this point in the history
…odes

Fixes: kubernetes-sigs#1158
Signed-off-by: Sohan Kunkerkar <sohank2602@gmail.com>
  • Loading branch information
sohankunkerkar committed May 18, 2023
1 parent e73a713 commit 2ef9cff
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion pkg/validate/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sort"

"github.com/kubernetes-sigs/cri-tools/pkg/framework"
"k8s.io/apimachinery/pkg/api/errors"
internalapi "k8s.io/cri-api/pkg/apis"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"

Expand Down Expand Up @@ -166,6 +167,48 @@ var _ = framework.KubeDescribe("Image Manager", func() {
}
}
})

It("should handle signature validation failed error", func() {
imageName := "gcr.io/k8s-staging-cri-tools/test-image-1:latest"

_, err := c.PullImage(context.Background(), &runtimeapi.ImageSpec{
Image: imageName,
}, nil, testImagePodSandbox)
Expect(err).To(HaveOccurred())

_, err = c.ImageStatus(context.Background(), &runtimeapi.ImageSpec{
Image: imageName}, false)
Expect(err).To(HaveOccurred())
Expect(errors.IsInvalid(err)).To(BeTrue())
Expect(err.Error()).To(ContainSubstring("signature validation failed"))

// Clean up by removing the pulled image
err = c.RemoveImage(context.Background(), &runtimeapi.ImageSpec{
Image: imageName,
})
Expect(err).ToNot(HaveOccurred())
})

It("should handle registry unavailable error", func() {
imageName := "registry.example.com/myimage:latest"

_, err := c.PullImage(context.Background(), &runtimeapi.ImageSpec{
Image: imageName,
}, nil, testImagePodSandbox)
Expect(err).To(HaveOccurred())

_, err = c.ImageStatus(context.Background(), &runtimeapi.ImageSpec{
Image: imageName}, false)
Expect(err).To(HaveOccurred())
Expect(errors.IsInvalid(err)).To(BeTrue())
Expect(err.Error()).To(ContainSubstring("registry unavailable"))

// Clean up by removing the pulled image
err = c.RemoveImage(context.Background(), &runtimeapi.ImageSpec{
Image: imageName,
})
Expect(err).ToNot(HaveOccurred())
})
})

// testRemoveImage removes the image name imageName and check if it successes.
Expand Down Expand Up @@ -231,7 +274,7 @@ func removeDuplicates(ss []string) []string {
encountered := map[string]bool{}
result := []string{}
for _, s := range ss {
if encountered[s] == true {
if encountered[s] {
continue
}
encountered[s] = true
Expand Down

0 comments on commit 2ef9cff

Please sign in to comment.