MediaWiki  1.30.2
PasswordAuthenticationRequestTest.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 [
23  ];
24  }
25 
26  public function testGetFieldInfo2() {
27  $info = [];
28  foreach ( [
33  ] as $action ) {
35  $req->action = $action;
36  $info[$action] = $req->getFieldInfo();
37  }
38 
39  $this->assertSame( [], $info[AuthManager::ACTION_REMOVE], 'No data needed to remove' );
40 
41  $this->assertArrayNotHasKey( 'retype', $info[AuthManager::ACTION_LOGIN],
42  'No need to retype password on login' );
43  $this->assertArrayHasKey( 'retype', $info[AuthManager::ACTION_CREATE],
44  'Need to retype when creating new password' );
45  $this->assertArrayHasKey( 'retype', $info[AuthManager::ACTION_CHANGE],
46  'Need to retype when changing password' );
47 
48  $this->assertNotEquals(
49  $info[AuthManager::ACTION_LOGIN]['password']['label'],
50  $info[AuthManager::ACTION_CHANGE]['password']['label'],
51  'Password field for change is differentiated from login'
52  );
53  $this->assertNotEquals(
54  $info[AuthManager::ACTION_CREATE]['password']['label'],
55  $info[AuthManager::ACTION_CHANGE]['password']['label'],
56  'Password field for change is differentiated from create'
57  );
58  $this->assertNotEquals(
59  $info[AuthManager::ACTION_CREATE]['retype']['label'],
60  $info[AuthManager::ACTION_CHANGE]['retype']['label'],
61  'Retype field for change is differentiated from create'
62  );
63  }
64 
65  public function provideLoadFromSubmission() {
66  return [
67  'Empty request, login' => [
69  [],
70  false,
71  ],
72  'Empty request, change' => [
74  [],
75  false,
76  ],
77  'Empty request, remove' => [
79  [],
80  false,
81  ],
82  'Username + password, login' => [
84  $data = [ 'username' => 'User', 'password' => 'Bar' ],
85  $data + [ 'action' => AuthManager::ACTION_LOGIN ],
86  ],
87  'Username + password, change' => [
89  [ 'username' => 'User', 'password' => 'Bar' ],
90  false,
91  ],
92  'Username + password + retype' => [
94  [ 'username' => 'User', 'password' => 'Bar', 'retype' => 'baz' ],
95  [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager::ACTION_CHANGE ],
96  ],
97  'Username empty, login' => [
99  [ 'username' => '', 'password' => 'Bar' ],
100  false,
101  ],
102  'Username empty, change' => [
104  [ 'username' => '', 'password' => 'Bar', 'retype' => 'baz' ],
105  [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager::ACTION_CHANGE ],
106  ],
107  'Password empty, login' => [
109  [ 'username' => 'User', 'password' => '' ],
110  false,
111  ],
112  'Password empty, login, with retype' => [
114  [ 'username' => 'User', 'password' => '', 'retype' => 'baz' ],
115  false,
116  ],
117  'Retype empty' => [
119  [ 'username' => 'User', 'password' => 'Bar', 'retype' => '' ],
120  false,
121  ],
122  ];
123  }
124 
125  public function testDescribeCredentials() {
128  $req->username = 'UTSysop';
129  $ret = $req->describeCredentials();
130  $this->assertInternalType( 'array', $ret );
131  $this->assertArrayHasKey( 'provider', $ret );
132  $this->assertInstanceOf( 'Message', $ret['provider'] );
133  $this->assertSame( 'authmanager-provider-password', $ret['provider']->getKey() );
134  $this->assertArrayHasKey( 'account', $ret );
135  $this->assertInstanceOf( 'Message', $ret['account'] );
136  $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );
137  }
138 }
MediaWiki\$action
String $action
Cache what action this request is.
Definition: MediaWiki.php:47
$req
this hook is for auditing only $req
Definition: hooks.txt:988
MediaWiki\Auth\PasswordAuthenticationRequestTest\provideGetFieldInfo
static provideGetFieldInfo()
Definition: PasswordAuthenticationRequestTest.php:17
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\PasswordAuthenticationRequest
This is a value object for authentication requests with a username and password.
Definition: PasswordAuthenticationRequest.php:29
MediaWiki\Auth\PasswordAuthenticationRequestTest
AuthManager MediaWiki\Auth\PasswordAuthenticationRequest.
Definition: PasswordAuthenticationRequestTest.php:9
MediaWiki\Auth\PasswordAuthenticationRequestTest\provideLoadFromSubmission
provideLoadFromSubmission()
Definition: PasswordAuthenticationRequestTest.php:65
MediaWiki\Auth\AuthManager\ACTION_CREATE
const ACTION_CREATE
Create a new user.
Definition: AuthManager.php:89
MediaWiki\Auth\AuthManager\ACTION_CHANGE
const ACTION_CHANGE
Change a user's credentials.
Definition: AuthManager.php:99
MediaWiki\Auth\PasswordAuthenticationRequestTest\testDescribeCredentials
testDescribeCredentials()
Definition: PasswordAuthenticationRequestTest.php:125
$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:1965
MediaWiki\Auth\PasswordAuthenticationRequestTest\testGetFieldInfo2
testGetFieldInfo2()
Definition: PasswordAuthenticationRequestTest.php:26
MediaWiki\Auth\AuthManager\ACTION_REMOVE
const ACTION_REMOVE
Remove a user's credentials.
Definition: AuthManager.php:101
$args
if( $line===false) $args
Definition: cdb.php:63
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:84
MediaWiki\Auth\AuthenticationRequestTestCase
AuthManager.
Definition: AuthenticationRequestTestCase.php:8
MediaWiki\Auth\PasswordAuthenticationRequestTest\getInstance
getInstance(array $args=[])
Definition: PasswordAuthenticationRequestTest.php:11
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
array
the array() calling protocol came about after MediaWiki 1.4rc1.