Skip to content

Commit 48c19ea

Browse files
committed
Merge branch '4.4'
2 parents 13c1668 + d54ba64 commit 48c19ea

File tree

8 files changed

+228
-98
lines changed

8 files changed

+228
-98
lines changed

phpunit-integration-rest.xml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<phpunit
2-
backupGlobals="false"
3-
backupStaticAttributes="false"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
85
beStrictAboutTestsThatDoNotTestAnything="false"
96
colors="true"
107
>
@@ -18,9 +15,4 @@
1815
<directory>tests/bundle/Functional</directory>
1916
</testsuite>
2017
</testsuites>
21-
<filter>
22-
<whitelist>
23-
<directory>src</directory>
24-
</whitelist>
25-
</filter>
2618
</phpunit>

phpunit.xml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<phpunit
2-
backupGlobals="false"
3-
backupStaticAttributes="false"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
85
beStrictAboutTestsThatDoNotTestAnything="false"
96
colors="true"
107
>
@@ -22,9 +19,4 @@
2219
<directory>tests/lib/Server</directory>
2320
</testsuite>
2421
</testsuites>
25-
<filter>
26-
<whitelist>
27-
<directory>src</directory>
28-
</whitelist>
29-
</filter>
3022
</phpunit>

src/bundle/Resources/config/input_parsers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ services:
663663
Ibexa\Rest\Server\Input\Parser\Aggregation\Range\FloatRangeParser:
664664
parent: Ibexa\Rest\Server\Common\Parser
665665
tags:
666-
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.aggregation..range.FloatRange }
666+
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.aggregation.range.FloatRange }
667667

668668
Ibexa\Rest\Server\Input\Parser\Aggregation\Range\IntRangeParser:
669669
parent: Ibexa\Rest\Server\Common\Parser

src/lib/Server/Controller/SessionController.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ public function createSessionAction(Request $request)
7878

7979
try {
8080
$session = $request->getSession();
81-
if ($session->isStarted() && $this->hasStoredCsrfToken()) {
82-
$this->checkCsrfToken($request);
83-
}
84-
8581
$token = $this->getAuthenticator()->authenticate($request);
8682
$csrfToken = $this->getCsrfToken();
8783

@@ -217,13 +213,8 @@ private function checkCsrfToken(Request $request)
217213
return;
218214
}
219215

220-
$exception = new UnauthorizedException(
221-
'Missing or invalid CSRF token',
222-
$request->getMethod() . ' ' . $request->getPathInfo()
223-
);
224-
225216
if (!$request->headers->has('X-CSRF-Token')) {
226-
throw $exception;
217+
throw $this->createInvalidCsrfTokenException($request);
227218
}
228219

229220
$csrfToken = new CsrfToken(
@@ -232,7 +223,7 @@ private function checkCsrfToken(Request $request)
232223
);
233224

234225
if (!$this->csrfTokenManager->isTokenValid($csrfToken)) {
235-
throw $exception;
226+
throw $this->createInvalidCsrfTokenException($request);
236227
}
237228
}
238229

@@ -263,6 +254,14 @@ private function getAuthenticator(): ?AuthenticatorInterface
263254

264255
return $this->authenticator;
265256
}
257+
258+
private function createInvalidCsrfTokenException(Request $request): UnauthorizedException
259+
{
260+
return new UnauthorizedException(
261+
'Missing or invalid CSRF token',
262+
$request->getMethod() . ' ' . $request->getPathInfo()
263+
);
264+
}
266265
}
267266

268267
class_alias(SessionController::class, 'EzSystems\EzPlatformRest\Server\Controller\SessionController');

src/lib/Server/Controller/Views.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function __construct(SearchService $searchService)
3737
*/
3838
public function createView(Request $request)
3939
{
40+
/** @var \Ibexa\Rest\Server\Values\RestViewInput $viewInput */
4041
$viewInput = $this->inputDispatcher->parse(
4142
new Message(
4243
['Content-Type' => $request->headers->get('Content-Type')],
@@ -45,9 +46,9 @@ public function createView(Request $request)
4546
);
4647

4748
if ($viewInput->query instanceof LocationQuery) {
48-
$method = 'findLocations';
49+
$method = [$this->searchService, 'findLocations'];
4950
} else {
50-
$method = 'findContent';
51+
$method = [$this->searchService, 'findContent'];
5152
}
5253

5354
$languageFilter = [
@@ -62,7 +63,7 @@ public function createView(Request $request)
6263
return new Values\RestExecutedView(
6364
[
6465
'identifier' => $viewInput->identifier,
65-
'searchResults' => $this->searchService->$method(
66+
'searchResults' => $method(
6667
$viewInput->query,
6768
$languageFilter
6869
),

src/lib/Server/Output/ValueObjectVisitor/Location.php

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace Ibexa\Rest\Server\Output\ValueObjectVisitor;
88

99
use Ibexa\Contracts\Core\Repository\ContentService;
10+
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
1011
use Ibexa\Contracts\Core\Repository\LocationService;
11-
use Ibexa\Contracts\Core\Repository\Values\Content\Location as LocationValue;
12+
use Ibexa\Contracts\Core\Repository\Values\Content;
1213
use Ibexa\Contracts\Rest\Output\Generator;
1314
use Ibexa\Contracts\Rest\Output\ValueObjectVisitor;
1415
use Ibexa\Contracts\Rest\Output\Visitor;
15-
use Ibexa\Core\Base\Exceptions\UnauthorizedException;
1616
use Ibexa\Rest\Server\Values\RestContent as RestContentValue;
1717

1818
/**
@@ -26,8 +26,10 @@ class Location extends ValueObjectVisitor
2626
/** @var \Ibexa\Contracts\Core\Repository\ContentService */
2727
private $contentService;
2828

29-
public function __construct(LocationService $locationService, ContentService $contentService)
30-
{
29+
public function __construct(
30+
LocationService $locationService,
31+
ContentService $contentService
32+
) {
3133
$this->locationService = $locationService;
3234
$this->contentService = $contentService;
3335
}
@@ -48,8 +50,15 @@ public function visit(Visitor $visitor, Generator $generator, $location)
4850
$generator->endObjectElement('Location');
4951
}
5052

51-
protected function visitLocationAttributes(Visitor $visitor, Generator $generator, LocationValue $location)
52-
{
53+
/**
54+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
55+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
56+
*/
57+
protected function visitLocationAttributes(
58+
Visitor $visitor,
59+
Generator $generator,
60+
Content\Location $location
61+
) {
5362
$generator->startAttribute(
5463
'href',
5564
$this->router->generate(
@@ -153,15 +162,8 @@ protected function visitLocationAttributes(Visitor $visitor, Generator $generato
153162
$generator->endAttribute('href');
154163

155164
$content = $location->getContent();
156-
$contentInfo = $location->contentInfo;
157-
158-
try {
159-
$mainLocation = $contentInfo->mainLocationId === $location->id
160-
? $location
161-
: $this->locationService->loadLocation($contentInfo->mainLocationId);
162-
} catch (UnauthorizedException $e) {
163-
$mainLocation = null;
164-
}
165+
$contentInfo = $location->getContentInfo();
166+
$mainLocation = $this->resolveMainLocation($contentInfo, $location);
165167

166168
$visitor->visitValueObject(
167169
new RestContentValue(
@@ -175,6 +177,29 @@ protected function visitLocationAttributes(Visitor $visitor, Generator $generato
175177

176178
$generator->endObjectElement('ContentInfo');
177179
}
180+
181+
/**
182+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
183+
*/
184+
private function resolveMainLocation(
185+
Content\ContentInfo $contentInfo,
186+
Content\Location $location
187+
): ?Content\Location {
188+
$mainLocationId = $contentInfo->getMainLocationId();
189+
if ($mainLocationId === null) {
190+
return null;
191+
}
192+
193+
if ($mainLocationId === $location->id) {
194+
return $location;
195+
}
196+
197+
try {
198+
return $this->locationService->loadLocation($mainLocationId);
199+
} catch (UnauthorizedException $e) {
200+
return null;
201+
}
202+
}
178203
}
179204

180205
class_alias(Location::class, 'EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\Location');

0 commit comments

Comments
 (0)