Skip to content

Commit 69a3b47

Browse files
Merge pull request #1033 from Checkmarx/feature/saraChen/notEvaluatePolicy
Skip of policy evaluated when the scan not finished(AST-81796)
2 parents 5f94c8c + 6db95a5 commit 69a3b47

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

internal/commands/result.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,14 @@ func runGetResultCommand(
986986
return errors.Errorf("%s: CODE: %d, %s", failedGettingScan, errorModel.Code, errorModel.Message)
987987
}
988988

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

994999
if sastRedundancy {

test/integration/scan_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,3 +2135,32 @@ func TestScanCreate_WithContainerFilterFlagsAndResubmitFlag_CreatingScanWithLate
21352135
assert.Equal(t, createdScanConfig.Value[commands.ConfigContainersImagesFilterKey], "*dev", "Image tag filter should be equal")
21362136
assert.Equal(t, createdScanConfig.Value[commands.ConfigContainersPackagesFilterKey], "^internal-.*", "Package filter should be equal")
21372137
}
2138+
2139+
func TestCreateScanWithAsyncFlag_TryShowResults_PolicyNotEvaluated(t *testing.T) {
2140+
createASTIntegrationTestCommand(t)
2141+
configuration.LoadConfiguration()
2142+
args := []string{
2143+
"scan", "create",
2144+
flag(params.ProjectName), getProjectNameForScanTests(),
2145+
flag(params.SourcesFlag), Zip,
2146+
flag(params.ScanTypes), "sast,iac-security,sca",
2147+
flag(params.BranchFlag), "main",
2148+
flag(params.AsyncFlag),
2149+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
2150+
}
2151+
scanID, _ := executeCreateScan(t, args)
2152+
assert.Assert(t, scanID != "", "Scan ID should not be empty")
2153+
2154+
var buf bytes.Buffer
2155+
log.SetOutput(&buf)
2156+
2157+
_ = executeCmdNilAssertion(
2158+
t, "Results show generating JSON report with options should pass",
2159+
"results", "show",
2160+
flag(params.ScanIDFlag), scanID,
2161+
flag(params.TargetFormatFlag), printer.FormatSummaryConsole,
2162+
flag(params.DebugFlag),
2163+
)
2164+
log.SetOutput(os.Stderr)
2165+
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")
2166+
}

0 commit comments

Comments
 (0)