From c9544fec5e3c97c80000e40e21e1410820006c84 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 21 Oct 2022 19:42:14 +0000
Subject: [PATCH 01/87] Make SVG file extensions configurable.
---
ap-svg-files.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/ap-svg-files.php b/ap-svg-files.php
index 7fee87ce8..027a5f467 100644
--- a/ap-svg-files.php
+++ b/ap-svg-files.php
@@ -68,11 +68,11 @@ function vipgoci_ap_svg_files(
/*
* If not a SVG file, do not do anything.
*/
-
- if (
- 'svg' !==
- $pr_diff_file_extension
- ) {
+ if ( false === in_array(
+ $pr_diff_file_extension,
+ $options['svg-file-extensions'],
+ true
+ ) ) {
continue;
}
From 7aa83fedb3c1b9dbb117b8c3bd44f512094d49ea Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 21 Oct 2022 19:46:03 +0000
Subject: [PATCH 02/87] Make SVG file extensions configurable.
---
svg-scan.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/svg-scan.php b/svg-scan.php
index 74eabb105..3aa466d54 100644
--- a/svg-scan.php
+++ b/svg-scan.php
@@ -237,7 +237,11 @@ function vipgoci_svg_scan_single_file(
* Could not determine? Return null.
* We only process SVG files.
*/
- if ( 'svg' !== $file_extension ) {
+ if ( true === in_array(
+ $file_extension,
+ $options['svg-file-extensions'],
+ true
+ ) ) {
vipgoci_runtime_measure( VIPGOCI_RUNTIME_STOP, 'svg_scan_single_file' );
vipgoci_log(
From ff9394ea60eab5ef248d0fbeae03fb7fe4e2594d Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 21 Oct 2022 19:47:25 +0000
Subject: [PATCH 03/87] Make SVG and PHP file extensions configurable.
---
phpcs-scan.php | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/phpcs-scan.php b/phpcs-scan.php
index 0371c9e4e..91b2c343c 100644
--- a/phpcs-scan.php
+++ b/phpcs-scan.php
@@ -554,9 +554,9 @@ function vipgoci_phpcs_scan_commit(
array(
// If SVG-checks are enabled, include it in the file-extensions.
'file_extensions' => array_merge(
- array( 'php', 'js', 'twig' ),
+ $options['phpcs-file-extensions'],
( $options['svg-checks'] ?
- array( 'svg' ) :
+ $options['svg-file-extensions'] :
array()
)
),
@@ -632,7 +632,12 @@ function vipgoci_phpcs_scan_commit(
*/
$scanning_func =
(
- ( 'svg' === $file_extension ) &&
+ ( true === in_array(
+ $file_extension,
+ $options['svg-file-extensions'],
+ true
+ ) )
+ &&
( $options['svg-checks'] )
) ?
'vipgoci_svg_scan_single_file' :
From b085b779a2baa2f911fc4f097fd09e42dd6a7c1b Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 21 Oct 2022 19:48:23 +0000
Subject: [PATCH 04/87] Make PHP and SVG file extensions configurable
---
defines.php | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/defines.php b/defines.php
index 94e6f6b0e..dd7b8b3ce 100644
--- a/defines.php
+++ b/defines.php
@@ -220,8 +220,10 @@
define( 'VIPGOCI_LINT_ERROR_STR', 'PHP Syntax Errors Found' );
/*
- * Messages relating to PHPCS scanning.
+ * Defines relating to PHPCS scanning.
*/
+define( 'VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT', array( 'php', 'js', 'twig' ) );
+
define(
'VIPGOCI_PHPCS_SCAN_REVIEW_START',
'%1$s has identified potential problems in this pull request ' .
@@ -275,6 +277,11 @@
'
'
);
+/*
+ * Defines for SVG scanning.
+ */
+define( 'VIPGOCI_SVG_FILE_EXTENSIONS_DEFAULT', array( 'svg' ) );
+
/*
* Defines for addons generally.
*/
From 08491024c4e57d9e217d6ff73c59ef730e27212a Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 15:01:50 +0000
Subject: [PATCH 05/87] Adding option
'autoapprove-php-nonfunctional-changes-file-extensions'
---
ap-nonfunctional-changes.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ap-nonfunctional-changes.php b/ap-nonfunctional-changes.php
index fb57233ed..a9da3a0a3 100644
--- a/ap-nonfunctional-changes.php
+++ b/ap-nonfunctional-changes.php
@@ -92,7 +92,7 @@ function vipgoci_ap_nonfunctional_changes(
*/
if ( in_array(
$pr_diff_file_extension,
- array( 'php' ),
+ $options['autoapprove-php-nonfunctional-changes-file-extensions'],
true
) === false ) {
continue;
From b396de67d7163983754d1efef0b6967543e45b98 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 15:02:56 +0000
Subject: [PATCH 06/87] Add option 'lint-file-extensions'
---
lint-scan.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lint-scan.php b/lint-scan.php
index 85d64ad1a..bf7a5ae29 100644
--- a/lint-scan.php
+++ b/lint-scan.php
@@ -637,7 +637,7 @@ function vipgoci_lint_scan_commit(
false, // Exclude removed files.
false, // Exclude permission changes.
array(
- 'file_extensions' => array( 'php' ),
+ 'file_extensions' => $options['lint-file-extensions'],
'skip_folders' => $options['lint-skip-folders'],
),
true
@@ -654,7 +654,7 @@ function vipgoci_lint_scan_commit(
$options,
$commit_id,
array(
- 'file_extensions' => array( 'php' ),
+ 'file_extensions' => $options['lint-file-extensions'],
'skip_folders' => $options['lint-skip-folders'],
)
);
From 973c12f467db8c7e724fd8ce50e589a9a0a721a4 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 15:03:41 +0000
Subject: [PATCH 07/87] Adding option 'wpscan-api-file-extensions'
---
wpscan-scan.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/wpscan-scan.php b/wpscan-scan.php
index 8c27f12b2..c0e17ab41 100644
--- a/wpscan-scan.php
+++ b/wpscan-scan.php
@@ -217,6 +217,7 @@ function vipgoci_wpscan_scan_dirs_altered(
foreach ( $addon_dirs_relevant_to_scan as $addon_dir_relevant ) {
$addon_data_for_dir = vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
$options['local-git-repo'] . DIRECTORY_SEPARATOR . $addon_dir_relevant,
+ $options['wpscan-api-file-extensions'],
( ! in_array( $addon_dir_relevant, $options['wpscan-api-paths'], true ) )
);
From 02d91a29422ac9012208d460fd4c576b1d9f2d06 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 15:12:57 +0000
Subject: [PATCH 08/87] Add file extensions parameter so the value can be
configured.
---
wp-core-misc.php | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/wp-core-misc.php b/wp-core-misc.php
index c48fc7ca9..01b2e008a 100644
--- a/wp-core-misc.php
+++ b/wp-core-misc.php
@@ -233,6 +233,7 @@ function vipgoci_wpcore_misc_get_addon_headers_and_type(
* The function is adopted from WordPress: https://core.trac.wordpress.org/browser/tags/6.0/src/wp-admin/includes/plugin.php#L254
*
* @param string $path Path to scan for plugins and themes. Usually this would point a structure similar to wp-content/plugins.
+ * @param array $file_extensions File extensions to consider when determining what to analyze.
* @param bool $process_subdirectories If to process sub-directories.
*
* @link https://developer.wordpress.org/reference/functions/get_plugins/
@@ -259,6 +260,7 @@ function vipgoci_wpcore_misc_get_addon_headers_and_type(
*/
function vipgoci_wpcore_misc_scan_directory_for_addons(
string $path,
+ array $file_extensions,
bool $process_subdirectories = true
): array {
if (
@@ -283,7 +285,7 @@ function vipgoci_wpcore_misc_scan_directory_for_addons(
$path,
$process_subdirectories,
array(
- 'file_extensions' => array( 'php', 'css' ),
+ 'file_extensions' => $file_extensions,
)
);
@@ -688,6 +690,7 @@ function vipgoci_wpcore_misc_assign_addon_fields(
* API about the plugins/themes, return the information after processing.
*
* @param string $path Path to directory to analyze.
+ * @param array $file_extensions File extensions to consider when determining what to analyze.
* @param bool $process_subdirectories If to process sub-directories.
*
* @return array Information about plugins or themes found. Includes
@@ -721,10 +724,13 @@ function vipgoci_wpcore_misc_assign_addon_fields(
*/
function vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
string $path,
- bool $process_subdirectories = true
+ array $file_extensions,
+ bool $process_subdirectories = true,
+
) :array {
$addons_found = vipgoci_wpcore_misc_scan_directory_for_addons(
$path,
+ $file_extensions,
$process_subdirectories
);
From c863894124a36862fc22d7f168c0912e1829060f Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 15:25:39 +0000
Subject: [PATCH 09/87] Update vipgoci_option_array_handle() so forbidden
values can be array.
---
options.php | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/options.php b/options.php
index 8158b54cb..e2e7d47ae 100644
--- a/options.php
+++ b/options.php
@@ -822,19 +822,22 @@ function vipgoci_option_array_handle(
$options[ $option_name ] = $default_value;
}
- if ( ! empty( $forbidden_value ) ) {
- if ( in_array(
- $forbidden_value,
- $options[ $option_name ],
- true
+ if ( null !== $forbidden_value ) {
+ if ( is_string( $forbidden_value ) ) {
+ $forbidden_value = array( $forbidden_value );
+ }
+
+ if ( ! empty(
+ array_intersect(
+ $forbidden_value,
+ $options[ $option_name ],
+ )
) ) {
vipgoci_sysexit(
- 'Parameter --' .
- $option_name . ' ' .
+ 'Parameter --' . $option_name . ' ' .
'can not contain \'' .
- $forbidden_value .
- '\' as one of ' .
- 'the values',
+ '"' . implode( ',', $forbidden_value ) . '"' .
+ '\' as one of the values',
array(),
VIPGOCI_EXIT_USAGE_ERROR
);
From 2d7c53c84d0e91f6360218b586ad4cfe3a4e99b4 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 16:09:37 +0000
Subject: [PATCH 10/87] Fix whitespace.
---
wp-core-misc.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/wp-core-misc.php b/wp-core-misc.php
index 01b2e008a..55fed5716 100644
--- a/wp-core-misc.php
+++ b/wp-core-misc.php
@@ -725,8 +725,7 @@ function vipgoci_wpcore_misc_assign_addon_fields(
function vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
string $path,
array $file_extensions,
- bool $process_subdirectories = true,
-
+ bool $process_subdirectories = true
) :array {
$addons_found = vipgoci_wpcore_misc_scan_directory_for_addons(
$path,
From 4c38674a2afe9fdadb53925fd6f9db068fab915d Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 16:16:31 +0000
Subject: [PATCH 11/87] Adding constants.
---
defines.php | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/defines.php b/defines.php
index 9217c90a4..4e2f08cd4 100644
--- a/defines.php
+++ b/defines.php
@@ -81,9 +81,10 @@
define( 'VIPGOCI_ISSUE_TYPE_ERROR', 'error' );
/*
- * Define auto-approval types
+ * Defines for auto-approvals.
*/
define( 'VIPGOCI_APPROVAL_AUTOAPPROVE', 'auto-approval' );
+define( 'VIPGOCI_APPROVAL_AUTOAPPROVE_NON_FUNCTIONAL_CHANGES_FILE_EXTENSIONS_DEFAULT', array( 'php' ) );
/*
* Defines for vipgoci_runtime_measure() function.
@@ -204,8 +205,10 @@
);
/*
- * Messages related to PHP linting.
+ * Defines related to PHP linting.
*/
+define( 'VIPGOCI_LINT_FILE_EXTENSIONS_DEFAULT', array( 'php' ) );
+
define(
'VIPGOCI_LINT_REPORT_START',
'%1$s has identified PHP syntax errors during automated linting. ' .
@@ -305,6 +308,8 @@
define( 'VIPGOCI_WPSCAN_BASE_URL', 'https://wpscan.com' );
define( 'VIPGOCI_WPSCAN_API_BASE_URL', VIPGOCI_WPSCAN_BASE_URL . '/api/v3' );
+define( 'VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT', array( 'php', 'css' ) );
+
define( 'VIPGOCI_WPSCAN_UPDATEURI_WP_ORG_URLS', array( 'w.org', 'wordpress.org' ) );
define( 'VIPGOCI_WPSCAN_VULNERABLE', 'vulnerable' );
From b7e9646c4b674aa491f45d801a7e820fcebd7ef1 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 16:35:20 +0000
Subject: [PATCH 12/87] Make file extensions configurable for each scanner type
---
main.php | 158 +++++++++++++++++++++++++++++++------------------------
1 file changed, 90 insertions(+), 68 deletions(-)
mode change 100644 => 100755 main.php
diff --git a/main.php b/main.php
old mode 100644
new mode 100755
index 459e824f8..2c372130d
--- a/main.php
+++ b/main.php
@@ -84,6 +84,8 @@ function vipgoci_help_print() :void {
"\t" . ' files in the PR to be scanned. Default is true. It can be ' . PHP_EOL .
"\t" . ' modified via options file ("' . VIPGOCI_OPTIONS_FILE_NAME . '") placed in' . PHP_EOL .
"\t" . ' root of the repository.' . PHP_EOL .
+ "\t" . '--lint-file-extensions=ARRAY Use specified file extensions to select which altered files to PHP lint.' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_LINT_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--lint-skip-folders=STRING Specify folders relative to root of the git repository in which' . PHP_EOL .
"\t" . ' files should not be PHP linted. Values are comma separated.' . PHP_EOL .
"\t" . '--lint-skip-folders-in-repo-options-file=BOOL Whether to allow specifying folders that are not' . PHP_EOL .
@@ -105,6 +107,8 @@ function vipgoci_help_print() :void {
"\t" . ' should be an array with items separated by commas.' . PHP_EOL .
"\t" . '--phpcs-sniffs-exclude=ARRAY Specify which sniffs to exclude from PHPCS scanning,' . PHP_EOL .
"\t" . ' should be an array with items separated by commas.' . PHP_EOL .
+ "\t" . '--phpcs-file-extensions=ARRAY Use specified file extensions to select which altered files to PHPCS scan.' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--phpcs-runtime-set=STRING Specify --runtime-set values passed on to PHPCS' . PHP_EOL .
"\t" . ' -- expected to be a comma-separated value string of' . PHP_EOL .
"\t" . ' key-value pairs.' . PHP_EOL .
@@ -131,6 +135,8 @@ function vipgoci_help_print() :void {
"\t" . ' $PATH will be used instead.' . PHP_EOL .
"\t" . '--svg-scanner-path=FILE Path to SVG scanning tool. Should return similar output' . PHP_EOL .
"\t" . ' as PHPCS.' . PHP_EOL .
+ "\t" . '--svg-file-extensions=ARRAY Use specified file extensions to select which altered files to SVG scan. ' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_SVG_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
PHP_EOL .
'WPScan API scanning configuration:' . PHP_EOL .
"\t" . '--wpscan-api=BOOL Enable or disable WPScan API scanning. Disabled by default.' . PHP_EOL .
@@ -140,6 +146,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-file-extensions=ARRAY Use specified file extensions to select which altered files to scan with WPScan API.' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT ) . '"' . 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. Limited' . PHP_EOL .
"\t" . ' Markdown syntax allowed.' . PHP_EOL .
@@ -153,6 +161,9 @@ function vipgoci_help_print() :void {
"\t" . ' PHP files approved that contain' . PHP_EOL .
"\t" . ' only non-functional changes, such as' . PHP_EOL .
"\t" . ' whitespacing and comment changes.' . PHP_EOL .
+ "\t" . '--autoapprove-php-nonfunctional-changes-file-extensions=ARRAY Use specified file extensions to select which files' . PHP_EOL .
+ "\t" . ' to consider for non-functional auto-approval.' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_APPROVAL_AUTOAPPROVE_NON_FUNCTIONAL_CHANGES_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--autoapprove-label=STRING String to use for labels when auto-approving.' . PHP_EOL .
PHP_EOL .
'GitHub reviews & generic comments configuration:' . PHP_EOL .
@@ -166,7 +177,8 @@ function vipgoci_help_print() :void {
"\t" . ' will be submitted.' . PHP_EOL .
"\t" . '--review-comments-total-max=NUMBER Maximum number of inline comments submitted to' . PHP_EOL .
"\t" . ' a single pull request by the program -- includes' . PHP_EOL .
- "\t" . ' comments from previous executions. A value of' . PHP_EOL .
+ "\t" . ' comments from previous executions. Includes only' . PHP_EOL .
+ "\t" . ' "active" comments, not obsolete ones. A value of' . PHP_EOL .
"\t" . ' \'0\' indicates no limit.' . PHP_EOL .
"\t" . '--review-comments-ignore=STRING Specify which result comments to ignore' . PHP_EOL .
"\t" . ' -- e.g. useful if one type of message is to be ignored' . PHP_EOL .
@@ -281,9 +293,10 @@ function vipgoci_options_recognized() :array {
* PHP Linting configuration.
*/
'lint:',
+ 'lint-modified-files-only:',
+ 'lint-file-extensions:',
'lint-skip-folders:',
'lint-skip-folders-in-repo-options-file:',
- 'lint-modified-files-only:',
'lint-php-version-paths:',
'lint-php-versions:',
@@ -298,6 +311,7 @@ function vipgoci_options_recognized() :array {
'phpcs-severity:',
'phpcs-sniffs-include:',
'phpcs-sniffs-exclude:',
+ 'phpcs-file-extensions:',
'phpcs-runtime-set:',
'phpcs-skip-scanning-via-labels-allowed:',
'phpcs-skip-folders:',
@@ -310,6 +324,7 @@ function vipgoci_options_recognized() :array {
'svg-checks:',
'svg-php-path:',
'svg-scanner-path:',
+ 'svg-file-extensions:',
/*
* WPScan API scanning configuration
@@ -319,6 +334,7 @@ function vipgoci_options_recognized() :array {
'wpscan-api-token:',
'wpscan-api-paths:',
'wpscan-api-skip-folders:',
+ 'wpscan-api-file-extensions:',
'wpscan-api-report-end-msg:',
/*
@@ -327,6 +343,7 @@ function vipgoci_options_recognized() :array {
'autoapprove:',
'autoapprove-filetypes:',
'autoapprove-php-nonfunctional-changes:',
+ 'autoapprove-php-nonfunctional-changes-file-extensions:',
'autoapprove-label:',
/*
@@ -635,6 +652,16 @@ function vipgoci_run_init_options_phpcs( array &$options ) :void {
);
}
+ /*
+ * Process --phpcs-file-extensions -- expected to be
+ * an array of strings.
+ */
+ vipgoci_option_array_handle(
+ $options,
+ 'phpcs-file-extensions',
+ VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT
+ );
+
/*
* Process --phpcs-runtime-set -- expected to be an
* array of values.
@@ -698,6 +725,16 @@ function vipgoci_run_init_options_wpscan( array &$options ) :void {
'wpscan-api-skip-folders'
);
+ /*
+ * Process --wpscan-api-file-extensions -- expected to be an
+ * array of values.
+ */
+ vipgoci_option_array_handle(
+ $options,
+ 'wpscan-api-file-extensions',
+ VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT
+ );
+
/*
* Process --wpscan-api-report-end-msg -- expected to be a string.
*/
@@ -801,6 +838,16 @@ function vipgoci_run_init_options_svg( array &$options ) :void {
} else {
$options['svg-scanner-path'] = null;
}
+
+ /*
+ * Process --svg-file-extensions -- expected to be
+ * an array of strings.
+ */
+ vipgoci_option_array_handle(
+ $options,
+ 'svg-file-extensions',
+ VIPGOCI_SVG_FILE_EXTENSIONS_DEFAULT
+ );
}
/**
@@ -819,17 +866,43 @@ function vipgoci_run_init_options_autoapprove( array &$options ) :void {
vipgoci_option_bool_handle( $options, 'autoapprove-php-nonfunctional-changes', 'false' );
+ vipgoci_option_array_handle(
+ $options,
+ 'autoapprove-php-nonfunctional-changes-file-extensions',
+ VIPGOCI_APPROVAL_AUTOAPPROVE_NON_FUNCTIONAL_CHANGES_FILE_EXTENSIONS_DEFAULT
+ );
+
/*
* Process --autoapprove-filetypes, array option.
*
* Values will be converted to lowercase.
*/
- vipgoci_option_array_handle(
- $options,
- 'autoapprove-filetypes',
- array(),
- 'php'
- );
+ if ( true === $options['autoapprove'] ) {
+ vipgoci_option_array_handle(
+ $options,
+ 'autoapprove-filetypes',
+ array(),
+ /*
+ * Cross-reference: We disallow autoapproving PHP
+ * linted and PHPCS scanned files here, because these
+ * could contain dangerous code.
+ *
+ * Also disallow autoapproving SVG files here, as there
+ * is a dedicated part of vip-go-ci to scan them and
+ * autoapprove. Similar applies to non-functional changes.
+ */
+ array_unique(
+ array_merge(
+ $options['lint-file-extensions'],
+ $options['phpcs-file-extensions'],
+ $options['svg-file-extensions'],
+ $options['autoapprove-php-nonfunctional-changes-file-extensions'],
+ )
+ )
+ );
+ } else {
+ $options['autoapprove-filetypes'] = array();
+ }
/*
* Process --autoapprove-label. Set to boolean
@@ -864,63 +937,6 @@ function vipgoci_run_init_options_autoapprove( array &$options ) :void {
VIPGOCI_EXIT_USAGE_ERROR
);
}
-
- /*
- * More sanity checking; ensure PHP and JS files cannot
- * be specified for auto-approval.
- */
- if (
- ( true === $options['autoapprove'] ) &&
-
- /*
- * Cross-reference: We disallow autoapproving
- * PHP and JS files here, because they chould contain
- * contain dangerous code.
- */
- (
- ( in_array(
- 'php',
- $options['autoapprove-filetypes'],
- true
- ) )
- ||
- ( in_array(
- 'js',
- $options['autoapprove-filetypes'],
- true
- ) )
- )
- ) {
- vipgoci_sysexit(
- 'PHP and JS files cannot be auto-approved on file-type basis, as they ' .
- 'can cause serious problems for execution',
- array(),
- VIPGOCI_EXIT_USAGE_ERROR
- );
- }
-
- /*
- * Also, we disallow autoapproving SVG files here, as
- * we have a dedicated part of vip-go-ci to scan them
- * and autoapprove.
- */
-
- if (
- ( true === $options['autoapprove'] ) &&
- ( in_array(
- 'svg',
- $options['autoapprove-filetypes'],
- true
- ) )
- ) {
- vipgoci_sysexit(
- 'SVG files cannot be auto-approved on file-type basis, as they ' .
- 'can contain problematic code. Use --svg-checks=true to ' .
- 'allow auto-approval of SVG files',
- array(),
- VIPGOCI_EXIT_USAGE_ERROR
- );
- }
}
/**
@@ -1091,6 +1107,12 @@ function vipgoci_run_init_options_lint( array &$options ) :void {
'true'
);
+ vipgoci_option_array_handle(
+ $options,
+ 'lint-file-extensions',
+ VIPGOCI_LINT_FILE_EXTENSIONS_DEFAULT
+ );
+
vipgoci_option_bool_handle(
$options,
'lint-skip-folders-in-repo-options-file',
@@ -2199,12 +2221,12 @@ function vipgoci_run_init_options(
// Set options relating to WPScan API.
vipgoci_run_init_options_wpscan( $options );
- // Process autoapprove options.
- vipgoci_run_init_options_autoapprove( $options );
-
// Set SVG options.
vipgoci_run_init_options_svg( $options );
+ // Process autoapprove options.
+ vipgoci_run_init_options_autoapprove( $options );
+
// Set git repository options.
vipgoci_run_init_options_git_repo( $options );
From 9e6028f641dc0ecd863ee37dac6906eb77679f53 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Wed, 26 Oct 2022 16:45:16 +0000
Subject: [PATCH 13/87] Add empty line.
---
main.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/main.php b/main.php
index 2c372130d..eef759151 100755
--- a/main.php
+++ b/main.php
@@ -882,6 +882,7 @@ function vipgoci_run_init_options_autoapprove( array &$options ) :void {
$options,
'autoapprove-filetypes',
array(),
+
/*
* Cross-reference: We disallow autoapproving PHP
* linted and PHPCS scanned files here, because these
From 2a4b44d7c600ab80abb9cf4fe4de91920f4c991c Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 09:45:39 +0000
Subject: [PATCH 14/87] Add --wpscan-api-file-extensions option
---
tests/unit/MainRunInitOptionsWpscanTest.php | 22 +++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/tests/unit/MainRunInitOptionsWpscanTest.php b/tests/unit/MainRunInitOptionsWpscanTest.php
index f6ce5a633..50feba1cd 100644
--- a/tests/unit/MainRunInitOptionsWpscanTest.php
+++ b/tests/unit/MainRunInitOptionsWpscanTest.php
@@ -68,6 +68,10 @@ public function testRunInitOptionsWpscanOptionsDefault() :void {
'dir2',
'dir3',
),
+ 'wpscan-api-file-extensions' => array(
+ 'php',
+ 'css',
+ ),
'wpscan-api-report-end-msg' => '',
),
$this->options
@@ -82,12 +86,13 @@ public function testRunInitOptionsWpscanOptionsDefault() :void {
*/
public function testRunInitOptionsWpscanOptionsCustom() :void {
$this->options = array(
- 'wpscan-api' => 'true',
- 'wpscan-api-dry-mode' => 'false',
- 'wpscan-api-token' => '123456789',
- 'wpscan-api-paths' => '/plugins/,themes/,/custom-path/custom-plugins',
- 'wpscan-api-skip-folders' => 'dir1,dir2,dir3',
- 'wpscan-api-report-end-msg' => 'abc',
+ 'wpscan-api' => 'true',
+ 'wpscan-api-dry-mode' => 'false',
+ 'wpscan-api-token' => '123456789',
+ 'wpscan-api-paths' => '/plugins/,themes/,/custom-path/custom-plugins',
+ 'wpscan-api-skip-folders' => 'dir1,dir2,dir3',
+ 'wpscan-api-file-extensions' => 'php,css,css2',
+ 'wpscan-api-report-end-msg' => 'abc',
);
vipgoci_run_init_options_wpscan( $this->options );
@@ -107,6 +112,11 @@ public function testRunInitOptionsWpscanOptionsCustom() :void {
'dir2',
'dir3',
),
+ 'wpscan-api-file-extensions' => array(
+ 'php',
+ 'css',
+ 'css2',
+ ),
'wpscan-api-report-end-msg' => 'abc',
),
$this->options
From 8669f8c9acab1e276898f58c17930d763a5dc99b Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 09:50:50 +0000
Subject: [PATCH 15/87] Add --lint-file-extensions option
---
tests/unit/MainRunInitOptionsLintTest.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/unit/MainRunInitOptionsLintTest.php b/tests/unit/MainRunInitOptionsLintTest.php
index 66929d11f..15b5dc9fb 100644
--- a/tests/unit/MainRunInitOptionsLintTest.php
+++ b/tests/unit/MainRunInitOptionsLintTest.php
@@ -126,6 +126,7 @@ public function testRunInitOptionsLintDefault() :void {
'7.4' => $this->php_paths['7.4'],
'8.1' => $this->php_paths['8.1'],
),
+ 'lint-file-extensions' => array( 'php' ),
),
$this->options
);
@@ -140,6 +141,7 @@ public function testRunInitOptionsLintDefault() :void {
public function testRunInitOptionsLintCustom() :void {
$this->options['lint'] = 'false';
$this->options['lint-modified-files-only'] = 'false';
+ $this->options['lint-file-extensions'] = 'php,inc';
$this->options['lint-skip-folders-in-repo-options-file'] = 'true';
vipgoci_run_init_options_lint(
@@ -154,6 +156,7 @@ public function testRunInitOptionsLintCustom() :void {
'lint-skip-folders' => array( 'folder1/folder2', 'folder3/folder4' ),
'lint-php-versions' => null,
'lint-php-version-paths' => null,
+ 'lint-file-extensions' => array( 'php', 'inc' ),
),
$this->options
);
From 4eea749680123c7d936210545f550ff11e4b950a Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 09:55:57 +0000
Subject: [PATCH 16/87] Sort option values
---
main.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/main.php b/main.php
index eef759151..999858e1b 100755
--- a/main.php
+++ b/main.php
@@ -293,12 +293,12 @@ function vipgoci_options_recognized() :array {
* PHP Linting configuration.
*/
'lint:',
+ 'lint-php-version-paths:',
+ 'lint-php-versions:',
'lint-modified-files-only:',
'lint-file-extensions:',
'lint-skip-folders:',
'lint-skip-folders-in-repo-options-file:',
- 'lint-php-version-paths:',
- 'lint-php-versions:',
/*
* PHPCS configuration
From e4cab038a61a770803f28ba723c05f78e982345a Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 09:59:04 +0000
Subject: [PATCH 17/87] Sort option values
---
main.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/main.php b/main.php
index 999858e1b..88302a015 100755
--- a/main.php
+++ b/main.php
@@ -107,12 +107,12 @@ function vipgoci_help_print() :void {
"\t" . ' should be an array with items separated by commas.' . PHP_EOL .
"\t" . '--phpcs-sniffs-exclude=ARRAY Specify which sniffs to exclude from PHPCS scanning,' . PHP_EOL .
"\t" . ' should be an array with items separated by commas.' . PHP_EOL .
- "\t" . '--phpcs-file-extensions=ARRAY Use specified file extensions to select which altered files to PHPCS scan.' . PHP_EOL .
- "\t" . ' Default is: "' . implode( ',', VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--phpcs-runtime-set=STRING Specify --runtime-set values passed on to PHPCS' . PHP_EOL .
"\t" . ' -- expected to be a comma-separated value string of' . PHP_EOL .
"\t" . ' key-value pairs.' . PHP_EOL .
"\t" . ' For example: --phpcs-runtime-set="key1 value1,key2 value2"' . PHP_EOL .
+ "\t" . '--phpcs-file-extensions=ARRAY Use specified file extensions to select which altered files to PHPCS scan.' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--phpcs-skip-scanning-via-labels-allowed=BOOL Whether to allow users to skip PHPCS' . PHP_EOL .
"\t" . ' scanning of pull requests via labels' . PHP_EOL .
"\t" . ' attached to them. The label should be' . PHP_EOL .
@@ -311,8 +311,8 @@ function vipgoci_options_recognized() :array {
'phpcs-severity:',
'phpcs-sniffs-include:',
'phpcs-sniffs-exclude:',
- 'phpcs-file-extensions:',
'phpcs-runtime-set:',
+ 'phpcs-file-extensions:',
'phpcs-skip-scanning-via-labels-allowed:',
'phpcs-skip-folders:',
'phpcs-skip-folders-in-repo-options-file:',
From 0eb75df7f28954223965dee4bb0460d5724a02b3 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 10:02:43 +0000
Subject: [PATCH 18/87] Sort option values
---
main.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/main.php b/main.php
index 88302a015..1079916d7 100755
--- a/main.php
+++ b/main.php
@@ -268,10 +268,10 @@ function vipgoci_options_recognized() :array {
'max-exec-time:',
'enforce-https-urls:',
'skip-draft-prs:',
- 'branches-ignore:',
- 'local-git-repo:',
'skip-large-files:',
'skip-large-files-limit:',
+ 'branches-ignore:',
+ 'local-git-repo:',
'name-to-use:',
/*
From 953ac2ca2579319a8f72409a5dcf0654b3b4bd64 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 10:07:00 +0000
Subject: [PATCH 19/87] Move code around
---
main.php | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/main.php b/main.php
index 1079916d7..b9c0e62c3 100755
--- a/main.php
+++ b/main.php
@@ -653,22 +653,22 @@ function vipgoci_run_init_options_phpcs( array &$options ) :void {
}
/*
- * Process --phpcs-file-extensions -- expected to be
- * an array of strings.
+ * Process --phpcs-runtime-set -- expected to be an
+ * array of values.
*/
- vipgoci_option_array_handle(
+ vipgoci_option_phpcs_runtime_set(
$options,
- 'phpcs-file-extensions',
- VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT
+ 'phpcs-runtime-set'
);
/*
- * Process --phpcs-runtime-set -- expected to be an
- * array of values.
+ * Process --phpcs-file-extensions -- expected to be
+ * an array of strings.
*/
- vipgoci_option_phpcs_runtime_set(
+ vipgoci_option_array_handle(
$options,
- 'phpcs-runtime-set'
+ 'phpcs-file-extensions',
+ VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT
);
/*
From 5845e4ce2e546626932d8aa6c75e3f3c90f4dae1 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 10:13:47 +0000
Subject: [PATCH 20/87] Move code around
---
main.php | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/main.php b/main.php
index b9c0e62c3..229298726 100755
--- a/main.php
+++ b/main.php
@@ -717,22 +717,22 @@ function vipgoci_run_init_options_wpscan( array &$options ) :void {
);
/*
- * Process --wpscan-api-skip-folders -- expected to be an
+ * Process --wpscan-api-file-extensions -- expected to be an
* array of values.
*/
- vipgoci_option_skip_folder_handle(
+ vipgoci_option_array_handle(
$options,
- 'wpscan-api-skip-folders'
+ 'wpscan-api-file-extensions',
+ VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT
);
/*
- * Process --wpscan-api-file-extensions -- expected to be an
+ * Process --wpscan-api-skip-folders -- expected to be an
* array of values.
*/
- vipgoci_option_array_handle(
+ vipgoci_option_skip_folder_handle(
$options,
- 'wpscan-api-file-extensions',
- VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT
+ 'wpscan-api-skip-folders'
);
/*
From 25f9d73bf0f72eef3d44e9c18256b761e0aca3c0 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 10:14:23 +0000
Subject: [PATCH 21/87] Sort option values
---
main.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/main.php b/main.php
index 229298726..5892b7fe0 100755
--- a/main.php
+++ b/main.php
@@ -333,8 +333,8 @@ function vipgoci_options_recognized() :array {
'wpscan-api-dry-mode:',
'wpscan-api-token:',
'wpscan-api-paths:',
- 'wpscan-api-skip-folders:',
'wpscan-api-file-extensions:',
+ 'wpscan-api-skip-folders:',
'wpscan-api-report-end-msg:',
/*
From 407a9c74be618557b27d777327cbdc8c979c0503 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 10:55:59 +0000
Subject: [PATCH 22/87] Add
--autoapprove-php-nonfunctional-changes-file-extensions option
---
tests/unit/MainRunInitOptionsAutoapproveTest.php | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tests/unit/MainRunInitOptionsAutoapproveTest.php b/tests/unit/MainRunInitOptionsAutoapproveTest.php
index 0d791cc5e..cf94a2453 100644
--- a/tests/unit/MainRunInitOptionsAutoapproveTest.php
+++ b/tests/unit/MainRunInitOptionsAutoapproveTest.php
@@ -4,6 +4,7 @@
namespace Vipgoci\Tests\Unit;
+require_once __DIR__ . '/../../defines.php';
require_once __DIR__ . '/../../main.php';
require_once __DIR__ . '/../../options.php';
require_once __DIR__ . '/../../misc.php';
@@ -42,6 +43,7 @@ public function testRunInitOptionsAutoapproveDefault() :void {
$this->options = array(
'autoapprove' => null,
'autoapprove-php-nonfunctional-changes' => null,
+ 'autoapprove-php-nonfunctional-changes-file-extensions' => null,
'autoapprove-filetypes' => 'txt,gif,png',
'autoapprove-label' => 'MyText1',
);
@@ -54,7 +56,8 @@ public function testRunInitOptionsAutoapproveDefault() :void {
array(
'autoapprove' => false,
'autoapprove-php-nonfunctional-changes' => false,
- 'autoapprove-filetypes' => array( 'txt', 'gif', 'png' ),
+ 'autoapprove-php-nonfunctional-changes-file-extensions' => array( 'php' ),
+ 'autoapprove-filetypes' => array(),
'autoapprove-label' => 'MyText1',
),
$this->options
@@ -71,8 +74,12 @@ public function testRunInitOptionsAutoapproveCustom() :void {
$this->options = array(
'autoapprove' => 'true',
'autoapprove-php-nonfunctional-changes' => 'true',
+ 'autoapprove-php-nonfunctional-changes-file-extensions' => 'php,inc',
'autoapprove-filetypes' => 'txt,gif,png,pdf',
'autoapprove-label' => 'MyText2',
+ 'lint-file-extensions' => array( 'php' ),
+ 'phpcs-file-extensions' => array( 'php', 'js', 'twig' ),
+ 'svg-file-extensions' => array( 'svg' ),
);
vipgoci_run_init_options_autoapprove(
@@ -83,8 +90,12 @@ public function testRunInitOptionsAutoapproveCustom() :void {
array(
'autoapprove' => true,
'autoapprove-php-nonfunctional-changes' => true,
+ 'autoapprove-php-nonfunctional-changes-file-extensions' => array( 'php', 'inc' ),
'autoapprove-filetypes' => array( 'txt', 'gif', 'png', 'pdf' ),
'autoapprove-label' => 'MyText2',
+ 'lint-file-extensions' => array( 'php' ),
+ 'phpcs-file-extensions' => array( 'php', 'js', 'twig' ),
+ 'svg-file-extensions' => array( 'svg' ),
),
$this->options
);
From 1e15d616120f2dff578e47bb02a2bf3610cb9e4b Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 11:00:10 +0000
Subject: [PATCH 23/87] Restructure test a bit
---
.../MainRunInitOptionsAutoapproveTest.php | 23 ++++++++++++++-----
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/tests/unit/MainRunInitOptionsAutoapproveTest.php b/tests/unit/MainRunInitOptionsAutoapproveTest.php
index cf94a2453..4d764b5c5 100644
--- a/tests/unit/MainRunInitOptionsAutoapproveTest.php
+++ b/tests/unit/MainRunInitOptionsAutoapproveTest.php
@@ -1,14 +1,14 @@
options = array();
}
/**
* Clear variable.
+ *
+ * @return void
*/
protected function tearDown() :void {
unset( $this->options );
@@ -38,6 +47,8 @@ protected function tearDown() :void {
* correctly provided.
*
* @covers ::vipgoci_run_init_options_autoapprove
+ *
+ * @return void
*/
public function testRunInitOptionsAutoapproveDefault() :void {
$this->options = array(
From 5f08a5043c5b5a2bc0a5a3301a1cdd147d5a632f Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 11:04:48 +0000
Subject: [PATCH 24/87] WP CS changes
---
tests/unit/OptionsArrayHandleTest.php | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/tests/unit/OptionsArrayHandleTest.php b/tests/unit/OptionsArrayHandleTest.php
index 97a4bd6df..60f286fa4 100644
--- a/tests/unit/OptionsArrayHandleTest.php
+++ b/tests/unit/OptionsArrayHandleTest.php
@@ -20,9 +20,9 @@
*/
final class OptionsArrayHandleTest extends TestCase {
/**
- * Setup function.
+ * Setup function. Require file.
*
- * All files should be required here. See README.md.
+ * @return void
*/
protected function setUp() :void {
require_once __DIR__ . './../../options.php';
@@ -32,6 +32,8 @@ protected function setUp() :void {
* Test when option is an empty string.
*
* @covers ::vipgoci_option_array_handle
+ *
+ * @return void
*/
public function testOptionsArrayHandle1() :void {
$options = array(
@@ -56,6 +58,8 @@ public function testOptionsArrayHandle1() :void {
* Test when option is empty.
*
* @covers ::vipgoci_option_array_handle
+ *
+ * @return void
*/
public function testOptionsArrayHandle2() :void {
$options = array();
@@ -81,6 +85,8 @@ public function testOptionsArrayHandle2() :void {
* and comma is the separator.
*
* @covers ::vipgoci_option_array_handle
+ *
+ * @return void
*/
public function testOptionsArrayHandle3() :void {
$options = array(
@@ -111,6 +117,8 @@ public function testOptionsArrayHandle3() :void {
* not be transformed to lower case.
*
* @covers ::vipgoci_option_array_handle
+ *
+ * @return void
*/
public function testOptionsArrayHandle4() :void {
$options = array(
From 673ae0b37976e017a2622827a3b9b997d78ba757 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 12:38:06 +0000
Subject: [PATCH 25/87] Transform forbidden values to lower case, if requested.
---
options.php | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/options.php b/options.php
index e2e7d47ae..15e54bb1f 100644
--- a/options.php
+++ b/options.php
@@ -769,6 +769,8 @@ function vipgoci_option_integer_handle(
* @param string|array|null $forbidden_value Values not permissible to use.
* @param string $array_separator String separator between values.
* @param bool $strlower_option_value If to convert values to lower case.
+ * If set to true, forbidden values are set
+ * to lower case as well before validation.
*
* @return void
*/
@@ -827,6 +829,14 @@ function vipgoci_option_array_handle(
$forbidden_value = array( $forbidden_value );
}
+ if ( true === $strlower_option_value ) {
+ // Transform to lower case.
+ $forbidden_value = array_map(
+ 'strtolower',
+ $forbidden_value
+ );
+ }
+
if ( ! empty(
array_intersect(
$forbidden_value,
From 326393e874cb71dae38434f7e56360cef2826d39 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 12:41:38 +0000
Subject: [PATCH 26/87] Add tests for forbidden values
---
tests/unit/OptionsArrayHandleTest.php | 104 +++++++++++++++++++++++++-
1 file changed, 103 insertions(+), 1 deletion(-)
diff --git a/tests/unit/OptionsArrayHandleTest.php b/tests/unit/OptionsArrayHandleTest.php
index 60f286fa4..0c49eddee 100644
--- a/tests/unit/OptionsArrayHandleTest.php
+++ b/tests/unit/OptionsArrayHandleTest.php
@@ -25,7 +25,18 @@ final class OptionsArrayHandleTest extends TestCase {
* @return void
*/
protected function setUp() :void {
- require_once __DIR__ . './../../options.php';
+ require_once __DIR__ . '/../../defines.php';
+ require_once __DIR__ . '/../../options.php';
+ require_once __DIR__ . '/helper/OptionsArrayHandle.php';
+ }
+
+ /**
+ * Teardown function.
+ *
+ * @return void
+ */
+ protected function tearDown() :void {
+ unset( $this->options );
}
/**
@@ -143,4 +154,95 @@ public function testOptionsArrayHandle4() :void {
$options['mytestoption']
);
}
+
+ /**
+ * Test forbidden values. No errors, as no forbidden value is used.
+ *
+ * @return void
+ */
+ public function testOptionsArrayHandle5() :void {
+ $options = array(
+ 'mytestoption' => 'myvalue1,myvalue2,MYVALUE3',
+ );
+
+ vipgoci_option_array_handle(
+ $options,
+ 'mytestoption',
+ 'myvalue',
+ array( 'myvalue4' ),
+ ',',
+ true // To lower case.
+ );
+
+ $this->assertSame(
+ array(
+ 'myvalue1',
+ 'myvalue2',
+ 'myvalue3',
+ ),
+ $options['mytestoption']
+ );
+ }
+
+ /**
+ * Test forbidden values. No errors, as no forbidden value is used.
+ *
+ * @return void
+ */
+ public function testOptionsArrayHandle6() :void {
+ $options = array(
+ 'mytestoption' => 'myvalue1,myvalue2,MYVALUE3',
+ );
+
+ vipgoci_option_array_handle(
+ $options,
+ 'mytestoption',
+ 'myvalue',
+ array( 'myvalue3' ), // Note: Different case than input, is allowed.
+ ',',
+ false // Do not transform to lower case.
+ );
+
+ $this->assertSame(
+ array(
+ 'myvalue1',
+ 'myvalue2',
+ 'MYVALUE3',
+ ),
+ $options['mytestoption']
+ );
+ }
+
+ /**
+ * Test forbidden values. Error, as forbidden value is used.
+ *
+ * @return void
+ */
+ public function testOptionsArrayHandle7() :void {
+ $options = array(
+ 'mytestoption' => 'myvalue1,myvalue2,MYVALUE3',
+ );
+
+ $error_msg = '';
+
+ try {
+ vipgoci_option_array_handle(
+ $options,
+ 'mytestoption',
+ 'myvalue',
+ array( 'myvalue3' ),
+ ',',
+ true
+ );
+ } catch ( \ErrorException $error ) {
+ $error_msg = $error->getMessage();
+ }
+
+ $this->assertSame(
+ 'vipgoci_sysexit() was called.',
+ $error_msg,
+ 'vipgoci_sysexit() not called when it should have'
+ );
+ }
}
+
From fcf3e0df368314a726ba10ddd63449c9459e5847 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 12:42:59 +0000
Subject: [PATCH 27/87] Add vipgoci_sysexit() helper
---
tests/unit/helper/OptionsArrayHandle.php | 33 ++++++++++++++++++++++++
1 file changed, 33 insertions(+)
create mode 100644 tests/unit/helper/OptionsArrayHandle.php
diff --git a/tests/unit/helper/OptionsArrayHandle.php b/tests/unit/helper/OptionsArrayHandle.php
new file mode 100644
index 000000000..4a97d6874
--- /dev/null
+++ b/tests/unit/helper/OptionsArrayHandle.php
@@ -0,0 +1,33 @@
+
Date: Thu, 27 Oct 2022 12:43:57 +0000
Subject: [PATCH 28/87] Include message string in exception
---
tests/unit/helper/OptionsArrayHandle.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/helper/OptionsArrayHandle.php b/tests/unit/helper/OptionsArrayHandle.php
index 4a97d6874..a74082f55 100644
--- a/tests/unit/helper/OptionsArrayHandle.php
+++ b/tests/unit/helper/OptionsArrayHandle.php
@@ -27,7 +27,7 @@ function vipgoci_sysexit(
bool $irc = false
) {
throw new ErrorException(
- 'vipgoci_sysexit() was called.',
+ 'vipgoci_sysexit() was called; message=' . $str,
);
}
From fb0d4ca7f215559c9040be496d5c2ef1562825ab Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 12:44:28 +0000
Subject: [PATCH 29/87] Ensure logged message is included in exception message
---
tests/unit/OptionsArrayHandleTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/OptionsArrayHandleTest.php b/tests/unit/OptionsArrayHandleTest.php
index 0c49eddee..2eae6ef32 100644
--- a/tests/unit/OptionsArrayHandleTest.php
+++ b/tests/unit/OptionsArrayHandleTest.php
@@ -239,7 +239,7 @@ public function testOptionsArrayHandle7() :void {
}
$this->assertSame(
- 'vipgoci_sysexit() was called.',
+ 'vipgoci_sysexit() was called; message=Parameter --mytestoption can not contain \'"myvalue3"\' as one of the values',
$error_msg,
'vipgoci_sysexit() not called when it should have'
);
From e08c4d50effd5b5c87d58a31636204b56cafe1d6 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 12:47:54 +0000
Subject: [PATCH 30/87] Update comment syntax
---
main.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/main.php b/main.php
index 5892b7fe0..94d7496e3 100755
--- a/main.php
+++ b/main.php
@@ -882,8 +882,7 @@ function vipgoci_run_init_options_autoapprove( array &$options ) :void {
$options,
'autoapprove-filetypes',
array(),
-
- /*
+ /**
* Cross-reference: We disallow autoapproving PHP
* linted and PHPCS scanned files here, because these
* could contain dangerous code.
From 40a5f2b5f108f1d2ee4056ff362727e8e09d1146 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 12:56:34 +0000
Subject: [PATCH 31/87] Adding helper function for
MainRunInitOptionsAutoapproveTest.
---
.../helper/MainRunInitOptionsAutoapprove.php | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
create mode 100644 tests/unit/helper/MainRunInitOptionsAutoapprove.php
diff --git a/tests/unit/helper/MainRunInitOptionsAutoapprove.php b/tests/unit/helper/MainRunInitOptionsAutoapprove.php
new file mode 100644
index 000000000..5e43c90a2
--- /dev/null
+++ b/tests/unit/helper/MainRunInitOptionsAutoapprove.php
@@ -0,0 +1,33 @@
+
Date: Thu, 27 Oct 2022 12:58:18 +0000
Subject: [PATCH 32/87] Add test for invalid --autoapprove-filetypes option
values
---
.../MainRunInitOptionsAutoapproveTest.php | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tests/unit/MainRunInitOptionsAutoapproveTest.php b/tests/unit/MainRunInitOptionsAutoapproveTest.php
index 4d764b5c5..2ee225e5b 100644
--- a/tests/unit/MainRunInitOptionsAutoapproveTest.php
+++ b/tests/unit/MainRunInitOptionsAutoapproveTest.php
@@ -29,6 +29,7 @@ protected function setUp() :void {
require_once __DIR__ . '/../../main.php';
require_once __DIR__ . '/../../options.php';
require_once __DIR__ . '/../../misc.php';
+ require_once __DIR__ . '/helper/MainRunInitOptionsAutoapprove.php';
$this->options = array();
}
@@ -111,4 +112,35 @@ public function testRunInitOptionsAutoapproveCustom() :void {
$this->options
);
}
+
+ /**
+ * Check if errors are correctly handled.
+ *
+ * @covers ::vipgoci_run_init_options_autoapprove
+ */
+ public function testRunInitOptionsAutoapproveErrors1() :void {
+ $this->options = array(
+ 'autoapprove' => 'true',
+ 'autoapprove-php-nonfunctional-changes' => 'true',
+ 'autoapprove-php-nonfunctional-changes-file-extensions' => 'php,inc',
+ 'autoapprove-filetypes' => 'txt,gif,png,pdf,php', // 'php' is not allowed.
+ 'autoapprove-label' => 'MyText2',
+ 'lint-file-extensions' => array( 'php' ),
+ 'phpcs-file-extensions' => array( 'php', 'js', 'twig' ),
+ 'svg-file-extensions' => array( 'svg' ),
+ );
+
+ try {
+ vipgoci_run_init_options_autoapprove(
+ $this->options
+ );
+ } catch( \ErrorException $error ) {
+ $error_msg = $error->getMessage();
+ }
+
+ $this->assertSame(
+ 'vipgoci_sysexit() was called; message=Parameter --autoapprove-filetypes can not contain \'"php,js,twig,svg,inc"\' as one of the values',
+ $error_msg
+ );
+ }
}
From 0e8896d018c5bfd297050bcca13ccff7e3fa97c8 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 13:17:41 +0000
Subject: [PATCH 33/87] Add test for invalid --autoapprove-filetypes and
--autoapprove-label options
---
.../MainRunInitOptionsAutoapproveTest.php | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tests/unit/MainRunInitOptionsAutoapproveTest.php b/tests/unit/MainRunInitOptionsAutoapproveTest.php
index 2ee225e5b..b66d35b43 100644
--- a/tests/unit/MainRunInitOptionsAutoapproveTest.php
+++ b/tests/unit/MainRunInitOptionsAutoapproveTest.php
@@ -143,4 +143,36 @@ public function testRunInitOptionsAutoapproveErrors1() :void {
$error_msg
);
}
+
+ /**
+ * Check if errors are correctly handled.
+ *
+ * @covers ::vipgoci_run_init_options_autoapprove
+ */
+ public function testRunInitOptionsAutoapproveErrors2() :void {
+ $this->options = array(
+ 'autoapprove' => 'true',
+ 'autoapprove-php-nonfunctional-changes' => 'true',
+ 'autoapprove-php-nonfunctional-changes-file-extensions' => 'php,inc',
+ 'autoapprove-filetypes' => '', // Should not be empty.
+ 'autoapprove-label' => false, // Should not be false.
+ 'lint-file-extensions' => array( 'php' ),
+ 'phpcs-file-extensions' => array( 'php', 'js', 'twig' ),
+ 'svg-file-extensions' => array( 'svg' ),
+ );
+
+ try {
+ vipgoci_run_init_options_autoapprove(
+ $this->options
+ );
+ } catch( \ErrorException $error ) {
+ $error_msg = $error->getMessage();
+ }
+
+ $this->assertSame(
+ 'vipgoci_sysexit() was called; message=To be able to auto-approve, file-types to approve must be specified, as well as a label; see --help for information',
+ $error_msg
+ );
+ }
+
}
From 105da2a173f36cc53afc6a8df1780e5a327f39bc Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 13:24:11 +0000
Subject: [PATCH 34/87] Setting
--autoapprove-php-nonfunctional-changes-file-extensions option
---
tests/integration/ApNonfunctionalChangesTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/integration/ApNonfunctionalChangesTest.php b/tests/integration/ApNonfunctionalChangesTest.php
index 76aa296f0..9fb4eabb8 100644
--- a/tests/integration/ApNonfunctionalChangesTest.php
+++ b/tests/integration/ApNonfunctionalChangesTest.php
@@ -56,6 +56,8 @@ protected function setUp(): void {
$this->options['branches-ignore'] = array();
$this->options['skip-draft-prs'] = false;
+
+ $this->options['autoapprove-php-nonfunctional-changes-file-extensions'] = array( 'php' );
}
protected function tearDown(): void {
From 68ee0ea1586e0b55042cb86eff802d1631f022f4 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 13:47:51 +0000
Subject: [PATCH 35/87] Add check
---
ap-svg-files.php | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/ap-svg-files.php b/ap-svg-files.php
index 027a5f467..a1e7270ec 100644
--- a/ap-svg-files.php
+++ b/ap-svg-files.php
@@ -68,11 +68,14 @@ function vipgoci_ap_svg_files(
/*
* If not a SVG file, do not do anything.
*/
- if ( false === in_array(
- $pr_diff_file_extension,
- $options['svg-file-extensions'],
- true
- ) ) {
+ if (
+ ( null === $pr_diff_file_extension ) ||
+ ( false === in_array(
+ $pr_diff_file_extension,
+ $options['svg-file-extensions'],
+ true
+ ) )
+ ) {
continue;
}
From 295b5e1f7f14ced3e534c8e2b7fe99ed1828a8c7 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 13:48:16 +0000
Subject: [PATCH 36/87] Fix check
---
svg-scan.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/svg-scan.php b/svg-scan.php
index 3aa466d54..8f77bf390 100644
--- a/svg-scan.php
+++ b/svg-scan.php
@@ -237,7 +237,7 @@ function vipgoci_svg_scan_single_file(
* Could not determine? Return null.
* We only process SVG files.
*/
- if ( true === in_array(
+ if ( false === in_array(
$file_extension,
$options['svg-file-extensions'],
true
From c6d281d0dcf230f7cb21a80b925afba14bd5a94d Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 13:49:05 +0000
Subject: [PATCH 37/87] Add --svg-file-extensions option
---
tests/integration/ApSvgFilesTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/integration/ApSvgFilesTest.php b/tests/integration/ApSvgFilesTest.php
index 024e73416..6893db532 100644
--- a/tests/integration/ApSvgFilesTest.php
+++ b/tests/integration/ApSvgFilesTest.php
@@ -113,6 +113,8 @@ protected function setUp(): void {
$this->options['skip-large-files-limit'] = 15;
$this->options['lint-modified-files-only'] = false;
+
+ $this->options['svg-file-extensions'] = array( 'svg' );
}
/**
From 414915dc88824861c8c2f9cb5beab0ab93f08536 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 13:53:18 +0000
Subject: [PATCH 38/87] Set --lint-file-extensions option
---
tests/integration/LintScanCommitTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/integration/LintScanCommitTest.php b/tests/integration/LintScanCommitTest.php
index d363e2451..6fb8c410a 100644
--- a/tests/integration/LintScanCommitTest.php
+++ b/tests/integration/LintScanCommitTest.php
@@ -99,6 +99,8 @@ protected function setUp(): void {
$this->options['lint-modified-files-only'] = false;
+ $this->options['lint-file-extensions'] = array( 'php' );
+
$this->options['lint-php-versions'] = array(
$this->options['lint-php1-version'],
$this->options['lint-php2-version'],
From 7c9bc089570c793542fc32d1b86bbd08ef3b8af1 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 13:59:06 +0000
Subject: [PATCH 39/87] Set --phpcs-file-extensions and --svg-file-extensions
options.
---
tests/integration/PhpcsScanScanCommitTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/integration/PhpcsScanScanCommitTest.php b/tests/integration/PhpcsScanScanCommitTest.php
index 2bf2579a3..5330cf083 100644
--- a/tests/integration/PhpcsScanScanCommitTest.php
+++ b/tests/integration/PhpcsScanScanCommitTest.php
@@ -70,10 +70,14 @@ protected function setUp(): void {
$this->options['phpcs'] = true;
+ $this->options['phpcs-file-extensions'] = array( 'php', 'js' );
+
$this->options['phpcs-skip-folders'] = array();
$this->options['phpcs-severity'] = (int) $this->options['phpcs-severity'];
+ $this->options['svg-file-extensions'] = array( 'svg' );
+
$this->options['skip-draft-prs'] = false;
$this->options['skip-large-files'] = false;
From aa40af6d4d31ce23ed6dc93426cfa3117921ac7f Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 14:02:15 +0000
Subject: [PATCH 40/87] Set --phpcs-file-extensions and --svg-file-extensions
options.
---
tests/integration/SvgScanScanCommitTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/integration/SvgScanScanCommitTest.php b/tests/integration/SvgScanScanCommitTest.php
index 90278d309..26ce4ddd7 100644
--- a/tests/integration/SvgScanScanCommitTest.php
+++ b/tests/integration/SvgScanScanCommitTest.php
@@ -75,8 +75,12 @@ protected function setUp(): void {
$this->options['skip-draft-prs'] = false;
+ $this->options['phpcs-file-extensions'] = array( 'php', 'js' );
+
$this->options['phpcs-skip-scanning-via-labels-allowed'] = false;
+ $this->options['svg-file-extensions'] = array( 'svg' );
+
$this->options['skip-large-files'] = false;
$this->options['skip-large-files-limit'] = 15;
From 1c3a0fd41ca72378bbfeabadc3749e35ce91b13b Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 14:05:53 +0000
Subject: [PATCH 41/87] Update function call
---
.../WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php b/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php
index 4eca62991..9d324e5b1 100644
--- a/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php
+++ b/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php
@@ -134,6 +134,7 @@ public function testGetAddonDataAndSlugsForDirectoryWithSubdirectories(): void {
$actual_results = vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
$this->temp_dir . '/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest',
+ array( 'php', 'css' ),
true
);
@@ -324,6 +325,7 @@ public function testGetAddonDataAndSlugsForDirectorySkipSubdirectories(): void {
$actual_results = vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
$this->temp_dir . '/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest',
+ array( 'php', 'css' ),
false
);
From 68a85a02870799e18ad721e3823b3d5a3abb9485 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 14:10:00 +0000
Subject: [PATCH 42/87] Update function call
---
tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php b/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php
index 835d53838..77f4fdffa 100644
--- a/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php
+++ b/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php
@@ -168,6 +168,7 @@ public function testWpcoreMiscScanDirectoryForAdddonsScanSubdirectories(): void
$results_actual = vipgoci_wpcore_misc_scan_directory_for_addons(
$this->temp_dir . '/WpCoreMiscScanDirectoryForAdddonsTest',
+ array( 'php', 'css' ),
true
);
@@ -243,6 +244,7 @@ public function testWpcoreMiscScanDirectoryForAdddonsSkipSubdirectories(): void
$results_actual = vipgoci_wpcore_misc_scan_directory_for_addons(
$this->temp_dir . '/WpCoreMiscScanDirectoryForAdddonsTest',
+ array( 'php', 'css' ),
false
);
From 18f22ee8a1c1a50481990d66a005386b093b4377 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 15:23:24 +0000
Subject: [PATCH 43/87] Set --svg-file-extensions option.
---
tests/integration/SvgScanScanSingleFileTest.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/integration/SvgScanScanSingleFileTest.php b/tests/integration/SvgScanScanSingleFileTest.php
index e405f5927..f34b3b675 100644
--- a/tests/integration/SvgScanScanSingleFileTest.php
+++ b/tests/integration/SvgScanScanSingleFileTest.php
@@ -50,6 +50,8 @@ protected function setUp(): void {
$this->options['svg-checks'] = true;
+ $this->options['svg-file-extensions'] = array( 'svg' );
+
$this->options['skip-large-files'] = true;
$this->options['skip-large-files-limit'] = 15000;
From 0a3d1240e9bdbb0528b82b4c71a0b69352c11079 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 15:25:24 +0000
Subject: [PATCH 44/87] Set --phpcs-file-extensions option.
---
tests/integration/MainRunInitOptionsPhpcsTest.php | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tests/integration/MainRunInitOptionsPhpcsTest.php b/tests/integration/MainRunInitOptionsPhpcsTest.php
index c1963079d..7987bfe1b 100644
--- a/tests/integration/MainRunInitOptionsPhpcsTest.php
+++ b/tests/integration/MainRunInitOptionsPhpcsTest.php
@@ -79,6 +79,7 @@ public function testRunInitOptionsPhpcsDefaults() :void {
'phpcs-sniffs-include' => null,
'phpcs-sniffs-exclude' => null,
'phpcs-runtime-set' => null,
+ 'phpcs-file-extensions' => null,
'phpcs-skip-folders' => null,
'phpcs-severity' => null,
),
@@ -100,6 +101,7 @@ public function testRunInitOptionsPhpcsDefaults() :void {
'phpcs-sniffs-include' => array(),
'phpcs-sniffs-exclude' => array(),
'phpcs-runtime-set' => array(),
+ 'phpcs-file-extensions' => array( 'php', 'js', 'twig' ),
'phpcs-skip-folders' => array(),
'phpcs-severity' => 1,
'phpcs-standard-file' => false,
@@ -138,6 +140,7 @@ public function testRunInitOptionsPhpcsCustom() :void {
'phpcs-sniffs-include' => 'Sniff1,Sniff2',
'phpcs-sniffs-exclude' => 'Sniff3,Sniff4',
'phpcs-runtime-set' => 'key1 value1,key2 value2',
+ 'phpcs-file-extensions' => 'php,js',
'phpcs-skip-folders' => 'myfolder1,myfolder2',
'phpcs-severity' => 5,
);
@@ -160,6 +163,7 @@ public function testRunInitOptionsPhpcsCustom() :void {
array( 'key1', 'value1' ),
array( 'key2', 'value2' ),
),
+ 'phpcs-file-extensions' => array( 'php', 'js' ),
'phpcs-skip-folders' => array( 'myfolder1', 'myfolder2' ),
'phpcs-severity' => 5,
'phpcs-standard-file' => false,
@@ -197,6 +201,7 @@ public function testRunInitOptionsPhpcsInvalid() :void {
'phpcs-sniffs-include' => 'Sniff1,Sniff2',
'phpcs-sniffs-exclude' => 'Sniff3,Sniff4',
'phpcs-runtime-set' => 'key1 value1,key2 value2',
+ 'phpcs-file-extensions' => 'php,js',
'phpcs-skip-folders' => 'myfolder1,myfolder2',
'phpcs-severity' => 5,
);
From 086b18cc9b67b8c6cd3b0b1ae62b36db60e08afb Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Thu, 27 Oct 2022 15:27:07 +0000
Subject: [PATCH 45/87] Set --svg-file-extensions option
---
.../integration/MainRunInitOptionsSvgTest.php | 21 +++++++++++--------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/tests/integration/MainRunInitOptionsSvgTest.php b/tests/integration/MainRunInitOptionsSvgTest.php
index c2e80c09a..496eb3f8b 100644
--- a/tests/integration/MainRunInitOptionsSvgTest.php
+++ b/tests/integration/MainRunInitOptionsSvgTest.php
@@ -76,9 +76,10 @@ public function testRunInitOptionsSvgDefault() :void {
$this->assertSame(
array(
- 'svg-checks' => false,
- 'svg-php-path' => null,
- 'svg-scanner-path' => null,
+ 'svg-checks' => false,
+ 'svg-php-path' => null,
+ 'svg-scanner-path' => null,
+ 'svg-file-extensions' => array( 'svg' ),
),
$this->options
);
@@ -98,9 +99,10 @@ public function testRunInitOptionsSvgCustom() :void {
return;
}
- $this->options['svg-checks'] = 'true';
- $this->options['svg-php-path'] = $this->svg_php_path;
- $this->options['svg-scanner-path'] = $this->svg_scanner_path;
+ $this->options['svg-checks'] = 'true';
+ $this->options['svg-php-path'] = $this->svg_php_path;
+ $this->options['svg-scanner-path'] = $this->svg_scanner_path;
+ $this->options['svg-file-extensions'] = 'svg,svg2';
vipgoci_run_init_options_svg(
$this->options
@@ -108,9 +110,10 @@ public function testRunInitOptionsSvgCustom() :void {
$this->assertSame(
array(
- 'svg-checks' => true,
- 'svg-php-path' => $this->svg_php_path,
- 'svg-scanner-path' => $this->svg_scanner_path,
+ 'svg-checks' => true,
+ 'svg-php-path' => $this->svg_php_path,
+ 'svg-scanner-path' => $this->svg_scanner_path,
+ 'svg-file-extensions' => array( 'svg', 'svg2' ),
),
$this->options
);
From 589317c0dd2c6c5c4cc16883c83e8294b333812f Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:09:56 +0000
Subject: [PATCH 46/87] Update test to reflect new output
---
...teScanDetailsAutoApproveConfigurationTest.php | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php b/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php
index 3ba3959dd..d74ff85ca 100644
--- a/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php
@@ -72,6 +72,13 @@ public function testCreateDetails1(): void {
)
);
+ $this->assertFalse(
+ strpos(
+ $actual_output,
+ 'Files with file extensions to consider for non-functional change auto-approval'
+ )
+ );
+
$this->assertFalse(
strpos(
$actual_output,
@@ -88,6 +95,7 @@ public function testCreateDetails1(): void {
public function testCreateDetails2(): void {
$this->options['autoapprove'] = true;
$this->options['autoapprove-php-nonfunctional-changes'] = true;
+ $this->options['autoapprove-php-nonfunctional-changes-file-extensions'] = array( 'php' );
$this->options['autoapprove-filetypes'] = array( 'txt', 'ini' );
$actual_output = vipgoci_report_create_scan_details_auto_approve_configuration(
@@ -117,6 +125,14 @@ public function testCreateDetails2(): void {
)
);
+ $this->assertNotFalse(
+ strpos(
+ $actual_output,
+ 'Files with file extensions to consider for non-functional change auto-approval:' . PHP_EOL .
+ 'php
'
+ )
+ );
+
$this->assertNotFalse(
strpos(
$actual_output,
From d69f1ced4e0a88c53b4ff89f67671d7b35cc5f3c Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:16:20 +0000
Subject: [PATCH 47/87] Update test to reflect new output
---
...eportCreateScanDetailsWpscanConfigurationTest.php | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
index 502213cf1..3fc89d3e9 100644
--- a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
@@ -74,6 +74,11 @@ public function testCreateDetails1(): void {
'Directories not scanned',
$actual_output
);
+
+ $this->assertStringNotContainsString(
+ 'Scan added/modified files with file extensions',
+ $actual_output
+ );
}
/**
@@ -85,6 +90,7 @@ public function testCreateDetails2(): void {
$this->options['wpscan-api'] = true;
$this->options['wpscan-api-paths'] = array( 'plugins', 'themes' );
$this->options['wpscan-api-skip-folders'] = array( 'skip-dir1', 'skip-dir2' );
+ $this->options['wpscan-api-file-extensions'] = array( 'php', 'css' );
$actual_output = vipgoci_report_create_scan_details_wpscan_configuration(
$this->options
@@ -118,5 +124,11 @@ public function testCreateDetails2(): void {
'' . PHP_EOL . 'skip-dir1
skip-dir2
',
$actual_output
);
+
+ $this->assertStringContainsString(
+ 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ '',
+ $actual_output
+ );
}
}
From 44d2c31fc9b24752d839e2369a31ed4aafee67d1 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:17:59 +0000
Subject: [PATCH 48/87] Update test to reflect new output
---
...portCreateScanDetailsSvgConfigurationTest.php | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php b/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
index f81f7b7d9..31b0f3b50 100644
--- a/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
@@ -64,6 +64,13 @@ public function testCreateDetails1(): void {
'false
'
)
);
+
+ $this->assertFalse(
+ strpos(
+ $actual_output,
+ 'Scan added/modified files with file extensions'
+ )
+ );
}
/**
@@ -73,6 +80,7 @@ public function testCreateDetails1(): void {
*/
public function testCreateDetails2(): void {
$this->options['svg-checks'] = true;
+ $this->options['svg-file-extensions'] = array( 'svg' );
$actual_output = vipgoci_report_create_scan_details_svg_configuration(
$this->options
@@ -92,5 +100,13 @@ public function testCreateDetails2(): void {
'true
'
)
);
+
+ $this->assertNotFalse(
+ strpos(
+ $actual_output,
+ 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ ''
+ )
+ );
}
}
From 1e0bfd17c9cc52c31dbf178f8cdc9b8aaae1408f Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:24:27 +0000
Subject: [PATCH 49/87] Update test to reflect new output
---
.../ReportCreateScanDetailsPhpLintOptionsTest.php | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php b/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
index 8a1c5d246..5033b6344 100644
--- a/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
+++ b/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
@@ -72,6 +72,13 @@ public function testCreateDetails1(): void {
)
);
+ $this->assertFalse(
+ strpos(
+ $actual_output,
+ 'Lint files with file extensions'
+ )
+ );
+
$this->assertFalse(
strpos(
$actual_output,
@@ -88,6 +95,7 @@ public function testCreateDetails1(): void {
public function testCreateDetails2(): void {
$this->options['lint'] = true;
$this->options['lint-modified-files-only'] = true;
+ $this->options['lint-file-extensions'] = array( 'php' );
$this->options['lint-skip-folders'] = array( 'path1', 'path2' );
$actual_output = vipgoci_report_create_scan_details_php_lint_options(
@@ -117,6 +125,13 @@ public function testCreateDetails2(): void {
)
);
+ $this->assertNotFalse(
+ strpos(
+ $actual_output,
+ 'Lint files with file extensions'
+ )
+ );
+
$this->assertNotFalse(
strpos(
$actual_output,
From 3a5ea7ef0ace2ff828e58ea7f0da42efad56f8ab Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:26:54 +0000
Subject: [PATCH 50/87] Update test to reflect new output
---
...reateScanDetailsPhpcsConfigurationTest.php | 43 +++++++++++++++----
1 file changed, 35 insertions(+), 8 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
index e35cbc61e..59aa7e5c0 100644
--- a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
@@ -79,6 +79,13 @@ public function testCreateDetails1(): void {
)
);
+ $this->assertFalse(
+ strpos(
+ $actual_output,
+ 'Scan added/modified files with file extensions'
+ )
+ );
+
$this->assertFalse(
strpos(
$actual_output,
@@ -107,14 +114,15 @@ public function testCreateDetails1(): void {
* @covers ::vipgoci_report_create_scan_details_phpcs_configuration
*/
public function testCreateDetails2(): void {
- $this->options['phpcs'] = true;
- $this->options['phpcs-severity'] = 3;
- $this->options['phpcs-standard-file'] = false;
- $this->options['phpcs-standard'] = array( 'WordPress', 'WordPress-VIP-Go' );
- $this->options['phpcs-runtime-set'] = array( array( 'opt1', 'key1' ) );
- $this->options['phpcs-sniffs-include'] = array();
- $this->options['phpcs-sniffs-exclude'] = array();
- $this->options['phpcs-skip-folders'] = array( 'path1', 'path2' );
+ $this->options['phpcs'] = true;
+ $this->options['phpcs-severity'] = 3;
+ $this->options['phpcs-standard-file'] = false;
+ $this->options['phpcs-standard'] = array( 'WordPress', 'WordPress-VIP-Go' );
+ $this->options['phpcs-runtime-set'] = array( array( 'opt1', 'key1' ) );
+ $this->options['phpcs-file-extensions'] = array( 'php', 'js', 'twig' );
+ $this->options['phpcs-sniffs-include'] = array();
+ $this->options['phpcs-sniffs-exclude'] = array();
+ $this->options['phpcs-skip-folders'] = array( 'path1', 'path2' );
$actual_output = vipgoci_report_create_scan_details_phpcs_configuration(
$this->options
@@ -161,6 +169,15 @@ public function testCreateDetails2(): void {
)
);
+ $this->assertNotFalse(
+ strpos(
+ $actual_output,
+ 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ '' . PHP_EOL .
+ 'php
js
twig
'
+ )
+ );
+
$this->assertNotFalse(
strpos(
$actual_output,
@@ -201,6 +218,7 @@ public function testCreateDetails3(): void {
$this->options['phpcs-standard'] = array( 'WordPress', 'WordPress-VIP-Go' );
$this->options['phpcs-standard-original'] = $this->options['phpcs-standard'];
$this->options['phpcs-runtime-set'] = array( array( 'opt1', 'key1' ) );
+ $this->options['phpcs-file-extensions'] = array( 'php', 'js', 'twig' );
$this->options['phpcs-sniffs-include'] = array( 'AdditionalStandard1' );
$this->options['phpcs-sniffs-exclude'] = array( 'SniffExclude1' );
$this->options['phpcs-skip-folders'] = array( 'path1', 'path2' );
@@ -250,6 +268,15 @@ public function testCreateDetails3(): void {
)
);
+ $this->assertNotFalse(
+ strpos(
+ $actual_output,
+ 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ '' . PHP_EOL .
+ 'php
js
twig
'
+ )
+ );
+
$this->assertNotFalse(
strpos(
$actual_output,
From fe206c80c2a59c8cafcce3432144ced9b8f9f7a2 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:31:43 +0000
Subject: [PATCH 51/87] Add new options to scan detail report
---
reports.php | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/reports.php b/reports.php
index 984c5c85f..7b68b9e08 100644
--- a/reports.php
+++ b/reports.php
@@ -243,7 +243,8 @@ function vipgoci_report_create_scan_details_php_lint_options(
if ( true === $options_copy['lint'] ) {
foreach (
array(
- 'lint-skip-folders' => 'Directories not PHP linted',
+ 'lint-file-extensions' => 'Lint files with file extensions',
+ 'lint-skip-folders' => 'Directories not PHP linted',
) as $key => $value
) {
$details .= '' . vipgoci_output_html_escape( $value ) . ':
' . PHP_EOL;
@@ -315,6 +316,7 @@ function ( $array_item ) {
array(
'phpcs-standard' => 'Standard(s) used',
'phpcs-runtime-set-tmp' => 'Runtime set',
+ 'phpcs-file-extensions' => 'Scan added/modified files with file extensions',
'phpcs-sniffs-include' => 'Custom sniffs included',
'phpcs-sniffs-exclude' => 'Custom sniffs excluded',
'phpcs-skip-folders' => 'Directories not PHPCS scanned',
@@ -375,8 +377,9 @@ function vipgoci_report_create_scan_details_wpscan_configuration(
foreach (
array(
- 'wpscan-api-paths' => 'Directories scanned',
- 'wpscan-api-skip-folders' => 'Directories not scanned',
+ 'wpscan-api-paths' => 'Directories scanned',
+ 'wpscan-api-skip-folders' => 'Directories not scanned',
+ 'wpscan-api-file-extensions' => 'Scan added/modified files with file extensions',
) as $key => $value
) {
$details .= '' . vipgoci_output_html_escape( $value ) . ':
' . PHP_EOL;
@@ -420,6 +423,20 @@ function vipgoci_report_create_scan_details_svg_configuration(
$details .= '';
+ if ( true === $options_copy['svg-checks'] ) {
+ $details .= 'Scan added/modified files with file extensions:
' . PHP_EOL;
+ $details .= '' . PHP_EOL;
+
+ $details .= vipgoci_report_create_scan_details_list(
+ '',
+ '
',
+ $options_copy['svg-file-extensions'],
+ '- None
'
+ );
+
+ $details .= '
' . PHP_EOL;
+ }
+
return $details;
}
@@ -440,6 +457,7 @@ function vipgoci_report_create_scan_details_auto_approve_configuration(
array(
'autoapprove' => 'Auto-approvals enabled',
'autoapprove-php-nonfunctional-changes' => 'Non-functional changes auto-approved',
+ 'autoapprove-php-nonfunctional-changes-file-extensions' => 'Files with file extensions to consider for non-functional change auto-approval',
) as $key => $value
) {
if (
From 670461cf3a81b0c79d2fbc994fdb26d68aad4e1c Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:54:20 +0000
Subject: [PATCH 52/87] Clarify message.
---
tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
index 3fc89d3e9..7696a3c14 100644
--- a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
@@ -126,7 +126,7 @@ public function testCreateDetails2(): void {
);
$this->assertStringContainsString(
- 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ 'Select added/modified add-ons to scan based on headers present in files with file extensions:
' . PHP_EOL .
'',
$actual_output
);
From f8c2d8c824cce4da6cbb87d0fe1b0f4b0819f631 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 13:54:42 +0000
Subject: [PATCH 53/87] Clarify message.
---
reports.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/reports.php b/reports.php
index 7b68b9e08..9a438706f 100644
--- a/reports.php
+++ b/reports.php
@@ -379,7 +379,7 @@ function vipgoci_report_create_scan_details_wpscan_configuration(
array(
'wpscan-api-paths' => 'Directories scanned',
'wpscan-api-skip-folders' => 'Directories not scanned',
- 'wpscan-api-file-extensions' => 'Scan added/modified files with file extensions',
+ 'wpscan-api-file-extensions' => 'Select added/modified add-ons to scan based on headers present in files with file extensions',
) as $key => $value
) {
$details .= '' . vipgoci_output_html_escape( $value ) . ':
' . PHP_EOL;
From 57a54c94ef73bcf410e798fe2ff6e1b9e4e48229 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 14:00:31 +0000
Subject: [PATCH 54/87] Clarify message again
---
reports.php | 2 +-
tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/reports.php b/reports.php
index 9a438706f..a2daeaadb 100644
--- a/reports.php
+++ b/reports.php
@@ -379,7 +379,7 @@ function vipgoci_report_create_scan_details_wpscan_configuration(
array(
'wpscan-api-paths' => 'Directories scanned',
'wpscan-api-skip-folders' => 'Directories not scanned',
- 'wpscan-api-file-extensions' => 'Select added/modified add-ons to scan based on headers present in files with file extensions',
+ 'wpscan-api-file-extensions' => 'Scan added/modified add-ons based on headers present in files with file extensions',
) as $key => $value
) {
$details .= '' . vipgoci_output_html_escape( $value ) . ':
' . PHP_EOL;
diff --git a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
index 7696a3c14..32cf2acc3 100644
--- a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
@@ -126,7 +126,7 @@ public function testCreateDetails2(): void {
);
$this->assertStringContainsString(
- 'Select added/modified add-ons to scan based on headers present in files with file extensions:
' . PHP_EOL .
+ 'Scan added/modified add-ons based on headers present in files with file extensions:
' . PHP_EOL .
'',
$actual_output
);
From e1e3ab6732969c04a1b52b8cf365d5b9ee699586 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 14:25:16 +0000
Subject: [PATCH 55/87] WP CS update
---
tests/unit/MainRunInitOptionsAutoapproveTest.php | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/tests/unit/MainRunInitOptionsAutoapproveTest.php b/tests/unit/MainRunInitOptionsAutoapproveTest.php
index b66d35b43..476153145 100644
--- a/tests/unit/MainRunInitOptionsAutoapproveTest.php
+++ b/tests/unit/MainRunInitOptionsAutoapproveTest.php
@@ -81,6 +81,8 @@ public function testRunInitOptionsAutoapproveDefault() :void {
* correctly parsed.
*
* @covers ::vipgoci_run_init_options_autoapprove
+ *
+ * @return void
*/
public function testRunInitOptionsAutoapproveCustom() :void {
$this->options = array(
@@ -117,6 +119,8 @@ public function testRunInitOptionsAutoapproveCustom() :void {
* Check if errors are correctly handled.
*
* @covers ::vipgoci_run_init_options_autoapprove
+ *
+ * @return void
*/
public function testRunInitOptionsAutoapproveErrors1() :void {
$this->options = array(
@@ -134,7 +138,7 @@ public function testRunInitOptionsAutoapproveErrors1() :void {
vipgoci_run_init_options_autoapprove(
$this->options
);
- } catch( \ErrorException $error ) {
+ } catch ( \ErrorException $error ) {
$error_msg = $error->getMessage();
}
@@ -148,6 +152,8 @@ public function testRunInitOptionsAutoapproveErrors1() :void {
* Check if errors are correctly handled.
*
* @covers ::vipgoci_run_init_options_autoapprove
+ *
+ * @return void
*/
public function testRunInitOptionsAutoapproveErrors2() :void {
$this->options = array(
@@ -165,7 +171,7 @@ public function testRunInitOptionsAutoapproveErrors2() :void {
vipgoci_run_init_options_autoapprove(
$this->options
);
- } catch( \ErrorException $error ) {
+ } catch ( \ErrorException $error ) {
$error_msg = $error->getMessage();
}
@@ -174,5 +180,4 @@ public function testRunInitOptionsAutoapproveErrors2() :void {
$error_msg
);
}
-
}
From 793614c72809ecd197e64ed040b7204bce41d844 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 14:28:31 +0000
Subject: [PATCH 56/87] Remove .vipgoci_phpcs_skip_folders
---
.vipgoci_phpcs_skip_folders | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 .vipgoci_phpcs_skip_folders
diff --git a/.vipgoci_phpcs_skip_folders b/.vipgoci_phpcs_skip_folders
deleted file mode 100644
index c293d3ab8..000000000
--- a/.vipgoci_phpcs_skip_folders
+++ /dev/null
@@ -1 +0,0 @@
-tests/unit
From 211c041cbd385fca5cf19ae98757d0f241dc3300 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 14:38:20 +0000
Subject: [PATCH 57/87] Remove extra whitespace
---
tests/unit/OptionsArrayHandleTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/OptionsArrayHandleTest.php b/tests/unit/OptionsArrayHandleTest.php
index 2eae6ef32..5a6f3287f 100644
--- a/tests/unit/OptionsArrayHandleTest.php
+++ b/tests/unit/OptionsArrayHandleTest.php
@@ -236,7 +236,7 @@ public function testOptionsArrayHandle7() :void {
);
} catch ( \ErrorException $error ) {
$error_msg = $error->getMessage();
- }
+ }
$this->assertSame(
'vipgoci_sysexit() was called; message=Parameter --mytestoption can not contain \'"myvalue3"\' as one of the values',
From 8499041a11fe0b38a1a0943eef944913ec9b0f64 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 14:43:43 +0000
Subject: [PATCH 58/87] Disable PHPCS sniff
VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
---
tests/unit/helper/MainRunInitOptionsAutoapprove.php | 3 ++-
tests/unit/helper/OptionsArrayHandle.php | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/tests/unit/helper/MainRunInitOptionsAutoapprove.php b/tests/unit/helper/MainRunInitOptionsAutoapprove.php
index 5e43c90a2..a3e3b0992 100644
--- a/tests/unit/helper/MainRunInitOptionsAutoapprove.php
+++ b/tests/unit/helper/MainRunInitOptionsAutoapprove.php
@@ -8,6 +8,7 @@
declare(strict_types=1);
+// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
/**
* Throws an exception indicating error when called.
*
@@ -30,4 +31,4 @@ function vipgoci_sysexit(
'vipgoci_sysexit() was called; message=' . $str,
);
}
-
+// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
diff --git a/tests/unit/helper/OptionsArrayHandle.php b/tests/unit/helper/OptionsArrayHandle.php
index a74082f55..915b4d228 100644
--- a/tests/unit/helper/OptionsArrayHandle.php
+++ b/tests/unit/helper/OptionsArrayHandle.php
@@ -8,6 +8,7 @@
declare(strict_types=1);
+// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
/**
* Throws an exception indicating error when called.
*
@@ -30,4 +31,4 @@ function vipgoci_sysexit(
'vipgoci_sysexit() was called; message=' . $str,
);
}
-
+// phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
From 0201e7634c4fac5dfce05cf6124cc8782d3ad635 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 16:04:41 +0000
Subject: [PATCH 59/87] Default value provided as array, add comment.
---
tests/unit/OptionsArrayHandleTest.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tests/unit/OptionsArrayHandleTest.php b/tests/unit/OptionsArrayHandleTest.php
index 5a6f3287f..dbdd68ad8 100644
--- a/tests/unit/OptionsArrayHandleTest.php
+++ b/tests/unit/OptionsArrayHandleTest.php
@@ -107,7 +107,7 @@ public function testOptionsArrayHandle3() :void {
vipgoci_option_array_handle(
$options,
'mytestoption',
- 'myvalue',
+ array( 'myvalue' ),
null,
','
);
@@ -139,7 +139,7 @@ public function testOptionsArrayHandle4() :void {
vipgoci_option_array_handle(
$options,
'mytestoption',
- 'myvalue',
+ array( 'myvalue' ),
null,
',',
false // Do not strtolower() values.
@@ -168,7 +168,7 @@ public function testOptionsArrayHandle5() :void {
vipgoci_option_array_handle(
$options,
'mytestoption',
- 'myvalue',
+ array( 'myvalue' ),
array( 'myvalue4' ),
',',
true // To lower case.
@@ -197,7 +197,7 @@ public function testOptionsArrayHandle6() :void {
vipgoci_option_array_handle(
$options,
'mytestoption',
- 'myvalue',
+ array( 'myvalue' ),
array( 'myvalue3' ), // Note: Different case than input, is allowed.
',',
false // Do not transform to lower case.
@@ -229,10 +229,10 @@ public function testOptionsArrayHandle7() :void {
vipgoci_option_array_handle(
$options,
'mytestoption',
- 'myvalue',
+ array( 'myvalue' ),
array( 'myvalue3' ),
',',
- true
+ true // Transform to lower case.
);
} catch ( \ErrorException $error ) {
$error_msg = $error->getMessage();
From b904477b4dc269e22b5b55a4598989f8d243b61d Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 16:07:30 +0000
Subject: [PATCH 60/87] $default_value and $forbidden_value can not be string.
---
options.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/options.php b/options.php
index 15e54bb1f..e004edd82 100644
--- a/options.php
+++ b/options.php
@@ -765,7 +765,7 @@ function vipgoci_option_integer_handle(
*
* @param array $options Options array for the program.
* @param string $option_name Option name to process.
- * @param array|string $default_value Default value if nothing is set.
+ * @param array $default_value Default value if nothing is set.
* @param string|array|null $forbidden_value Values not permissible to use.
* @param string $array_separator String separator between values.
* @param bool $strlower_option_value If to convert values to lower case.
@@ -777,8 +777,8 @@ function vipgoci_option_integer_handle(
function vipgoci_option_array_handle(
array &$options,
string $option_name,
- array|string $default_value = array(),
- string|array|null $forbidden_value = null,
+ array $default_value = array(),
+ array|null $forbidden_value = null,
string $array_separator = ',',
bool $strlower_option_value = true
) :void {
From 03078c5473f299c7187b80082a60f56b5a284a49 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 17:49:06 +0000
Subject: [PATCH 61/87] Add section about file extensions
---
README.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/README.md b/README.md
index 16666c022..6b2bbfbb6 100644
--- a/README.md
+++ b/README.md
@@ -548,6 +548,17 @@ For example:
-- with this option in place, any pull requests targetting branches called `foo` or `bar` will be ignored and no feedback will be posted to them.
+### Configuring file extensions
+
+Each scan type uses by default internally specified file extensions when considering which added or modified files to scan for a given pull request. This can be overridden by specifying command-line parameters for each scan type. The help message lists the available parameters and default file extensions for each scan type.
+
+Non-functional auto-approvals can be configured in similar way, impacting which files are considered when performing non-functional auto-approval.
+
+For example:
+
+> ./vip-go-ci.php --lint-file-extensions="php,inc"
+
+With this option configured, `.php` or `.inc` files will be linted using a PHP interpreter.
### Skipping certain folders
From 8d1ce9c9d7a26f585fc3c775c1fe3a1f62689980 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Fri, 28 Oct 2022 17:49:30 +0000
Subject: [PATCH 62/87] Adding error codes.
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index 6b2bbfbb6..c705b5ce7 100644
--- a/README.md
+++ b/README.md
@@ -731,6 +731,8 @@ All utilities in `tools-init.sh` follow the same pattern.
* Code `251`: Exiting due to a system problem.
* Code `252`: A fatal problem with GitHub was encountered leading to an exit.
* Code `253`: A problem with usage options was detected, leading to an exit.
+* Code `247`: Fatal error when communicating with HTTP API.
+* Code `248`: Commit specified is not the latest one in pull request.
## Tests
From dd0835d90386a28a7d3dfb942e94886ee530ef99 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:47:40 +0000
Subject: [PATCH 63/87] Adding default file-extension defines for plugins and
themes.
---
defines.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/defines.php b/defines.php
index 4e2f08cd4..86f8b19d1 100644
--- a/defines.php
+++ b/defines.php
@@ -308,7 +308,8 @@
define( 'VIPGOCI_WPSCAN_BASE_URL', 'https://wpscan.com' );
define( 'VIPGOCI_WPSCAN_API_BASE_URL', VIPGOCI_WPSCAN_BASE_URL . '/api/v3' );
-define( 'VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT', array( 'php', 'css' ) );
+define( 'VIPGOCI_WPSCAN_PLUGIN_FILE_EXTENSIONS_DEFAULT', array( 'php' ) );
+define( 'VIPGOCI_WPSCAN_THEME_FILE_EXTENSIONS_DEFAULT', array( 'css' ) );
define( 'VIPGOCI_WPSCAN_UPDATEURI_WP_ORG_URLS', array( 'w.org', 'wordpress.org' ) );
From 28a64b6a0c5b367b48301481f79018cc64cae409 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:49:38 +0000
Subject: [PATCH 64/87] Applying --wpscan-api-plugin-file-extensions and
--wpscan-api-theme-file-extensions
---
reports.php | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/reports.php b/reports.php
index a2daeaadb..aeefdfda8 100644
--- a/reports.php
+++ b/reports.php
@@ -377,9 +377,10 @@ function vipgoci_report_create_scan_details_wpscan_configuration(
foreach (
array(
- 'wpscan-api-paths' => 'Directories scanned',
- 'wpscan-api-skip-folders' => 'Directories not scanned',
- 'wpscan-api-file-extensions' => 'Scan added/modified add-ons based on headers present in files with file extensions',
+ 'wpscan-api-paths' => 'Directories scanned',
+ 'wpscan-api-skip-folders' => 'Directories not scanned',
+ 'wpscan-api-plugin-file-extensions' => 'Scan added/modified plugins based on headers present in files with file extensions',
+ 'wpscan-api-theme-file-extensions' => 'Scan added/modified themes based on headers present in files with file extensions',
) as $key => $value
) {
$details .= '' . vipgoci_output_html_escape( $value ) . ':
' . PHP_EOL;
From ba04cdeb2f985cfb71d9e1ae86a6c193236c8170 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:50:15 +0000
Subject: [PATCH 65/87] Updating test to reflect new parameters
---
.../WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php b/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php
index 9d324e5b1..9efa0dec7 100644
--- a/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php
+++ b/tests/integration/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest.php
@@ -134,7 +134,8 @@ public function testGetAddonDataAndSlugsForDirectoryWithSubdirectories(): void {
$actual_results = vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
$this->temp_dir . '/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest',
- array( 'php', 'css' ),
+ array( 'php' ),
+ array( 'css' ),
true
);
@@ -325,7 +326,8 @@ public function testGetAddonDataAndSlugsForDirectorySkipSubdirectories(): void {
$actual_results = vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
$this->temp_dir . '/WpCoreMiscGetAddonDataAndSlugsForDirectoryTest',
- array( 'php', 'css' ),
+ array( 'php' ),
+ array( 'css' ),
false
);
From 22ab89e00e064f5e45e98dc3dfcabc6e95ad0c68 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:51:36 +0000
Subject: [PATCH 66/87] Updating test to reflect new parameters
---
.../WpCoreMiscGetAddonHeadersAndTypeTest.php | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tests/integration/WpCoreMiscGetAddonHeadersAndTypeTest.php b/tests/integration/WpCoreMiscGetAddonHeadersAndTypeTest.php
index 09a3255e5..77377b359 100644
--- a/tests/integration/WpCoreMiscGetAddonHeadersAndTypeTest.php
+++ b/tests/integration/WpCoreMiscGetAddonHeadersAndTypeTest.php
@@ -110,7 +110,9 @@ public function testWpCoreMiscGetAddonHeadersAndTypeForPlugin(): void {
vipgoci_unittests_output_suppress();
$actual_result = vipgoci_wpcore_misc_get_addon_headers_and_type(
- $temp_file_name
+ $temp_file_name,
+ array( 'php' ),
+ array( 'css' ),
);
vipgoci_unittests_output_unsuppress();
@@ -212,7 +214,9 @@ public function testWpCoreMiscGetAddonHeadersAndTypeForTheme(): void {
vipgoci_unittests_output_suppress();
$actual_result = vipgoci_wpcore_misc_get_addon_headers_and_type(
- $temp_file_name
+ $temp_file_name,
+ array( 'php' ),
+ array( 'css' )
);
vipgoci_unittests_output_unsuppress();
@@ -292,7 +296,9 @@ public function testWpCoreMiscGetAddonHeadersAndTypeForInvalid(): void {
vipgoci_unittests_output_suppress();
$actual_result = vipgoci_wpcore_misc_get_addon_headers_and_type(
- $temp_file_name
+ $temp_file_name,
+ array( 'php' ),
+ array( 'css' ),
);
vipgoci_unittests_output_unsuppress();
From 20e6b4eb1a8f514db5161e196eba75cc8d4cda63 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:52:06 +0000
Subject: [PATCH 67/87] Applying --wpscan-api-plugin-file-extensions and
--wpscan-api-theme-file-extensions
---
wpscan-scan.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/wpscan-scan.php b/wpscan-scan.php
index c0e17ab41..61ee4a66e 100644
--- a/wpscan-scan.php
+++ b/wpscan-scan.php
@@ -217,7 +217,8 @@ function vipgoci_wpscan_scan_dirs_altered(
foreach ( $addon_dirs_relevant_to_scan as $addon_dir_relevant ) {
$addon_data_for_dir = vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
$options['local-git-repo'] . DIRECTORY_SEPARATOR . $addon_dir_relevant,
- $options['wpscan-api-file-extensions'],
+ $options['wpscan-api-plugin-file-extensions'],
+ $options['wpscan-api-theme-file-extensions'],
( ! in_array( $addon_dir_relevant, $options['wpscan-api-paths'], true ) )
);
From 7e48f87c04c9e474f4b3f018004817f79c8182f0 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:54:11 +0000
Subject: [PATCH 68/87] Updating test to reflect new parameters
---
tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php b/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php
index 77f4fdffa..313459844 100644
--- a/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php
+++ b/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php
@@ -168,7 +168,8 @@ public function testWpcoreMiscScanDirectoryForAdddonsScanSubdirectories(): void
$results_actual = vipgoci_wpcore_misc_scan_directory_for_addons(
$this->temp_dir . '/WpCoreMiscScanDirectoryForAdddonsTest',
- array( 'php', 'css' ),
+ array( 'php' ),
+ array( 'css' ),
true
);
@@ -244,7 +245,8 @@ public function testWpcoreMiscScanDirectoryForAdddonsSkipSubdirectories(): void
$results_actual = vipgoci_wpcore_misc_scan_directory_for_addons(
$this->temp_dir . '/WpCoreMiscScanDirectoryForAdddonsTest',
- array( 'php', 'css' ),
+ array( 'php' ),
+ array( 'css' ),
false
);
From da8d14f24447242443189b351e7f34a1fd4d7853 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:54:31 +0000
Subject: [PATCH 69/87] Updating test to reflect new parameters
---
tests/integration/WpscanScanCommitTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/integration/WpscanScanCommitTest.php b/tests/integration/WpscanScanCommitTest.php
index 2e0243471..38d358723 100644
--- a/tests/integration/WpscanScanCommitTest.php
+++ b/tests/integration/WpscanScanCommitTest.php
@@ -106,6 +106,10 @@ protected function setUp() :void {
$this->options['wpscan-api-skip-folders'] = array();
+ $this->options['wpscan-api-plugin-file-extensions'] = array( 'php' );
+
+ $this->options['wpscan-api-theme-file-extensions'] = array( 'css' );
+
$this->options['wpscan-api-token'] =
vipgoci_unittests_get_config_value(
'wpscan-api-scan',
From 86a95cdb73b8bc438f5ba3f37fc3c50827d482c7 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:54:45 +0000
Subject: [PATCH 70/87] Updating test to reflect new parameters
---
tests/integration/WpscanScanDirsAlteredTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/integration/WpscanScanDirsAlteredTest.php b/tests/integration/WpscanScanDirsAlteredTest.php
index e3557c804..158c56ea8 100644
--- a/tests/integration/WpscanScanDirsAlteredTest.php
+++ b/tests/integration/WpscanScanDirsAlteredTest.php
@@ -104,6 +104,10 @@ protected function setUp() :void {
$this->options['wpscan-api-skip-folders'] = array();
+ $this->options['wpscan-api-plugin-file-extensions'] = array( 'php' );
+
+ $this->options['wpscan-api-theme-file-extensions'] = array( 'css' );
+
$this->options['wpscan-api-token'] =
vipgoci_unittests_get_config_value(
'wpscan-api-scan',
From 29738313df13e51c101c251ffb94c2b53162ad92 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 11:56:30 +0000
Subject: [PATCH 71/87] Update test to reflect new output
---
...eateScanDetailsWpscanConfigurationTest.php | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
index 32cf2acc3..d636bd569 100644
--- a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
@@ -87,10 +87,11 @@ public function testCreateDetails1(): void {
* @covers ::vipgoci_report_create_scan_details_wpscan_configuration
*/
public function testCreateDetails2(): void {
- $this->options['wpscan-api'] = true;
- $this->options['wpscan-api-paths'] = array( 'plugins', 'themes' );
- $this->options['wpscan-api-skip-folders'] = array( 'skip-dir1', 'skip-dir2' );
- $this->options['wpscan-api-file-extensions'] = array( 'php', 'css' );
+ $this->options['wpscan-api'] = true;
+ $this->options['wpscan-api-paths'] = array( 'plugins', 'themes' );
+ $this->options['wpscan-api-skip-folders'] = array( 'skip-dir1', 'skip-dir2' );
+ $this->options['wpscan-api-plugin-file-extensions'] = array( 'php' );
+ $this->options['wpscan-api-theme-file-extensions'] = array( 'css' );
$actual_output = vipgoci_report_create_scan_details_wpscan_configuration(
$this->options
@@ -126,8 +127,14 @@ public function testCreateDetails2(): void {
);
$this->assertStringContainsString(
- 'Scan added/modified add-ons based on headers present in files with file extensions:
' . PHP_EOL .
- '',
+ 'Scan added/modified plugins based on headers present in files with file extensions:
' . PHP_EOL .
+ '',
+ $actual_output
+ );
+
+ $this->assertStringContainsString(
+ 'Scan added/modified themes based on headers present in files with file extensions:
' . PHP_EOL .
+ '',
$actual_output
);
}
From 3c60be821039cc79b4dd38b5f6b79e07670484de Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 12:07:10 +0000
Subject: [PATCH 72/87] Applying --wpscan-api-plugin-file-extensions and
--wpscan-api-theme-file-extensions
---
main.php | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/main.php b/main.php
index 94d7496e3..179b0e9c3 100755
--- a/main.php
+++ b/main.php
@@ -146,8 +146,10 @@ 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-file-extensions=ARRAY Use specified file extensions to select which altered files to scan with WPScan API.' . PHP_EOL .
- "\t" . ' Default is: "' . implode( ',', VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
+ "\t" . '--wpscan-api-plugin-file-extensions=ARRAY Use specified file extensions to select which altered plugin files to scan with WPScan API.' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_WPSCAN_PLUGIN_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
+ "\t" . '--wpscan-api-theme-file-extensions=ARRAY Use specified file extensions to select which altered theme files to scan with WPScan API.' . PHP_EOL .
+ "\t" . ' Default is: "' . implode( ',', VIPGOCI_WPSCAN_THEME_FILE_EXTENSIONS_DEFAULT ) . '"' . 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. Limited' . PHP_EOL .
"\t" . ' Markdown syntax allowed.' . PHP_EOL .
@@ -333,7 +335,8 @@ function vipgoci_options_recognized() :array {
'wpscan-api-dry-mode:',
'wpscan-api-token:',
'wpscan-api-paths:',
- 'wpscan-api-file-extensions:',
+ 'wpscan-api-plugin-file-extensions:',
+ 'wpscan-api-theme-file-extensions:',
'wpscan-api-skip-folders:',
'wpscan-api-report-end-msg:',
@@ -717,13 +720,23 @@ function vipgoci_run_init_options_wpscan( array &$options ) :void {
);
/*
- * Process --wpscan-api-file-extensions -- expected to be an
+ * Process --wpscan-api-plugin-file-extensions -- expected to be an
* array of values.
*/
vipgoci_option_array_handle(
$options,
- 'wpscan-api-file-extensions',
- VIPGOCI_WPSCAN_FILE_EXTENSIONS_DEFAULT
+ 'wpscan-api-plugin-file-extensions',
+ VIPGOCI_WPSCAN_PLUGIN_FILE_EXTENSIONS_DEFAULT
+ );
+
+ /*
+ * Process --wpscan-api-theme-file-extensions -- expected to be an
+ * array of values.
+ */
+ vipgoci_option_array_handle(
+ $options,
+ 'wpscan-api-theme-file-extensions',
+ VIPGOCI_WPSCAN_THEME_FILE_EXTENSIONS_DEFAULT
);
/*
From 46e43b880d40082af3bc4249f961123a01c392d2 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 12:11:16 +0000
Subject: [PATCH 73/87] Updating test to reflect new parameters
---
tests/unit/MainRunInitOptionsWpscanTest.php | 58 ++++++++++++---------
1 file changed, 32 insertions(+), 26 deletions(-)
diff --git a/tests/unit/MainRunInitOptionsWpscanTest.php b/tests/unit/MainRunInitOptionsWpscanTest.php
index 50feba1cd..dc3125cf3 100644
--- a/tests/unit/MainRunInitOptionsWpscanTest.php
+++ b/tests/unit/MainRunInitOptionsWpscanTest.php
@@ -44,35 +44,37 @@ protected function tearDown() :void {
*/
public function testRunInitOptionsWpscanOptionsDefault() :void {
$this->options = array(
- 'wpscan-api' => null,
- 'wpscan-api-dry-mode' => null,
- 'wpscan-api-token' => '123456789',
- 'wpscan-api-paths' => '/plugins/,themes/,/custom-path/custom-plugins',
- 'wpscan-api-skip-folders' => 'dir1,dir2,dir3',
+ 'wpscan-api' => null,
+ 'wpscan-api-dry-mode' => null,
+ 'wpscan-api-token' => '123456789',
+ 'wpscan-api-paths' => '/plugins/,themes/,/custom-path/custom-plugins',
+ 'wpscan-api-skip-folders' => 'dir1,dir2,dir3',
);
vipgoci_run_init_options_wpscan( $this->options );
$this->assertSame(
array(
- 'wpscan-api' => false,
- 'wpscan-api-dry-mode' => true,
- 'wpscan-api-token' => '123456789',
- 'wpscan-api-paths' => array(
+ 'wpscan-api' => false,
+ 'wpscan-api-dry-mode' => true,
+ 'wpscan-api-token' => '123456789',
+ 'wpscan-api-paths' => array(
'plugins',
'themes',
'custom-path/custom-plugins',
),
- 'wpscan-api-skip-folders' => array(
+ 'wpscan-api-skip-folders' => array(
'dir1',
'dir2',
'dir3',
),
- 'wpscan-api-file-extensions' => array(
+ 'wpscan-api-plugin-file-extensions' => array(
'php',
+ ),
+ 'wpscan-api-theme-file-extensions' => array(
'css',
),
- 'wpscan-api-report-end-msg' => '',
+ 'wpscan-api-report-end-msg' => '',
),
$this->options
);
@@ -86,38 +88,42 @@ public function testRunInitOptionsWpscanOptionsDefault() :void {
*/
public function testRunInitOptionsWpscanOptionsCustom() :void {
$this->options = array(
- 'wpscan-api' => 'true',
- 'wpscan-api-dry-mode' => 'false',
- 'wpscan-api-token' => '123456789',
- 'wpscan-api-paths' => '/plugins/,themes/,/custom-path/custom-plugins',
- 'wpscan-api-skip-folders' => 'dir1,dir2,dir3',
- 'wpscan-api-file-extensions' => 'php,css,css2',
- 'wpscan-api-report-end-msg' => 'abc',
+ 'wpscan-api' => 'true',
+ 'wpscan-api-dry-mode' => 'false',
+ 'wpscan-api-token' => '123456789',
+ 'wpscan-api-paths' => '/plugins/,themes/,/custom-path/custom-plugins',
+ 'wpscan-api-skip-folders' => 'dir1,dir2,dir3',
+ 'wpscan-api-plugin-file-extensions' => 'php,inc',
+ 'wpscan-api-theme-file-extensions' => 'css,css2',
+ 'wpscan-api-report-end-msg' => 'abc',
);
vipgoci_run_init_options_wpscan( $this->options );
$this->assertSame(
array(
- 'wpscan-api' => true,
- 'wpscan-api-dry-mode' => false,
- 'wpscan-api-token' => '123456789',
- 'wpscan-api-paths' => array(
+ 'wpscan-api' => true,
+ 'wpscan-api-dry-mode' => false,
+ 'wpscan-api-token' => '123456789',
+ 'wpscan-api-paths' => array(
'plugins',
'themes',
'custom-path/custom-plugins',
),
- 'wpscan-api-skip-folders' => array(
+ 'wpscan-api-skip-folders' => array(
'dir1',
'dir2',
'dir3',
),
- 'wpscan-api-file-extensions' => array(
+ 'wpscan-api-plugin-file-extensions' => array(
'php',
+ 'inc',
+ ),
+ 'wpscan-api-theme-file-extensions' => array(
'css',
'css2',
),
- 'wpscan-api-report-end-msg' => 'abc',
+ 'wpscan-api-report-end-msg' => 'abc',
),
$this->options
);
From 6ed86b7c235e15fc8082f332ba576bba3b4a0706 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 12:23:04 +0000
Subject: [PATCH 74/87] Applying --wpscan-api-plugin-file-extensions and
--wpscan-api-theme-file-extensions
---
wp-core-misc.php | 51 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 39 insertions(+), 12 deletions(-)
diff --git a/wp-core-misc.php b/wp-core-misc.php
index 55fed5716..2074b5572 100644
--- a/wp-core-misc.php
+++ b/wp-core-misc.php
@@ -108,14 +108,18 @@ function vipgoci_wpcore_misc_cleanup_header_comment(
* Name, AuthorName, Version, and so forth from a file.
* Also attempts to determine if file is part of a theme or a plugin.
*
- * @param string $file_name Path to file to try to fetch headers from.
+ * @param string $file_name Path to file to try to fetch headers from.
+ * @param array $plugin_file_extensions File extensions to consider when determining plugins to analyze.
+ * @param array $theme_file_extensions File extensions to consider when determining themes to analyze.
*
* @return null|array Null on failure to get headers.
* On success, associative array with type, version, and
* plugin/theme headers.
*/
function vipgoci_wpcore_misc_get_addon_headers_and_type(
- string $file_name
+ string $file_name,
+ array $plugin_file_extensions,
+ array $theme_file_extensions
) :null|array {
vipgoci_log(
'Attempting to determine plugin/theme headers for file',
@@ -128,7 +132,16 @@ function vipgoci_wpcore_misc_get_addon_headers_and_type(
// By default, assume no headers where found.
$type = null;
- if ( str_ends_with( $file_name, '.php' ) ) {
+ $file_extension = pathinfo(
+ $file_name,
+ PATHINFO_EXTENSION
+ );
+
+ if ( true === in_array(
+ $file_extension,
+ $plugin_file_extensions,
+ true
+ ) ) {
/*
* Try to retrieve plugin headers.
*/
@@ -159,9 +172,13 @@ function vipgoci_wpcore_misc_get_addon_headers_and_type(
$addon_headers = $plugin_data;
$version_detected = $plugin_data['Version'];
}
- } elseif ( str_ends_with( $file_name, '.css' ) ) {
+ } elseif ( true === in_array(
+ $file_extension,
+ $theme_file_extensions,
+ true
+ ) ) {
/*
- * If file is CSS, try fetching headers.
+ * If theme file extension, try fetching headers.
*/
$theme_data = vipgoci_wpcore_misc_get_file_wp_headers(
$file_name,
@@ -233,7 +250,8 @@ function vipgoci_wpcore_misc_get_addon_headers_and_type(
* The function is adopted from WordPress: https://core.trac.wordpress.org/browser/tags/6.0/src/wp-admin/includes/plugin.php#L254
*
* @param string $path Path to scan for plugins and themes. Usually this would point a structure similar to wp-content/plugins.
- * @param array $file_extensions File extensions to consider when determining what to analyze.
+ * @param array $plugin_file_extensions File extensions to consider when determining plugins to analyze.
+ * @param array $theme_file_extensions File extensions to consider when determining themes to analyze.
* @param bool $process_subdirectories If to process sub-directories.
*
* @link https://developer.wordpress.org/reference/functions/get_plugins/
@@ -260,7 +278,8 @@ function vipgoci_wpcore_misc_get_addon_headers_and_type(
*/
function vipgoci_wpcore_misc_scan_directory_for_addons(
string $path,
- array $file_extensions,
+ array $plugin_file_extensions,
+ array $theme_file_extensions,
bool $process_subdirectories = true
): array {
if (
@@ -285,7 +304,10 @@ function vipgoci_wpcore_misc_scan_directory_for_addons(
$path,
$process_subdirectories,
array(
- 'file_extensions' => $file_extensions,
+ 'file_extensions' => array_merge(
+ $plugin_file_extensions,
+ $theme_file_extensions
+ ),
)
);
@@ -316,7 +338,9 @@ function vipgoci_wpcore_misc_scan_directory_for_addons(
}
$addon_data = vipgoci_wpcore_misc_get_addon_headers_and_type(
- $tmp_path
+ $tmp_path,
+ $plugin_file_extensions,
+ $theme_file_extensions
);
// When no headers are found in file, ignore file.
@@ -690,7 +714,8 @@ function vipgoci_wpcore_misc_assign_addon_fields(
* API about the plugins/themes, return the information after processing.
*
* @param string $path Path to directory to analyze.
- * @param array $file_extensions File extensions to consider when determining what to analyze.
+ * @param array $plugin_file_extensions File extensions to consider when determining plugins to analyze.
+ * @param array $theme_file_extensions File extensions to consider when determining themes to analyze.
* @param bool $process_subdirectories If to process sub-directories.
*
* @return array Information about plugins or themes found. Includes
@@ -724,12 +749,14 @@ function vipgoci_wpcore_misc_assign_addon_fields(
*/
function vipgoci_wpcore_misc_get_addon_data_and_slugs_for_directory(
string $path,
- array $file_extensions,
+ array $plugin_file_extensions,
+ array $theme_file_extensions,
bool $process_subdirectories = true
) :array {
$addons_found = vipgoci_wpcore_misc_scan_directory_for_addons(
$path,
- $file_extensions,
+ $plugin_file_extensions,
+ $theme_file_extensions,
$process_subdirectories
);
From 11d937048ea0d1cdbdb9bb0837a064982f83d933 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 14:54:06 +0000
Subject: [PATCH 75/87] Replace assertFalse() with
assertStringNotContainsString(), assertNotFalse() with
assertStringContainsString()
---
...ortCreateScanDetailsPhpLintOptionsTest.php | 88 +++++++------------
1 file changed, 34 insertions(+), 54 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php b/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
index 5033b6344..75673bd30 100644
--- a/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
+++ b/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
@@ -50,40 +50,30 @@ public function testCreateDetails1(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP lint options'
- )
+ $this->assertStringContainsString(
+ 'PHP lint options',
+ $actual_output,
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP lint files enabled: ' . PHP_EOL .
- 'false
'
- )
+ $this->assertStringContainsString(
+ 'PHP lint files enabled: ' . PHP_EOL .
+ 'false
',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Lint modified files only'
- )
+ $this->assertStringNotContainsString(
+ 'Lint modified files only',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Lint files with file extensions'
- )
+ $this->assertStringNotContainsString(
+ 'Lint files with file extensions',
+ $actual_output,
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Directories not PHP linted'
- )
+ $this->assertStringNotContainsString(
+ 'Directories not PHP linted',
+ $actual_output,
);
}
@@ -102,43 +92,33 @@ public function testCreateDetails2(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP lint options'
- )
+ $this->assertStringContainsString(
+ 'PHP lint options',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP lint files enabled: ' . PHP_EOL .
- 'true
'
- )
+ $this->assertStringContainsString(
+ 'PHP lint files enabled: ' . PHP_EOL .
+ 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Lint modified files only: ' . PHP_EOL .
- 'true
'
- )
+ $this->assertStringContainsString(
+ 'Lint modified files only: ' . PHP_EOL .
+ 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Lint files with file extensions'
- )
+ $this->assertStringContainsString(
+ 'Lint files with file extensions',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Directories not PHP linted:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Directories not PHP linted:
' . PHP_EOL .
'' . PHP_EOL .
- 'path1
path2
'
- )
+ 'path1
path2
',
+ $actual_output
);
}
}
From 1c2f0b936d6642e7d7338ec7082c8ca9384ef0a4 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 14:57:07 +0000
Subject: [PATCH 76/87] Add more debug info to logging
---
wpscan-scan.php | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/wpscan-scan.php b/wpscan-scan.php
index 61ee4a66e..a74b7062b 100644
--- a/wpscan-scan.php
+++ b/wpscan-scan.php
@@ -548,9 +548,11 @@ function vipgoci_wpscan_scan_commit(
vipgoci_log(
'About to scan added/updated themes/plugins using WPScan API',
array(
- 'repo_owner' => $options['repo-owner'],
- 'repo_name' => $options['repo-name'],
- 'commit_id' => $options['commit'],
+ 'repo_owner' => $options['repo-owner'],
+ 'repo_name' => $options['repo-name'],
+ 'commit_id' => $options['commit'],
+ 'plugin-file-extensions' => $options['wpscan-api-plugin-file-extensions'],
+ 'theme-file-extensions' => $options['wpscan-api-theme-file-extensions'],
)
);
}
@@ -576,9 +578,11 @@ function vipgoci_wpscan_scan_commit(
vipgoci_log(
'Will not scan added/updated themes/plugins using WPScan API, no plugins/themes added/updated',
array(
- 'repo_owner' => $options['repo-owner'],
- 'repo_name' => $options['repo-name'],
- 'commit_id' => $options['commit'],
+ 'repo_owner' => $options['repo-owner'],
+ 'repo_name' => $options['repo-name'],
+ 'commit_id' => $options['commit'],
+ 'plugin-file-extensions' => $options['wpscan-api-plugin-file-extensions'],
+ 'theme-file-extensions' => $options['wpscan-api-theme-file-extensions'],
)
);
From e015a17dc6d659241a8b6dea3258d04741773067 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 15:11:16 +0000
Subject: [PATCH 77/87] Updating test string
---
tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
index d636bd569..b4376e3d7 100644
--- a/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsWpscanConfigurationTest.php
@@ -76,7 +76,7 @@ public function testCreateDetails1(): void {
);
$this->assertStringNotContainsString(
- 'Scan added/modified files with file extensions',
+ 'file extensions',
$actual_output
);
}
From 71fca7357b8743db55bddb28e8aabeb50c1dde4a Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 15:18:31 +0000
Subject: [PATCH 78/87] Replace assertFalse() with
assertStringNotContainsString(), assertNotFalse() with
assertStringContainsString()
---
...canDetailsAutoApproveConfigurationTest.php | 90 ++++++++-----------
1 file changed, 35 insertions(+), 55 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php b/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php
index d74ff85ca..7b8f8e767 100644
--- a/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsAutoApproveConfigurationTest.php
@@ -50,40 +50,30 @@ public function testCreateDetails1(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Auto-approval configuration'
- )
+ $this->assertStringContainsString(
+ 'Auto-approval configuration',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Auto-approvals enabled:' . PHP_EOL .
- 'false
'
- )
+ $this->assertStringContainsString(
+ 'Auto-approvals enabled:' . PHP_EOL .
+ 'false
',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Non-functional changes auto-approved'
- )
+ $this->assertStringNotContainsString(
+ 'Non-functional changes auto-approved',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Files with file extensions to consider for non-functional change auto-approval'
- )
+ $this->assertStringNotContainsString(
+ 'Files with file extensions to consider for non-functional change auto-approval',
+ $actual_output,
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Auto-approved file-types'
- )
+ $this->assertStringNotContainsString(
+ 'Auto-approved file-types',
+ $actual_output
);
}
@@ -102,44 +92,34 @@ public function testCreateDetails2(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Auto-approval configuration'
- )
+ $this->assertStringContainsString(
+ 'Auto-approval configuration',
+ $actual_output,
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Auto-approvals enabled:' . PHP_EOL .
- 'true
'
- )
+ $this->assertStringContainsString(
+ 'Auto-approvals enabled:' . PHP_EOL .
+ 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Non-functional changes auto-approved:' . PHP_EOL .
- 'true
'
- )
+ $this->assertStringContainsString(
+ 'Non-functional changes auto-approved:' . PHP_EOL .
+ 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Files with file extensions to consider for non-functional change auto-approval:' . PHP_EOL .
- 'php
'
- )
+ $this->assertStringContainsString(
+ 'Files with file extensions to consider for non-functional change auto-approval:' . PHP_EOL .
+ 'php
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Auto-approved file-types:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Auto-approved file-types:
' . PHP_EOL .
''
- )
+ 'txt
ini
',
+ $actual_output
);
}
}
From 9cdad1a88258987ffbee739c5500b9a013a8fc40 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 15:32:54 +0000
Subject: [PATCH 79/87] Replace assertFalse() with
assertStringNotContainsString(), assertNotFalse() with
assertStringContainsString()
---
...tCreateScanDetailsSoftwareVersionsTest.php | 170 +++++++-----------
1 file changed, 64 insertions(+), 106 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsSoftwareVersionsTest.php b/tests/unit/ReportCreateScanDetailsSoftwareVersionsTest.php
index 8fca15757..cf79fd3f8 100644
--- a/tests/unit/ReportCreateScanDetailsSoftwareVersionsTest.php
+++ b/tests/unit/ReportCreateScanDetailsSoftwareVersionsTest.php
@@ -53,60 +53,44 @@ public function testCreateDetails1(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Software versions'
- )
+ $this->assertStringContainsString(
+ 'Software versions',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'vip-go-ci version: ' . VIPGOCI_VERSION . '
'
- )
+ $this->assertStringContainsString(
+ 'vip-go-ci version: ' . VIPGOCI_VERSION . '
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP runtime version for vip-go-ci: ' . phpversion() . '
'
- )
+ $this->assertStringContainsString(
+ 'PHP runtime version for vip-go-ci: ' . phpversion() . '
',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'PHP runtime version for PHP linting'
- )
+ $this->assertStringNotContainsString(
+ 'PHP runtime version for PHP linting',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'PHP runtime version for PHPCS'
- )
+ $this->assertStringNotContainsString(
+ 'PHP runtime version for PHPCS',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'PHPCS version'
- )
+ $this->assertStringNotContainsString(
+ 'PHPCS version',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'SVG scanner'
- )
+ $this->assertStringNotContainsString(
+ 'SVG scanner',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Options file enabled: ' . PHP_EOL . 'false
'
- )
+ $this->assertStringContainsString(
+ 'Options file enabled: ' . PHP_EOL . 'false
',
+ $actual_output
);
}
@@ -140,97 +124,71 @@ public function testCreateDetails2(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP runtime version for PHPCS: 7.3.1
'
- )
+ $this->assertStringContainsString(
+ 'PHP runtime version for PHPCS: 7.3.1
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Software versions'
- )
+ $this->assertStringContainsString(
+ 'Software versions',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'vip-go-ci version: ' . VIPGOCI_VERSION . '
'
- )
+ $this->assertStringContainsString(
+ 'vip-go-ci version: ' . VIPGOCI_VERSION . '
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP runtime version for vip-go-ci: ' . phpversion() . '
'
- )
+ $this->assertStringContainsString(
+ 'PHP runtime version for vip-go-ci: ' . phpversion() . '
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP runtime for linting:'
- )
+ $this->assertStringContainsString(
+ 'PHP runtime for linting:',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP 7.4: 7.4.2
'
- )
+ $this->assertStringContainsString(
+ 'PHP 7.4: 7.4.2
',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'PHP 8.0'
- )
+ $this->assertStringNotContainsString(
+ 'PHP 8.0',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP 8.1: 8.1.4
'
- )
+ $this->assertStringContainsString(
+ 'PHP 8.1: 8.1.4
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP runtime version for PHPCS: 7.3.1
'
- )
+ $this->assertStringContainsString(
+ 'PHP runtime version for PHPCS: 7.3.1
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS version: 3.5.5
'
- )
+ $this->assertStringContainsString(
+ 'PHPCS version: 3.5.5
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHP runtime version for SVG scanner: 8.0.3
'
- )
+ $this->assertStringContainsString(
+ 'PHP runtime version for SVG scanner: 8.0.3
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Options file enabled: ' . PHP_EOL . 'true
'
- )
+ $this->assertStringContainsString(
+ 'Options file enabled: ' . PHP_EOL . 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Options altered:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Options altered:
' . PHP_EOL .
'' . PHP_EOL .
- 'a
set to1
b
set to2
' . PHP_EOL
- )
+ 'a
set to1
b
set to2
' . PHP_EOL,
+ $actual_output
);
}
}
From 85e391c21eb2c633f4cdb13377e63ac9021373c9 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 15:42:12 +0000
Subject: [PATCH 80/87] Replace assertFalse() with
assertStringNotContainsString(), assertNotFalse() with
assertStringContainsString()
---
...tCreateScanDetailsSvgConfigurationTest.php | 54 ++++++++-----------
1 file changed, 21 insertions(+), 33 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php b/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
index 31b0f3b50..37706b9d6 100644
--- a/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
@@ -50,26 +50,20 @@ public function testCreateDetails1(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'SVG configuration'
- )
+ $this->assertStringContainsString(
+ 'SVG configuration',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'SVG scanning enabled: ' . PHP_EOL .
- 'false
'
- )
+ $this->assertStringContainsString(
+ 'SVG scanning enabled: ' . PHP_EOL .
+ 'false
',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Scan added/modified files with file extensions'
- )
+ $this->assertStringNotContainsString(
+ 'Scan added/modified files with file extensions',
+ $actual_output
);
}
@@ -86,27 +80,21 @@ public function testCreateDetails2(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'SVG configuration'
- )
+ $this->assertStringContainsString(
+ 'SVG configuration',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'SVG scanning enabled: ' . PHP_EOL .
- 'true
'
- )
+ $this->assertStringContainsString(
+ 'SVG scanning enabled: ' . PHP_EOL .
+ 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Scan added/modified files with file extensions:
' . PHP_EOL .
- ''
- )
+ $this->assertStringContainsString(
+ 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ '',
+ $actual_output
);
}
}
From e292c8504439d768df8e0c665b550a699fd51d09 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 16:10:05 +0000
Subject: [PATCH 81/87] Replace assertFalse() with
assertStringNotContainsString(), assertNotFalse() with
assertStringContainsString()
---
...reateScanDetailsPhpcsConfigurationTest.php | 242 +++++++-----------
1 file changed, 95 insertions(+), 147 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
index 59aa7e5c0..a3b880a30 100644
--- a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
@@ -50,61 +50,45 @@ public function testCreateDetails1(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS configuration'
- )
+ $this->assertStringContainsString(
+ 'PHPCS configuration',
+ $actual_output,
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS scanning enabled: ' . PHP_EOL .
- 'false
'
- )
+ $this->assertStringContainsString(
+ 'PHPCS scanning enabled: ' . PHP_EOL .
+ 'false
',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Standard(s) used'
- )
+ $this->assertStringNotContainsString(
+ 'Standard(s) used',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Runtime set'
- )
+ $this->assertStringNotContainsString(
+ 'Runtime set',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Scan added/modified files with file extensions'
- )
+ $this->assertStringNotContainsString(
+ 'Scan added/modified files with file extensions',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Custom sniffs included'
- )
+ $this->assertStringNotContainsString(
+ 'Custom sniffs included',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Custom sniffs excluded'
- )
+ $this->assertStringNotContainsString(
+ 'Custom sniffs excluded',
+ $actual_output
);
- $this->assertFalse(
- strpos(
- $actual_output,
- 'Directories not PHPCS scanned'
- )
+ $this->assertStringNotContainsString(
+ 'Directories not PHPCS scanned',
+ $actual_output
);
}
@@ -128,81 +112,63 @@ public function testCreateDetails2(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS configuration'
- )
+ $this->assertStringContainsString(
+ 'PHPCS configuration',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS scanning enabled: ' . PHP_EOL .
- 'true
'
- )
+ $this->assertStringContainsString(
+ 'PHPCS scanning enabled: ' . PHP_EOL .
+ 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS severity level: ' . PHP_EOL .
- '3
'
- )
+ $this->assertStringContainsString(
+ 'PHPCS severity level: ' . PHP_EOL .
+ '3
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Standard(s) used:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Standard(s) used:
' . PHP_EOL .
'' . PHP_EOL .
- 'WordPress
WordPress-VIP-Go
'
- )
+ 'WordPress
WordPress-VIP-Go
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Runtime set:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Runtime set:
' . PHP_EOL .
'' . PHP_EOL .
- 'opt1 key1
'
- )
+ 'opt1 key1
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Scan added/modified files with file extensions:
' . PHP_EOL .
'' . PHP_EOL .
- 'php
js
twig
'
- )
+ 'php
js
twig
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Custom sniffs included:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Custom sniffs included:
' . PHP_EOL .
'' . PHP_EOL
- )
+ 'None' . PHP_EOL,
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Custom sniffs excluded:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Custom sniffs excluded:
' . PHP_EOL .
''
- )
+ 'None',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Directories not PHPCS scanned:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Directories not PHPCS scanned:
' . PHP_EOL .
'' . PHP_EOL .
- 'path1
path2
'
- )
+ 'path1
path2
',
+ $actual_output
);
}
@@ -227,81 +193,63 @@ public function testCreateDetails3(): void {
$this->options
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS configuration'
- )
+ $this->assertStringContainsString(
+ 'PHPCS configuration',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS scanning enabled: ' . PHP_EOL .
- 'true
'
- )
+ $this->assertStringContainsString(
+ 'PHPCS scanning enabled: ' . PHP_EOL .
+ 'true
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'PHPCS severity level: ' . PHP_EOL .
- '3
'
- )
+ $this->assertStringContainsString(
+ 'PHPCS severity level: ' . PHP_EOL .
+ '3
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Standard(s) used:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Standard(s) used:
' . PHP_EOL .
'' . PHP_EOL .
- 'WordPress
WordPress-VIP-Go
'
- )
+ 'WordPress
WordPress-VIP-Go
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Runtime set:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Runtime set:
' . PHP_EOL .
'' . PHP_EOL .
- 'opt1 key1
'
- )
+ 'opt1 key1
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Scan added/modified files with file extensions:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Scan added/modified files with file extensions:
' . PHP_EOL .
'' . PHP_EOL .
- 'php
js
twig
'
- )
+ 'php
js
twig
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Custom sniffs included:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Custom sniffs included:
' . PHP_EOL .
'' . PHP_EOL .
- 'AdditionalStandard1
' . PHP_EOL
- )
+ 'AdditionalStandard1
' . PHP_EOL,
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Custom sniffs excluded:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Custom sniffs excluded:
' . PHP_EOL .
'' . PHP_EOL .
- 'SniffExclude1
'
- )
+ 'SniffExclude1
',
+ $actual_output
);
- $this->assertNotFalse(
- strpos(
- $actual_output,
- 'Directories not PHPCS scanned:
' . PHP_EOL .
+ $this->assertStringContainsString(
+ 'Directories not PHPCS scanned:
' . PHP_EOL .
'' . PHP_EOL .
- 'path1
path2
'
- )
+ 'path1
path2
',
+ $actual_output
);
}
}
From 8607e0359d0753a609bcd52ea1b02dc4c8301978 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 16:10:58 +0000
Subject: [PATCH 82/87] Renaming test
---
...orAdddonsTest.php => WpCoreMiscScanDirectoryForAddonsTest.php} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename tests/integration/{WpCoreMiscScanDirectoryForAdddonsTest.php => WpCoreMiscScanDirectoryForAddonsTest.php} (100%)
diff --git a/tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php b/tests/integration/WpCoreMiscScanDirectoryForAddonsTest.php
similarity index 100%
rename from tests/integration/WpCoreMiscScanDirectoryForAdddonsTest.php
rename to tests/integration/WpCoreMiscScanDirectoryForAddonsTest.php
From 350fd81022efbccae05b20b49e88b27c6782b3b9 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 16:11:12 +0000
Subject: [PATCH 83/87] Renaming test
---
tests/integration/WpCoreMiscScanDirectoryForAddonsTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/integration/WpCoreMiscScanDirectoryForAddonsTest.php b/tests/integration/WpCoreMiscScanDirectoryForAddonsTest.php
index 313459844..46ee94161 100644
--- a/tests/integration/WpCoreMiscScanDirectoryForAddonsTest.php
+++ b/tests/integration/WpCoreMiscScanDirectoryForAddonsTest.php
@@ -17,7 +17,7 @@
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
-final class WpCoreMiscScanDirectoryForAdddonsTest extends TestCase {
+final class WpCoreMiscScanDirectoryForAddonsTest extends TestCase {
/**
* Temporary directory.
*
From 80893c59a83d0b8fc44316b118417500ca9a8e7a Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Mon, 31 Oct 2022 16:30:34 +0000
Subject: [PATCH 84/87] WP CS change
---
tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
index a3b880a30..6525e82e6 100644
--- a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
@@ -235,7 +235,7 @@ public function testCreateDetails3(): void {
'Custom sniffs included:
' . PHP_EOL .
'' . PHP_EOL .
'AdditionalStandard1
' . PHP_EOL,
- $actual_output
+ $actual_output
);
$this->assertStringContainsString(
From 081d80a329d18e52b36f2bade1918e6f678f712d Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Tue, 1 Nov 2022 10:06:19 +0000
Subject: [PATCH 85/87] Ensure variable is always defined
---
tests/unit/MainRunInitOptionsAutoapproveTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/unit/MainRunInitOptionsAutoapproveTest.php b/tests/unit/MainRunInitOptionsAutoapproveTest.php
index 476153145..ae1defcf3 100644
--- a/tests/unit/MainRunInitOptionsAutoapproveTest.php
+++ b/tests/unit/MainRunInitOptionsAutoapproveTest.php
@@ -134,6 +134,8 @@ public function testRunInitOptionsAutoapproveErrors1() :void {
'svg-file-extensions' => array( 'svg' ),
);
+ $error_msg = '';
+
try {
vipgoci_run_init_options_autoapprove(
$this->options
@@ -167,6 +169,8 @@ public function testRunInitOptionsAutoapproveErrors2() :void {
'svg-file-extensions' => array( 'svg' ),
);
+ $error_msg = '';
+
try {
vipgoci_run_init_options_autoapprove(
$this->options
From 88aa77eccce24524061a291bde646478fbf36eea Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Tue, 1 Nov 2022 12:10:43 +0000
Subject: [PATCH 86/87] Update test string.
---
tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php b/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
index 75673bd30..a016de1e5 100644
--- a/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
+++ b/tests/unit/ReportCreateScanDetailsPhpLintOptionsTest.php
@@ -67,7 +67,7 @@ public function testCreateDetails1(): void {
);
$this->assertStringNotContainsString(
- 'Lint files with file extensions',
+ 'file extensions',
$actual_output,
);
From e80b43a7e946eb40aaa4e35cb7989b6b66e8b022 Mon Sep 17 00:00:00 2001
From: Gudmundur Haraldsson
Date: Tue, 1 Nov 2022 12:11:16 +0000
Subject: [PATCH 87/87] Update test string.
---
tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php | 2 +-
tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
index 6525e82e6..8656a7592 100644
--- a/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsPhpcsConfigurationTest.php
@@ -72,7 +72,7 @@ public function testCreateDetails1(): void {
);
$this->assertStringNotContainsString(
- 'Scan added/modified files with file extensions',
+ 'file extensions',
$actual_output
);
diff --git a/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php b/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
index 37706b9d6..9e817b549 100644
--- a/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
+++ b/tests/unit/ReportCreateScanDetailsSvgConfigurationTest.php
@@ -62,7 +62,7 @@ public function testCreateDetails1(): void {
);
$this->assertStringNotContainsString(
- 'Scan added/modified files with file extensions',
+ 'file extensions',
$actual_output
);
}