MediaWiki REL1_33
PasswordTestCase.php
Go to the documentation of this file.
1<?php
26abstract class PasswordTestCase extends MediaWikiTestCase {
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
55 public static function providePasswordTests() {
56 throw new MWException( "Not implemented" );
57 }
58
62 public function testHashing( $shouldMatch, $hash, $password ) {
63 $passwordObj = $this->passwordFactory->newFromCiphertext( $hash );
64 $this->assertSame( $shouldMatch, $passwordObj->verify( $password ) );
65 }
66
70 public function testStringSerialization( $shouldMatch, $hash, $password ) {
71 $hashObj = $this->passwordFactory->newFromCiphertext( $hash );
72 $serialized = $hashObj->toString();
73 $unserialized = $this->passwordFactory->newFromCiphertext( $serialized );
74 $this->assertEquals( $hashObj->toString(), $unserialized->toString() );
75 }
76
81 public function testInvalidUnequalNormal( $shouldMatch, $hash, $password ) {
82 $invalid = $this->passwordFactory->newFromCiphertext( null );
83 $normal = $this->passwordFactory->newFromCiphertext( $hash );
84
85 $this->assertFalse( $invalid->equals( $normal ) );
86 $this->assertFalse( $normal->equals( $invalid ) );
87 $this->assertFalse( $invalid->verify( $hash ) );
88 }
89
90 protected function getValidTypes() {
91 return array_keys( $this->getTypeConfigs() );
92 }
93
94 public function provideTypes( $type ) {
95 $params = [];
96 foreach ( $this->getValidTypes() as $type ) {
97 $params[] = [ $type ];
98 }
99 return $params;
100 }
101
105 public function testCrypt( $type ) {
106 $fromType = $this->passwordFactory->newFromType( $type );
107 $fromType->crypt( 'password' );
108 $fromPlaintext = $this->passwordFactory->newFromPlaintext( 'password', $fromType );
109 $this->assertTrue( $fromType->verify( 'password' ) );
110 $this->assertTrue( $fromPlaintext->verify( 'password' ) );
111 $this->assertFalse( $fromType->verify( 'different password' ) );
112 $this->assertFalse( $fromPlaintext->verify( 'different password' ) );
113 $this->assertEquals( get_class( $fromType ),
114 get_class( $fromPlaintext ),
115 'newFromPlaintext() should produce instance of the same class as newFromType()'
116 );
117 }
118}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
MediaWiki exception.
Factory class for creating and checking Password objects.
PasswordFactory $passwordFactory
getTypeConfigs()
Return an array of configs to be used for this class's password type.
testHashing( $shouldMatch, $hash, $password)
providePasswordTests
static providePasswordTests()
An array of tests in the form of (bool, string, string), where the first element is whether the secon...
testInvalidUnequalNormal( $shouldMatch, $hash, $password)
providePasswordTests InvalidPassword
testCrypt( $type)
provideTypes
testStringSerialization( $shouldMatch, $hash, $password)
providePasswordTests
$params
foreach( $res as $row) $serialized