Skip to content

Commit 1f739c2

Browse files
integration tests
1 parent be26f12 commit 1f739c2

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

test/integration/scan_test.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,122 @@ func TestScanCreate_WithContainerFilterFlagsAndResubmitFlag_CreatingScanWithLate
22792279
assert.Equal(t, createdScanConfig.Value[commands.ConfigContainersPackagesFilterKey], "^internal-.*", "Package filter should be equal")
22802280
}
22812281

2282+
func TestScanCreate_GitScanWithContainerResolveLocallyAndCustomImages_ShouldIncludeUserCustomImages(t *testing.T) {
2283+
bindKeysToEnvAndDefault(t)
2284+
var createdScan wrappers.ScanResponseModel
2285+
var createdScanConfig wrappers.Config
2286+
scansPath := viper.GetString(params.ScansPathKey)
2287+
scanWrapper := wrappers.NewHTTPScansWrapper(scansPath)
2288+
2289+
customImages := "nginx:alpine,mysql:5.7"
2290+
gitRepo := SlowRepo // Use the git repository from root_test.go
2291+
2292+
args := []string{
2293+
"scan", "create",
2294+
flag(params.ProjectName), GenerateRandomProjectNameForScan(),
2295+
flag(params.SourcesFlag), gitRepo, // Git URL for git scan
2296+
flag(params.ScanTypes), params.ContainersTypeFlag,
2297+
flag(params.ContainerImagesFlag), customImages,
2298+
flag(params.ContainerResolveLocallyFlag), // Enable resolve locally
2299+
flag(params.BranchFlag), "main",
2300+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
2301+
flag(params.AsyncFlag),
2302+
}
2303+
scanID, projectID := executeCreateScan(t, args)
2304+
2305+
mapParams := make(map[string]string)
2306+
mapParams["project-id"] = projectID
2307+
allScansModel, _, _ := scanWrapper.Get(mapParams)
2308+
2309+
createdScan = allScansModel.Scans[0]
2310+
2311+
assert.Assert(t, createdScan.ID == scanID, "Scan ID should be equal")
2312+
assert.Equal(t, len(createdScan.Metadata.Configs), 1, "Scan should have only containers config")
2313+
2314+
createdScanConfig = createdScan.Metadata.Configs[0]
2315+
2316+
assert.Equal(t, createdScanConfig.Type, params.ContainersType, "Scan type should be equal")
2317+
// For git scans, UserCustomImages should be included even with containerResolveLocally=true
2318+
assert.Equal(t, createdScanConfig.Value[commands.ConfigUserCustomImagesKey], customImages, "UserCustomImages should be set for git scan even with resolve locally")
2319+
}
2320+
2321+
func TestScanCreate_UploadScanWithContainerResolveLocallyAndCustomImages_ShouldNotIncludeUserCustomImages(t *testing.T) {
2322+
bindKeysToEnvAndDefault(t)
2323+
var createdScan wrappers.ScanResponseModel
2324+
var createdScanConfig wrappers.Config
2325+
scansPath := viper.GetString(params.ScansPathKey)
2326+
scanWrapper := wrappers.NewHTTPScansWrapper(scansPath)
2327+
2328+
customImages := "nginx:alpine,mysql:5.7"
2329+
2330+
args := []string{
2331+
"scan", "create",
2332+
flag(params.ProjectName), GenerateRandomProjectNameForScan(),
2333+
flag(params.SourcesFlag), ".", // Local directory for upload scan
2334+
flag(params.ScanTypes), params.ContainersTypeFlag,
2335+
flag(params.ContainerImagesFlag), customImages,
2336+
flag(params.ContainerResolveLocallyFlag), // Enable resolve locally
2337+
flag(params.BranchFlag), "main",
2338+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
2339+
flag(params.AsyncFlag),
2340+
}
2341+
scanID, projectID := executeCreateScan(t, args)
2342+
2343+
mapParams := make(map[string]string)
2344+
mapParams["project-id"] = projectID
2345+
allScansModel, _, _ := scanWrapper.Get(mapParams)
2346+
2347+
createdScan = allScansModel.Scans[0]
2348+
2349+
assert.Assert(t, createdScan.ID == scanID, "Scan ID should be equal")
2350+
assert.Equal(t, len(createdScan.Metadata.Configs), 1, "Scan should have only containers config")
2351+
2352+
createdScanConfig = createdScan.Metadata.Configs[0]
2353+
2354+
assert.Equal(t, createdScanConfig.Type, params.ContainersType, "Scan type should be equal")
2355+
// For upload scans with containerResolveLocally=true, UserCustomImages should NOT be included
2356+
assert.Equal(t, createdScanConfig.Value[commands.ConfigUserCustomImagesKey], nil, "UserCustomImages should not be set for upload scan with resolve locally")
2357+
}
2358+
2359+
func TestScanCreate_GitScanWithoutContainerResolveLocallyAndCustomImages_ShouldIncludeUserCustomImages(t *testing.T) {
2360+
bindKeysToEnvAndDefault(t)
2361+
var createdScan wrappers.ScanResponseModel
2362+
var createdScanConfig wrappers.Config
2363+
scansPath := viper.GetString(params.ScansPathKey)
2364+
scanWrapper := wrappers.NewHTTPScansWrapper(scansPath)
2365+
2366+
customImages := "nginx:alpine,mysql:5.7"
2367+
gitRepo := SlowRepo // Use the git repository from root_test.go
2368+
2369+
args := []string{
2370+
"scan", "create",
2371+
flag(params.ProjectName), GenerateRandomProjectNameForScan(),
2372+
flag(params.SourcesFlag), gitRepo, // Git URL for git scan
2373+
flag(params.ScanTypes), params.ContainersTypeFlag,
2374+
flag(params.ContainerImagesFlag), customImages,
2375+
// Note: NOT using ContainerResolveLocallyFlag
2376+
flag(params.BranchFlag), "main",
2377+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
2378+
flag(params.AsyncFlag),
2379+
}
2380+
scanID, projectID := executeCreateScan(t, args)
2381+
2382+
mapParams := make(map[string]string)
2383+
mapParams["project-id"] = projectID
2384+
allScansModel, _, _ := scanWrapper.Get(mapParams)
2385+
2386+
createdScan = allScansModel.Scans[0]
2387+
2388+
assert.Assert(t, createdScan.ID == scanID, "Scan ID should be equal")
2389+
assert.Equal(t, len(createdScan.Metadata.Configs), 1, "Scan should have only containers config")
2390+
2391+
createdScanConfig = createdScan.Metadata.Configs[0]
2392+
2393+
assert.Equal(t, createdScanConfig.Type, params.ContainersType, "Scan type should be equal")
2394+
// For git scans without containerResolveLocally, UserCustomImages should be included (existing behavior)
2395+
assert.Equal(t, createdScanConfig.Value[commands.ConfigUserCustomImagesKey], customImages, "UserCustomImages should be set for git scan without resolve locally")
2396+
}
2397+
22822398
func TestCreateScanWithAsyncFlag_TryShowResults_PolicyNotEvaluated(t *testing.T) {
22832399
createASTIntegrationTestCommand(t)
22842400
configuration.LoadConfiguration()

0 commit comments

Comments
 (0)