diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php |
first commit
Diffstat (limited to 'www/wiki/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php')
-rw-r--r-- | www/wiki/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php b/www/wiki/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php new file mode 100644 index 00000000..ab4a174e --- /dev/null +++ b/www/wiki/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php @@ -0,0 +1,79 @@ +<?php + +namespace MediaWiki\Auth; + +/** + * @group AuthManager + * @covers MediaWiki\Auth\TemporaryPasswordAuthenticationRequest + */ +class TemporaryPasswordAuthenticationRequestTest extends AuthenticationRequestTestCase { + + protected function getInstance( array $args = [] ) { + $ret = new TemporaryPasswordAuthenticationRequest; + $ret->action = $args[0]; + return $ret; + } + + public static function provideGetFieldInfo() { + return [ + [ [ AuthManager::ACTION_CREATE ] ], + [ [ AuthManager::ACTION_CHANGE ] ], + [ [ AuthManager::ACTION_REMOVE ] ], + ]; + } + + public function testNewRandom() { + global $wgPasswordPolicy; + + $this->stashMwGlobals( 'wgPasswordPolicy' ); + $wgPasswordPolicy['policies']['default'] += [ + 'MinimalPasswordLength' => 1, + 'MinimalPasswordLengthToLogin' => 1, + ]; + + $ret1 = TemporaryPasswordAuthenticationRequest::newRandom(); + $ret2 = TemporaryPasswordAuthenticationRequest::newRandom(); + $this->assertNotSame( '', $ret1->password ); + $this->assertNotSame( '', $ret2->password ); + $this->assertNotSame( $ret1->password, $ret2->password ); + } + + public function testNewInvalid() { + $ret = TemporaryPasswordAuthenticationRequest::newInvalid(); + $this->assertNull( $ret->password ); + } + + public function provideLoadFromSubmission() { + return [ + 'Empty request' => [ + [ AuthManager::ACTION_REMOVE ], + [], + false, + ], + 'Create, empty request' => [ + [ AuthManager::ACTION_CREATE ], + [], + false, + ], + 'Create, mailpassword set' => [ + [ AuthManager::ACTION_CREATE ], + [ 'mailpassword' => 1 ], + [ 'mailpassword' => true, 'action' => AuthManager::ACTION_CREATE ], + ], + ]; + } + + public function testDescribeCredentials() { + $req = new TemporaryPasswordAuthenticationRequest; + $req->action = AuthManager::ACTION_LOGIN; + $req->username = 'UTSysop'; + $ret = $req->describeCredentials(); + $this->assertInternalType( 'array', $ret ); + $this->assertArrayHasKey( 'provider', $ret ); + $this->assertInstanceOf( \Message::class, $ret['provider'] ); + $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() ); + $this->assertArrayHasKey( 'account', $ret ); + $this->assertInstanceOf( \Message::class, $ret['account'] ); + $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() ); + } +} |