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 $this->stashMwGlobals( 'wgPasswordPolicy' );
29 $wgPasswordPolicy['policies']['default'] +
= [
30 'MinimalPasswordLength' => 1,
31 'MinimalPasswordLengthToLogin' => 1,
34 $ret1 = TemporaryPasswordAuthenticationRequest
::newRandom();
35 $ret2 = TemporaryPasswordAuthenticationRequest
::newRandom();
36 $this->assertNotSame( '', $ret1->password
);
37 $this->assertNotSame( '', $ret2->password
);
38 $this->assertNotSame( $ret1->password
, $ret2->password
);
41 public function testNewInvalid() {
42 $ret = TemporaryPasswordAuthenticationRequest
::newInvalid();
43 $this->assertNull( $ret->password
);
46 public function provideLoadFromSubmission() {
49 [ AuthManager
::ACTION_REMOVE
],
53 'Create, empty request' => [
54 [ AuthManager
::ACTION_CREATE
],
58 'Create, mailpassword set' => [
59 [ AuthManager
::ACTION_CREATE
],
60 [ 'mailpassword' => 1 ],
61 [ 'mailpassword' => true, 'action' => AuthManager
::ACTION_CREATE
],
66 public function testDescribeCredentials() {
67 $req = new TemporaryPasswordAuthenticationRequest
;
68 $req->action
= AuthManager
::ACTION_LOGIN
;
69 $req->username
= 'UTSysop';
70 $ret = $req->describeCredentials();
71 $this->assertInternalType( 'array', $ret );
72 $this->assertArrayHasKey( 'provider', $ret );
73 $this->assertInstanceOf( 'Message', $ret['provider'] );
74 $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() );
75 $this->assertArrayHasKey( 'account', $ret );
76 $this->assertInstanceOf( 'Message', $ret['account'] );
77 $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );