From 22e63225634042de567b97971390e91b9f7660a5 Mon Sep 17 00:00:00 2001 From: Gudmundur Haraldsson Date: Fri, 8 Jul 2022 13:55:10 +0000 Subject: [PATCH] --wpscan-api-report-end-msg option supports placeholder; update tests. --- main.php | 3 ++- tests/unit/WpscanReportEndTest.php | 18 ++++++++++++++---- wpscan-reports.php | 12 +++++++++--- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/main.php b/main.php index 681a7de4d..e672c5207 100755 --- a/main.php +++ b/main.php @@ -141,7 +141,8 @@ function vipgoci_help_print() :void { "\t" . ' with items separated by commas.' . PHP_EOL . "\t" . '--wpscan-api-skip-folders=ARRAY Directories not to scan using WPScan API scanning. Should be an' . PHP_EOL . "\t" . ' array with items separated by commas.' . PHP_EOL . - "\t" . '--wpscan-api-report-end-msg=STRING Message to append to end of WPScan API reports.' . PHP_EOL . + "\t" . '--wpscan-api-report-end-msg=STRING Message to append to end of WPScan API reports. The "%addon_type%" placeholder' . PHP_EOL . + "\t" . ' will be replaced by either "plugin" or "theme", depending on the report.' . PHP_EOL . PHP_EOL . 'Auto approve configuration:' . PHP_EOL . "\t" . '--autoapprove=BOOL Whether to auto-approve pull requests that fulfil' . PHP_EOL . diff --git a/tests/unit/WpscanReportEndTest.php b/tests/unit/WpscanReportEndTest.php index 1da90f9c3..4df5ded94 100644 --- a/tests/unit/WpscanReportEndTest.php +++ b/tests/unit/WpscanReportEndTest.php @@ -45,11 +45,16 @@ protected function setUp() :void { public function testWpscanReportEndPlugin(): void { $report_end = vipgoci_wpscan_report_end( VIPGOCI_WPSCAN_PLUGIN, - 'Message ends.' + 'Type: %addon_type%. Message ends.' + ); + + $this->assertStringContainsString( + 'Type: plugin.', + $report_end ); $this->assertStringNotContainsString( - 'themes', + 'theme', $report_end ); @@ -70,11 +75,16 @@ public function testWpscanReportEndPlugin(): void { public function testWpscanReportEndTheme(): void { $report_end = vipgoci_wpscan_report_end( VIPGOCI_WPSCAN_THEME, - 'Message ends.', + 'Type: %addon_type%. Message ends.' + ); + + $this->assertStringContainsString( + 'Type: theme.', + $report_end ); $this->assertStringNotContainsString( - 'plugins', + 'plugin', $report_end ); diff --git a/wpscan-reports.php b/wpscan-reports.php index f496c54e8..524d8b926 100644 --- a/wpscan-reports.php +++ b/wpscan-reports.php @@ -54,8 +54,8 @@ function vipgoci_wpscan_report_start( /** * Returns end of a WPScan API report comment. * - * @param string $issue_type Type of result being processed; VIPGOCI_WPSCAN_PLUGIN or VIPGOCI_WPSCAN_THEME. - * @param string wpscan_api_report_end_msg Message to append to end of WPScan API report. + * @param string $issue_type Type of result being processed; VIPGOCI_WPSCAN_PLUGIN or VIPGOCI_WPSCAN_THEME. + * @param string $wpscan_api_report_end_msg Message to append to end of WPScan API report. * * @return string Returns end of comment. */ @@ -78,7 +78,13 @@ function vipgoci_wpscan_report_end( return ''; // For unit-test. } - return vipgoci_output_html_escape( $wpscan_api_report_end_msg ) . "\n\r"; + return vipgoci_output_html_escape( + str_replace( + '%addon_type%', + $comment_type, + $wpscan_api_report_end_msg + ) + ) . "\n\r"; } /**