Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '7.0'
  • Loading branch information
andrerom committed Mar 16, 2018
2 parents 34b52f8 + a0cb8da commit b7bf66e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions Repository/Tests/ContentServiceAuthorizationTest.php
Expand Up @@ -1577,6 +1577,7 @@ public function testCopyContentToAuthorizedLocation()
);
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'read'));
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'versionread'));
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'manage_locations'));

$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'create');
$policyCreateStruct->addLimitation($locationLimitation);
Expand Down
59 changes: 59 additions & 0 deletions Repository/Tests/LocationServiceAuthorizationTest.php
Expand Up @@ -10,6 +10,7 @@

use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\User\Limitation\OwnerLimitation;
use eZ\Publish\API\Repository\Values\User\Limitation\SubtreeLimitation;

/**
* Test case for operations in the LocationService using in memory storage.
Expand Down Expand Up @@ -61,6 +62,64 @@ public function testCreateLocationThrowsUnauthorizedException()
/* END: Use Case */
}

/**
* Test for the createLocation() method. Tests a case when user doesn't have content/manage_locations policy for the new location ID.
*
* @see \eZ\Publish\API\Repository\LocationService::createLocation()
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
*/
public function testCreateLocationThrowsUnauthorizedExceptionDueToLackOfContentManageLocationsPolicy()
{
$repository = $this->getRepository();

$mediaDirectoryLocationId = $this->generateId('location', '43');

/* BEGIN: Use Case */
$locationService = $repository->getLocationService();
// Location for "Media" directory
$contentLocation = $locationService->loadLocation($mediaDirectoryLocationId);

// Create the new "Dummy" user group
$userService = $repository->getUserService();
$userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB');
$userGroupCreateStruct->setField('name', 'Dummy');
$dummyUserGroup = $userService->createUserGroup($userGroupCreateStruct, $userService->loadUserGroup(4));

// Create the new "Dummy" role with content/* policy limited by Subtree to "Media" folder
$roleService = $repository->getRoleService();
$role = $this->createRoleWithPolicies('Dummy', [
[
'module' => 'content',
'function' => 'read',
'limitations' => [],
],
[
'module' => 'content',
'function' => 'manage_locations',
'limitations' => [new SubtreeLimitation(['limitationValues' => [$contentLocation->pathString]])],
],
]);

$user = $this->createUser('johndoe', 'John', 'Doe', $dummyUserGroup);
$roleService->assignRoleToUser($role, $user);
// Set current user to newly created user
$repository->setCurrentUser($user);

$locationCreateStruct = $locationService->newLocationCreateStruct('2');
$locationCreateStruct->priority = 12;
$locationCreateStruct->hidden = false;
$locationCreateStruct->sortField = Location::SORT_FIELD_NODE_ID;
$locationCreateStruct->sortOrder = Location::SORT_ORDER_DESC;

// This call will fail with an "UnauthorizedException"
$locationService->createLocation(
$contentLocation->contentInfo,
$locationCreateStruct
);
/* END: Use Case */
}

/**
* Test for the loadLocation() method.
*
Expand Down

0 comments on commit b7bf66e

Please sign in to comment.