Skip to content

Commit 3436623

Browse files
Reet00J12934
authored andcommitted
Add unit-test for image with underscore
Signed-off-by: Samreet Singh <samreet.singh@iteratec.com>
1 parent 7164cf2 commit 3436623

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

auto-discovery/kubernetes/controllers/container_scan_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ func getScanName(imageID string, scanConfig config.ScanConfig) string {
182182
result = strings.ReplaceAll(result, "/", "-")
183183
result = strings.ReplaceAll(result, "_", "-")
184184

185-
186185
//limit scan name length to kubernetes limits
187186
return result[:62]
188187
}

auto-discovery/kubernetes/controllers/container_scan_controller_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,30 @@ var _ = Describe("ContainerScan controller", func() {
141141
!checkIfScanExists(ctx, juiceShopScanName2, namespace, juiceShopScanGoTemplate)
142142
}, timeout, interval).Should(BeTrue())
143143
})
144+
145+
It("Should create a scan for an image with underscores", func() {
146+
fakeDeployment2 := map[string]string{"test_image": "1237b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31"}
147+
148+
createPodWithMultipleContainers(ctx, "fake-deployment-pod3", namespace, fakeDeployment2)
149+
testScanName1 := "test-image-test-scan-at-1237b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31"
150+
testScanName1 = testScanName1[:62]
151+
152+
testScanGoTemplate := scanGoTemplate{
153+
map[string]string{"testAnnotation": namespace},
154+
map[string]string{
155+
"testLabel": namespace,
156+
"app.kubernetes.io/managed-by": "securecodebox-autodiscovery",
157+
},
158+
[]string{"-p", namespace},
159+
nil,
160+
nil,
161+
nil,
162+
}
163+
Eventually(func() bool {
164+
return checkIfScanExists(ctx, testScanName1, namespace, testScanGoTemplate)
165+
}, timeout, interval).Should(BeTrue())
166+
})
167+
144168
})
145169
Context("Container autodiscovery with imagePullSecrets", func() {
146170
namespace := "container-autodiscovery-imagepullsecrets"

0 commit comments

Comments
 (0)