7use Wikimedia\TestingAccessWrapper;
17 $config = new \HashConfig();
18 $config->set(
'CookiePrefix',
'wgCookiePrefix' );
21 'sessionCookieName' =>
$name,
22 'sessionCookieOptions' => [],
24 if ( $prefix !==
null ) {
25 $params[
'sessionCookieOptions'][
'prefix'] = $prefix;
28 $provider = $this->getMockBuilder( ImmutableSessionProviderWithCookie::class )
29 ->setConstructorArgs( [
$params ] )
30 ->getMockForAbstractClass();
32 $provider->setConfig( $config );
39 $provider = $this->getMockBuilder( ImmutableSessionProviderWithCookie::class )
40 ->getMockForAbstractClass();
41 $priv = TestingAccessWrapper::newFromObject( $provider );
42 $this->assertNull( $priv->sessionCookieName );
43 $this->assertSame( [], $priv->sessionCookieOptions );
45 $provider = $this->getMockBuilder( ImmutableSessionProviderWithCookie::class )
46 ->setConstructorArgs( [ [
47 'sessionCookieName' =>
'Foo',
48 'sessionCookieOptions' => [
'Bar' ],
50 ->getMockForAbstractClass();
51 $priv = TestingAccessWrapper::newFromObject( $provider );
52 $this->assertSame(
'Foo', $priv->sessionCookieName );
53 $this->assertSame( [
'Bar' ], $priv->sessionCookieOptions );
56 $provider = $this->getMockBuilder( ImmutableSessionProviderWithCookie::class )
57 ->setConstructorArgs( [ [
58 'sessionCookieName' =>
false,
60 ->getMockForAbstractClass();
61 $this->fail(
'Expected exception not thrown' );
62 }
catch ( \InvalidArgumentException $ex ) {
64 'sessionCookieName must be a string',
70 $provider = $this->getMockBuilder( ImmutableSessionProviderWithCookie::class )
71 ->setConstructorArgs( [ [
72 'sessionCookieOptions' =>
'x',
74 ->getMockForAbstractClass();
75 $this->fail(
'Expected exception not thrown' );
76 }
catch ( \InvalidArgumentException $ex ) {
78 'sessionCookieOptions must be an array',
86 $this->assertFalse( $provider->persistsSessionID() );
87 $this->assertFalse( $provider->canChangeUser() );
90 $this->assertTrue( $provider->persistsSessionID() );
91 $this->assertFalse( $provider->canChangeUser() );
93 $msg = $provider->whyNoSession();
94 $this->assertInstanceOf( \Message::class, $msg );
95 $this->assertSame(
'sessionprovider-nocookies', $msg->getKey() );
100 $this->assertSame( [], $provider->getVaryCookies() );
103 $this->assertSame( [
'wgCookiePrefixFoo' ], $provider->getVaryCookies() );
106 $this->assertSame( [
'BarFoo' ], $provider->getVaryCookies() );
109 $this->assertSame( [
'Foo' ], $provider->getVaryCookies() );
113 $this->
setMwGlobals(
'wgCookiePrefix',
'wgCookiePrefix' );
116 '' =>
'empty---------------------------',
117 'Foo' =>
'foo-----------------------------',
118 'wgCookiePrefixFoo' =>
'wgfoo---------------------------',
119 'BarFoo' =>
'foobar--------------------------',
123 $provider = TestingAccessWrapper::newFromObject( $this->
getProvider(
null ) );
125 $provider->getSessionIdFromCookie(
$request );
126 $this->fail(
'Expected exception not thrown' );
127 }
catch ( \BadMethodCallException $ex ) {
129 'MediaWiki\\Session\\ImmutableSessionProviderWithCookie::getSessionIdFromCookie ' .
130 'may not be called when $this->sessionCookieName === null',
135 $provider = TestingAccessWrapper::newFromObject( $this->
getProvider(
'Foo' ) );
137 'wgfoo---------------------------',
138 $provider->getSessionIdFromCookie(
$request )
141 $provider = TestingAccessWrapper::newFromObject( $this->
getProvider(
'Foo',
'Bar' ) );
143 'foobar--------------------------',
144 $provider->getSessionIdFromCookie(
$request )
147 $provider = TestingAccessWrapper::newFromObject( $this->
getProvider(
'Foo',
'' ) );
149 'foo-----------------------------',
150 $provider->getSessionIdFromCookie(
$request )
153 $provider = TestingAccessWrapper::newFromObject( $this->
getProvider(
'bad',
'' ) );
154 $this->assertSame(
null, $provider->getSessionIdFromCookie(
$request ) );
156 $provider = TestingAccessWrapper::newFromObject( $this->
getProvider(
'none',
'' ) );
157 $this->assertSame(
null, $provider->getSessionIdFromCookie(
$request ) );
161 $sentResponse = $this->getMockBuilder( \FauxResponse::class )
162 ->setMethods( [
'headersSent',
'setCookie',
'header' ] )
164 $sentResponse->expects( $this->any() )->method(
'headersSent' )
165 ->will( $this->returnValue(
true ) );
166 $sentResponse->expects( $this->never() )->method(
'setCookie' );
167 $sentResponse->expects( $this->never() )->method(
'header' );
169 $sentRequest = $this->getMockBuilder( \FauxRequest::class )
170 ->setMethods( [
'response' ] )->getMock();
171 $sentRequest->expects( $this->any() )->method(
'response' )
172 ->will( $this->returnValue( $sentResponse ) );
183 'wgCookieExpiration' => 100,
184 'wgSecureLogin' =>
false,
188 $provider->setLogger(
new \Psr\Log\NullLogger() );
189 $priv = TestingAccessWrapper::newFromObject( $provider );
190 $priv->sessionCookieOptions = [
192 'path' =>
'CookiePath',
193 'domain' =>
'CookieDomain',
198 $sessionId =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
200 $this->assertFalse(
$user->requiresHTTPS(),
'sanity check' );
205 'provider' => $provider,
212 new \Psr\Log\NullLogger(),
215 TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling =
false;
216 $backend->setRememberUser( $remember );
217 $backend->setForceHTTPS( $secure );
220 $priv->sessionCookieName =
null;
222 $provider->persistSession( $backend,
$request );
223 $this->assertSame( [],
$request->response()->getCookies() );
226 $priv->sessionCookieName =
'session';
229 $provider->persistSession( $backend,
$request );
231 $cookie =
$request->response()->getCookieData(
'xsession' );
232 $this->assertInternalType(
'array', $cookie );
233 if ( isset( $cookie[
'expire'] ) && $cookie[
'expire'] > 0 ) {
235 $cookie[
'expire'] = round( $cookie[
'expire'] -
$time, -2 );
237 $this->assertEquals( [
238 'value' => $sessionId,
240 'path' =>
'CookiePath',
241 'domain' =>
'CookieDomain',
247 $cookie =
$request->response()->getCookieData(
'forceHTTPS' );
249 $this->assertInternalType(
'array', $cookie );
250 if ( isset( $cookie[
'expire'] ) && $cookie[
'expire'] > 0 ) {
252 $cookie[
'expire'] = round( $cookie[
'expire'] -
$time, -2 );
254 $this->assertEquals( [
257 'path' =>
'CookiePath',
258 'domain' =>
'CookieDomain',
264 $this->assertNull( $cookie );
269 $provider->persistSession( $backend,
$request );
270 $this->assertSame( [],
$request->response()->getCookies() );
284 $provider->setLogger(
new \Psr\Log\NullLogger() );
285 $priv = TestingAccessWrapper::newFromObject( $provider );
288 $priv->sessionCookieName =
null;
290 $provider->unpersistSession(
$request );
291 $this->assertSame(
null,
$request->response()->getCookie(
'session',
'' ) );
294 $priv->sessionCookieName =
'session';
296 $provider->unpersistSession(
$request );
297 $this->assertSame(
'',
$request->response()->getCookie(
'session',
'' ) );
301 $provider->unpersistSession(
$request );
302 $this->assertSame(
null,
$request->response()->getCookie(
'session',
'' ) );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
A logger that may be configured to either buffer logs or to print them to the output where PHPUnit wi...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
see documentation in includes Linker php for Linker::makeImageLink & $time
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Allows to change the fields on the form that will be generated $name
processing should stop and the error should be shown to the user * false
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