namespace MediaWiki\Auth;
use Config;
+use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Session\SessionInfo;
use MediaWiki\Session\UserInfo;
use Psr\Log\LoggerInterface;
/** @var TestingAccessWrapper */
protected $managerPriv;
- protected function setUp() {
- parent::setUp();
-
- $this->setMwGlobals( [ 'wgAuth' => null ] );
- }
-
/**
* Sets a mock on a hook
* @param string $hook
$readOnlyMode->setReason( false );
$this->setGroupPermissions( '*', 'createaccount', false );
+ $this->overrideMwServices();
$status = $this->manager->checkAccountCreatePermissions( new \User );
$this->assertFalse( $status->isOK() );
$this->assertTrue( $status->hasMessage( 'badaccess-groups' ) );
\TestUser::setPasswordForUser( $user, 'UTBlockeePassword' );
$user->saveSettings();
}
- $oldBlock = \Block::newFromTarget( 'UTBlockee' );
+ $oldBlock = DatabaseBlock::newFromTarget( 'UTBlockee' );
if ( $oldBlock ) {
// An old block will prevent our new one from saving.
$oldBlock->delete();
'expiry' => time() + 100500,
'createAccount' => true,
];
- $block = new \Block( $blockOptions );
+ $block = new DatabaseBlock( $blockOptions );
$block->insert();
+ $this->overrideMwServices();
$status = $this->manager->checkAccountCreatePermissions( $user );
$this->assertFalse( $status->isOK() );
$this->assertTrue( $status->hasMessage( 'cantcreateaccount-text' ) );
'expiry' => time() + 100500,
'createAccount' => true,
];
- $block = new \Block( $blockOptions );
+ $block = new DatabaseBlock( $blockOptions );
$block->insert();
$scopeVariable = new ScopedCallback( [ $block, 'delete' ] );
$status = $this->manager->checkAccountCreatePermissions( new \User );
],
'wgProxyWhitelist' => [],
] );
+ $this->overrideMwServices();
$status = $this->manager->checkAccountCreatePermissions( new \User );
$this->assertFalse( $status->isOK() );
$this->assertTrue( $status->hasMessage( 'sorbs_create_account_reason' ) );
$this->setMwGlobals( 'wgProxyWhitelist', [ '127.0.0.1' ] );
+ $this->overrideMwServices();
$status = $this->manager->checkAccountCreatePermissions( new \User );
$this->assertTrue( $status->isGood() );
}
}
public function testAutoAccountCreation() {
- global $wgHooks;
-
// PHPUnit seems to have a bug where it will call the ->with()
// callbacks for our hooks again after the test is run (WTF?), which
// breaks here because $username no longer matches $user by the end of
$this->mergeMwGlobalArrayValue( 'wgObjectCaches',
[ __METHOD__ => [ 'class' => 'HashBagOStuff' ] ] );
$this->setMwGlobals( [ 'wgMainCacheType' => __METHOD__ ] );
+ // Supply services with updated globals
+ $this->overrideMwServices();
// Set up lots of mocks...
$mocks = [];
// IP unable to create accounts
$this->setGroupPermissions( '*', 'createaccount', false );
$this->setGroupPermissions( '*', 'autocreateaccount', false );
+ $this->overrideMwServices();
$session->clear();
$user = \User::newFromName( $username );
$this->hook( 'LocalUserCreated', $this->never() );
$session->clear();
$user = \User::newFromName( $username );
$this->hook( 'LocalUserCreated', $this->never() );
+ $this->overrideMwServices();
$ret = $this->manager->autoCreateUser( $user, AuthManager::AUTOCREATE_SOURCE_SESSION, true );
$this->unhook( 'LocalUserCreated' );
$this->assertEquals( \Status::newFatal( 'ok' ), $ret );
// Test backoff
$cache = \ObjectCache::getLocalClusterInstance();
- $backoffKey = wfMemcKey( 'AuthManager', 'autocreate-failed', md5( $username ) );
+ $backoffKey = $cache->makeKey( 'AuthManager', 'autocreate-failed', md5( $username ) );
$cache->set( $backoffKey, true );
$session->clear();
$user = \User::newFromName( $username );
// Test addToDatabase throws an exception
$cache = \ObjectCache::getLocalClusterInstance();
- $backoffKey = wfMemcKey( 'AuthManager', 'autocreate-failed', md5( $username ) );
+ $backoffKey = $cache->makeKey( 'AuthManager', 'autocreate-failed', md5( $username ) );
$this->assertFalse( $cache->get( $backoffKey ), 'sanity check' );
$session->clear();
$user = $this->getMockBuilder( \User::class )
$session->clear();
$username = self::usernameForCreation();
$user = \User::newFromName( $username );
- $this->hook( 'AuthPluginAutoCreate', $this->once() )
- ->with( $callback );
- $this->hideDeprecated( 'AuthPluginAutoCreate hook (used in ' .
- get_class( $wgHooks['AuthPluginAutoCreate'][0] ) . '::onAuthPluginAutoCreate)' );
$this->hook( 'LocalUserCreated', $this->once() )
->with( $callback, $this->equalTo( true ) );
$ret = $this->manager->autoCreateUser( $user, AuthManager::AUTOCREATE_SOURCE_SESSION, true );
$this->unhook( 'LocalUserCreated' );
- $this->unhook( 'AuthPluginAutoCreate' );
$this->assertEquals( \Status::newGood(), $ret );
$this->assertNotEquals( 0, $user->getId() );
$this->assertEquals( $username, $user->getName() );