diff --git a/.readme-partials/USING.md b/.readme-partials/USING.md index 40e84b4f8..ff473cb1a 100644 --- a/.readme-partials/USING.md +++ b/.readme-partials/USING.md @@ -460,6 +460,16 @@ chmod +x ~/wp-cli/wp WP_CLI_BIN_DIR=~/wp-cli composer behat ``` +#### Project configuration trust + +WP-CLI asks for confirmation before acting on directives that can run code or redirect a command, such as `require`, `exec`, `env`, `ssh-args` or SSH aliases, when they come from a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. + +Set the `WP_CLI_TRUST_PROJECT_CONFIG` environment variable yourself to override that default for the whole run. Individual scenarios can override it per command: + +```gherkin +When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version` +``` + #### Xdebug Step Debugging Set `WP_CLI_TEST_XDEBUG` to step debug the WP-CLI and WordPress code that the scenarios run, with Xdebug 3: diff --git a/README.md b/README.md index 9445f06d1..b25707884 100644 --- a/README.md +++ b/README.md @@ -471,6 +471,16 @@ chmod +x ~/wp-cli/wp WP_CLI_BIN_DIR=~/wp-cli composer behat ``` +#### Project configuration trust + +WP-CLI asks for confirmation before acting on directives that can run code or redirect a command, such as `require`, `exec`, `env`, `ssh-args` or SSH aliases, when they come from a project-level `wp-cli.yml` file. Test fixtures create such files all the time and a test run cannot answer an interactive prompt, so the Behat context passes `WP_CLI_TRUST_PROJECT_CONFIG=1` to every command it runs. + +Set the `WP_CLI_TRUST_PROJECT_CONFIG` environment variable yourself to override that default for the whole run. Individual scenarios can override it per command: + +```gherkin +When I try `WP_CLI_TRUST_PROJECT_CONFIG=false wp cli version` +``` + #### Xdebug Step Debugging Set `WP_CLI_TEST_XDEBUG` to step debug the WP-CLI and WordPress code that the scenarios run, with Xdebug 3: diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 5824fa9ad..1ae430230 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -552,6 +552,14 @@ private static function get_process_env_variables(): array { } } + // Test fixtures routinely create project-level `wp-cli.yml` files that contain + // `require`, `exec`, `env` or `ssh-args` directives. WP-CLI gates those behind a + // trust confirmation, which cannot be answered in a non-interactive test run, so + // trust them by default. Scenarios that specifically test the trust mechanism can + // still override this by prefixing their command with their own value. + $trust_project_config = getenv( 'WP_CLI_TRUST_PROJECT_CONFIG' ); + $env['WP_CLI_TRUST_PROJECT_CONFIG'] = false !== $trust_project_config ? $trust_project_config : '1'; + $env = array_filter( array_merge( $env, self::get_php_tuning_env_variables(), self::get_xdebug_env_variables() ), static function ( $value ) { diff --git a/utils/behat-parallel.php b/utils/behat-parallel.php index e1e0d5fd6..ba33b5298 100644 --- a/utils/behat-parallel.php +++ b/utils/behat-parallel.php @@ -633,7 +633,7 @@ function wp_cli_tests_docker_worker_command( $name, $php_image, $db_image, array } foreach ( getenv() as $key => $value ) { - if ( preg_match( '/^(WP_VERSION|NO_COLOR|CI|GITHUB_TOKEN|WP_CLI_TEST_(DBTYPE|OBJECT_CACHE|CORE_ZIP|QUIET|LOG_RUN_TIMES|PHP_TUNING|WP_VERSION_CACHE_TTL))$/', $key ) ) { + if ( preg_match( '/^(WP_VERSION|NO_COLOR|CI|GITHUB_TOKEN|WP_CLI_TEST_(DBTYPE|OBJECT_CACHE|CORE_ZIP|QUIET|LOG_RUN_TIMES|PHP_TUNING|WP_VERSION_CACHE_TTL)|WP_CLI_TRUST_PROJECT_CONFIG)$/', $key ) ) { $env[ $key ] = $value; } }