$reset = TestUtils::setSessionManagerSingleton( null );
$singleton = SessionManager::singleton();
- $this->assertInstanceOf( 'MediaWiki\\Session\\SessionManager', $singleton );
+ $this->assertInstanceOf( SessionManager::class, $singleton );
$this->assertSame( $singleton, SessionManager::singleton() );
}
if ( !PHPSessionHandler::isInstalled() ) {
PHPSessionHandler::install( SessionManager::singleton() );
}
- $rProp = new \ReflectionProperty( 'MediaWiki\\Session\\PHPSessionHandler', 'instance' );
+ $rProp = new \ReflectionProperty( PHPSessionHandler::class, 'instance' );
$rProp->setAccessible( true );
$handler = \TestingAccessWrapper::newFromObject( $rProp->getValue() );
$oldEnable = $handler->enable;
$request->info1 = null;
$request->info2 = null;
$session = $manager->getSessionForRequest( $request );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $idEmpty, $session->getId() );
$this->assertFalse( $request->unpersist1 );
$this->assertFalse( $request->unpersist2 );
'idIsSafe' => true,
] );
$session = $manager->getSessionForRequest( $request );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $id2, $session->getId() );
$this->assertFalse( $request->unpersist1 );
$this->assertFalse( $request->unpersist2 );
'idIsSafe' => true,
] );
$session = $manager->getSessionForRequest( $request );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $id1, $session->getId() );
$this->assertFalse( $request->unpersist1 );
$this->assertFalse( $request->unpersist2 );
'idIsSafe' => true,
] );
$session = $manager->getSessionForRequest( $request );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $id2, $session->getId() );
$this->logger->setCollect( false );
$this->assertTrue( $request->unpersist1 );
'idIsSafe' => true,
] );
$session = $manager->getSessionForRequest( $request );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $id1, $session->getId() );
$this->logger->setCollect( false );
$this->assertFalse( $request->unpersist1 );
] );
$request->info2 = null;
$session = $manager->getSessionForRequest( $request );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $id1, $session->getId() );
$this->assertTrue( $request->unpersist1 ); // The saving of the session does it
$this->assertFalse( $request->unpersist2 );
// Unknown session ID
$id = $manager->generateSessionId();
$session = $manager->getSessionById( $id, true );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $id, $session->getId() );
$id = $manager->generateSessionId();
// Known session ID
$this->store->setSession( $id, [] );
$session = $manager->getSessionById( $id, false );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $id, $session->getId() );
+
+ // Store isn't checked if the session is already loaded
+ $this->store->setSession( $id, [ 'metadata' => [
+ 'userId' => User::idFromName( 'UTSysop' ),
+ 'userToken' => 'bad',
+ ] ] );
+ $session2 = $manager->getSessionById( $id, false );
+ $this->assertInstanceOf( Session::class, $session2 );
+ $this->assertSame( $id, $session2->getId() );
+ unset( $session, $session2 );
+ $this->logger->setCollect( true );
+ $this->assertNull( $manager->getSessionById( $id, true ) );
+ $this->logger->setCollect( false );
+
+ // Failure to create an empty session
+ $manager = $this->getManager();
+ $provider = $this->getMockBuilder( 'DummySessionProvider' )
+ ->setMethods( [ 'provideSessionInfo', 'newSessionInfo', '__toString' ] )
+ ->getMock();
+ $provider->expects( $this->any() )->method( 'provideSessionInfo' )
+ ->will( $this->returnValue( null ) );
+ $provider->expects( $this->any() )->method( 'newSessionInfo' )
+ ->will( $this->returnValue( null ) );
+ $provider->expects( $this->any() )->method( '__toString' )
+ ->will( $this->returnValue( 'MockProvider' ) );
+ $this->config->set( 'SessionProviders', [
+ $this->objectCacheDef( $provider ),
+ ] );
+ $this->logger->setCollect( true );
+ $this->assertNull( $manager->getSessionById( $id, true ) );
+ $this->logger->setCollect( false );
+ $this->assertSame( [
+ [ LogLevel::ERROR, 'Failed to create empty session: {exception}' ]
+ ], $this->logger->getBuffer() );
}
public function testGetEmptySession() {
] );
$info2 = null;
$session = $manager->getEmptySession();
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( 'empty---------------------------', $session->getId() );
// Info, explicitly
] );
$info2 = null;
$session = $pmanager->getEmptySessionInternal( null, $expectId );
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( $expectId, $session->getId() );
// Wrong ID
'idIsSafe' => true,
] );
$session = $manager->getEmptySession();
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( 'empty1--------------------------', $session->getId() );
$expectId = null;
'idIsSafe' => true,
] );
$session = $manager->getEmptySession();
- $this->assertInstanceOf( 'MediaWiki\\Session\\Session', $session );
+ $this->assertInstanceOf( Session::class, $session );
$this->assertSame( 'empty2--------------------------', $session->getId() );
// Tied priorities throw an exception
}
}
+ public function testInvalidateSessionsForUser() {
+ $user = User::newFromName( 'UTSysop' );
+ $manager = $this->getManager();
+
+ $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' )
+ ->setMethods( [ 'invalidateSessionsForUser', '__toString' ] );
+
+ $provider1 = $providerBuilder->getMock();
+ $provider1->expects( $this->once() )->method( 'invalidateSessionsForUser' )
+ ->with( $this->identicalTo( $user ) );
+ $provider1->expects( $this->any() )->method( '__toString' )
+ ->will( $this->returnValue( 'MockProvider1' ) );
+
+ $provider2 = $providerBuilder->getMock();
+ $provider2->expects( $this->once() )->method( 'invalidateSessionsForUser' )
+ ->with( $this->identicalTo( $user ) );
+ $provider2->expects( $this->any() )->method( '__toString' )
+ ->will( $this->returnValue( 'MockProvider2' ) );
+
+ $this->config->set( 'SessionProviders', [
+ $this->objectCacheDef( $provider1 ),
+ $this->objectCacheDef( $provider2 ),
+ ] );
+
+ $oldToken = $user->getToken( true );
+ $manager->invalidateSessionsForUser( $user );
+ $this->assertNotEquals( $oldToken, $user->getToken() );
+ }
+
public function testGetVaryHeaders() {
$manager = $this->getManager();
$manager = \TestingAccessWrapper::newFromObject( $this->getManager() );
$manager->setLogger( new \Psr\Log\NullLogger() );
- $mock = $this->getMock( 'stdClass', [ 'save' ] );
- $mock->expects( $this->once() )->method( 'save' );
+ $mock = $this->getMock( 'stdClass', [ 'shutdown' ] );
+ $mock->expects( $this->once() )->method( 'shutdown' );
$manager->allSessionBackends = [ $mock ];
$manager->shutdown();
'provider' => 'Mock',
];
- $builder = $this->getMockBuilder( 'MediaWiki\\Session\\SessionProvider' )
+ $builder = $this->getMockBuilder( SessionProvider::class )
->setMethods( [ '__toString', 'mergeMetadata', 'refreshSessionInfo' ] );
$provider = $builder->getMockForAbstractClass();
] );
$this->assertFalse( $info->isIdSafe(), 'sanity check' );
$this->assertTrue( $loadSessionInfoFromStore( $info ) );
- $this->assertInstanceOf( 'MediaWiki\\Session\\UserInfo', $info->getUserInfo() );
+ $this->assertInstanceOf( UserInfo::class, $info->getUserInfo() );
$this->assertTrue( $info->getUserInfo()->isVerified() );
$this->assertTrue( $info->getUserInfo()->isAnon() );
$this->assertFalse( $info->isIdSafe() );