MediaWiki  1.33.0
TemporaryPasswordAuthenticationRequestTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
10 
11  protected function getInstance( array $args = [] ) {
13  $ret->action = $args[0];
14  return $ret;
15  }
16 
17  public static function provideGetFieldInfo() {
18  return [
22  ];
23  }
24 
25  public function testNewRandom() {
26  global $wgPasswordPolicy;
27 
28  $policy = $wgPasswordPolicy;
29  unset( $policy['policies'] );
30  $policy['policies']['default'] = [
31  'MinimalPasswordLength' => 1,
32  'MinimumPasswordLengthToLogin' => 1,
33  ];
34 
35  $this->setMwGlobals( [
36  'wgMinimalPasswordLength' => 10,
37  'wgPasswordPolicy' => $policy,
38  ] );
39 
42  $this->assertEquals( 10, strlen( $ret1->password ) );
43  $this->assertEquals( 10, strlen( $ret2->password ) );
44  $this->assertNotSame( $ret1->password, $ret2->password );
45 
46  $policy['policies']['default']['MinimalPasswordLength'] = 15;
47  $this->setMwGlobals( 'wgPasswordPolicy', $policy );
49  $this->assertEquals( 15, strlen( $ret->password ) );
50 
51  $policy['policies']['default']['MinimalPasswordLength'] = [ 'value' => 20 ];
52  $this->setMwGlobals( 'wgPasswordPolicy', $policy );
54  $this->assertEquals( 20, strlen( $ret->password ) );
55  }
56 
57  public function testNewInvalid() {
59  $this->assertNull( $ret->password );
60  }
61 
62  public function provideLoadFromSubmission() {
63  return [
64  'Empty request' => [
66  [],
67  false,
68  ],
69  'Create, empty request' => [
71  [],
72  false,
73  ],
74  'Create, mailpassword set' => [
76  [ 'mailpassword' => 1 ],
77  [ 'mailpassword' => true, 'action' => AuthManager::ACTION_CREATE ],
78  ],
79  ];
80  }
81 
82  public function testDescribeCredentials() {
85  $req->username = 'UTSysop';
86  $ret = $req->describeCredentials();
87  $this->assertInternalType( 'array', $ret );
88  $this->assertArrayHasKey( 'provider', $ret );
89  $this->assertInstanceOf( \Message::class, $ret['provider'] );
90  $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() );
91  $this->assertArrayHasKey( 'account', $ret );
92  $this->assertInstanceOf( \Message::class, $ret['account'] );
93  $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );
94  }
95 }
MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest\provideGetFieldInfo
static provideGetFieldInfo()
Definition: TemporaryPasswordAuthenticationRequestTest.php:17
MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest\testNewRandom
testNewRandom()
Definition: TemporaryPasswordAuthenticationRequestTest.php:25
$req
this hook is for auditing only $req
Definition: hooks.txt:979
php
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
Definition: injection.txt:35
MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest\provideLoadFromSubmission
provideLoadFromSubmission()
Definition: TemporaryPasswordAuthenticationRequestTest.php:62
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\newInvalid
static newInvalid()
Return an instance with an invalid password.
Definition: TemporaryPasswordAuthenticationRequest.php:86
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest\testDescribeCredentials
testDescribeCredentials()
Definition: TemporaryPasswordAuthenticationRequestTest.php:82
MediaWiki\Auth\AuthManager\ACTION_CREATE
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:91
MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest\getInstance
getInstance(array $args=[])
Definition: TemporaryPasswordAuthenticationRequestTest.php:11
MediaWiki\Auth\AuthManager\ACTION_CHANGE
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:101
$ret
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 & $ret
Definition: hooks.txt:1985
MediaWiki\Auth\AuthManager\ACTION_REMOVE
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:103
$args
if( $line===false) $args
Definition: cdb.php:64
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
This represents the intention to set a temporary password for the user.
Definition: TemporaryPasswordAuthenticationRequest.php:31
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:86
MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest\testNewInvalid
testNewInvalid()
Definition: TemporaryPasswordAuthenticationRequestTest.php:57
MediaWiki\Auth\AuthenticationRequestTestCase
AuthManager.
Definition: AuthenticationRequestTestCase.php:8
class
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
Definition: maintenance.txt:52
$wgPasswordPolicy
$wgPasswordPolicy
Password policy for the wiki.
Definition: DefaultSettings.php:4460
MediaWiki\Auth\TemporaryPasswordAuthenticationRequest\newRandom
static newRandom()
Return an instance with a new, random password.
Definition: TemporaryPasswordAuthenticationRequest.php:65
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\TemporaryPasswordAuthenticationRequestTest
AuthManager \MediaWiki\Auth\TemporaryPasswordAuthenticationRequest.
Definition: TemporaryPasswordAuthenticationRequestTest.php:9