@@ -132,23 +132,26 @@ public function test_auth_cookie_generated_with_plain_bcrypt_hash_remains_valid(
132132
133133 /**
134134 * @ticket 23494
135+ * @dataProvider data_passwords_for_trimming
135136 */
136- public function test_password_trimming () {
137- $ passwords_to_test = array (
138- 'a password with no trailing or leading spaces ' ,
139- 'a password with trailing spaces ' ,
140- ' a password with leading spaces ' ,
141- ' a password with trailing and leading spaces ' ,
142- );
137+ public function test_password_trimming ( $ password_to_test ) {
138+ wp_set_password ( $ password_to_test , $ this ->user ->ID );
139+ $ authed_user = wp_authenticate ( $ this ->user ->user_login , $ password_to_test );
143140
144- foreach ( $ passwords_to_test as $ password_to_test ) {
145- wp_set_password ( $ password_to_test , $ this ->user ->ID );
146- $ authed_user = wp_authenticate ( $ this ->user ->user_login , $ password_to_test );
141+ $ this ->assertNotWPError ( $ authed_user );
142+ $ this ->assertInstanceOf ( 'WP_User ' , $ authed_user );
143+ $ this ->assertSame ( $ this ->user ->ID , $ authed_user ->ID );
144+ }
147145
148- $ this ->assertNotWPError ( $ authed_user );
149- $ this ->assertInstanceOf ( 'WP_User ' , $ authed_user );
150- $ this ->assertSame ( $ this ->user ->ID , $ authed_user ->ID );
151- }
146+ public function data_passwords_for_trimming () {
147+ return array (
148+ 'no spaces ' => array ( 'a password with no trailing or leading spaces ' ),
149+ 'trailing space ' => array ( 'a password with trailing spaces ' ),
150+ 'leading space ' => array ( ' a password with leading spaces ' ),
151+ 'leading and trailing ' => array ( ' a password with trailing and leading spaces ' ),
152+ 'multiple leading spaces ' => array ( ' a password with multiple leading spaces ' ),
153+ 'multiple trailing spaces ' => array ( 'a password with multiple trailing spaces ' ),
154+ );
152155 }
153156
154157 /**
@@ -180,23 +183,20 @@ public function test_wp_set_password_action() {
180183 * wp_hash_password function
181184 *
182185 * @ticket 24973
186+ * @dataProvider data_passwords_with_whitespace
183187 */
184- public function test_wp_hash_password_trimming () {
185-
186- $ password = ' pass with leading whitespace ' ;
187- $ this ->assertTrue ( wp_check_password ( 'pass with leading whitespace ' , wp_hash_password ( $ password ) ) );
188-
189- $ password = 'pass with trailing whitespace ' ;
190- $ this ->assertTrue ( wp_check_password ( 'pass with trailing whitespace ' , wp_hash_password ( $ password ) ) );
191-
192- $ password = ' pass with whitespace ' ;
193- $ this ->assertTrue ( wp_check_password ( 'pass with whitespace ' , wp_hash_password ( $ password ) ) );
194-
195- $ password = "pass with new line \n" ;
196- $ this ->assertTrue ( wp_check_password ( 'pass with new line ' , wp_hash_password ( $ password ) ) );
188+ public function test_wp_hash_password_trimming ( $ password_with_whitespace , $ expected_password ) {
189+ $ this ->assertTrue ( wp_check_password ( $ expected_password , wp_hash_password ( $ password_with_whitespace ) ) );
190+ }
197191
198- $ password = "pass with vertical tab o_O \x0B" ;
199- $ this ->assertTrue ( wp_check_password ( 'pass with vertical tab o_O ' , wp_hash_password ( $ password ) ) );
192+ public function data_passwords_with_whitespace () {
193+ return array (
194+ 'leading whitespace ' => array ( ' pass with leading whitespace ' , 'pass with leading whitespace ' ),
195+ 'trailing whitespace ' => array ( 'pass with trailing whitespace ' , 'pass with trailing whitespace ' ),
196+ 'both whitespace ' => array ( ' pass with whitespace ' , 'pass with whitespace ' ),
197+ 'new line ' => array ( "pass with new line \n" , 'pass with new line ' ),
198+ 'vertical tab ' => array ( "pass with vertical tab o_O \x0B" , 'pass with vertical tab o_O ' ),
199+ );
200200 }
201201
202202 /**
0 commit comments