Skip to content

Commit 6ae67d9

Browse files
committed
Build/Test Tools: Reduce the bcrypt cost during testing in order to speed up tests.
The lowest allowable cost in PHP is 4, so 5 is used which means tests can still to reduce the cost by one when testing alterations to the cost. See #63026 git-svn-id: https://develop.svn.wordpress.org/trunk@60298 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1e641a3 commit 6ae67d9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

tests/phpunit/includes/abstract-testcase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ public function set_up() {
136136
$this->start_transaction();
137137
$this->expectDeprecated();
138138
add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
139+
add_filter( 'wp_hash_password_options', array( $this, 'wp_hash_password_options' ), 1, 2 );
140+
}
141+
142+
/**
143+
* Sets the bcrypt cost option for password hashing during tests.
144+
*
145+
* @param array $options The options for password hashing.
146+
* @param string|int $algorithm The algorithm to use for hashing. This is a string in PHP 7.4+ and an integer in PHP 7.3 and earlier.
147+
*/
148+
public function wp_hash_password_options( array $options, $algorithm ): array {
149+
if ( PASSWORD_BCRYPT === $algorithm ) {
150+
$options['cost'] = 5;
151+
}
152+
153+
return $options;
139154
}
140155

141156
/**

tests/phpunit/tests/auth.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,9 +2089,6 @@ private static function set_application_password( string $hash, int $user_id ) {
20892089
}
20902090

20912091
private static function get_default_bcrypt_cost(): int {
2092-
$hash = password_hash( 'password', PASSWORD_BCRYPT );
2093-
$info = password_get_info( $hash );
2094-
2095-
return $info['options']['cost'];
2092+
return 5;
20962093
}
20972094
}

0 commit comments

Comments
 (0)