Skip to content

Commit 6ca38a0

Browse files
Containers cloud scan integration tests (AST-107639) (#1347)
* integration tets done * tests fix --------- Co-authored-by: Anurag Dalke <anurag.dalke@checkmarx.com>
1 parent 0bb42e2 commit 6ca38a0

File tree

3 files changed

+754
-0
lines changed

3 files changed

+754
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
//go:build integration
2+
3+
package integration
4+
5+
import (
6+
"testing"
7+
8+
"github.com/checkmarx/ast-cli/internal/commands/util/printer"
9+
"github.com/checkmarx/ast-cli/internal/params"
10+
"gotest.tools/assert"
11+
)
12+
13+
// TestContainerScan_EmptyFolderWithExternalImages tests scanning with empty folders and external container images
14+
func TestContainerScan_EmptyFolderWithExternalImages(t *testing.T) {
15+
createASTIntegrationTestCommand(t)
16+
testArgs := []string{
17+
"scan", "create",
18+
flag(params.ProjectName), getProjectNameForScanTests(),
19+
flag(params.SourcesFlag), "data/empty-folder.zip",
20+
flag(params.ContainerImagesFlag), "nginx:alpine",
21+
flag(params.BranchFlag), "dummy_branch",
22+
flag(params.ScanTypes), params.ContainersTypeFlag,
23+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
24+
}
25+
scanID, projectID := executeCreateScan(t, testArgs)
26+
assert.Assert(t, scanID != "", "Scan ID should not be empty for empty folder with external images")
27+
assert.Assert(t, projectID != "", "Project ID should not be empty for empty folder with external images")
28+
}
29+
30+
// TestContainerScan_EmptyFolderWithMultipleExternalImages tests scanning empty folder with multiple external images
31+
func TestContainerScan_EmptyFolderWithMultipleExternalImages(t *testing.T) {
32+
createASTIntegrationTestCommand(t)
33+
testArgs := []string{
34+
"scan", "create",
35+
flag(params.ProjectName), getProjectNameForScanTests(),
36+
flag(params.SourcesFlag), "data/empty-folder.zip",
37+
flag(params.ContainerImagesFlag), "nginx:alpine,mysql:5.7,debian:9",
38+
flag(params.BranchFlag), "dummy_branch",
39+
flag(params.ScanTypes), params.ContainersTypeFlag,
40+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
41+
}
42+
scanID, projectID := executeCreateScan(t, testArgs)
43+
assert.Assert(t, scanID != "", "Scan ID should not be empty for empty folder with multiple external images")
44+
assert.Assert(t, projectID != "", "Project ID should not be empty for empty folder with multiple external images")
45+
}
46+
47+
// TestContainerScan_EmptyFolderWithExternalImagesAndDebug tests with debug flag enabled
48+
func TestContainerScan_EmptyFolderWithExternalImagesAndDebug(t *testing.T) {
49+
createASTIntegrationTestCommand(t)
50+
testArgs := []string{
51+
"scan", "create",
52+
flag(params.ProjectName), getProjectNameForScanTests(),
53+
flag(params.SourcesFlag), "data/empty-folder.zip",
54+
flag(params.ContainerImagesFlag), "mysql:5.7",
55+
flag(params.BranchFlag), "dummy_branch",
56+
flag(params.DebugFlag),
57+
flag(params.ScanTypes), params.ContainersTypeFlag,
58+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
59+
}
60+
scanID, projectID := executeCreateScan(t, testArgs)
61+
assert.Assert(t, scanID != "", "Scan ID should not be empty for empty folder with debug flag")
62+
assert.Assert(t, projectID != "", "Project ID should not be empty for empty folder with debug flag")
63+
}
64+
65+
// TestContainerScan_EmptyFolderWithComplexImageNames tests empty folder with complex image names
66+
func TestContainerScan_EmptyFolderWithComplexImageNames(t *testing.T) {
67+
createASTIntegrationTestCommand(t)
68+
testArgs := []string{
69+
"scan", "create",
70+
flag(params.ProjectName), getProjectNameForScanTests(),
71+
flag(params.SourcesFlag), "data/empty-folder.zip",
72+
flag(params.ContainerImagesFlag), "docker.io/library/nginx:1.21.6,mysql:5.7.38",
73+
flag(params.BranchFlag), "dummy_branch",
74+
flag(params.ScanTypes), params.ContainersTypeFlag,
75+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
76+
}
77+
scanID, projectID := executeCreateScan(t, testArgs)
78+
assert.Assert(t, scanID != "", "Scan ID should not be empty for complex image names")
79+
assert.Assert(t, projectID != "", "Project ID should not be empty for complex image names")
80+
}
81+
82+
// TestContainerScan_EmptyFolderWithRegistryImages tests empty folder with registry-prefixed images
83+
func TestContainerScan_EmptyFolderWithRegistryImages(t *testing.T) {
84+
createASTIntegrationTestCommand(t)
85+
testArgs := []string{
86+
"scan", "create",
87+
flag(params.ProjectName), getProjectNameForScanTests(),
88+
flag(params.SourcesFlag), "data/empty-folder.zip",
89+
flag(params.ContainerImagesFlag), "checkmarx/kics:v2.1.11",
90+
flag(params.BranchFlag), "dummy_branch",
91+
flag(params.ScanTypes), params.ContainersTypeFlag,
92+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
93+
}
94+
scanID, projectID := executeCreateScan(t, testArgs)
95+
assert.Assert(t, scanID != "", "Scan ID should not be empty for registry images")
96+
assert.Assert(t, projectID != "", "Project ID should not be empty for registry images")
97+
}
98+
99+
// TestContainerScan_EmptyFolderInvalidImageShouldFail tests that validation still works with empty folders
100+
func TestContainerScan_EmptyFolderInvalidImageShouldFail(t *testing.T) {
101+
createASTIntegrationTestCommand(t)
102+
testArgs := []string{
103+
"scan", "create",
104+
flag(params.ProjectName), getProjectNameForScanTests(),
105+
flag(params.SourcesFlag), "data/empty-folder.zip",
106+
flag(params.ContainerImagesFlag), "invalid-image-without-tag",
107+
flag(params.BranchFlag), "dummy_branch",
108+
flag(params.ScanTypes), params.ContainersTypeFlag,
109+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
110+
}
111+
err, _ := executeCommand(t, testArgs...)
112+
assert.Assert(t, err != nil, "Expected error for invalid image format with empty folder")
113+
assertError(t, err, "image does not have a tag")
114+
}
115+
116+
// TestContainerScan_EmptyFolderMixedValidInvalidImages tests mixed valid/invalid images with empty folder
117+
func TestContainerScan_EmptyFolderMixedValidInvalidImages(t *testing.T) {
118+
createASTIntegrationTestCommand(t)
119+
testArgs := []string{
120+
"scan", "create",
121+
flag(params.ProjectName), getProjectNameForScanTests(),
122+
flag(params.SourcesFlag), "data/empty-folder.zip",
123+
flag(params.ContainerImagesFlag), "nginx:alpine,invalid-image,mysql:5.7",
124+
flag(params.BranchFlag), "dummy_branch",
125+
flag(params.ScanTypes), params.ContainersTypeFlag,
126+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
127+
}
128+
err, _ := executeCommand(t, testArgs...)
129+
assert.Assert(t, err != nil, "Expected error for mixed valid/invalid images with empty folder")
130+
assertError(t, err, "image does not have a tag")
131+
}

0 commit comments

Comments
 (0)