13 $providerPriv = \TestingAccessWrapper::newFromObject( $provider );
14 $config = new \HashConfig( [
15 'AccountCreationThrottle' => [ [
19 'PasswordAttemptThrottle' => [ [
24 $provider->setConfig( $config );
26 'accountCreationThrottle' => [ [
'count' => 123,
'seconds' => 86400 ] ],
27 'passwordAttemptThrottle' => [ [
'count' => 5,
'seconds' => 300 ] ]
28 ], $providerPriv->throttleSettings );
29 $accountCreationThrottle = \TestingAccessWrapper::newFromObject(
30 $providerPriv->accountCreationThrottle );
31 $this->assertSame( [ [
'count' => 123,
'seconds' => 86400 ] ],
32 $accountCreationThrottle->conditions );
33 $passwordAttemptThrottle = \TestingAccessWrapper::newFromObject(
34 $providerPriv->passwordAttemptThrottle );
35 $this->assertSame( [ [
'count' => 5,
'seconds' => 300 ] ],
36 $passwordAttemptThrottle->conditions );
39 'accountCreationThrottle' => [ [
'count' => 43,
'seconds' => 10000 ] ],
40 'passwordAttemptThrottle' => [ [
'count' => 11,
'seconds' => 100 ] ],
42 $providerPriv = \TestingAccessWrapper::newFromObject( $provider );
43 $config = new \HashConfig( [
44 'AccountCreationThrottle' => [ [
48 'PasswordAttemptThrottle' => [ [
53 $provider->setConfig( $config );
55 'accountCreationThrottle' => [ [
'count' => 43,
'seconds' => 10000 ] ],
56 'passwordAttemptThrottle' => [ [
'count' => 11,
'seconds' => 100 ] ],
57 ], $providerPriv->throttleSettings );
59 $cache = new \HashBagOStuff();
61 $providerPriv = \TestingAccessWrapper::newFromObject( $provider );
63 'AccountCreationThrottle' => [ [
'count' => 1,
'seconds' => 1 ] ],
64 'PasswordAttemptThrottle' => [ [
'count' => 1,
'seconds' => 1 ] ],
66 $accountCreationThrottle = \TestingAccessWrapper::newFromObject(
67 $providerPriv->accountCreationThrottle );
68 $this->assertSame(
$cache, $accountCreationThrottle->cache );
69 $passwordAttemptThrottle = \TestingAccessWrapper::newFromObject(
70 $providerPriv->passwordAttemptThrottle );
71 $this->assertSame(
$cache, $passwordAttemptThrottle->cache );
76 'accountCreationThrottle' => [],
77 'passwordAttemptThrottle' => [],
80 $provider->setLogger(
new \Psr\Log\NullLogger() );
82 'AccountCreationThrottle' =>
null,
83 'PasswordAttemptThrottle' =>
null,
88 \StatusValue::newGood(),
89 $provider->testForAccountCreation(
90 \User::newFromName(
'Created' ),
91 \User::newFromName(
'Creator' ),
96 \StatusValue::newGood(),
97 $provider->testForAuthentication( [] )
109 'accountCreationThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
112 $provider->setLogger(
new \Psr\Log\NullLogger() );
114 'AccountCreationThrottle' =>
null,
115 'PasswordAttemptThrottle' =>
null,
119 $user = \User::newFromName(
'RandomUser' );
120 $creator = \User::newFromName( $creatorname );
122 $mock = $this->getMock(
'stdClass', [
'onExemptFromAccountCreationThrottle' ] );
123 $mock->expects( $this->any() )->method(
'onExemptFromAccountCreationThrottle' )
124 ->will( $this->returnValue(
false ) );
126 'ExemptFromAccountCreationThrottle' => [ $mock ],
132 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
137 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
141 $succeed ?
true :
false,
142 $provider->testForAccountCreation(
$user, $creator, [] )->isOK(),
149 'Normal user' => [
'NormalUser',
false,
false ],
150 'Sysop' => [
'UTSysop',
true,
false ],
151 'Normal user with hook' => [
'NormalUser',
true,
true ],
157 'passwordAttemptThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
160 $provider->setLogger(
new \Psr\Log\NullLogger() );
162 'AccountCreationThrottle' =>
null,
163 'PasswordAttemptThrottle' =>
null,
168 $req->username =
'SomeUser';
169 for ( $i = 1; $i <= 3; $i++ ) {
170 $status = $provider->testForAuthentication( [
$req ] );
171 $this->assertEquals( $i < 3, $status->isGood(),
"attempt #$i" );
173 $this->assertCount( 1,
$status->getErrors() );
174 $msg = new \Message(
$status->getErrors()[0][
'message'],
$status->getErrors()[0][
'params'] );
175 $this->assertEquals(
'login-throttled', $msg->getKey() );
177 $provider->postAuthentication( \User::newFromName(
'SomeUser' ),
179 $this->assertFalse( $provider->testForAuthentication( [
$req ] )->isGood(),
'after FAIL' );
181 $provider->postAuthentication( \User::newFromName(
'SomeUser' ),
183 $this->assertTrue( $provider->testForAuthentication( [
$req ] )->isGood(),
'after PASS' );
186 $req1->username =
'foo';
188 $req2->username =
'bar';
189 $this->assertTrue( $provider->testForAuthentication( [ $req1, $req2 ] )->isGood() );
192 $req->username =
'Some user';
193 $provider->testForAuthentication( [
$req ] );
194 $req->username =
'Some_user';
195 $provider->testForAuthentication( [
$req ] );
196 $req->username =
'some user';
197 $status = $provider->testForAuthentication( [
$req ] );
198 $this->assertFalse(
$status->isGood(),
'denormalized usernames are normalized' );
203 'passwordAttemptThrottle' => [],
208 'AccountCreationThrottle' =>
null,
209 'PasswordAttemptThrottle' =>
null,
212 $provider->postAuthentication( \User::newFromName(
'SomeUser' ),
216 'passwordAttemptThrottle' => [ [
'count' => 2,
'seconds' => 86400 ] ],
219 $logger = new \TestLogger(
true );
220 $provider->setLogger( $logger );
222 'AccountCreationThrottle' =>
null,
223 'PasswordAttemptThrottle' =>
null,
226 $provider->postAuthentication( \User::newFromName(
'SomeUser' ),
229 [ \Psr\Log\LogLevel::ERROR,
'throttler data not found for {user}' ],
230 ], $logger->getBuffer() );
Simple store for keeping values in an associative array for the current process.
A Config instance which stores all settings as a member variable.
A logger that may be configured to either buffer logs or to print them to the output where PHPUnit wi...
this hook is for auditing only $req
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
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
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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
processing should stop and the error should be shown to the user * false
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