diff --git a/internal/commands/result.go b/internal/commands/result.go index 597e9c8ec..c4ddaa7aa 100644 --- a/internal/commands/result.go +++ b/internal/commands/result.go @@ -73,15 +73,14 @@ const ( pendingStatus = "Pending" pdfToEmailFlagDescription = "Send the PDF report to the specified email address." + " Use \",\" as the delimiter for multiple emails" - pdfOptionsFlagDescription = "Sections to generate PDF report. Available options: Iac-Security,Sast,Sca and " + - defaultPdfOptionsDataSections + defaultPdfOprtionsImprovedDataSections + pdfOptionsFlagDescription = "Sections to generate PDF report. Available options: Iac-Security,Sast,Sca," + + defaultPdfOptionsDataSections sbomReportFlagDescription = "Sections to generate SBOM report. Available options: CycloneDxJson,CycloneDxXml,SpdxJson" delayValueForReport = 10 reportNameScanReport = "scan-report" reportNameImprovedScanReport = "improved-scan-report" reportTypeEmail = "email" - defaultPdfOptionsDataSections = "ScanSummary,ExecutiveSummary,ScanResults with NEW_SAST_SCAN_REPORT_ENABLED feature flag disabled or " - defaultPdfOprtionsImprovedDataSections = "scan-information,results-overview,scan-results,categories,resolved-results,vulnerability-details with the flag enabled" + defaultPdfOptionsDataSections = "ScanSummary,ExecutiveSummary,ScanResults" defaultSbomOption = "CycloneDxJson" exploitablePathFlagDescription = "Enable or disable exploitable path in scan. Available options: true,false" scaLastScanTimeFlagDescription = "SCA last scan time. Available options: integer above 1" @@ -204,7 +203,7 @@ func resultShowSubCommand( ) resultShowCmd.PersistentFlags().String(commonParams.ReportFormatPdfToEmailFlag, "", pdfToEmailFlagDescription) resultShowCmd.PersistentFlags().String(commonParams.ReportSbomFormatFlag, defaultSbomOption, sbomReportFlagDescription) - resultShowCmd.PersistentFlags().String(commonParams.ReportFormatPdfOptionsFlag, "", pdfOptionsFlagDescription) + resultShowCmd.PersistentFlags().String(commonParams.ReportFormatPdfOptionsFlag, defaultPdfOptionsDataSections, pdfOptionsFlagDescription) resultShowCmd.PersistentFlags().String(commonParams.TargetFlag, "cx_result", "Output file") resultShowCmd.PersistentFlags().String(commonParams.TargetPathFlag, ".", "Output Path") resultShowCmd.PersistentFlags().StringSlice(commonParams.FilterFlag, []string{}, filterResultsListFlagUsage) @@ -1306,14 +1305,7 @@ func parsePDFOptions(pdfOptions string, enabledEngines []string, reportName stri "executivesummary": "ExecutiveSummary", "scanresults": "ScanResults", } - var pdfOptionsSectionsMapImproved = map[string]string{ - "scan-information": "scan-information", - "results-overview": "results-overview", - "scan-results": "scan-results", - "categories": "categories", - "resolved-results": "resolved-results", - "vulnerability-details": "vulnerability-details", - } + var pdfOptionsEnginesMap = map[string]string{ commonParams.ScaType: "SCA", commonParams.SastType: "SAST", @@ -1321,28 +1313,13 @@ func parsePDFOptions(pdfOptions string, enabledEngines []string, reportName stri commonParams.IacType: "KICS", } - var pdfReportOptionsSections = map[string]map[string]string{ - reportNameImprovedScanReport: pdfOptionsSectionsMapImproved, - reportNameScanReport: pdfOptionsSectionsMap, - } - - var pdfReportOptionsEngines = map[string]map[string]string{ - reportNameImprovedScanReport: pdfOptionsEnginesMap, - reportNameScanReport: pdfOptionsEnginesMap, - } - pdfOptions = strings.ToLower(strings.ReplaceAll(pdfOptions, " ", "")) - // if no options are provided, report service defaults to all values - if pdfOptions == "" { - return pdfOptionsSections, pdfOptionsSections, nil - } - options := strings.Split(strings.ReplaceAll(pdfOptions, "\n", ""), ",") for _, s := range options { - if pdfReportOptionsEngines[reportName][s] != "" { - pdfOptionsEngines = append(pdfOptionsEngines, pdfReportOptionsEngines[reportName][s]) - } else if pdfReportOptionsSections[reportName][s] != "" { - pdfOptionsSections = append(pdfOptionsSections, pdfReportOptionsSections[reportName][s]) + if pdfOptionsEnginesMap[s] != "" { + pdfOptionsEngines = append(pdfOptionsEngines, pdfOptionsEnginesMap[s]) + } else if pdfOptionsSectionsMap[s] != "" { + pdfOptionsSections = append(pdfOptionsSections, pdfOptionsSectionsMap[s]) } else { return nil, nil, errors.Errorf("report option \"%s\" unavailable", s) } @@ -1350,13 +1327,36 @@ func parsePDFOptions(pdfOptions string, enabledEngines []string, reportName stri if pdfOptionsEngines == nil { for _, engine := range enabledEngines { if pdfOptionsEnginesMap[engine] != "" { - pdfOptionsEngines = append(pdfOptionsEngines, pdfReportOptionsEngines[reportName][engine]) + pdfOptionsEngines = append(pdfOptionsEngines, pdfOptionsEnginesMap[engine]) } } } + + if reportName == reportNameImprovedScanReport { + pdfOptionsSections = translateReportSectionsForImproved(pdfOptionsSections) + } + return pdfOptionsSections, pdfOptionsEngines, nil } +func translateReportSectionsForImproved(sections []string) []string { + var resultSections = make([]string, 0) + + var pdfOptionsSectionsImprovedTranslation = map[string][]string{ + "ScanSummary": {"scan-information"}, + "ExecutiveSummary": {"results-overview"}, + "ScanResults": {"scan-results", "categories", "resolved-results", "vulnerability-details"}, + } + + for _, section := range sections { + if translatedSections := pdfOptionsSectionsImprovedTranslation[section]; translatedSections != nil { + resultSections = append(resultSections, translatedSections...) + } + } + + return resultSections +} + func convertCxResultsToSarif(results *wrappers.ScanResultsCollection) *wrappers.SarifResultsCollection { var sarif = new(wrappers.SarifResultsCollection) sarif.Schema = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json" diff --git a/internal/commands/result_test.go b/internal/commands/result_test.go index 6f2c6f157..5f77bdde0 100644 --- a/internal/commands/result_test.go +++ b/internal/commands/result_test.go @@ -291,7 +291,7 @@ func TestRunGetResultsGeneratingPdfReportWithEmailAndOptions(t *testing.T) { assert.NilError(t, err) } -func TestRunGetResultsGeneratingPdfReportWithOptionsImproved(t *testing.T) { +func TestRunGetResultsGeneratingPdfReportWithOptionsImprovedMappingHappens(t *testing.T) { mock.Flags = wrappers.FeatureFlagsResponseModel{{Name: wrappers.NewScanReportEnabled, Status: true}} cmd := createASTTestCommand() err := executeTestCommand(cmd, @@ -299,7 +299,7 @@ func TestRunGetResultsGeneratingPdfReportWithOptionsImproved(t *testing.T) { "--report-format", "pdf", "--scan-id", "MOCK", "--report-pdf-email", "ab@cd.pt,test@test.pt", - "--report-pdf-options", "Iac-Security,Sast,Sca,scan-information") + "--report-pdf-options", "Iac-Security,Sast,Sca,scansummary,scanresults") assert.NilError(t, err) } @@ -311,8 +311,8 @@ func TestRunGetResultsGeneratingPdfReportWithInvalidOptionsImproved(t *testing.T "--report-format", "pdf", "--scan-id", "MOCK", "--report-pdf-email", "ab@cd.pt,test@test.pt", - "--report-pdf-options", "Iac-Security,Sast,Sca,ScanSummary") - assert.Error(t, err, "report option \"scansummary\" unavailable") + "--report-pdf-options", "Iac-Security,Sast,Sca,scan-information") + assert.Error(t, err, "report option \"scan-information\" unavailable") } func TestRunGetResultsGeneratingPdfReportWithOptions(t *testing.T) { diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 65dc68464..3d15bb0de 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -557,7 +557,7 @@ func scanCreateSubCommand( createScanCmd.PersistentFlags().String(commonParams.ScaPrivatePackageVersionFlag, "", scaPrivatePackageVersionFlagDescription) createScanCmd.PersistentFlags().String(commonParams.ReportFormatPdfToEmailFlag, "", pdfToEmailFlagDescription) createScanCmd.PersistentFlags().String(commonParams.ReportSbomFormatFlag, defaultSbomOption, sbomReportFlagDescription) - createScanCmd.PersistentFlags().String(commonParams.ReportFormatPdfOptionsFlag, "", pdfOptionsFlagDescription) + createScanCmd.PersistentFlags().String(commonParams.ReportFormatPdfOptionsFlag, defaultPdfOptionsDataSections, pdfOptionsFlagDescription) createScanCmd.PersistentFlags().String(commonParams.TargetFlag, "cx_result", "Output file") createScanCmd.PersistentFlags().String(commonParams.TargetPathFlag, ".", "Output Path") createScanCmd.PersistentFlags().StringSlice(commonParams.FilterFlag, []string{}, filterResultsListFlagUsage) diff --git a/test/integration/result_test.go b/test/integration/result_test.go index 78a9755be..444c41e28 100644 --- a/test/integration/result_test.go +++ b/test/integration/result_test.go @@ -210,7 +210,7 @@ func TestResultsGeneratingPdfReportWithPdfOptions(t *testing.T) { "results", "show", flag(params.ScanIDFlag), scanID, flag(params.TargetFormatFlag), "pdf", - flag(params.ReportFormatPdfOptionsFlag), "Iac-Security,scan-information", + flag(params.ReportFormatPdfOptionsFlag), "Iac-Security,ScanSummary,ExecutiveSummary,ScanResults", flag(params.TargetFlag), fileName, ) defer func() { @@ -229,7 +229,7 @@ func TestResultsGeneratingPdfReportAndSendToEmail(t *testing.T) { "results", "show", flag(params.ScanIDFlag), scanID, flag(params.TargetFormatFlag), "pdf", - flag(params.ReportFormatPdfOptionsFlag), "Iac-Security,scan-information", + flag(params.ReportFormatPdfOptionsFlag), "Iac-Security,ScanSummary,ExecutiveSummary,ScanResults", flag(params.ReportFormatPdfToEmailFlag), "test@checkmarx.com,test+2@checkmarx.com", ) assert.Assert(t, outputBuffer != nil, "Scan must complete successfully") diff --git a/test/integration/scan_test.go b/test/integration/scan_test.go index ceedf4b1f..715bee077 100644 --- a/test/integration/scan_test.go +++ b/test/integration/scan_test.go @@ -1069,7 +1069,7 @@ func TestScanGeneratingPdfReportWithPdfOptions(t *testing.T) { flag(params.PresetName), "Checkmarx Default", flag(params.BranchFlag), "dummy_branch", flag(params.TargetFormatFlag), "pdf", - flag(params.ReportFormatPdfOptionsFlag), "Iac-Security,scan-information", + flag(params.ReportFormatPdfOptionsFlag), "Iac-Security,ScanSummary,ExecutiveSummary,ScanResults", flag(params.TargetFlag), fileName, ) defer func() { diff --git a/test/integration/util_command.go b/test/integration/util_command.go index 0ecec9c58..a8ce7f418 100644 --- a/test/integration/util_command.go +++ b/test/integration/util_command.go @@ -203,7 +203,7 @@ func executeCmdWithTimeOutNilAssertion( func executeWithTimeout(cmd *cobra.Command, timeout time.Duration, args ...string) error { args = append(args, flag(params.RetryFlag), "3", flag(params.RetryDelayFlag), "5") - args = appendProxyArgs(args) + //args = appendProxyArgs(args) cmd.SetArgs(args) ctx, cancel := context.WithTimeout(context.Background(), timeout)