MediaWiki  REL1_31
PasswordTestCase.php
Go to the documentation of this file.
1 <?php
26 abstract class PasswordTestCase extends MediaWikiTestCase {
30  protected $passwordFactory;
31 
32  protected function setUp() {
33  parent::setUp();
34 
35  $this->passwordFactory = new PasswordFactory();
36  foreach ( $this->getTypeConfigs() as $type => $config ) {
37  $this->passwordFactory->register( $type, $config );
38  }
39  }
40 
46  abstract protected function getTypeConfigs();
47 
56  public static function providePasswordTests() {
57  throw new MWException( "Not implemented" );
58  }
59 
63  public function testHashing( $shouldMatch, $hash, $password ) {
64  $hash = $this->passwordFactory->newFromCiphertext( $hash );
65  $password = $this->passwordFactory->newFromPlaintext( $password, $hash );
66  $this->assertSame( $shouldMatch, $hash->equals( $password ) );
67  }
68 
72  public function testStringSerialization( $shouldMatch, $hash, $password ) {
73  $hashObj = $this->passwordFactory->newFromCiphertext( $hash );
74  $serialized = $hashObj->toString();
75  $unserialized = $this->passwordFactory->newFromCiphertext( $serialized );
76  $this->assertTrue( $hashObj->equals( $unserialized ) );
77  }
78 
83  public function testInvalidUnequalNormal( $shouldMatch, $hash, $password ) {
84  $invalid = $this->passwordFactory->newFromCiphertext( null );
85  $normal = $this->passwordFactory->newFromCiphertext( $hash );
86 
87  $this->assertFalse( $invalid->equals( $normal ) );
88  $this->assertFalse( $normal->equals( $invalid ) );
89  }
90 
91  protected function getValidTypes() {
92  return array_keys( $this->getTypeConfigs() );
93  }
94 
95  public function provideTypes( $type ) {
96  $params = [];
97  foreach ( $this->getValidTypes() as $type ) {
98  $params[] = [ $type ];
99  }
100  return $params;
101  }
102 
106  public function testCrypt( $type ) {
107  $fromType = $this->passwordFactory->newFromType( $type );
108  $fromType->crypt( 'password' );
109  $fromPlaintext = $this->passwordFactory->newFromPlaintext( 'password', $fromType );
110  $this->assertTrue( $fromType->equals( $fromPlaintext ) );
111  }
112 }
PasswordTestCase\testCrypt
testCrypt( $type)
provideTypes
Definition: PasswordTestCase.php:106
PasswordTestCase\testStringSerialization
testStringSerialization( $shouldMatch, $hash, $password)
providePasswordTests
Definition: PasswordTestCase.php:72
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:81
PasswordTestCase
Definition: PasswordTestCase.php:26
$params
$params
Definition: styleTest.css.php:40
PasswordTestCase\provideTypes
provideTypes( $type)
Definition: PasswordTestCase.php:95
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:37
PasswordTestCase\$passwordFactory
PasswordFactory $passwordFactory
Definition: PasswordTestCase.php:30
MWException
MediaWiki exception.
Definition: MWException.php:26
PasswordTestCase\testHashing
testHashing( $shouldMatch, $hash, $password)
providePasswordTests
Definition: PasswordTestCase.php:63
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
PasswordTestCase\providePasswordTests
static providePasswordTests()
An array of tests in the form of (bool, string, string), where the first element is whether the secon...
Definition: PasswordTestCase.php:56
PasswordTestCase\setUp
setUp()
Definition: PasswordTestCase.php:32
PasswordTestCase\getTypeConfigs
getTypeConfigs()
Return an array of configs to be used for this class's password type.
PasswordTestCase\getValidTypes
getValidTypes()
Definition: PasswordTestCase.php:91
PasswordTestCase\testInvalidUnequalNormal
testInvalidUnequalNormal( $shouldMatch, $hash, $password)
providePasswordTests InvalidPassword
Definition: PasswordTestCase.php:83
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:22
PasswordFactory
Factory class for creating and checking Password objects.
Definition: PasswordFactory.php:28
$type
$type
Definition: testCompression.php:48