Skip to content

Commit f17e409

Browse files
added-integration-tests
1 parent 69dbcfb commit f17e409

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

internal/commands/scan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const (
122122

123123
jsonExt = ".json"
124124
xmlExt = ".xml"
125-
sbomScanTypeErrMsg = "--sbom-only flag is only supported with scan type: sca"
125+
sbomScanTypeErrMsg = "The --sbom-only flag can only be used with scan type: sca"
126126
)
127127

128128
var (
@@ -811,7 +811,7 @@ func scanCreateSubCommand(
811811
createScanCmd.PersistentFlags().String(commonParams.ContainersImageTagFilterFlag, "", "Exclude images by image name and/or tag, ex: \"*dev\"")
812812

813813
// reading sbom-only flag
814-
createScanCmd.PersistentFlags().Bool(commonParams.SbomFlag, false, "Execute SBOM scan exclusively on the provided XML/JSON file.")
814+
createScanCmd.PersistentFlags().Bool(commonParams.SbomFlag, false, "Run an SBOM scan only on the specified XML or JSON file.")
815815

816816
return createScanCmd
817817
}
@@ -3152,7 +3152,7 @@ func createMinimalZipFile() (string, error) {
31523152
func isValidJSONOrXML(path string) (bool, error) {
31533153
ext := strings.ToLower(filepath.Ext(path))
31543154
if ext != jsonExt && ext != xmlExt {
3155-
return false, nil
3155+
return false, fmt.Errorf("not a JSON/XML file, provide valid JSON/XMl file")
31563156
}
31573157

31583158
data, err := ioutil.ReadFile(path)

test/integration/scan_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,3 +2373,48 @@ func TestCreateScan_WithScaResolver_ZipSource_Fail(t *testing.T) {
23732373
err, _ := executeCommand(t, args...)
23742374
assert.Error(t, err, "Scanning Zip files is not supported by ScaResolver.Please use non-zip source")
23752375
}
2376+
2377+
func TestCreateScan_SbomScanForInvalidScanTypes(t *testing.T) {
2378+
args := []string{
2379+
"scan", "create",
2380+
flag(params.ProjectName), "random_proj",
2381+
flag(params.SourcesFlag), "data/project-with-directory-symlink",
2382+
flag(params.ScanTypes), "sast,sca",
2383+
flag(params.BranchFlag), "dummy_branch",
2384+
flag(params.SbomFlag),
2385+
}
2386+
2387+
err, _ := executeCommand(t, args...)
2388+
assert.Error(t, err, "The --sbom-only flag can only be used with scan type: sca")
2389+
2390+
}
2391+
2392+
func TestCreateScan_SbomScanForInvalidFileExtension(t *testing.T) {
2393+
args := []string{
2394+
"scan", "create",
2395+
flag(params.ProjectName), "random_proj",
2396+
flag(params.SourcesFlag), "data/project-with-directory-symlink",
2397+
flag(params.ScanTypes), "sca",
2398+
flag(params.BranchFlag), "dummy_branch",
2399+
flag(params.SbomFlag),
2400+
}
2401+
2402+
err, _ := executeCommand(t, args...)
2403+
assert.Error(t, err, "Failed creating a scan: Input in bad format: not a JSON/XML file, provide valid JSON/XMl file")
2404+
2405+
}
2406+
2407+
func TestCreateScan_SbomScanForNotExistingFile(t *testing.T) {
2408+
args := []string{
2409+
"scan", "create",
2410+
flag(params.ProjectName), "random_proj",
2411+
flag(params.SourcesFlag), "data/sbom.json",
2412+
flag(params.ScanTypes), "sca",
2413+
flag(params.BranchFlag), "dummy_branch",
2414+
flag(params.SbomFlag),
2415+
}
2416+
2417+
err, _ := executeCommand(t, args...)
2418+
assert.ErrorContains(t, err, "Failed creating a scan: Input in bad format: failed to read file:")
2419+
2420+
}

0 commit comments

Comments
 (0)