21 $this->config = new \HashConfig( [
22 'LanguageCode' =>
'en',
23 'SessionCacheType' =>
'testSessionStore',
24 'ObjectCacheSessionExpiry' => 100,
25 'SessionProviders' => [
26 [
'class' =>
'DummySessionProvider' ],
29 $this->logger = new \TestLogger(
false,
function ( $m ) {
30 return substr( $m, 0, 15 ) ===
'SessionBackend ' ? null : $m;
35 'config' => $this->config,
36 'logger' => $this->logger,
37 'store' => $this->store,
42 return [
'factory' =>
function ()
use ( $object ) {
62 $rProp->setAccessible(
true );
65 $reset[] = new \Wikimedia\ScopedCallback(
function ()
use (
$handler, $oldEnable ) {
67 session_write_close();
76 $id =
$request->getSession()->getId();
80 $this->assertSame( $id, $session->getId() );
82 session_id(
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' );
84 $this->assertSame(
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', $session->getId() );
85 $this->assertSame(
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
$request->getSession()->getId() );
87 session_write_close();
91 $id =
$request->getSession()->getId();
95 $this->assertSame( $id, $session->getId() );
97 session_id(
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' );
99 $this->assertSame( $id, $session->getId() );
100 $this->assertSame( $id,
$request->getSession()->getId() );
105 $this->assertSame( $this->config, $manager->config );
106 $this->assertSame( $this->logger, $manager->logger );
107 $this->assertSame( $this->
store, $manager->store );
113 'config' => $this->config,
118 'config' =>
'$options[\'config\'] must be an instance of Config',
119 'logger' =>
'$options[\'logger\'] must be an instance of LoggerInterface',
120 'store' =>
'$options[\'store\'] must be an instance of BagOStuff',
121 ]
as $key => $error ) {
124 $this->fail(
'Expected exception not thrown' );
126 $this->assertSame( $error, $ex->getMessage() );
139 $idEmpty =
'empty-session-------------------';
141 $providerBuilder = $this->getMockBuilder(
'DummySessionProvider' )
143 [
'provideSessionInfo',
'newSessionInfo',
'__toString',
'describe',
'unpersistSession' ]
146 $provider1 = $providerBuilder->getMock();
147 $provider1->expects( $this->any() )->method(
'provideSessionInfo' )
148 ->with( $this->identicalTo(
$request ) )
149 ->will( $this->returnCallback(
function (
$request ) {
152 $provider1->expects( $this->any() )->method(
'newSessionInfo' )
153 ->will( $this->returnCallback(
function ()
use ( $idEmpty, $provider1 ) {
155 'provider' => $provider1,
161 $provider1->expects( $this->any() )->method(
'__toString' )
162 ->will( $this->returnValue(
'Provider1' ) );
163 $provider1->expects( $this->any() )->method(
'describe' )
164 ->will( $this->returnValue(
'#1 sessions' ) );
165 $provider1->expects( $this->any() )->method(
'unpersistSession' )
166 ->will( $this->returnCallback(
function (
$request ) {
170 $provider2 = $providerBuilder->getMock();
171 $provider2->expects( $this->any() )->method(
'provideSessionInfo' )
172 ->with( $this->identicalTo(
$request ) )
173 ->will( $this->returnCallback(
function (
$request ) {
176 $provider2->expects( $this->any() )->method(
'__toString' )
177 ->will( $this->returnValue(
'Provider2' ) );
178 $provider2->expects( $this->any() )->method(
'describe' )
179 ->will( $this->returnValue(
'#2 sessions' ) );
180 $provider2->expects( $this->any() )->method(
'unpersistSession' )
181 ->will( $this->returnCallback(
function (
$request ) {
185 $this->config->set(
'SessionProviders', [
193 $session = $manager->getSessionForRequest(
$request );
195 $this->assertSame( $idEmpty, $session->getId() );
196 $this->assertFalse(
$request->unpersist1 );
197 $this->assertFalse(
$request->unpersist2 );
201 'provider' => $provider1,
202 'id' => ( $id1 = $manager->generateSessionId() ),
207 'provider' => $provider2,
208 'id' => ( $id2 = $manager->generateSessionId() ),
212 $session = $manager->getSessionForRequest(
$request );
214 $this->assertSame( $id2, $session->getId() );
215 $this->assertFalse(
$request->unpersist1 );
216 $this->assertFalse(
$request->unpersist2 );
219 'provider' => $provider1,
220 'id' => ( $id1 = $manager->generateSessionId() ),
225 'provider' => $provider2,
226 'id' => ( $id2 = $manager->generateSessionId() ),
230 $session = $manager->getSessionForRequest(
$request );
232 $this->assertSame( $id1, $session->getId() );
233 $this->assertFalse(
$request->unpersist1 );
234 $this->assertFalse(
$request->unpersist2 );
238 'provider' => $provider1,
239 'id' => ( $id1 = $manager->generateSessionId() ),
245 'provider' => $provider2,
246 'id' => ( $id2 = $manager->generateSessionId() ),
252 $manager->getSessionForRequest(
$request );
253 $this->fail(
'Expcected exception not thrown' );
254 }
catch ( \OverflowException $ex ) {
255 $this->assertStringStartsWith(
256 'Multiple sessions for this request tied for top priority: ',
259 $this->assertCount( 2, $ex->sessionInfos );
260 $this->assertContains(
$request->info1, $ex->sessionInfos );
261 $this->assertContains(
$request->info2, $ex->sessionInfos );
263 $this->assertFalse(
$request->unpersist1 );
264 $this->assertFalse(
$request->unpersist2 );
268 'provider' => $provider2,
269 'id' => ( $id1 = $manager->generateSessionId() ),
275 $manager->getSessionForRequest(
$request );
276 $this->fail(
'Expcected exception not thrown' );
279 'Provider1 returned session info for a different provider: ' .
$request->info1,
283 $this->assertFalse(
$request->unpersist1 );
284 $this->assertFalse(
$request->unpersist2 );
287 $this->logger->setCollect(
true );
289 'provider' => $provider1,
290 'id' => ( $id1 = $manager->generateSessionId() ),
296 'provider' => $provider2,
297 'id' => ( $id2 = $manager->generateSessionId() ),
301 $session = $manager->getSessionForRequest(
$request );
303 $this->assertSame( $id2, $session->getId() );
304 $this->logger->setCollect(
false );
305 $this->assertTrue(
$request->unpersist1 );
306 $this->assertFalse(
$request->unpersist2 );
309 $this->logger->setCollect(
true );
311 'provider' => $provider1,
312 'id' => ( $id1 = $manager->generateSessionId() ),
317 'provider' => $provider2,
318 'id' => ( $id2 = $manager->generateSessionId() ),
323 $session = $manager->getSessionForRequest(
$request );
325 $this->assertSame( $id1, $session->
getId() );
326 $this->logger->setCollect(
false );
327 $this->assertFalse(
$request->unpersist1 );
328 $this->assertTrue(
$request->unpersist2 );
333 'provider' => $provider1,
334 'id' => ( $id1 = $manager->generateSessionId() ),
335 'persisted' =>
false,
340 $session = $manager->getSessionForRequest(
$request );
342 $this->assertSame( $id1, $session->
getId() );
343 $this->assertTrue(
$request->unpersist1 );
344 $this->assertFalse(
$request->unpersist2 );
346 $this->assertTrue( $session->isPersistent(),
'sanity check' );
352 $manager->getSessionById(
'bad' );
353 $this->fail(
'Expected exception not thrown' );
355 $this->assertSame(
'Invalid session ID', $ex->getMessage() );
359 $id = $manager->generateSessionId();
360 $session = $manager->getSessionById( $id,
true );
362 $this->assertSame( $id, $session->getId() );
364 $id = $manager->generateSessionId();
365 $this->assertNull( $manager->getSessionById( $id,
false ) );
368 $this->logger->setCollect(
true );
369 $id = $manager->generateSessionId();
370 $this->
store->setSession( $id, [
'metadata' => [
372 'userToken' =>
'bad',
375 $this->assertNull( $manager->getSessionById( $id,
true ) );
376 $this->assertNull( $manager->getSessionById( $id,
false ) );
377 $this->logger->setCollect(
false );
380 $this->
store->setSession( $id, [] );
381 $session = $manager->getSessionById( $id,
false );
383 $this->assertSame( $id, $session->getId() );
386 $this->
store->setSession( $id, [
'metadata' => [
388 'userToken' =>
'bad',
390 $session2 = $manager->getSessionById( $id,
false );
392 $this->assertSame( $id, $session2->getId() );
393 unset( $session, $session2 );
394 $this->logger->setCollect(
true );
395 $this->assertNull( $manager->getSessionById( $id,
true ) );
396 $this->logger->setCollect(
false );
400 $provider = $this->getMockBuilder(
'DummySessionProvider' )
401 ->setMethods( [
'provideSessionInfo',
'newSessionInfo',
'__toString' ] )
403 $provider->expects( $this->any() )->method(
'provideSessionInfo' )
404 ->will( $this->returnValue( null ) );
405 $provider->expects( $this->any() )->method(
'newSessionInfo' )
406 ->will( $this->returnValue( null ) );
407 $provider->expects( $this->any() )->method(
'__toString' )
408 ->will( $this->returnValue(
'MockProvider' ) );
409 $this->config->set(
'SessionProviders', [
412 $this->logger->setCollect(
true );
413 $this->assertNull( $manager->getSessionById( $id,
true ) );
414 $this->logger->setCollect(
false );
416 [ LogLevel::ERROR,
'Failed to create empty session: {exception}' ]
417 ], $this->logger->getBuffer() );
425 $providerBuilder = $this->getMockBuilder(
'DummySessionProvider' )
426 ->setMethods( [
'provideSessionInfo',
'newSessionInfo',
'__toString' ] );
432 $provider1 = $providerBuilder->getMock();
433 $provider1->expects( $this->any() )->method(
'provideSessionInfo' )
434 ->will( $this->returnValue( null ) );
435 $provider1->expects( $this->any() )->method(
'newSessionInfo' )
436 ->with( $this->callback(
function ( $id )
use ( &$expectId ) {
437 return $id === $expectId;
439 ->will( $this->returnCallback(
function ()
use ( &$info1 ) {
442 $provider1->expects( $this->any() )->method(
'__toString' )
443 ->will( $this->returnValue(
'MockProvider1' ) );
445 $provider2 = $providerBuilder->getMock();
446 $provider2->expects( $this->any() )->method(
'provideSessionInfo' )
447 ->will( $this->returnValue( null ) );
448 $provider2->expects( $this->any() )->method(
'newSessionInfo' )
449 ->with( $this->callback(
function ( $id )
use ( &$expectId ) {
450 return $id === $expectId;
452 ->will( $this->returnCallback(
function ()
use ( &$info2 ) {
455 $provider1->expects( $this->any() )->method(
'__toString' )
456 ->will( $this->returnValue(
'MockProvider2' ) );
458 $this->config->set(
'SessionProviders', [
468 $manager->getEmptySession();
469 $this->fail(
'Expected exception not thrown' );
472 'No provider could provide an empty session!',
480 'provider' => $provider1,
481 'id' =>
'empty---------------------------',
486 $session = $manager->getEmptySession();
488 $this->assertSame(
'empty---------------------------', $session->getId() );
491 $expectId =
'expected------------------------';
493 'provider' => $provider1,
499 $session = $pmanager->getEmptySessionInternal( null, $expectId );
501 $this->assertSame( $expectId, $session->getId() );
504 $expectId =
'expected-----------------------2';
506 'provider' => $provider1,
507 'id' =>
"un$expectId",
513 $pmanager->getEmptySessionInternal( null, $expectId );
514 $this->fail(
'Expected exception not thrown' );
517 'MockProvider1 returned empty session info with a wrong id: ' .
518 "un$expectId != $expectId",
524 $expectId =
'expected-----------------------2';
526 'provider' => $provider1,
532 $pmanager->getEmptySessionInternal( null, $expectId );
533 $this->fail(
'Expected exception not thrown' );
536 'MockProvider1 returned empty session info with id flagged unsafe',
544 'provider' => $provider2,
545 'id' =>
'empty---------------------------',
551 $manager->getEmptySession();
552 $this->fail(
'Expected exception not thrown' );
555 'MockProvider1 returned an empty session info for a different provider: ' . $info1,
563 'provider' => $provider1,
564 'id' =>
'empty1--------------------------',
569 'provider' => $provider2,
570 'id' =>
'empty2--------------------------',
574 $session = $manager->getEmptySession();
576 $this->assertSame(
'empty1--------------------------', $session->getId() );
580 'provider' => $provider1,
581 'id' =>
'empty1--------------------------',
586 'provider' => $provider2,
587 'id' =>
'empty2--------------------------',
591 $session = $manager->getEmptySession();
593 $this->assertSame(
'empty2--------------------------', $session->getId() );
598 'provider' => $provider1,
599 'id' =>
'empty1--------------------------',
605 'provider' => $provider2,
606 'id' =>
'empty2--------------------------',
612 $manager->getEmptySession();
613 $this->fail(
'Expected exception not thrown' );
615 $this->assertStringStartsWith(
616 'Multiple empty sessions tied for top priority: ',
623 $pmanager->getEmptySessionInternal( null,
'bad' );
624 $this->fail(
'Expected exception not thrown' );
626 $this->assertSame(
'Invalid session ID', $ex->getMessage() );
630 $expectId =
'expected-----------------------3';
631 $this->
store->setSessionMeta( $expectId, [
632 'provider' =>
'MockProvider2',
638 $pmanager->getEmptySessionInternal( null, $expectId );
639 $this->fail(
'Expected exception not thrown' );
641 $this->assertSame(
'Session ID already exists', $ex->getMessage() );
649 $providerBuilder = $this->getMockBuilder(
'DummySessionProvider' )
650 ->setMethods( [
'invalidateSessionsForUser',
'__toString' ] );
652 $provider1 = $providerBuilder->getMock();
653 $provider1->expects( $this->once() )->method(
'invalidateSessionsForUser' )
654 ->with( $this->identicalTo(
$user ) );
655 $provider1->expects( $this->any() )->method(
'__toString' )
656 ->will( $this->returnValue(
'MockProvider1' ) );
658 $provider2 = $providerBuilder->getMock();
659 $provider2->expects( $this->once() )->method(
'invalidateSessionsForUser' )
660 ->with( $this->identicalTo(
$user ) );
661 $provider2->expects( $this->any() )->method(
'__toString' )
662 ->will( $this->returnValue(
'MockProvider2' ) );
664 $this->config->set(
'SessionProviders', [
669 $oldToken =
$user->getToken(
true );
670 $manager->invalidateSessionsForUser(
$user );
671 $this->assertNotEquals( $oldToken,
$user->getToken() );
677 $providerBuilder = $this->getMockBuilder(
'DummySessionProvider' )
678 ->setMethods( [
'getVaryHeaders',
'__toString' ] );
680 $provider1 = $providerBuilder->getMock();
681 $provider1->expects( $this->once() )->method(
'getVaryHeaders' )
682 ->will( $this->returnValue( [
684 'Bar' => [
'X',
'Bar1' ],
687 $provider1->expects( $this->any() )->method(
'__toString' )
688 ->will( $this->returnValue(
'MockProvider1' ) );
690 $provider2 = $providerBuilder->getMock();
691 $provider2->expects( $this->once() )->method(
'getVaryHeaders' )
692 ->will( $this->returnValue( [
694 'Bar' => [
'X',
'Bar2' ],
695 'Quux' => [
'Quux' ],
697 $provider2->expects( $this->any() )->method(
'__toString' )
698 ->will( $this->returnValue(
'MockProvider2' ) );
700 $this->config->set(
'SessionProviders', [
707 'Bar' => [
'X',
'Bar1', 3 =>
'Bar2' ],
708 'Quux' => [
'Quux' ],
712 $this->assertEquals( $expect, $manager->getVaryHeaders() );
715 $this->assertEquals( $expect, $manager->getVaryHeaders() );
721 $providerBuilder = $this->getMockBuilder(
'DummySessionProvider' )
722 ->setMethods( [
'getVaryCookies',
'__toString' ] );
724 $provider1 = $providerBuilder->getMock();
725 $provider1->expects( $this->once() )->method(
'getVaryCookies' )
726 ->will( $this->returnValue( [
'Foo',
'Bar' ] ) );
727 $provider1->expects( $this->any() )->method(
'__toString' )
728 ->will( $this->returnValue(
'MockProvider1' ) );
730 $provider2 = $providerBuilder->getMock();
731 $provider2->expects( $this->once() )->method(
'getVaryCookies' )
732 ->will( $this->returnValue( [
'Foo',
'Baz' ] ) );
733 $provider2->expects( $this->any() )->method(
'__toString' )
734 ->will( $this->returnValue(
'MockProvider2' ) );
736 $this->config->set(
'SessionProviders', [
741 $expect = [
'Foo',
'Bar',
'Baz' ];
743 $this->assertEquals( $expect, $manager->getVaryCookies() );
746 $this->assertEquals( $expect, $manager->getVaryCookies() );
753 $this->config->set(
'SessionProviders', [
754 [
'class' =>
'DummySessionProvider' ],
756 $providers = $manager->getProviders();
757 $this->assertArrayHasKey(
'DummySessionProvider', $providers );
759 $this->assertSame( $manager->logger, $provider->logger );
760 $this->assertSame( $manager->config, $provider->config );
761 $this->assertSame( $realManager, $provider->getManager() );
763 $this->config->set(
'SessionProviders', [
764 [
'class' =>
'DummySessionProvider' ],
765 [
'class' =>
'DummySessionProvider' ],
767 $manager->sessionProviders = null;
769 $manager->getProviders();
770 $this->fail(
'Expected exception not thrown' );
773 'Duplicate provider name "DummySessionProvider"',
781 $manager->setLogger(
new \Psr\Log\NullLogger() );
783 $mock = $this->getMock(
'stdClass', [
'shutdown' ] );
784 $mock->expects( $this->once() )->method(
'shutdown' );
786 $manager->allSessionBackends = [ $mock ];
787 $manager->shutdown();
794 $id =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
797 'provider' => $manager->getProvider(
'DummySessionProvider' ),
805 $manager->getSessionFromInfo( $info,
$request )
808 $manager->getSessionFromInfo( $info,
$request )
811 $this->assertSame( $session1->backend, $session2->backend );
812 $this->assertNotEquals( $session1->index, $session2->index );
813 $this->assertSame( $session1->getSessionId(), $session2->getSessionId() );
814 $this->assertSame( $id, $session1->getId() );
817 $session3 = $manager->getSessionFromInfo( $info,
$request );
818 $this->assertNotSame( $id, $session3->getId() );
824 $session = $manager->getSessionForRequest(
new \
FauxRequest );
826 $sessionId = $session->getSessionId();
829 $this->assertSame( $sessionId, $manager->getSessionById( $id,
true )->getSessionId() );
831 $manager->changeBackendId( $backend );
832 $this->assertSame( $sessionId, $session->getSessionId() );
833 $this->assertNotEquals( $id, (
string)$sessionId );
836 $this->assertSame( $sessionId, $manager->getSessionById( $id,
true )->getSessionId() );
842 $manager->changeBackendId( $backend );
843 $this->fail(
'Expected exception not thrown' );
846 'Backend was not registered with this SessionManager', $ex->getMessage()
851 $manager->deregisterSessionBackend( $backend );
852 $this->fail(
'Expected exception not thrown' );
855 'Backend was not registered with this SessionManager', $ex->getMessage()
859 $session = $manager->getSessionById( $id,
true );
860 $this->assertSame( $sessionId, $session->getSessionId() );
866 $id = $manager->generateSessionId();
873 $providerBuilder = $this->getMockBuilder(
'DummySessionProvider' )
874 ->setMethods( [
'preventSessionsForUser',
'__toString' ] );
876 $provider1 = $providerBuilder->getMock();
877 $provider1->expects( $this->once() )->method(
'preventSessionsForUser' )
878 ->with( $this->equalTo(
'UTSysop' ) );
879 $provider1->expects( $this->any() )->method(
'__toString' )
880 ->will( $this->returnValue(
'MockProvider1' ) );
882 $this->config->set(
'SessionProviders', [
886 $this->assertFalse( $manager->isUserSessionPrevented(
'UTSysop' ) );
887 $manager->preventSessionsForUser(
'UTSysop' );
888 $this->assertTrue( $manager->isUserSessionPrevented(
'UTSysop' ) );
893 $logger = new \TestLogger(
true );
894 $manager->setLogger( $logger );
898 $rClass = new \ReflectionClass( $manager );
899 $rMethod = $rClass->getMethod(
'loadSessionInfoFromStore' );
900 $rMethod->setAccessible(
true );
901 $loadSessionInfoFromStore =
function ( &$info )
use ( $rMethod, $manager,
$request ) {
902 return $rMethod->invokeArgs( $manager, [ &$info,
$request ] );
908 $id =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
910 'userId' => $userInfo->getId(),
911 'userName' => $userInfo->getName(),
912 'userToken' => $userInfo->getToken(
true ),
913 'provider' =>
'Mock',
917 ->setMethods( [
'__toString',
'mergeMetadata',
'refreshSessionInfo' ] );
919 $provider = $builder->getMockForAbstractClass();
920 $provider->setManager( $manager );
921 $provider->expects( $this->any() )->method(
'persistsSessionId' )
922 ->will( $this->returnValue(
true ) );
923 $provider->expects( $this->any() )->method(
'canChangeUser' )
924 ->will( $this->returnValue(
true ) );
925 $provider->expects( $this->any() )->method(
'refreshSessionInfo' )
926 ->will( $this->returnValue(
true ) );
927 $provider->expects( $this->any() )->method(
'__toString' )
928 ->will( $this->returnValue(
'Mock' ) );
929 $provider->expects( $this->any() )->method(
'mergeMetadata' )
930 ->will( $this->returnCallback(
function ( $a, $b ) {
931 if ( $b === [
'Throw' ] ) {
937 $provider2 = $builder->getMockForAbstractClass();
938 $provider2->setManager( $manager );
939 $provider2->expects( $this->any() )->method(
'persistsSessionId' )
940 ->will( $this->returnValue(
false ) );
941 $provider2->expects( $this->any() )->method(
'canChangeUser' )
942 ->will( $this->returnValue(
false ) );
943 $provider2->expects( $this->any() )->method(
'__toString' )
944 ->will( $this->returnValue(
'Mock2' ) );
945 $provider2->expects( $this->any() )->method(
'refreshSessionInfo' )
946 ->will( $this->returnCallback(
function ( $info,
$request, &$metadata ) {
947 $metadata[
'changed'] =
true;
951 $provider3 = $builder->getMockForAbstractClass();
952 $provider3->setManager( $manager );
953 $provider3->expects( $this->any() )->method(
'persistsSessionId' )
954 ->will( $this->returnValue(
true ) );
955 $provider3->expects( $this->any() )->method(
'canChangeUser' )
956 ->will( $this->returnValue(
true ) );
957 $provider3->expects( $this->once() )->method(
'refreshSessionInfo' )
958 ->will( $this->returnValue(
false ) );
959 $provider3->expects( $this->any() )->method(
'__toString' )
960 ->will( $this->returnValue(
'Mock3' ) );
963 (
string)$provider => $provider,
964 (
string)$provider2 => $provider2,
965 (
string)$provider3 => $provider3,
970 'provider' => $provider,
972 'userInfo' => $userInfo
974 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
975 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
976 $this->assertFalse( $info->isIdSafe() );
977 $this->assertSame( [], $logger->getBuffer() );
980 'provider' => $provider,
981 'userInfo' => $userInfo
983 $this->assertTrue( $info->isIdSafe(),
'sanity check' );
984 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
985 $this->assertTrue( $info->isIdSafe() );
986 $this->assertSame( [], $logger->getBuffer() );
989 'provider' => $provider2,
991 'userInfo' => $userInfo
993 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
994 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
995 $this->assertTrue( $info->isIdSafe() );
996 $this->assertSame( [], $logger->getBuffer() );
1000 'provider' => $provider,
1002 'userInfo' => $unverifiedUserInfo
1004 $this->assertSame( $unverifiedUserInfo, $info->getUserInfo() );
1005 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1006 $this->assertSame( [
1009 'Session "{session}": Unverified user provided and no metadata to auth it',
1011 ], $logger->getBuffer() );
1012 $logger->clearBuffer();
1017 'userInfo' => $userInfo
1019 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1020 $this->assertSame( [
1021 [ LogLevel::WARNING,
'Session "{session}": Null provider and no metadata' ],
1022 ], $logger->getBuffer() );
1023 $logger->clearBuffer();
1026 'provider' => $provider,
1029 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1030 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1032 $this->assertTrue( $info->getUserInfo()->isVerified() );
1033 $this->assertTrue( $info->getUserInfo()->isAnon() );
1034 $this->assertFalse( $info->isIdSafe() );
1035 $this->assertSame( [], $logger->getBuffer() );
1038 'provider' => $provider2,
1041 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1042 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1043 $this->assertSame( [
1044 [ LogLevel::INFO,
'Session "{session}": No user provided and provider cannot set user' ]
1045 ], $logger->getBuffer() );
1046 $logger->clearBuffer();
1049 $this->
store->setRawSession( $id,
true );
1050 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1051 $this->assertSame( [
1052 [ LogLevel::WARNING,
'Session "{session}": Bad data' ],
1053 ], $logger->getBuffer() );
1054 $logger->clearBuffer();
1056 $this->
store->setRawSession( $id, [
'data' => [] ] );
1057 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1058 $this->assertSame( [
1059 [ LogLevel::WARNING,
'Session "{session}": Bad data structure' ],
1060 ], $logger->getBuffer() );
1061 $logger->clearBuffer();
1063 $this->
store->deleteSession( $id );
1064 $this->
store->setRawSession( $id, [
'metadata' => $metadata ] );
1065 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1066 $this->assertSame( [
1067 [ LogLevel::WARNING,
'Session "{session}": Bad data structure' ],
1068 ], $logger->getBuffer() );
1069 $logger->clearBuffer();
1071 $this->
store->setRawSession( $id, [
'metadata' => $metadata,
'data' =>
true ] );
1072 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1073 $this->assertSame( [
1074 [ LogLevel::WARNING,
'Session "{session}": Bad data structure' ],
1075 ], $logger->getBuffer() );
1076 $logger->clearBuffer();
1078 $this->
store->setRawSession( $id, [
'metadata' =>
true,
'data' => [] ] );
1079 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1080 $this->assertSame( [
1081 [ LogLevel::WARNING,
'Session "{session}": Bad data structure' ],
1082 ], $logger->getBuffer() );
1083 $logger->clearBuffer();
1085 foreach ( $metadata
as $key => $dummy ) {
1087 unset( $tmp[$key] );
1088 $this->
store->setRawSession( $id, [
'metadata' => $tmp,
'data' => [] ] );
1089 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1090 $this->assertSame( [
1091 [ LogLevel::WARNING,
'Session "{session}": Bad metadata' ],
1092 ], $logger->getBuffer() );
1093 $logger->clearBuffer();
1097 $this->
store->setRawSession( $id, [
'metadata' => $metadata,
'data' => [] ] );
1099 'provider' => $provider,
1101 'userInfo' => $userInfo
1103 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1104 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1105 $this->assertTrue( $info->isIdSafe() );
1106 $this->assertSame( [], $logger->getBuffer() );
1109 $this->
store->setSessionMeta( $id, [
'provider' =>
'Bad' ] + $metadata );
1111 'provider' => $provider,
1113 'userInfo' => $userInfo
1115 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1116 $this->assertSame( [
1117 [ LogLevel::WARNING,
'Session "{session}": Wrong provider Bad !== Mock' ],
1118 ], $logger->getBuffer() );
1119 $logger->clearBuffer();
1122 $this->
store->setSessionMeta( $id, [
'provider' =>
'Bad' ] + $metadata );
1125 'userInfo' => $userInfo
1127 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1128 $this->assertSame( [
1129 [ LogLevel::WARNING,
'Session "{session}": Unknown provider Bad' ],
1130 ], $logger->getBuffer() );
1131 $logger->clearBuffer();
1134 $this->
store->setSessionMeta( $id, $metadata );
1137 'userInfo' => $userInfo
1139 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1140 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1141 $this->assertTrue( $info->isIdSafe() );
1142 $this->assertSame( [], $logger->getBuffer() );
1145 $this->
store->setSessionMeta( $id, [
'userId' => -1,
'userToken' => null ] + $metadata );
1147 'provider' => $provider,
1150 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1151 $this->assertSame( [
1152 [ LogLevel::ERROR,
'Session "{session}": {exception}' ],
1153 ], $logger->getBuffer() );
1154 $logger->clearBuffer();
1156 $this->
store->setSessionMeta(
1157 $id, [
'userId' => 0,
'userName' =>
'<X>',
'userToken' => null ] + $metadata
1160 'provider' => $provider,
1163 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1164 $this->assertSame( [
1165 [ LogLevel::ERROR,
'Session "{session}": {exception}', ],
1166 ], $logger->getBuffer() );
1167 $logger->clearBuffer();
1170 $this->
store->setSessionMeta(
1171 $id, [
'userId' => $userInfo->getId() + 1,
'userToken' => null ] + $metadata
1174 'provider' => $provider,
1176 'userInfo' => $userInfo
1178 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1179 $this->assertSame( [
1180 [ LogLevel::WARNING,
'Session "{session}": User ID mismatch, {uid_a} !== {uid_b}' ],
1181 ], $logger->getBuffer() );
1182 $logger->clearBuffer();
1185 $this->
store->setSessionMeta(
1186 $id, [
'userId' => 0,
'userName' =>
'X',
'userToken' => null ] + $metadata
1189 'provider' => $provider,
1191 'userInfo' => $userInfo
1193 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1194 $this->assertSame( [
1195 [ LogLevel::WARNING,
'Session "{session}": User name mismatch, {uname_a} !== {uname_b}' ],
1196 ], $logger->getBuffer() );
1197 $logger->clearBuffer();
1200 $this->
store->setSessionMeta(
1201 $id, [
'userId' => $userInfo->getId(),
'userName' =>
'X',
'userToken' => null ] + $metadata
1204 'provider' => $provider,
1206 'userInfo' => $userInfo
1208 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1209 $this->assertSame( [
1212 'Session "{session}": User ID matched but name didn\'t (rename?), {uname_a} !== {uname_b}'
1214 ], $logger->getBuffer() );
1215 $logger->clearBuffer();
1218 $this->
store->setSessionMeta(
1219 $id, [
'userId' => 0,
'userName' => null,
'userToken' => null ] + $metadata
1222 'provider' => $provider,
1224 'userInfo' => $userInfo
1226 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1227 $this->assertSame( [
1230 'Session "{session}": Metadata has an anonymous user, ' .
1231 'but a non-anon user was provided',
1233 ], $logger->getBuffer() );
1234 $logger->clearBuffer();
1237 $this->
store->setSessionMeta( $id, [
'userToken' => null ] + $metadata );
1239 'provider' => $provider,
1242 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1243 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1244 $this->assertSame( $userInfo->getId(), $info->getUserInfo()->getId() );
1245 $this->assertTrue( $info->isIdSafe() );
1246 $this->assertSame( [], $logger->getBuffer() );
1249 $this->
store->setSessionMeta(
1250 $id, [
'userId' => 0,
'userName' =>
'UTSysop',
'userToken' => null ] + $metadata
1253 'provider' => $provider,
1256 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1257 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1258 $this->assertSame( $userInfo->getId(), $info->getUserInfo()->getId() );
1259 $this->assertTrue( $info->isIdSafe() );
1260 $this->assertSame( [], $logger->getBuffer() );
1263 $this->
store->setSessionMeta(
1264 $id, [
'userId' => 0,
'userName' => null,
'userToken' => null ] + $metadata
1267 'provider' => $provider,
1270 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1271 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1272 $this->assertTrue( $info->getUserInfo()->isAnon() );
1273 $this->assertTrue( $info->isIdSafe() );
1274 $this->assertSame( [], $logger->getBuffer() );
1277 $this->
store->setSessionMeta( $id, $metadata );
1279 'provider' => $provider,
1281 'userInfo' => $unverifiedUserInfo
1283 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1284 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1285 $this->assertTrue( $info->getUserInfo()->isVerified() );
1286 $this->assertSame( $unverifiedUserInfo->getId(), $info->getUserInfo()->getId() );
1287 $this->assertSame( $unverifiedUserInfo->getName(), $info->getUserInfo()->getName() );
1288 $this->assertTrue( $info->isIdSafe() );
1289 $this->assertSame( [], $logger->getBuffer() );
1292 $this->
store->setSessionMeta( $id, $metadata );
1294 'provider' => $provider,
1296 'userInfo' => $unverifiedUserInfo
1298 $this->assertFalse( $info->isIdSafe(),
'sanity check' );
1299 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1300 $this->assertTrue( $info->getUserInfo()->isVerified() );
1301 $this->assertSame( $unverifiedUserInfo->getId(), $info->getUserInfo()->getId() );
1302 $this->assertSame( $unverifiedUserInfo->getName(), $info->getUserInfo()->getName() );
1303 $this->assertTrue( $info->isIdSafe() );
1304 $this->assertSame( [], $logger->getBuffer() );
1307 $this->
store->setSessionMeta( $id, [
'userToken' =>
'Bad' ] + $metadata );
1309 'provider' => $provider,
1311 'userInfo' => $userInfo
1313 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1314 $this->assertSame( [
1315 [ LogLevel::WARNING,
'Session "{session}": User token mismatch' ],
1316 ], $logger->getBuffer() );
1317 $logger->clearBuffer();
1320 $this->
store->setSessionMeta( $id, [
'provider' =>
'Mock2' ] + $metadata );
1322 'provider' => $provider2,
1324 'userInfo' => $userInfo,
1325 'metadata' => [
'Info' ],
1327 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1328 $this->assertSame( [
'Info',
'changed' =>
true ], $info->getProviderMetadata() );
1329 $this->assertSame( [], $logger->getBuffer() );
1331 $this->
store->setSessionMeta( $id, [
'providerMetadata' => [
'Saved' ] ] + $metadata );
1333 'provider' => $provider,
1335 'userInfo' => $userInfo,
1337 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1338 $this->assertSame( [
'Saved' ], $info->getProviderMetadata() );
1339 $this->assertSame( [], $logger->getBuffer() );
1342 'provider' => $provider,
1344 'userInfo' => $userInfo,
1345 'metadata' => [
'Info' ],
1347 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1348 $this->assertSame( [
'Merged' ], $info->getProviderMetadata() );
1349 $this->assertSame( [], $logger->getBuffer() );
1352 'provider' => $provider,
1354 'userInfo' => $userInfo,
1355 'metadata' => [
'Throw' ],
1357 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1358 $this->assertSame( [
1361 'Session "{session}": Metadata merge failed: {exception}',
1363 ], $logger->getBuffer() );
1364 $logger->clearBuffer();
1367 $this->
store->setSessionMeta( $id, $metadata );
1369 'provider' => $provider,
1372 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1373 $this->assertFalse( $info->wasRemembered() );
1374 $this->assertSame( [], $logger->getBuffer() );
1376 $this->
store->setSessionMeta( $id, [
'remember' =>
true ] + $metadata );
1378 'provider' => $provider,
1381 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1382 $this->assertTrue( $info->wasRemembered() );
1383 $this->assertSame( [], $logger->getBuffer() );
1385 $this->
store->setSessionMeta( $id, [
'remember' =>
false ] + $metadata );
1387 'provider' => $provider,
1389 'userInfo' => $userInfo
1391 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1392 $this->assertTrue( $info->wasRemembered() );
1393 $this->assertSame( [], $logger->getBuffer() );
1396 $this->
store->setSessionMeta( $id, $metadata );
1398 'provider' => $provider,
1400 'userInfo' => $userInfo
1402 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1403 $this->assertFalse( $info->forceHTTPS() );
1404 $this->assertSame( [], $logger->getBuffer() );
1406 $this->
store->setSessionMeta( $id, [
'forceHTTPS' =>
true ] + $metadata );
1408 'provider' => $provider,
1410 'userInfo' => $userInfo
1412 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1413 $this->assertTrue( $info->forceHTTPS() );
1414 $this->assertSame( [], $logger->getBuffer() );
1416 $this->
store->setSessionMeta( $id, [
'forceHTTPS' =>
false ] + $metadata );
1418 'provider' => $provider,
1420 'userInfo' => $userInfo,
1421 'forceHTTPS' =>
true
1423 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1424 $this->assertTrue( $info->forceHTTPS() );
1425 $this->assertSame( [], $logger->getBuffer() );
1428 $this->
store->setSessionMeta( $id, $metadata );
1430 'provider' => $provider,
1432 'userInfo' => $userInfo
1434 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1435 $this->assertFalse( $info->wasPersisted() );
1436 $this->assertSame( [], $logger->getBuffer() );
1438 $this->
store->setSessionMeta( $id, [
'persisted' =>
true ] + $metadata );
1440 'provider' => $provider,
1442 'userInfo' => $userInfo
1444 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1445 $this->assertTrue( $info->wasPersisted() );
1446 $this->assertSame( [], $logger->getBuffer() );
1448 $this->
store->setSessionMeta( $id, [
'persisted' =>
false ] + $metadata );
1450 'provider' => $provider,
1452 'userInfo' => $userInfo,
1455 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1456 $this->assertTrue( $info->wasPersisted() );
1457 $this->assertSame( [], $logger->getBuffer() );
1461 'provider' => $provider3,
1463 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1464 $this->assertSame( [], $logger->getBuffer() );
1468 $data = [
'foo' => 1 ];
1469 $this->
store->setSession( $id, [
'metadata' => $metadata,
'data' => $data ] );
1471 'provider' => $provider,
1473 'userInfo' => $userInfo
1476 'SessionCheckInfo' => [
function ( &$reason, $i, $r, $m, $d )
use (
1477 $info, $metadata, $data,
$request, &$called
1479 $this->assertSame( $info->getId(), $i->getId() );
1480 $this->assertSame( $info->getProvider(), $i->getProvider() );
1481 $this->assertSame( $info->getUserInfo(), $i->getUserInfo() );
1483 $this->assertEquals( $metadata, $m );
1484 $this->assertEquals( $data, $d );
1489 $this->assertFalse( $loadSessionInfoFromStore( $info ) );
1490 $this->assertTrue( $called );
1491 $this->assertSame( [
1492 [ LogLevel::WARNING,
'Session "{session}": Hook aborted' ],
1493 ], $logger->getBuffer() );
1494 $logger->clearBuffer();
1498 $this->
store->setSessionMeta( $id, [
'userToken' =>
'Bad' ] + $metadata );
1500 'provider' => $provider,
1502 'userInfo' => $userInfo,
1505 $this->assertTrue( $loadSessionInfoFromStore( $info ) );
1506 $this->assertFalse( $this->
store->getSession( $id ) );
1507 $this->assertSame( [
1508 [ LogLevel::WARNING,
'Session "{session}": User token mismatch' ],
1509 ], $logger->getBuffer() );
1510 $logger->clearBuffer();
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
MediaWiki s SiteStore can be cached and stored in a flat in a json format If the SiteStore is frequently the file cache may provide a performance benefit over a database store
static BagOStuff[] $instances
Map of (id => BagOStuff)
static getMain()
Static methods.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
error also a ContextSource you ll probably need to make sure the header is varied on $request
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
static idFromName($name, $flags=self::READ_NORMAL)
Get database id given a user name.
static newFromObject($object)
Return the same object, without access restrictions.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler