Make WordPress Core


Ignore:
Timestamp:
12/04/2015 11:24:56 PM (11 years ago)
Author:
boonebgorges
Message:

Use 'invalid_username' error code when tripping 'illegal_user_logins'.

This gives us better compatibility with existing errors thrown by
sanitize_user(), especially in Multisite, where user_login has more
restrictions on allowed characters.

Props markjaquith.
Fixes #27317.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user.php

    r35735 r35772  
    623623                $response = wp_insert_user( $user_data );
    624624                $this->assertInstanceOf( 'WP_Error', $response );
    625                 $this->assertEquals( 'illegal_user_login', $response->get_error_code() );
     625                $this->assertEquals( 'invalid_username', $response->get_error_code() );
    626626
    627627                remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
    … …  
    634634        /**
    635635         * @ticket 27317
     636         * @dataProvider _illegal_user_logins_data
     637         */
     638        function test_illegal_user_logins_single_wp_create_user( $user_login ) {
     639                $user_email = 'testuser-' . $user_login . '@example.com';
     640
     641                add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
     642
     643                $response = register_new_user( $user_login, $user_email );
     644                $this->assertInstanceOf( 'WP_Error', $response );
     645                $this->assertEquals( 'invalid_username', $response->get_error_code() );
     646
     647                remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
     648
     649                $response = register_new_user( $user_login, $user_email );
     650                $user = get_user_by( 'id', $response );
     651                $this->assertInstanceOf( 'WP_User', $user );
     652        }
     653
     654        /**
     655         * @ticket 27317
    636656         */
    637657        function test_illegal_user_logins_multisite() {
    … …  
    659679
    660680        function _illegal_user_logins_data() {
    661                 return array(
    662                         array( 'testuser' ),
    663                         array( 'TestUser' ),
    664                 );
     681                $data = array(
     682                        array( 'testuser' )
     683                );
     684
     685                // Multisite doesn't allow mixed case logins ever
     686                if ( ! is_multisite() ) {
     687                        $data[] = array( 'TestUser' );
     688                }
     689                return $data;
    665690        }
    666691
Note: See TracChangeset for help on using the changeset viewer.