|
| 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 | +// This tests the createMinimalZipFile functionality introduced in the cloud-default-scan branch |
| 15 | +func TestContainerScan_EmptyFolderWithExternalImages(t *testing.T) { |
| 16 | + createASTIntegrationTestCommand(t) |
| 17 | + testArgs := []string{ |
| 18 | + "scan", "create", |
| 19 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 20 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 21 | + flag(params.ContainerImagesFlag), "nginx:alpine", |
| 22 | + flag(params.BranchFlag), "dummy_branch", |
| 23 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 24 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 25 | + } |
| 26 | + scanID, projectID := executeCreateScan(t, testArgs) |
| 27 | + assert.Assert(t, scanID != "", "Scan ID should not be empty for empty folder with external images") |
| 28 | + assert.Assert(t, projectID != "", "Project ID should not be empty for empty folder with external images") |
| 29 | +} |
| 30 | + |
| 31 | +// TestContainerScan_EmptyFolderWithMultipleExternalImages tests scanning empty folder with multiple external images |
| 32 | +func TestContainerScan_EmptyFolderWithMultipleExternalImages(t *testing.T) { |
| 33 | + createASTIntegrationTestCommand(t) |
| 34 | + testArgs := []string{ |
| 35 | + "scan", "create", |
| 36 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 37 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 38 | + flag(params.ContainerImagesFlag), "nginx:alpine,mysql:5.7,debian:9", |
| 39 | + flag(params.BranchFlag), "dummy_branch", |
| 40 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 41 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 42 | + } |
| 43 | + scanID, projectID := executeCreateScan(t, testArgs) |
| 44 | + assert.Assert(t, scanID != "", "Scan ID should not be empty for empty folder with multiple external images") |
| 45 | + assert.Assert(t, projectID != "", "Project ID should not be empty for empty folder with multiple external images") |
| 46 | +} |
| 47 | + |
| 48 | +// TestContainerScan_EmptyFolderWithExternalImagesAndDebug tests with debug flag enabled |
| 49 | +func TestContainerScan_EmptyFolderWithExternalImagesAndDebug(t *testing.T) { |
| 50 | + createASTIntegrationTestCommand(t) |
| 51 | + testArgs := []string{ |
| 52 | + "scan", "create", |
| 53 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 54 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 55 | + flag(params.ContainerImagesFlag), "mysql:5.7", |
| 56 | + flag(params.BranchFlag), "dummy_branch", |
| 57 | + flag(params.DebugFlag), |
| 58 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 59 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 60 | + } |
| 61 | + scanID, projectID := executeCreateScan(t, testArgs) |
| 62 | + assert.Assert(t, scanID != "", "Scan ID should not be empty for empty folder with debug flag") |
| 63 | + assert.Assert(t, projectID != "", "Project ID should not be empty for empty folder with debug flag") |
| 64 | +} |
| 65 | + |
| 66 | +// TestContainerScan_EmptyFolderWithoutExternalImages tests that empty folder without external images still works |
| 67 | +func TestContainerScan_EmptyFolderWithoutExternalImages(t *testing.T) { |
| 68 | + createASTIntegrationTestCommand(t) |
| 69 | + testArgs := []string{ |
| 70 | + "scan", "create", |
| 71 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 72 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 73 | + flag(params.BranchFlag), "dummy_branch", |
| 74 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 75 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 76 | + } |
| 77 | + // This should succeed but may not find any containers to scan |
| 78 | + err, _ := executeCommand(t, testArgs...) |
| 79 | + // We don't assert error here as the behavior may vary |
| 80 | + // The important thing is that it doesn't crash |
| 81 | + t.Logf("Empty folder without external images result: %v", err) |
| 82 | +} |
| 83 | + |
| 84 | +// TestContainerScan_MinimalProjectWithExternalImages tests minimal project content with external images |
| 85 | +func TestContainerScan_MinimalProjectWithExternalImages(t *testing.T) { |
| 86 | + createASTIntegrationTestCommand(t) |
| 87 | + testArgs := []string{ |
| 88 | + "scan", "create", |
| 89 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 90 | + flag(params.SourcesFlag), "data/insecure.zip", |
| 91 | + flag(params.ContainerImagesFlag), "nginx:alpine,mysql:8.0", |
| 92 | + flag(params.BranchFlag), "dummy_branch", |
| 93 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 94 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 95 | + } |
| 96 | + scanID, projectID := executeCreateScan(t, testArgs) |
| 97 | + assert.Assert(t, scanID != "", "Scan ID should not be empty") |
| 98 | + assert.Assert(t, projectID != "", "Project ID should not be empty") |
| 99 | +} |
| 100 | + |
| 101 | +// TestContainerScan_EmptyFolderWithComplexImageNames tests empty folder with complex image names |
| 102 | +func TestContainerScan_EmptyFolderWithComplexImageNames(t *testing.T) { |
| 103 | + createASTIntegrationTestCommand(t) |
| 104 | + testArgs := []string{ |
| 105 | + "scan", "create", |
| 106 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 107 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 108 | + flag(params.ContainerImagesFlag), "docker.io/library/nginx:1.21.6,mysql:5.7.38", |
| 109 | + flag(params.BranchFlag), "dummy_branch", |
| 110 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 111 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 112 | + } |
| 113 | + scanID, projectID := executeCreateScan(t, testArgs) |
| 114 | + assert.Assert(t, scanID != "", "Scan ID should not be empty for complex image names") |
| 115 | + assert.Assert(t, projectID != "", "Project ID should not be empty for complex image names") |
| 116 | +} |
| 117 | + |
| 118 | +// TestContainerScan_EmptyFolderWithRegistryImages tests empty folder with registry-prefixed images |
| 119 | +func TestContainerScan_EmptyFolderWithRegistryImages(t *testing.T) { |
| 120 | + createASTIntegrationTestCommand(t) |
| 121 | + testArgs := []string{ |
| 122 | + "scan", "create", |
| 123 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 124 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 125 | + flag(params.ContainerImagesFlag), "checkmarx/kics:v2.1.11", |
| 126 | + flag(params.BranchFlag), "dummy_branch", |
| 127 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 128 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 129 | + } |
| 130 | + scanID, projectID := executeCreateScan(t, testArgs) |
| 131 | + assert.Assert(t, scanID != "", "Scan ID should not be empty for registry images") |
| 132 | + assert.Assert(t, projectID != "", "Project ID should not be empty for registry images") |
| 133 | +} |
| 134 | + |
| 135 | +// TestContainerScan_EmptyFolderInvalidImageShouldFail tests that validation still works with empty folders |
| 136 | +func TestContainerScan_EmptyFolderInvalidImageShouldFail(t *testing.T) { |
| 137 | + createASTIntegrationTestCommand(t) |
| 138 | + testArgs := []string{ |
| 139 | + "scan", "create", |
| 140 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 141 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 142 | + flag(params.ContainerImagesFlag), "invalid-image-without-tag", |
| 143 | + flag(params.BranchFlag), "dummy_branch", |
| 144 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 145 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 146 | + } |
| 147 | + err, _ := executeCommand(t, testArgs...) |
| 148 | + assert.Assert(t, err != nil, "Expected error for invalid image format with empty folder") |
| 149 | + assertError(t, err, "Invalid value for --container-images flag") |
| 150 | +} |
| 151 | + |
| 152 | +// TestContainerScan_EmptyFolderMixedValidInvalidImages tests mixed valid/invalid images with empty folder |
| 153 | +func TestContainerScan_EmptyFolderMixedValidInvalidImages(t *testing.T) { |
| 154 | + createASTIntegrationTestCommand(t) |
| 155 | + testArgs := []string{ |
| 156 | + "scan", "create", |
| 157 | + flag(params.ProjectName), getProjectNameForScanTests(), |
| 158 | + flag(params.SourcesFlag), "data/empty-folder.zip", |
| 159 | + flag(params.ContainerImagesFlag), "nginx:alpine,invalid-image,mysql:5.7", |
| 160 | + flag(params.BranchFlag), "dummy_branch", |
| 161 | + flag(params.ScanTypes), params.ContainersTypeFlag, |
| 162 | + flag(params.ScanInfoFormatFlag), printer.FormatJSON, |
| 163 | + } |
| 164 | + err, _ := executeCommand(t, testArgs...) |
| 165 | + assert.Assert(t, err != nil, "Expected error for mixed valid/invalid images with empty folder") |
| 166 | + assertError(t, err, "Invalid value for --container-images flag") |
| 167 | +} |
0 commit comments