Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI | Add Muted and Snoozed Packages Test (AST-66088) #876

Merged
merged 14 commits into from
Sep 22, 2024
Binary file not shown.
46 changes: 46 additions & 0 deletions test/integration/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,49 @@ func TestResultsGeneratingReportWithExcludeNotExploitableStateAndSeverityAndStat
assert.NilError(t, err, "Report file should exist: "+fileName+printer.FormatJSON)
assert.Assert(t, outputBuffer != nil, "Scan must complete successfully")
}

func TestResultsShow_ScanIDWithSnoozedAndMutedAllVulnerabilities_NoVulnerabilitiesInScan(t *testing.T) {
//----------------------------------------------------------------------------------------------------------------------
// This scanID is associated with the CXOne project: ASTCLI/HideDevAndTestsVulnerabilities/Test (DEU, Galactica tenant).
// All vulnerable packages in this project have been snoozed or muted, so no vulnerabilities should appear in this scan.
// If the test fails, verify the scan exists in this project. If it doesn't, create a new scan for the project using
// DevAndTestsVulnerabilitiesProject.zip, mute and snooze all packages, and update the scanID accordingly.
scanID := "28d29a61-bc5e-4f5a-9fdd-e18c5a10c05b"
//----------------------------------------------------------------------------------------------------------------------
reportFilePath := fmt.Sprintf("%s%s.%s", resultsDirectory, fileName, printer.FormatJSON)

_ = executeCmdNilAssertion(
t, "Results show generating JSON report with options should pass",
"results", "show",
flag(params.ScanIDFlag), scanID,
flag(params.TargetFormatFlag), printer.FormatJSON,
flag(params.TargetPathFlag), resultsDirectory,
flag(params.TargetFlag), fileName,
)

defer func() {
_ = os.RemoveAll(resultsDirectory)
}()

assertFileExists(t, reportFilePath)

var result wrappers.ScanResultsCollection
readAndUnmarshalFile(t, reportFilePath, &result)

for _, res := range result.Results {
assert.Equal(t, "NOT_EXPLOITABLE", res.State, "Should be marked as not exploitable")
miryamfoiferCX marked this conversation as resolved.
Show resolved Hide resolved
}
}

func assertFileExists(t *testing.T, path string) {
_, err := os.Stat(path)
assert.NilError(t, err, "Report file should exist at path "+path)
}

func readAndUnmarshalFile(t *testing.T, path string, v interface{}) {
file, err := os.ReadFile(path)
assert.NilError(t, err, "Error reading file at path "+path)

err = json.Unmarshal(file, v)
assert.NilError(t, err, "Error unmarshalling JSON data")
}
1 change: 1 addition & 0 deletions test/integration/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ func getCreateArgsWithNameAndGroups(source string, tags map[string]string, group
flag(params.TagList), formatTags(tags),
flag(params.BranchFlag), SlowRepoBranch,
flag(params.ProjectGroupList), formatGroups(groups),
flag(params.DebugFlag),
}

if strings.Contains(scanTypes, "scs") {
Expand Down
Loading