2014-05-13 00:02:25 +02:00
|
|
|
<?php
|
|
|
|
class EditUserPasswordJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testEditing()
|
|
|
|
{
|
|
|
|
$this->testValidPassword('flintstone');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testVeryLongPassword()
|
|
|
|
{
|
|
|
|
$this->testValidPassword(str_repeat('flintstone', 100));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTooShortPassword()
|
|
|
|
{
|
2014-05-17 15:00:30 +02:00
|
|
|
$this->grantAccess('editUserPassword');
|
2014-05-13 21:08:07 +02:00
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
|
2014-05-15 10:32:53 +02:00
|
|
|
$newPassword = str_repeat('a', Core::getConfig()->registration->passMinLength - 1);
|
2014-05-13 00:02:25 +02:00
|
|
|
$oldPasswordHash = $user->getPasswordHash();
|
|
|
|
|
|
|
|
$this->assert->throws(function() use ($user, $newPassword)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditUserPasswordJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
|
|
|
JobArgs::ARG_NEW_PASSWORD => $newPassword,
|
|
|
|
]);
|
|
|
|
}, 'Password must have at least');
|
|
|
|
|
|
|
|
$this->assert->areEqual($oldPasswordHash, $user->getPasswordHash());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function testValidPassword($newPassword)
|
|
|
|
{
|
2014-05-17 15:00:30 +02:00
|
|
|
$this->grantAccess('editUserPassword');
|
2014-05-13 21:08:07 +02:00
|
|
|
$user = $this->userMocker->mockSingle();
|
2014-05-13 00:02:25 +02:00
|
|
|
|
|
|
|
$newPasswordHash = UserModel::hashPassword($newPassword, $user->getPasswordSalt());
|
|
|
|
|
|
|
|
$user = $this->assert->doesNotThrow(function() use ($user, $newPassword)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditUserPasswordJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_USER_NAME => $user->getName(),
|
|
|
|
JobArgs::ARG_NEW_PASSWORD => $newPassword,
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual($newPasswordHash, $user->getPasswordHash());
|
|
|
|
|
2014-05-15 10:32:53 +02:00
|
|
|
Core::getConfig()->registration->needEmailForRegistering = false;
|
2014-05-13 00:02:25 +02:00
|
|
|
$this->assert->doesNotThrow(function() use ($user, $newPassword)
|
|
|
|
{
|
|
|
|
Auth::login($user->getName(), $newPassword, false);
|
|
|
|
});
|
|
|
|
$this->assert->isTrue(Auth::isLoggedIn());
|
|
|
|
}
|
|
|
|
}
|