MediaWiki REL1_30
EncryptedPasswordTest.php
Go to the documentation of this file.
1<?php
2
10 protected function getTypeConfigs() {
11 return [
12 'both' => [
13 'class' => 'EncryptedPassword',
14 'underlying' => 'pbkdf2',
15 'secrets' => [
16 md5( 'secret1' ),
17 md5( 'secret2' ),
18 ],
19 'cipher' => 'aes-256-cbc',
20 ],
21 'secret1' => [
22 'class' => 'EncryptedPassword',
23 'underlying' => 'pbkdf2',
24 'secrets' => [
25 md5( 'secret1' ),
26 ],
27 'cipher' => 'aes-256-cbc',
28 ],
29 'secret2' => [
30 'class' => 'EncryptedPassword',
31 'underlying' => 'pbkdf2',
32 'secrets' => [
33 md5( 'secret2' ),
34 ],
35 'cipher' => 'aes-256-cbc',
36 ],
37 'pbkdf2' => [
38 'class' => 'Pbkdf2Password',
39 'algo' => 'sha256',
40 'cost' => '10',
41 'length' => '64',
42 ],
43 ];
44 }
45
46 public static function providePasswordTests() {
47 return [
48 // Encrypted with secret1
49 [ true, ':both:aes-256-cbc:0:izBpxujqC1YbzpCB3qAzgg==:ZqHnitT1pL4YJqKqFES2KEevZYSy2LtlibW5+IMi4XKOGKGy6sE638BXyBbLQQsBtTSrt+JyzwOayKtwIfRbaQsBridx/O1JwBSai1TkGkOsYMBXnlu2Bu/EquCBj5QpjYh7p3Uq4rpiop1KQlin1BJMwnAa1PovhxjpxnYhlhkM4X5ALoGi3XM0bapN48vt', 'password' ],
50 [ true, ':secret1:aes-256-cbc:0:izBpxujqC1YbzpCB3qAzgg==:ZqHnitT1pL4YJqKqFES2KEevZYSy2LtlibW5+IMi4XKOGKGy6sE638BXyBbLQQsBtTSrt+JyzwOayKtwIfRbaQsBridx/O1JwBSai1TkGkOsYMBXnlu2Bu/EquCBj5QpjYh7p3Uq4rpiop1KQlin1BJMwnAa1PovhxjpxnYhlhkM4X5ALoGi3XM0bapN48vt', 'password' ],
51 [ false, ':secret1:aes-256-cbc:0:izBpxujqC1YbzpCB3qAzgg==:ZqHnitT1pL4YJqKqFES2KEevZYSy2LtlibW5+IMi4XKOGKGy6sE638BXyBbLQQsBtTSrt+JyzwOayKtwIfRbaQsBridx/O1JwBSai1TkGkOsYMBXnlu2Bu/EquCBj5QpjYh7p3Uq4rpiop1KQlin1BJMwnAa1PovhxjpxnYhlhkM4X5ALoGi3XM0bapN48vt', 'notpassword' ],
52
53 // Encrypted with secret2
54 [ true, ':both:aes-256-cbc:1:m1LCnQVIakfYBNlr9KEgQg==:5yPTctqrzsybdgaMEag18AZYbnL37pAtXVBqmWxkjXbnNmiDH+1bHoL8lsEVTH/sJntC82kNVgE7zeiD8xUVLYF2VUnvB5+sU+aysE45/zwsCu7a22TaischMAOWrsHZ/tIgS/TnZY2d+HNyxgsEeeYf/QoL+FhmqHquK02+4SRbA5lLuj9niYy1r5CoM9cQ', 'password' ],
55 [ true, ':secret2:aes-256-cbc:0:m1LCnQVIakfYBNlr9KEgQg==:5yPTctqrzsybdgaMEag18AZYbnL37pAtXVBqmWxkjXbnNmiDH+1bHoL8lsEVTH/sJntC82kNVgE7zeiD8xUVLYF2VUnvB5+sU+aysE45/zwsCu7a22TaischMAOWrsHZ/tIgS/TnZY2d+HNyxgsEeeYf/QoL+FhmqHquK02+4SRbA5lLuj9niYy1r5CoM9cQ', 'password' ],
56 ];
57 }
58
63 public function testDecryptionError() {
64 $hash = ':secret1:aes-256-cbc:0:m1LCnQVIakfYBNlr9KEgQg==:5yPTctqrzsybdgaMEag18AZYbnL37pAtXVBqmWxkjXbnNmiDH+1bHoL8lsEVTH/sJntC82kNVgE7zeiD8xUVLYF2VUnvB5+sU+aysE45/zwsCu7a22TaischMAOWrsHZ/tIgS/TnZY2d+HNyxgsEeeYf/QoL+FhmqHquK02+4SRbA5lLuj9niYy1r5CoM9cQ';
65 $password = $this->passwordFactory->newFromCiphertext( $hash );
66 $password->crypt( 'password' );
67 }
68
69 public function testUpdate() {
70 $hash = ':both:aes-256-cbc:0:izBpxujqC1YbzpCB3qAzgg==:ZqHnitT1pL4YJqKqFES2KEevZYSy2LtlibW5+IMi4XKOGKGy6sE638BXyBbLQQsBtTSrt+JyzwOayKtwIfRbaQsBridx/O1JwBSai1TkGkOsYMBXnlu2Bu/EquCBj5QpjYh7p3Uq4rpiop1KQlin1BJMwnAa1PovhxjpxnYhlhkM4X5ALoGi3XM0bapN48vt';
71 $fromHash = $this->passwordFactory->newFromCiphertext( $hash );
72 $fromPlaintext = $this->passwordFactory->newFromPlaintext( 'password', $fromHash );
73 $this->assertTrue( $fromHash->update() );
74
75 $serialized = $fromHash->toString();
76 $this->assertRegExp( '/^:both:aes-256-cbc:1:/', $serialized );
77 $fromNewHash = $this->passwordFactory->newFromCiphertext( $serialized );
78 $fromPlaintext = $this->passwordFactory->newFromPlaintext( 'password', $fromNewHash );
79 $this->assertTrue( $fromHash->equals( $fromPlaintext ) );
80 }
81}
EncryptedPassword ParameterizedPassword Password Generic.Files.LineLength.
getTypeConfigs()
Return an array of configs to be used for this class's password type.
testDecryptionError()
Wrong encryption key selected PasswordError.
static providePasswordTests()
An array of tests in the form of (bool, string, string), where the first element is whether the secon...
foreach( $res as $row) $serialized