3 namespace MediaWiki\Auth
;
7 * @covers \MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
9 class TemporaryPasswordAuthenticationRequestTest
extends AuthenticationRequestTestCase
{
11 protected function getInstance( array $args = [] ) {
12 $ret = new TemporaryPasswordAuthenticationRequest
;
13 $ret->action
= $args[0];
17 public static function provideGetFieldInfo() {
19 [ [ AuthManager
::ACTION_CREATE
] ],
20 [ [ AuthManager
::ACTION_CHANGE
] ],
21 [ [ AuthManager
::ACTION_REMOVE
] ],
25 public function testNewRandom() {
26 global $wgPasswordPolicy;
28 $policy = $wgPasswordPolicy;
29 unset( $policy['policies'] );
30 $policy['policies']['default'] = [
31 'MinimalPasswordLength' => 1,
32 'MinimumPasswordLengthToLogin' => 1,
35 $this->setMwGlobals( [
36 'wgMinimalPasswordLength' => 10,
37 'wgPasswordPolicy' => $policy,
40 $ret1 = TemporaryPasswordAuthenticationRequest
::newRandom();
41 $ret2 = TemporaryPasswordAuthenticationRequest
::newRandom();
42 $this->assertEquals( 10, strlen( $ret1->password
) );
43 $this->assertEquals( 10, strlen( $ret2->password
) );
44 $this->assertNotSame( $ret1->password
, $ret2->password
);
46 $policy['policies']['default']['MinimalPasswordLength'] = 15;
47 $this->setMwGlobals( 'wgPasswordPolicy', $policy );
48 $ret = TemporaryPasswordAuthenticationRequest
::newRandom();
49 $this->assertEquals( 15, strlen( $ret->password
) );
51 $policy['policies']['default']['MinimalPasswordLength'] = [ 'value' => 20 ];
52 $this->setMwGlobals( 'wgPasswordPolicy', $policy );
53 $ret = TemporaryPasswordAuthenticationRequest
::newRandom();
54 $this->assertEquals( 20, strlen( $ret->password
) );
57 public function testNewInvalid() {
58 $ret = TemporaryPasswordAuthenticationRequest
::newInvalid();
59 $this->assertNull( $ret->password
);
62 public function provideLoadFromSubmission() {
65 [ AuthManager
::ACTION_REMOVE
],
69 'Create, empty request' => [
70 [ AuthManager
::ACTION_CREATE
],
74 'Create, mailpassword set' => [
75 [ AuthManager
::ACTION_CREATE
],
76 [ 'mailpassword' => 1 ],
77 [ 'mailpassword' => true, 'action' => AuthManager
::ACTION_CREATE
],
82 public function testDescribeCredentials() {
83 $req = new TemporaryPasswordAuthenticationRequest
;
84 $req->action
= AuthManager
::ACTION_LOGIN
;
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() );