74 $this->markTestIncomplete(
'This test needs $wgServer to be set in LocalSettings.php' );
77 $user = self::$users[
'sysop'];
78 $userName = $user->getUser()->getName();
79 $password = $user->getPassword();
80 $user->getUser()->logout();
84 "lgname" => $userName,
85 "lgpassword" => $password,
90 $this->assertNotInternalType(
"bool", $result );
91 $this->assertNotInternalType(
"null", $result[
"login"] );
93 $a = $result[
"login"][
"result"];
94 $this->assertEquals(
"NeedToken", $a );
95 $token = $result[
"login"][
"token"];
101 "lgname" => $userName,
102 "lgpassword" => $password,
109 $this->assertNotInternalType(
"bool", $result );
110 $a = $result[
"login"][
"result"];
112 $this->assertEquals(
"Success", $a );
119 $this->markTestIncomplete(
"The server can't do external HTTP requests, "
120 .
"and the internal one won't give cookies" );
125 $this->markTestIncomplete(
'This test needs $wgServer to be set in LocalSettings.php' );
127 $user = self::$users[
'sysop'];
128 $userName = $user->getUser()->getName();
129 $password = $user->getPassword();
131 $req = MWHttpRequest::factory( self::$apiUrl .
"?action=login&format=xml",
132 [
"method" =>
"POST",
134 "lgname" => $userName,
135 "lgpassword" => $password
142 libxml_use_internal_errors(
true );
143 $sxe = simplexml_load_string(
$req->getContent() );
144 $this->assertNotInternalType(
"bool", $sxe );
145 $this->assertThat( $sxe, $this->isInstanceOf(
"SimpleXMLElement" ) );
146 $this->assertNotInternalType(
"null", $sxe->login[0] );
148 $a = $sxe->login[0]->attributes()->result[0];
149 $this->assertEquals(
' result="NeedToken"', $a->asXML() );
150 $token = (
string)$sxe->login[0]->attributes()->token;
154 "lgname" => $userName,
155 "lgpassword" => $password ] );
158 $cj =
$req->getCookieJar();
159 $serverName = parse_url(
$wgServer, PHP_URL_HOST );
160 $this->assertNotEquals(
false, $serverName );
161 $serializedCookie = $cj->serializeToHttpRequest(
$wgScriptPath, $serverName );
162 $this->assertNotEquals(
'', $serializedCookie );
164 '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . $user->userName .
'; .*Token=/',
170 $user = self::$users[
'sysop'];
171 $userName = $user->getUser()->getName();
172 $password = $user->getPassword();
176 'lgname' => $userName,
177 'lgpassword' => $password ] );
179 $this->assertArrayHasKey(
"login", $data[0] );
180 $this->assertArrayHasKey(
"result", $data[0][
'login'] );
181 $this->assertEquals(
"NeedToken", $data[0][
'login'][
'result'] );
182 $token = $data[0][
'login'][
'token'];
187 "lgname" => $userName,
188 "lgpassword" => $password ], $data[2] );
190 $this->assertArrayHasKey(
"login", $data[0] );
191 $this->assertArrayHasKey(
"result", $data[0][
'login'] );
192 $this->assertEquals(
"Success", $data[0][
'login'][
'result'] );
199 $this->markTestIncomplete(
'This test needs $wgServer to be set in LocalSettings.php' );
205 'class' =>
MediaWiki\Session\BotPasswordSessionProvider::class,
206 'args' => [ [
'priority' => 40 ] ],
209 'wgEnableBotPasswords' =>
true,
210 'wgBotPasswordsDatabase' =>
false,
211 'wgCentralIdLookupProvider' =>
'local',
212 'wgGrantPermissions' => [
213 'test' => [
'read' =>
true ],
218 $manager = TestingAccessWrapper::newFromObject(
MediaWiki\Session\SessionManager::singleton() );
219 if ( !isset( $manager->sessionProviders[
MediaWiki\Session\BotPasswordSessionProvider::class] ) ) {
220 $tmp = $manager->sessionProviders;
221 $manager->sessionProviders =
null;
222 $manager->sessionProviders = $tmp + $manager->getProviders();
224 $this->assertNotNull(
225 MediaWiki\Session\SessionManager::singleton()->getProvider(
226 MediaWiki\Session\BotPasswordSessionProvider::class
231 $user = self::$users[
'sysop'];
233 $this->assertNotEquals( 0, $centralId,
'sanity check' );
235 $password =
'ngfhmjm64hv0854493hsj5nncjud2clk';
239 $passwordHash = $passwordFactory->newFromPlaintext( $password );
245 'bp_user' => $centralId,
246 'bp_app_id' =>
'foo',
247 'bp_password' => $passwordHash->toString(),
250 'bp_grants' =>
'["test"]',
255 $lgName = $user->getUser()->getName() . BotPassword::getSeparator() .
'foo';
260 'lgpassword' => $password,
264 $this->assertNotInternalType(
'bool', $result );
265 $this->assertNotInternalType(
'null', $result[
'login'] );
267 $a = $result[
'login'][
'result'];
268 $this->assertEquals(
'NeedToken', $a );
269 $token = $result[
'login'][
'token'];
275 'lgpassword' => $password,
279 $this->assertNotInternalType(
'bool', $result );
280 $a = $result[
'login'][
'result'];
282 $this->assertEquals(
'Success', $a );