MediaWiki REL1_31
EncryptedPasswordTest.php
Go to the documentation of this file.
1<?php
2
9 protected function getTypeConfigs() {
10 return [
11 'both' => [
12 'class' => EncryptedPassword::class,
13 'underlying' => 'pbkdf2',
14 'secrets' => [
15 md5( 'secret1' ),
16 md5( 'secret2' ),
17 ],
18 'cipher' => 'aes-256-cbc',
19 ],
20 'secret1' => [
21 'class' => EncryptedPassword::class,
22 'underlying' => 'pbkdf2',
23 'secrets' => [
24 md5( 'secret1' ),
25 ],
26 'cipher' => 'aes-256-cbc',
27 ],
28 'secret2' => [
29 'class' => EncryptedPassword::class,
30 'underlying' => 'pbkdf2',
31 'secrets' => [
32 md5( 'secret2' ),
33 ],
34 'cipher' => 'aes-256-cbc',
35 ],
36 'pbkdf2' => [
37 'class' => Pbkdf2Password::class,
38 'algo' => 'sha256',
39 'cost' => '10',
40 'length' => '64',
41 ],
42 ];
43 }
44
45 public static function providePasswordTests() {
46 // phpcs:disable Generic.Files.LineLength
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 // phpcs:enable
58 }
59
64 public function testDecryptionError() {
65 // phpcs:ignore Generic.Files.LineLength
66 $hash = ':secret1:aes-256-cbc:0:m1LCnQVIakfYBNlr9KEgQg==:5yPTctqrzsybdgaMEag18AZYbnL37pAtXVBqmWxkjXbnNmiDH+1bHoL8lsEVTH/sJntC82kNVgE7zeiD8xUVLYF2VUnvB5+sU+aysE45/zwsCu7a22TaischMAOWrsHZ/tIgS/TnZY2d+HNyxgsEeeYf/QoL+FhmqHquK02+4SRbA5lLuj9niYy1r5CoM9cQ';
67 $password = $this->passwordFactory->newFromCiphertext( $hash );
68 $password->crypt( 'password' );
69 }
70
71 public function testUpdate() {
72 // phpcs:ignore Generic.Files.LineLength
73 $hash = ':both:aes-256-cbc:0:izBpxujqC1YbzpCB3qAzgg==:ZqHnitT1pL4YJqKqFES2KEevZYSy2LtlibW5+IMi4XKOGKGy6sE638BXyBbLQQsBtTSrt+JyzwOayKtwIfRbaQsBridx/O1JwBSai1TkGkOsYMBXnlu2Bu/EquCBj5QpjYh7p3Uq4rpiop1KQlin1BJMwnAa1PovhxjpxnYhlhkM4X5ALoGi3XM0bapN48vt';
74 $fromHash = $this->passwordFactory->newFromCiphertext( $hash );
75 $fromPlaintext = $this->passwordFactory->newFromPlaintext( 'password', $fromHash );
76 $this->assertTrue( $fromHash->update() );
77
78 $serialized = $fromHash->toString();
79 $this->assertRegExp( '/^:both:aes-256-cbc:1:/', $serialized );
80 $fromNewHash = $this->passwordFactory->newFromCiphertext( $serialized );
81 $fromPlaintext = $this->passwordFactory->newFromPlaintext( 'password', $fromNewHash );
82 $this->assertTrue( $fromHash->equals( $fromPlaintext ) );
83 }
84}
EncryptedPassword ParameterizedPassword Password.
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