Skip to content

Commit

Permalink
Add sys_get_temp_dir() to open_basedir tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
costdev committed Sep 19, 2023
1 parent 48b9b6c commit fcca8ba
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tests/phpunit/tests/admin/wpAutomaticUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,17 @@ public function test_is_allowed_dir_should_return_true_if_open_basedir_is_set_an
$abspath_grandparent = trailingslashit( dirname( $abspath_parent ) );

$open_basedir_backup = ini_get( 'open_basedir' );

/*
* Windows must use a semi-colon as a separator.
* For all other operating systems, a colon should be used.
*
* See https://www.php.net/manual/en/ini.core.php#ini.open-basedir
*/
$separator = 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ? ';' : ':';

// Allow access to the directory one level above the repository.
ini_set( 'open_basedir', wp_normalize_path( $abspath_grandparent ) );
ini_set( 'open_basedir', sys_get_temp_dir() . $separator . wp_normalize_path( $abspath_grandparent ) );

// Checking an allowed directory should succeed.
$actual = self::$updater->is_allowed_dir( wp_normalize_path( ABSPATH ) );
Expand Down Expand Up @@ -644,8 +653,17 @@ public function test_is_allowed_dir_should_return_false_if_open_basedir_is_set_a
$abspath_grandparent = trailingslashit( dirname( $abspath_parent ) );

$open_basedir_backup = ini_get( 'open_basedir' );

/*
* Windows must use a semi-colon as a separator.
* For all other operating systems, a colon should be used.
*
* See https://www.php.net/manual/en/ini.core.php#ini.open-basedir
*/
$separator = 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ? ';' : ':';

// Allow access to the directory one level above the repository.
ini_set( 'open_basedir', wp_normalize_path( $abspath_grandparent ) );
ini_set( 'open_basedir', sys_get_temp_dir() . $separator . wp_normalize_path( $abspath_grandparent ) );

// Checking a directory not within the allowed path should trigger an `open_basedir` warning.
$actual = self::$updater->is_allowed_dir( '/.git' );
Expand Down

0 comments on commit fcca8ba

Please sign in to comment.