Skip to content

Commit 62038dd

Browse files
author
Gregory Haddow
committed
fix: authorizer response with status should be honoured when unauthenticated
1 parent 8a2db50 commit 62038dd

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/Http/Requests/FormRequest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ protected function passesAuthorization()
254254
}
255255

256256
} catch (AuthorizationException $ex) {
257-
$this->failIfUnauthenticated();
257+
if (!$ex->hasStatus() || $ex->hasStatus() && $ex->status() === 403) {
258+
$this->failIfUnauthenticated();
259+
}
258260
throw $ex;
259261
}
260262
return true;

tests/dummy/app/Policies/UserPolicy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public function updatePhone(User $user, User $other): bool
5555
/**
5656
* Determine if the user can delete the other user.
5757
*
58-
* @param User $user
58+
* @param ?User $user
5959
* @param User $other
6060
* @return bool|Response
6161
*/
62-
public function delete(User $user, User $other)
62+
public function delete(?User $user, User $other)
6363
{
64-
return $user->is($other) ? true : Response::denyAsNotFound('not found message');
64+
return $user?->is($other) ? true : Response::denyAsNotFound('not found message');
6565
}
6666

6767
}

tests/dummy/tests/Api/V1/Users/DeleteTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,22 @@ public function test(): void
3535
'title' => 'Not Found',
3636
]);
3737
}
38+
39+
public function testUnauthenticated(): void
40+
{
41+
$user = User::factory()->createOne();
42+
43+
$expected = $this->serializer
44+
->user($user);
45+
$response = $this
46+
->jsonApi('users')
47+
->delete(url('/api/v1/users', $expected['id']));
48+
49+
$response->assertNotFound()
50+
->assertHasError(404, [
51+
'detail' => 'not found message',
52+
'status' => '404',
53+
'title' => 'Not Found',
54+
]);
55+
}
3856
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy