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 $policy['policies']['default'] +
= [
30 'MinimalPasswordLength' => 1,
31 'MinimalPasswordLengthToLogin' => 1,
34 $this->setMwGlobals( 'wgPasswordPolicy', $policy );
36 $ret1 = TemporaryPasswordAuthenticationRequest
::newRandom();
37 $ret2 = TemporaryPasswordAuthenticationRequest
::newRandom();
38 $this->assertNotSame( '', $ret1->password
);
39 $this->assertNotSame( '', $ret2->password
);
40 $this->assertNotSame( $ret1->password
, $ret2->password
);
43 public function testNewInvalid() {
44 $ret = TemporaryPasswordAuthenticationRequest
::newInvalid();
45 $this->assertNull( $ret->password
);
48 public function provideLoadFromSubmission() {
51 [ AuthManager
::ACTION_REMOVE
],
55 'Create, empty request' => [
56 [ AuthManager
::ACTION_CREATE
],
60 'Create, mailpassword set' => [
61 [ AuthManager
::ACTION_CREATE
],
62 [ 'mailpassword' => 1 ],
63 [ 'mailpassword' => true, 'action' => AuthManager
::ACTION_CREATE
],
68 public function testDescribeCredentials() {
69 $req = new TemporaryPasswordAuthenticationRequest
;
70 $req->action
= AuthManager
::ACTION_LOGIN
;
71 $req->username
= 'UTSysop';
72 $ret = $req->describeCredentials();
73 $this->assertInternalType( 'array', $ret );
74 $this->assertArrayHasKey( 'provider', $ret );
75 $this->assertInstanceOf( \Message
::class, $ret['provider'] );
76 $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() );
77 $this->assertArrayHasKey( 'account', $ret );
78 $this->assertInstanceOf( \Message
::class, $ret['account'] );
79 $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );