3 namespace MediaWiki\Tests\Auth
;
5 use MediaWiki\Auth\AuthManager
;
6 use MediaWiki\Auth\PasswordDomainAuthenticationRequest
;
7 use MediaWiki\Message\Message
;
11 * @covers \MediaWiki\Auth\PasswordDomainAuthenticationRequest
13 class PasswordDomainAuthenticationRequestTest
extends AuthenticationRequestTestCase
{
15 protected function getInstance( array $args = [] ) {
16 $ret = new PasswordDomainAuthenticationRequest( [ 'd1', 'd2' ] );
17 $ret->action
= $args[0];
21 public static function provideGetFieldInfo() {
23 [ [ AuthManager
::ACTION_LOGIN
] ],
24 [ [ AuthManager
::ACTION_CREATE
] ],
25 [ [ AuthManager
::ACTION_CHANGE
] ],
26 [ [ AuthManager
::ACTION_REMOVE
] ],
30 public function testGetFieldInfo2() {
33 AuthManager
::ACTION_LOGIN
,
34 AuthManager
::ACTION_CREATE
,
35 AuthManager
::ACTION_CHANGE
,
36 AuthManager
::ACTION_REMOVE
,
38 $req = new PasswordDomainAuthenticationRequest( [ 'd1', 'd2' ] );
39 $req->action
= $action;
40 $info[$action] = $req->getFieldInfo();
43 $this->assertSame( [], $info[AuthManager
::ACTION_REMOVE
], 'No data needed to remove' );
45 $this->assertArrayNotHasKey( 'retype', $info[AuthManager
::ACTION_LOGIN
],
46 'No need to retype password on login' );
47 $this->assertArrayHasKey( 'domain', $info[AuthManager
::ACTION_LOGIN
],
48 'Domain needed on login' );
49 $this->assertArrayHasKey( 'retype', $info[AuthManager
::ACTION_CREATE
],
50 'Need to retype when creating new password' );
51 $this->assertArrayHasKey( 'domain', $info[AuthManager
::ACTION_CREATE
],
52 'Domain needed on account creation' );
53 $this->assertArrayHasKey( 'retype', $info[AuthManager
::ACTION_CHANGE
],
54 'Need to retype when changing password' );
55 $this->assertArrayNotHasKey( 'domain', $info[AuthManager
::ACTION_CHANGE
],
56 'Domain not needed on account creation' );
58 $this->assertNotEquals(
59 $info[AuthManager
::ACTION_LOGIN
]['password']['label'],
60 $info[AuthManager
::ACTION_CHANGE
]['password']['label'],
61 'Password field for change is differentiated from login'
63 $this->assertNotEquals(
64 $info[AuthManager
::ACTION_CREATE
]['password']['label'],
65 $info[AuthManager
::ACTION_CHANGE
]['password']['label'],
66 'Password field for change is differentiated from create'
68 $this->assertNotEquals(
69 $info[AuthManager
::ACTION_CREATE
]['retype']['label'],
70 $info[AuthManager
::ACTION_CHANGE
]['retype']['label'],
71 'Retype field for change is differentiated from create'
75 public static function provideLoadFromSubmission() {
76 $domainList = [ 'domainList' => [ 'd1', 'd2' ] ];
78 'Empty request, login' => [
79 [ AuthManager
::ACTION_LOGIN
],
83 'Empty request, change' => [
84 [ AuthManager
::ACTION_CHANGE
],
88 'Empty request, remove' => [
89 [ AuthManager
::ACTION_REMOVE
],
93 'Username + password, login' => [
94 [ AuthManager
::ACTION_LOGIN
],
95 $data = [ 'username' => 'User', 'password' => 'Bar' ],
98 'Username + password + domain, login' => [
99 [ AuthManager
::ACTION_LOGIN
],
100 $data = [ 'username' => 'User', 'password' => 'Bar', 'domain' => 'd1' ],
101 $data +
[ 'action' => AuthManager
::ACTION_LOGIN
] +
$domainList,
103 'Username + password + bad domain, login' => [
104 [ AuthManager
::ACTION_LOGIN
],
105 $data = [ 'username' => 'User', 'password' => 'Bar', 'domain' => 'd5' ],
108 'Username + password + domain, change' => [
109 [ AuthManager
::ACTION_CHANGE
],
110 [ 'username' => 'User', 'password' => 'Bar', 'domain' => 'd1' ],
113 'Username + password + domain + retype' => [
114 [ AuthManager
::ACTION_CHANGE
],
115 [ 'username' => 'User', 'password' => 'Bar', 'retype' => 'baz', 'domain' => 'd1' ],
116 [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager
::ACTION_CHANGE
] +
119 'Username empty, login' => [
120 [ AuthManager
::ACTION_LOGIN
],
121 [ 'username' => '', 'password' => 'Bar', 'domain' => 'd1' ],
124 'Username empty, change' => [
125 [ AuthManager
::ACTION_CHANGE
],
126 [ 'username' => '', 'password' => 'Bar', 'retype' => 'baz', 'domain' => 'd1' ],
127 [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager
::ACTION_CHANGE
] +
130 'Password empty, login' => [
131 [ AuthManager
::ACTION_LOGIN
],
132 [ 'username' => 'User', 'password' => '', 'domain' => 'd1' ],
135 'Password empty, login, with retype' => [
136 [ AuthManager
::ACTION_LOGIN
],
137 [ 'username' => 'User', 'password' => '', 'retype' => 'baz', 'domain' => 'd1' ],
141 [ AuthManager
::ACTION_CHANGE
],
142 [ 'username' => 'User', 'password' => 'Bar', 'retype' => '', 'domain' => 'd1' ],
148 public function testDescribeCredentials() {
149 $username = 'TestDescribeCredentials';
150 $req = new PasswordDomainAuthenticationRequest( [ 'd1', 'd2' ] );
151 $req->action
= AuthManager
::ACTION_LOGIN
;
152 $req->username
= $username;
154 $ret = $req->describeCredentials();
155 $this->assertIsArray( $ret );
156 $this->assertArrayHasKey( 'provider', $ret );
157 $this->assertInstanceOf( Message
::class, $ret['provider'] );
158 $this->assertSame( 'authmanager-provider-password-domain', $ret['provider']->getKey() );
159 $this->assertArrayHasKey( 'account', $ret );
160 $this->assertInstanceOf( Message
::class, $ret['account'] );
161 $this->assertSame( 'authmanager-account-password-domain', $ret['account']->getKey() );
162 $this->assertSame( [ $username, 'd2' ], $ret['account']->getParams() );