ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMd5PasswordEncoderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\Attributes\Depends;
22
24{
26 {
27 $encoder = new ilMd5PasswordEncoder();
28 $this->assertInstanceOf(ilMd5PasswordEncoder::class, $encoder);
29 return $encoder;
30 }
31
32 #[Depends('testInstanceCanBeCreated')]
34 {
35 $this->assertSame(md5('password'), $encoder->encodePassword('password', ''));
36 }
37
38 #[Depends('testInstanceCanBeCreated')]
39 public function testPasswordCanBeVerified(ilMd5PasswordEncoder $encoder): void
40 {
41 $this->assertTrue($encoder->isPasswordValid(md5('password'), 'password', ''));
42 }
43
44 #[Depends('testInstanceCanBeCreated')]
46 {
47 $this->assertFalse($encoder->requiresSalt());
48 }
49
50 #[Depends('testInstanceCanBeCreated')]
52 {
53 $this->assertFalse($encoder->requiresReencoding('hello'));
54 }
55
56 #[Depends('testInstanceCanBeCreated')]
59 ): void {
60 $this->expectException(ilPasswordException::class);
61 $encoder->encodePassword(str_repeat('a', 5000), '');
62 }
63
64 #[Depends('testInstanceCanBeCreated')]
67 ): void {
68 $this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), ''));
69 }
70
71 #[Depends('testInstanceCanBeCreated')]
72 public function testNameShouldBeMd5(ilMd5PasswordEncoder $encoder): void
73 {
74 $this->assertSame('md5', $encoder->getName());
75 }
76}
requiresSalt()
Returns whether the encoder requires a salt.
requiresReencoding(string $encoded)
Returns whether the encoded password needs to be re-encoded.
testEncoderDoesNotSupportReencoding(ilMd5PasswordEncoder $encoder)
testPasswordCanBeVerified(ilMd5PasswordEncoder $encoder)
testExceptionIsRaisedIfThePasswordExceedsTheSupportedLengthOnEncoding(ilMd5PasswordEncoder $encoder)
testNameShouldBeMd5(ilMd5PasswordEncoder $encoder)
testPasswordShouldBeCorrectlyEncoded(ilMd5PasswordEncoder $encoder)
testPasswordVerificationShouldFailIfTheRawPasswordExceedsTheSupportedLength(ilMd5PasswordEncoder $encoder)
testEncoderDoesNotRelyOnSalts(ilMd5PasswordEncoder $encoder)
encodePassword(string $raw, string $salt)
Encodes the raw password.
getName()
Returns a unique name/id of the concrete password encoder.
isPasswordValid(string $encoded, string $raw, string $salt)
Checks a raw password against an encoded password.
Class for user password exception handling in ILIAS.