Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions internal/commands/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,14 @@ func runGetResultCommand(
return errors.Errorf("%s: CODE: %d, %s", failedGettingScan, errorModel.Code, errorModel.Message)
}

policyResponseModel, err := services.HandlePolicyEvaluation(cmd, policyWrapper, scan, ignorePolicy, agent, waitDelay, policyTimeout)
if err != nil {
return err
var policyResponseModel *wrappers.PolicyResponseModel
if !isScanPending(string(scan.Status)) {
policyResponseModel, err = services.HandlePolicyEvaluation(cmd, policyWrapper, scan, ignorePolicy, agent, waitDelay, policyTimeout)
if err != nil {
return err
}
} else {
logger.PrintIfVerbose("Policy violations aren't returned in the pipeline for scans run in async mode.")
}

if sastRedundancy {
Expand Down
29 changes: 29 additions & 0 deletions test/integration/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,3 +2135,32 @@ func TestScanCreate_WithContainerFilterFlagsAndResubmitFlag_CreatingScanWithLate
assert.Equal(t, createdScanConfig.Value[commands.ConfigContainersImagesFilterKey], "*dev", "Image tag filter should be equal")
assert.Equal(t, createdScanConfig.Value[commands.ConfigContainersPackagesFilterKey], "^internal-.*", "Package filter should be equal")
}

func TestCreateScanWithAsyncFlag_TryShowResults_PolicyNotEvaluated(t *testing.T) {
createASTIntegrationTestCommand(t)
configuration.LoadConfiguration()
args := []string{
"scan", "create",
flag(params.ProjectName), getProjectNameForScanTests(),
flag(params.SourcesFlag), Zip,
flag(params.ScanTypes), "sast,iac-security,sca",
flag(params.BranchFlag), "main",
flag(params.AsyncFlag),
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
}
scanID, _ := executeCreateScan(t, args)
assert.Assert(t, scanID != "", "Scan ID should not be empty")

var buf bytes.Buffer
log.SetOutput(&buf)

_ = executeCmdNilAssertion(
t, "Results show generating JSON report with options should pass",
"results", "show",
flag(params.ScanIDFlag), scanID,
flag(params.TargetFormatFlag), printer.FormatSummaryConsole,
flag(params.DebugFlag),
)
log.SetOutput(os.Stderr)
assert.Assert(t, strings.Contains(buf.String(), "Policy violations aren't returned in the pipeline for scans run in async mode."), "policy shouldn't evaluate in running scan")
}
Loading