From 752e1ede5757f393a997ceab91bf61ac59697e16 Mon Sep 17 00:00:00 2001 From: Lupacescu Eduard Date: Tue, 2 Aug 2022 13:28:37 +0300 Subject: [PATCH] [7.x] Fix authorization http code (#501) * fix: [7.x] Use 401 unathorized http code. * fix: wip * fix: adding test * fix: wip * Fix styling * fix: wip * Fix styling Co-authored-by: binaryk --- src/Http/Middleware/AuthorizeRestify.php | 2 +- tests/Middleware/AuthorizeRestifyTest.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/Middleware/AuthorizeRestifyTest.php diff --git a/src/Http/Middleware/AuthorizeRestify.php b/src/Http/Middleware/AuthorizeRestify.php index c40b00a3..40054ccf 100644 --- a/src/Http/Middleware/AuthorizeRestify.php +++ b/src/Http/Middleware/AuthorizeRestify.php @@ -22,6 +22,6 @@ public function handle($request, $next) return $next($request); } - abort(403, __('Unauthorized to view restify.')); + abort(401, __('Unauthorized to view restify.')); } } diff --git a/tests/Middleware/AuthorizeRestifyTest.php b/tests/Middleware/AuthorizeRestifyTest.php new file mode 100644 index 00000000..44320bed --- /dev/null +++ b/tests/Middleware/AuthorizeRestifyTest.php @@ -0,0 +1,23 @@ + false; + + $this->getJson(UserRepository::route()) + ->assertStatus(401); + + Restify::$authUsing = fn () => true; + + $this->getJson(UserRepository::route()) + ->assertStatus(200); + } +}