From de0143015ae13ad09f9993b459ead6051d183779 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 9 Oct 2018 21:32:01 +0300 Subject: [PATCH] Use non-deprecated login in ApiLoginTest Change-Id: I62c7bfce88aeda7ec1429493e733f868887976a9 --- tests/phpunit/includes/api/ApiLoginTest.php | 52 +++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/api/ApiLoginTest.php b/tests/phpunit/includes/api/ApiLoginTest.php index 12ca2b89ba..15486fedc3 100644 --- a/tests/phpunit/includes/api/ApiLoginTest.php +++ b/tests/phpunit/includes/api/ApiLoginTest.php @@ -58,6 +58,49 @@ class ApiLoginTest extends ApiTestCase { $this->assertSame( 'Failed', $ret[0]['login']['result'] ); } + /** + * @dataProvider provideEnableBotPasswords + */ + public function testDeprecatedUserLogin( $enableBotPasswords ) { + $this->setMwGlobals( 'wgEnableBotPasswords', $enableBotPasswords ); + + $user = $this->getTestUser(); + + $ret = $this->doApiRequest( [ + 'action' => 'login', + 'lgname' => $user->getUser()->getName(), + ] ); + + $this->assertSame( + [ 'warnings' => ApiErrorFormatter::stripMarkup( wfMessage( + 'apiwarn-deprecation-login-token' )->text() ) ], + $ret[0]['warnings']['login'] + ); + $this->assertSame( 'NeedToken', $ret[0]['login']['result'] ); + + $ret = $this->doApiRequest( [ + 'action' => 'login', + 'lgtoken' => $ret[0]['login']['token'], + 'lgname' => $user->getUser()->getName(), + 'lgpassword' => $user->getPassword(), + ], $ret[2] ); + + $this->assertSame( + [ 'warnings' => ApiErrorFormatter::stripMarkup( wfMessage( + 'apiwarn-deprecation-login-' . ( $enableBotPasswords ? '' : 'no' ) . 'botpw' ) + ->text() ) ], + $ret[0]['warnings']['login'] + ); + $this->assertSame( + [ + 'result' => 'Success', + 'lguserid' => $user->getUser()->getId(), + 'lgusername' => $user->getUser()->getName(), + ], + $ret[0]['login'] + ); + } + /** * Attempts to log in with the given name and password, retrieves the returned token, and makes * a second API request to actually log in with the token. @@ -69,16 +112,17 @@ class ApiLoginTest extends ApiTestCase { */ private function doUserLogin( $name, $password, array $params = [] ) { $ret = $this->doApiRequest( [ - 'action' => 'login', - 'lgname' => $name, + 'action' => 'query', + 'meta' => 'tokens', + 'type' => 'login', ] ); - $this->assertSame( 'NeedToken', $ret[0]['login']['result'] ); + $this->assertArrayNotHasKey( 'warnings', $ret ); return $this->doApiRequest( array_merge( [ 'action' => 'login', - 'lgtoken' => $ret[0]['login']['token'], + 'lgtoken' => $ret[0]['query']['tokens']['logintoken'], 'lgname' => $name, 'lgpassword' => $password, ], $params -- 2.20.1