Skip to content

Commit

Permalink
Merge branch '6.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Nov 14, 2017
2 parents b6cd7c1 + ac0be44 commit 5ec4e0d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
77 changes: 76 additions & 1 deletion Repository/Tests/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use eZ\Publish\Core\Repository\Values\Content\VersionInfo;
use eZ\Publish\Core\Repository\Values\User\UserGroup;
use Exception;
use ReflectionClass;

/**
* Test case for operations in the UserService using in memory storage.
Expand Down Expand Up @@ -1573,6 +1574,80 @@ public function testUpdateUser()
return $userVersion2;
}

/**
* Test for the updateUser() method.
*
* @return \eZ\Publish\API\Repository\Values\User\User
*
* @see \eZ\Publish\API\Repository\UserService::updateUser()
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserUpdateStruct
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
*/
public function testUpdateUserNoPassword()
{
$repository = $this->getRepository();
$signalSlotUserService = $repository->getUserService();

$signalSlotUserServiceReflection = new ReflectionClass($signalSlotUserService);
$userServiceProperty = $signalSlotUserServiceReflection->getProperty('service');
$userServiceProperty->setAccessible(true);
$userService = $userServiceProperty->getValue($signalSlotUserService);

$userServiceReflection = new ReflectionClass($userService);
$settingsProperty = $userServiceReflection->getProperty('settings');
$settingsProperty->setAccessible(true);
$settingsProperty->setValue(
$userService,
[
'hashType' => User::PASSWORD_HASH_MD5_USER,
] + $settingsProperty->getValue($userService)
);

/* BEGIN: Use Case */
$user = $this->createUserVersion1();

$settingsProperty->setValue(
$userService,
[
'hashType' => User::PASSWORD_HASH_PHP_DEFAULT,
] + $settingsProperty->getValue($userService)
);

// Create a new update struct instance
$userUpdate = $userService->newUserUpdateStruct();

// Set new values for maxLogin, don't change password
$userUpdate->maxLogin = 43;
$userUpdate->enabled = false;

// Updated the user record.
$userVersion2 = $userService->updateUser($user, $userUpdate);
/* END: Use Case */

$this->assertInstanceOf(User::class, $user);

$this->assertEquals(
[
'login' => $user->login,
'email' => $user->email,
'passwordHash' => $user->passwordHash,
'hashAlgorithm' => $user->hashAlgorithm,
'maxLogin' => 43,
'enabled' => false,
],
[
'login' => $userVersion2->login,
'email' => $userVersion2->email,
'passwordHash' => $userVersion2->passwordHash,
'hashAlgorithm' => $userVersion2->hashAlgorithm,
'maxLogin' => $userVersion2->maxLogin,
'enabled' => $userVersion2->enabled,
]
);
}

/**
* Test for the updateUser() method.
*
Expand Down Expand Up @@ -1607,7 +1682,7 @@ public function testUpdateUserUpdatesExpectedProperties(User $user)
* @see \eZ\Publish\API\Repository\UserService::updateUser()
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser
*/
public function testUpdateUserReturnsPublishedVersion($user)
public function testUpdateUserReturnsPublishedVersion(User $user)
{
$this->assertEquals(
APIVersionInfo::STATUS_PUBLISHED,
Expand Down
30 changes: 30 additions & 0 deletions Repository/Values/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@
*/
abstract class User extends Content implements UserReference
{
/**
* @var int MD5 of password, not recommended
*/
const PASSWORD_HASH_MD5_PASSWORD = 1;

/**
* @var int MD5 of user and password
*/
const PASSWORD_HASH_MD5_USER = 2;

/**
* @var int MD5 of site, user and password
*/
const PASSWORD_HASH_MD5_SITE = 3;

/**
* @var int Passwords in plaintext, should not be used for real sites
*/
const PASSWORD_HASH_PLAINTEXT = 5;

/**
* @var int Passwords in bcrypt
*/
const PASSWORD_HASH_BCRYPT = 6;

/**
* @var int Passwords hashed by PHPs default algorithm, which may change over time
*/
const PASSWORD_HASH_PHP_DEFAULT = 7;

/**
* User login.
*
Expand Down

0 comments on commit 5ec4e0d

Please sign in to comment.