Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Unit/UserTest.php
Show All 34 Lines | public function testSetPasswordLdapAttribute(): void | ||||
$ssh512 = "{SSHA512}7iaw3Ur350mqGo7jwQrpkj9hiYB3Lkc/iBml1JQODbJ" | $ssh512 = "{SSHA512}7iaw3Ur350mqGo7jwQrpkj9hiYB3Lkc/iBml1JQODbJ" | ||||
. "6wYX4oOHV+E+IvIh/1nsUNzLDBMxfqa2Ob1f1ACio/w=="; | . "6wYX4oOHV+E+IvIh/1nsUNzLDBMxfqa2Ob1f1ACio/w=="; | ||||
$this->assertRegExp('/^\$2y\$12\$[0-9a-zA-Z\/.]{53}$/', $user->password); | $this->assertRegExp('/^\$2y\$12\$[0-9a-zA-Z\/.]{53}$/', $user->password); | ||||
$this->assertSame($ssh512, $user->password_ldap); | $this->assertSame($ssh512, $user->password_ldap); | ||||
} | } | ||||
/** | /** | ||||
* Test User password validation | |||||
*/ | |||||
public function testPasswordValidation(): void | |||||
{ | |||||
$user = new User(['email' => 'user@email.com']); | |||||
$user->password = 'test'; | |||||
$this->assertSame(true, $user->validateCredentials('user@email.com', 'test')); | |||||
$this->assertSame(false, $user->validateCredentials('user@email.com', 'wrong')); | |||||
$this->assertSame(true, $user->validateCredentials('User@Email.Com', 'test')); | |||||
$this->assertSame(false, $user->validateCredentials('wrong', 'test')); | |||||
// Ensure the fallback to the ldap_password works if the current password is empty | |||||
$ssh512 = "{SSHA512}7iaw3Ur350mqGo7jwQrpkj9hiYB3Lkc/iBml1JQODbJ" | |||||
. "6wYX4oOHV+E+IvIh/1nsUNzLDBMxfqa2Ob1f1ACio/w=="; | |||||
$ldapUser = new User(['email' => 'user2@email.com']); | |||||
$ldapUser->setRawAttributes(['password' => '', 'password_ldap' => $ssh512, 'email' => 'user2@email.com']); | |||||
$this->assertSame($ldapUser->password, ''); | |||||
$this->assertSame($ldapUser->password_ldap, $ssh512); | |||||
$this->assertSame(true, $ldapUser->validateCredentials('user2@email.com', 'test', false)); | |||||
$ldapUser->delete(); | |||||
} | |||||
/** | |||||
* Test basic User funtionality | * Test basic User funtionality | ||||
*/ | */ | ||||
public function testStatus(): void | public function testStatus(): void | ||||
{ | { | ||||
$statuses = [ | $statuses = [ | ||||
User::STATUS_NEW, | User::STATUS_NEW, | ||||
User::STATUS_ACTIVE, | User::STATUS_ACTIVE, | ||||
User::STATUS_SUSPENDED, | User::STATUS_SUSPENDED, | ||||
Show All 39 Lines |