17 $logger = new \TestLogger();
18 $config = new \HashConfig();
20 $provider = $this->getMockForAbstractClass( SessionProvider::class );
21 $priv = TestingAccessWrapper::newFromObject( $provider );
23 $provider->setConfig( $config );
24 $this->assertSame( $config, $priv->config );
25 $provider->setLogger( $logger );
26 $this->assertSame( $logger, $priv->logger );
27 $provider->setManager( $manager );
28 $this->assertSame( $manager, $priv->manager );
29 $this->assertSame( $manager, $provider->getManager() );
31 $provider->invalidateSessionsForUser(
new \
User );
33 $this->assertSame( [], $provider->getVaryHeaders() );
34 $this->assertSame( [], $provider->getVaryCookies() );
35 $this->assertSame(
null, $provider->suggestLoginUsername(
new \
FauxRequest ) );
37 $this->assertSame( get_class( $provider ), (
string)$provider );
39 $this->assertNull( $provider->getRememberUserDuration() );
41 $this->assertNull( $provider->whyNoSession() );
44 'id' =>
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
45 'provider' => $provider,
47 $metadata = [
'foo' ];
48 $this->assertTrue( $provider->refreshSessionInfo( $info,
new \
FauxRequest, $metadata ) );
49 $this->assertSame( [
'foo' ], $metadata );
61 $provider = $this->getMockBuilder( SessionProvider::class )
62 ->setMethods( [
'canChangeUser',
'persistsSessionId' ] )
63 ->getMockForAbstractClass();
64 $provider->expects( $this->any() )->method(
'persistsSessionId' )
65 ->will( $this->returnValue( $persistId ) );
66 $provider->expects( $this->any() )->method(
'canChangeUser' )
67 ->will( $this->returnValue( $persistUser ) );
68 $provider->setManager( $manager );
71 $info = $provider->newSessionInfo();
72 $this->assertNotNull( $info );
73 $this->assertFalse( $info->wasPersisted() );
74 $this->assertTrue( $info->isIdSafe() );
76 $id =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
77 $info = $provider->newSessionInfo( $id );
78 $this->assertNotNull( $info );
79 $this->assertSame( $id, $info->getId() );
80 $this->assertFalse( $info->wasPersisted() );
81 $this->assertTrue( $info->isIdSafe() );
83 $this->assertNull( $provider->newSessionInfo() );
120 $provider = $this->getMockBuilder( SessionProvider::class )
121 ->setMethods( [
'canChangeUser',
'persistsSessionId' ] )
122 ->getMockForAbstractClass();
123 $provider->expects( $this->any() )->method(
'canChangeUser' )
124 ->will( $this->returnValue(
true ) );
125 $provider->preventSessionsForUser(
'Foo' );
127 $provider = $this->getMockBuilder( SessionProvider::class )
128 ->setMethods( [
'canChangeUser',
'persistsSessionId' ] )
129 ->getMockForAbstractClass();
130 $provider->expects( $this->any() )->method(
'canChangeUser' )
131 ->will( $this->returnValue(
false ) );
133 $provider->preventSessionsForUser(
'Foo' );
134 $this->fail(
'Expected exception not thrown' );
135 }
catch ( \BadMethodCallException $ex ) {
137 'MediaWiki\\Session\\SessionProvider::preventSessionsForUser must be implemented ' .
138 'when canChangeUser() is false',
145 $config = new \HashConfig( [
146 'SecretKey' =>
'Shhh!',
149 $provider = $this->getMockForAbstractClass( SessionProvider::class,
150 [],
'MockSessionProvider' );
151 $provider->setConfig( $config );
152 $priv = TestingAccessWrapper::newFromObject( $provider );
154 $this->assertSame(
'eoq8cb1mg7j30ui5qolafps4hg29k5bb', $priv->hashToSessionId(
'foobar' ) );
155 $this->assertSame(
'4do8j7tfld1g8tte9jqp3csfgmulaun9',
156 $priv->hashToSessionId(
'foobar',
'secret' ) );
159 $priv->hashToSessionId( [] );
160 $this->fail(
'Expected exception not thrown' );
161 }
catch ( \InvalidArgumentException $ex ) {
163 '$data must be a string, array was passed',
168 $priv->hashToSessionId(
'',
false );
169 $this->fail(
'Expected exception not thrown' );
170 }
catch ( \InvalidArgumentException $ex ) {
172 '$key must be a string or null, boolean was passed',
189 $provider = $this->getMockForAbstractClass( SessionProvider::class );
193 $provider->getAllowedUserRights( $backend );
194 $this->fail(
'Expected exception not thrown' );
195 }
catch ( \InvalidArgumentException $ex ) {
197 'Backend\'s provider isn\'t $this',
202 TestingAccessWrapper::newFromObject( $backend )->provider = $provider;
203 $this->assertNull( $provider->getAllowedUserRights( $backend ) );