Code is Poetry.

WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105978 additions and 78184 deletions
+44 -34
View File
@@ -16,9 +16,11 @@ class Tests_Auth extends WP_UnitTestCase {
protected $nonce_failure_hook = 'wp_verify_nonce_failed';
public static function wpSetUpBeforeClass( $factory ) {
self::$_user = $factory->user->create_and_get( array(
'user_login' => 'password-tests'
) );
self::$_user = $factory->user->create_and_get(
array(
'user_login' => 'password-tests',
)
);
self::$user_id = self::$_user->ID;
@@ -48,9 +50,9 @@ class Tests_Auth extends WP_UnitTestCase {
$cookie = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'auth' );
$this->assertEquals( false, wp_validate_auth_cookie( $cookie, 'logged_in' ), 'wrong auth scheme' );
$cookie = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'auth' );
list($a, $b, $c) = explode('|', $cookie);
$cookie = $a . '|' . ($b + 1) . '|' . $c;
$cookie = wp_generate_auth_cookie( self::$user_id, time() + 3600, 'auth' );
list($a, $b, $c) = explode( '|', $cookie );
$cookie = $a . '|' . ( $b + 1 ) . '|' . $c;
$this->assertEquals( false, wp_validate_auth_cookie( self::$user_id, 'auth' ), 'altered cookie' );
}
@@ -75,7 +77,7 @@ class Tests_Auth extends WP_UnitTestCase {
' a password with trailing and leading spaces ',
);
foreach( $passwords_to_test as $password_to_test ) {
foreach ( $passwords_to_test as $password_to_test ) {
wp_set_password( $password_to_test, $this->user->ID );
$authed_user = wp_authenticate( $this->user->user_login, $password_to_test );
@@ -157,7 +159,7 @@ class Tests_Auth extends WP_UnitTestCase {
// A valid nonce needs to be set so the check doesn't die()
$_REQUEST['_wpnonce'] = wp_create_nonce( -1 );
$result = check_admin_referer();
$result = check_admin_referer();
$this->assertSame( 1, $result );
unset( $_REQUEST['_wpnonce'] );
@@ -171,7 +173,7 @@ class Tests_Auth extends WP_UnitTestCase {
// A valid nonce needs to be set so the check doesn't die()
$_REQUEST['_wpnonce'] = wp_create_nonce( -1 );
$result = check_ajax_referer();
$result = check_ajax_referer();
$this->assertSame( 1, $result );
unset( $_REQUEST['_wpnonce'] );
@@ -230,12 +232,14 @@ class Tests_Auth extends WP_UnitTestCase {
function test_user_activation_key_is_checked() {
global $wpdb;
$key = wp_generate_password( 20, false );
$wpdb->update( $wpdb->users, array(
'user_activation_key' => strtotime( '-1 hour' ) . ':' . self::$wp_hasher->HashPassword( $key ),
), array(
'ID' => $this->user->ID,
) );
$key = wp_generate_password( 20, false );
$wpdb->update(
$wpdb->users, array(
'user_activation_key' => strtotime( '-1 hour' ) . ':' . self::$wp_hasher->HashPassword( $key ),
), array(
'ID' => $this->user->ID,
)
);
// A valid key should be accepted
$check = check_password_reset_key( $key, $this->user->user_login );
@@ -253,7 +257,7 @@ class Tests_Auth extends WP_UnitTestCase {
// A truncated key should be rejected
$partial = substr( $key, 0, 10 );
$check = check_password_reset_key( $partial, $this->user->user_login );
$check = check_password_reset_key( $partial, $this->user->user_login );
$this->assertInstanceOf( 'WP_Error', $check );
}
@@ -263,12 +267,14 @@ class Tests_Auth extends WP_UnitTestCase {
function test_expired_user_activation_key_is_rejected() {
global $wpdb;
$key = wp_generate_password( 20, false );
$wpdb->update( $wpdb->users, array(
'user_activation_key' => strtotime( '-48 hours' ) . ':' . self::$wp_hasher->HashPassword( $key ),
), array(
'ID' => $this->user->ID,
) );
$key = wp_generate_password( 20, false );
$wpdb->update(
$wpdb->users, array(
'user_activation_key' => strtotime( '-48 hours' ) . ':' . self::$wp_hasher->HashPassword( $key ),
), array(
'ID' => $this->user->ID,
)
);
// An expired but otherwise valid key should be rejected
$check = check_password_reset_key( $key, $this->user->user_login );
@@ -296,12 +302,14 @@ class Tests_Auth extends WP_UnitTestCase {
// A legacy user_activation_key is one without the `time()` prefix introduced in WordPress 4.3.
$key = wp_generate_password( 20, false );
$wpdb->update( $wpdb->users, array(
'user_activation_key' => self::$wp_hasher->HashPassword( $key ),
), array(
'ID' => $this->user->ID,
) );
$key = wp_generate_password( 20, false );
$wpdb->update(
$wpdb->users, array(
'user_activation_key' => self::$wp_hasher->HashPassword( $key ),
), array(
'ID' => $this->user->ID,
)
);
// A legacy user_activation_key should not be accepted
$check = check_password_reset_key( $key, $this->user->user_login );
@@ -321,12 +329,14 @@ class Tests_Auth extends WP_UnitTestCase {
// A plaintext user_activation_key is one stored before hashing was introduced in WordPress 3.7.
$key = wp_generate_password( 20, false );
$wpdb->update( $wpdb->users, array(
'user_activation_key' => $key,
), array(
'ID' => $this->user->ID,
) );
$key = wp_generate_password( 20, false );
$wpdb->update(
$wpdb->users, array(
'user_activation_key' => $key,
), array(
'ID' => $this->user->ID,
)
);
// A plaintext user_activation_key should not allow an otherwise valid key to be accepted
$check = check_password_reset_key( $key, $this->user->user_login );