コード例 #1
0
 public function testAbstractAuthenticationProvider()
 {
     $provider = $this->getMockForAbstractClass(AbstractAuthenticationProvider::class);
     $providerPriv = \TestingAccessWrapper::newFromObject($provider);
     $obj = $this->getMockForAbstractClass('Psr\\Log\\LoggerInterface');
     $provider->setLogger($obj);
     $this->assertSame($obj, $providerPriv->logger, 'setLogger');
     $obj = AuthManager::singleton();
     $provider->setManager($obj);
     $this->assertSame($obj, $providerPriv->manager, 'setManager');
     $obj = $this->getMockForAbstractClass('Config');
     $provider->setConfig($obj);
     $this->assertSame($obj, $providerPriv->config, 'setConfig');
     $this->assertType('string', $provider->getUniqueId(), 'getUniqueId');
 }
コード例 #2
0
 public function testPostAuthentication()
 {
     $provider = new ThrottlePreAuthenticationProvider(['passwordAttemptThrottle' => [], 'cache' => new \HashBagOStuff()]);
     $provider->setLogger(new \TestLogger());
     $provider->setConfig(new \HashConfig(['AccountCreationThrottle' => null, 'PasswordAttemptThrottle' => null]));
     $provider->setManager(AuthManager::singleton());
     $provider->postAuthentication(\User::newFromName('SomeUser'), AuthenticationResponse::newPass());
     $provider = new ThrottlePreAuthenticationProvider(['passwordAttemptThrottle' => [['count' => 2, 'seconds' => 86400]], 'cache' => new \HashBagOStuff()]);
     $logger = new \TestLogger(true);
     $provider->setLogger($logger);
     $provider->setConfig(new \HashConfig(['AccountCreationThrottle' => null, 'PasswordAttemptThrottle' => null]));
     $provider->setManager(AuthManager::singleton());
     $provider->postAuthentication(\User::newFromName('SomeUser'), AuthenticationResponse::newPass());
     $this->assertSame([[\Psr\Log\LogLevel::ERROR, 'throttler data not found for {user}']], $logger->getBuffer());
 }
 public function testRangeBlock()
 {
     $blockOptions = ['address' => '127.0.0.0/24', 'reason' => __METHOD__, 'expiry' => time() + 100500, 'createAccount' => true];
     $block = new \Block($blockOptions);
     $block->insert();
     $scopeVariable = new \Wikimedia\ScopedCallback([$block, 'delete']);
     $user = \User::newFromName('UTNormalUser');
     if ($user->getID() == 0) {
         $user->addToDatabase();
         \TestUser::setPasswordForUser($user, 'UTNormalUserPassword');
         $user->saveSettings();
     }
     $this->setMwGlobals(['wgUser' => $user]);
     $newuser = \User::newFromName('RandomUser');
     $provider = new CheckBlocksSecondaryAuthenticationProvider(['blockDisablesLogin' => true]);
     $provider->setLogger(new \Psr\Log\NullLogger());
     $provider->setConfig(new \HashConfig());
     $provider->setManager(AuthManager::singleton());
     $ret = $provider->beginSecondaryAuthentication($user, []);
     $this->assertEquals(AuthenticationResponse::FAIL, $ret->status);
     $status = $provider->testUserForCreation($newuser, AuthManager::AUTOCREATE_SOURCE_SESSION);
     $this->assertInstanceOf('StatusValue', $status);
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('cantcreateaccount-range-text'));
     $status = $provider->testUserForCreation($newuser, false);
     $this->assertInstanceOf('StatusValue', $status);
     $this->assertFalse($status->isOK());
     $this->assertTrue($status->hasMessage('cantcreateaccount-range-text'));
 }