Skip to content

Commit ed0413f

Browse files
committed
fix(readlistner): fix error 500 on not existing entity
1 parent 43ad1f9 commit ed0413f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

features/authorization/deny.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ Feature: Authorization checking
211211
And the response should contain "ownerOnlyProperty"
212212
And the JSON node "ownerOnlyProperty" should be equal to the string "updated"
213213

214+
Scenario: An non existing entity should return Not found
215+
When I add "Accept" header equal to "application/ld+json"
216+
And I add "Content-Type" header equal to "application/ld+json"
217+
And I add "Authorization" header equal to "Basic ZHVuZ2xhczprZXZpbg=="
218+
And I send a "GET" request to "/secured_dummies/40000/related"
219+
Then the response status code should be 404
220+
214221
Scenario: An user can get related linked dummies for an secured dummy they own
215222
Given there are 1 SecuredDummy objects owned by dunglas with related dummies
216223
When I add "Accept" header equal to "application/ld+json"

src/Symfony/EventListener/ReadListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ public function onKernelRequest(RequestEvent $event): void
100100
if (!$uriVariable instanceof Link || !$uriVariable->getSecurity()) {
101101
continue;
102102
}
103-
$operationUriVariables = $uriVariable->getIdentifiers();
104103
$relationClass = $uriVariable->getFromClass();
105104
try {
106105
$tmp = $this->provider->provide($this->resourceMetadataCollectionFactory->create($relationClass)->getOperation(null, false, true), [$uriVariable->getIdentifiers()[0] => $parameters[$key]], $context);
106+
if (null === $tmp) {
107+
throw new NotFoundHttpException('Not Found');
108+
}
107109
$request->attributes->set($uriVariable->getToProperty(), $tmp);
108110
} catch (InvalidIdentifierException|InvalidUriVariableException $e) {
109111
throw new NotFoundHttpException('Invalid identifier value or configuration.', $e);

0 commit comments

Comments
 (0)