Skip to content

Commit

Permalink
EZP-30822: Fixed wrong usage of hasAccess in URLAliasService (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikadamczyk authored and lserwatka committed Aug 9, 2019
1 parent 886e6c2 commit 144757e
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 590 deletions.
Expand Up @@ -8,13 +8,14 @@
*/
namespace eZ\Publish\API\Repository\Tests;

use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;

class URLAliasServiceAuthorizationTest extends BaseTest
{
/**
* Test for the createUrlAlias() method.
*
* @covers \eZ\Publish\API\Repository\URLAliasService::createUrlAlias()
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @depends \eZ\Publish\API\Repository\Tests\URLAliasServiceTest::testCreateUrlAlias
*/
public function testCreateUrlAliasThrowsUnauthorizedException()
Expand All @@ -31,12 +32,13 @@ public function testCreateUrlAliasThrowsUnauthorizedException()
$urlAliasService = $repository->getURLAliasService();
$locationService = $repository->getLocationService();

$location = $locationService->newLocationCreateStruct($parentLocationId);
$content = $this->createFolder(['eng-GB' => 'Foo'], $parentLocationId);
$location = $locationService->loadLocation($content->contentInfo->mainLocationId);

$anonymousUser = $userService->loadUser($anonymousUserId);
$repository->getPermissionResolver()->setCurrentUserReference($anonymousUser);

// This call will fail with an UnauthorizedException
$this->expectException(UnauthorizedException::class);
$urlAliasService->createUrlAlias($location, '/Home/My-New-Site', 'eng-US');
/* END: Use Case */
}
Expand Down
81 changes: 30 additions & 51 deletions eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php
Expand Up @@ -87,7 +87,7 @@ public function testCreateUrlAlias()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -144,7 +144,7 @@ public function testCreateUrlAliasWithForwarding()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -200,7 +200,7 @@ public function testCreateUrlAliasWithAlwaysAvailable()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -279,7 +279,7 @@ public function testCreateGlobalUrlAlias()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -331,7 +331,7 @@ public function testCreateGlobalUrlAliasWithForward()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -384,7 +384,7 @@ public function testCreateGlobalUrlAliasWithAlwaysAvailable()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -443,7 +443,7 @@ public function testCreateGlobalUrlAliasForLocation()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -478,7 +478,7 @@ public function testCreateGlobalUrlAliasForLocationVariation()
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$createdUrlAlias
);

Expand Down Expand Up @@ -569,13 +569,10 @@ public function testListLocationAliases()
$loadedAliases = $urlAliasService->listLocationAliases($location);
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertIsArray($loadedAliases);

// Only 1 non-history alias
$this->assertEquals(1, count($loadedAliases));
$this->assertCount(1, $loadedAliases);

return [$loadedAliases, $location];
}
Expand All @@ -591,7 +588,7 @@ public function testListLocationAliasesLoadsCorrectly(array $testData)

foreach ($loadedAliases as $loadedAlias) {
$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$loadedAlias
);
$this->assertEquals(
Expand Down Expand Up @@ -626,11 +623,8 @@ public function testListLocationAliasesWithCustomFilter()
$loadedAliases = $urlAliasService->listLocationAliases($location, false, 'eng-US');
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(1, count($loadedAliases));
$this->assertIsArray($loadedAliases);
$this->assertCount(1, $loadedAliases);
}

/**
Expand All @@ -657,11 +651,8 @@ public function testListLocationAliasesWithLanguageCodeFilter()
$loadedAliases = $urlAliasService->listLocationAliases($location, true, 'eng-US');
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(1, count($loadedAliases));
$this->assertIsArray($loadedAliases);
$this->assertCount(1, $loadedAliases);
}

/**
Expand All @@ -683,11 +674,8 @@ public function testListGlobalAliases()
$loadedAliases = $urlAliasService->listGlobalAliases();
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(3, count($loadedAliases));
$this->assertIsArray($loadedAliases);
$this->assertCount(3, $loadedAliases);
}

/**
Expand Down Expand Up @@ -736,11 +724,8 @@ public function testListGlobalAliasesWithLanguageFilter()
$loadedAliases = $urlAliasService->listGlobalAliases('eng-US');
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(2, count($loadedAliases));
$this->assertIsArray($loadedAliases);
$this->assertCount(2, $loadedAliases);
}

/**
Expand All @@ -762,11 +747,8 @@ public function testListGlobalAliasesWithOffset()
$loadedAliases = $urlAliasService->listGlobalAliases(null, 1);
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(2, count($loadedAliases));
$this->assertIsArray($loadedAliases);
$this->assertCount(2, $loadedAliases);
}

/**
Expand All @@ -788,11 +770,8 @@ public function testListGlobalAliasesWithLimit()
$loadedAliases = $urlAliasService->listGlobalAliases(null, 0, 1);
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedAliases
);
$this->assertEquals(1, count($loadedAliases));
$this->assertIsArray($loadedAliases);
$this->assertCount(1, $loadedAliases);
}

/**
Expand Down Expand Up @@ -876,11 +855,11 @@ public function testLookUp()
/* BEGIN: Use Case */
$urlAliasService = $repository->getURLAliasService();

$loadedAlias = $urlAliasService->lookUp('/Setup2');
$loadedAlias = $urlAliasService->lookup('/Setup2');
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$loadedAlias
);

Expand All @@ -902,11 +881,11 @@ public function testLookUpWithLanguageFilter()
// Create aliases in multiple languages
$this->createGlobalAliases();

$loadedAlias = $urlAliasService->lookUp('/My/Special-Support', 'eng-US');
$loadedAlias = $urlAliasService->lookup('/My/Special-Support', 'eng-US');
/* END: Use Case */

$this->assertInstanceOf(
'eZ\\Publish\\API\\Repository\\Values\\Content\\URLAlias',
URLAlias::class,
$loadedAlias
);
$this->assertEquals(
Expand All @@ -929,7 +908,7 @@ public function testLookUpThrowsNotFoundException()
$urlAliasService = $repository->getURLAliasService();

// Throws NotFoundException
$loadedAlias = $urlAliasService->lookUp('/non-existent-url');
$urlAliasService->lookup('/non-existent-url');
/* END: Use Case */
}

Expand All @@ -947,7 +926,7 @@ public function testLookUpThrowsNotFoundExceptionWithLanguageFilter()
$urlAliasService = $repository->getURLAliasService();

// Throws NotFoundException
$loadedAlias = $urlAliasService->lookUp('/Contact-Us', 'ger-DE');
$urlAliasService->lookup('/Contact-Us', 'ger-DE');
/* END: Use Case */
}

Expand All @@ -965,7 +944,7 @@ public function testLookUpThrowsInvalidArgumentException()
$urlAliasService = $repository->getURLAliasService();

// Throws InvalidArgumentException
$loadedAlias = $urlAliasService->lookUp(str_repeat('/1', 99), 'ger-DE');
$loadedAlias = $urlAliasService->lookup(str_repeat('/1', 99), 'ger-DE');
/* END: Use Case */
}

Expand Down
1 change: 1 addition & 0 deletions eZ/Publish/Core/Repository/Repository.php
Expand Up @@ -626,6 +626,7 @@ public function getURLAliasService()
$this,
$this->persistenceHandler->urlAliasHandler(),
$this->getNameSchemaService(),
$this->getPermissionResolver(),
$this->serviceSettings['urlAlias']
);

Expand Down

0 comments on commit 144757e

Please sign in to comment.