Skip to content

Commit

Permalink
updating split logic to account for local registries not containing n…
Browse files Browse the repository at this point in the history
…amespace

Signed-off-by: Adam D. Cornett <adc@redhat.com>
  • Loading branch information
acornett21 committed Dec 10, 2024
1 parent e02ce0d commit 9bd6d67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/policy/container/has_prohibited_container_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func (p HasProhibitedContainerName) Validate(ctx context.Context, imageReference
func (p HasProhibitedContainerName) getDataForValidate(imageRepository string) string {
// splitting on '/' to get container name, at this point we know that
// crane's ParseReference has set ImageReference.imageRepository in a valid format
return strings.Split(imageRepository, "/")[1]
repository := strings.Split(imageRepository, "/")

// always return last element which is container name
return repository[len(repository)-1]
}

func (p HasProhibitedContainerName) validate(ctx context.Context, containerName string) (bool, error) {
Expand Down
10 changes: 10 additions & 0 deletions internal/policy/container/has_prohibited_container_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ var _ = Describe("HasProhibitedContainerName", func() {
Expect(ok).To(BeTrue())
})
})
Context("When a local registry container name does not violate trademark", func() {
BeforeEach(func() {
imageRef.ImageRepository = "simple-demo-operator"
})
It("should pass Validate", func() {
ok, err := hasProhibitedContainerName.Validate(context.TODO(), imageRef)
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
})
})
Context("When a container name violates trademark", func() {
BeforeEach(func() {
imageRef.ImageRepository = "opdev/red-hat-container"
Expand Down

0 comments on commit 9bd6d67

Please sign in to comment.