Skip to content

Commit

Permalink
[7.x] Fix authorization http code (#501)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
binaryk and binaryk authored Aug 2, 2022
1 parent dae2293 commit 752e1ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Middleware/AuthorizeRestify.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function handle($request, $next)
return $next($request);
}

abort(403, __('Unauthorized to view restify.'));
abort(401, __('Unauthorized to view restify.'));
}
}
23 changes: 23 additions & 0 deletions tests/Middleware/AuthorizeRestifyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Binaryk\LaravelRestify\Tests\Middleware;

use Binaryk\LaravelRestify\Restify;
use Binaryk\LaravelRestify\Tests\Fixtures\User\UserRepository;
use Binaryk\LaravelRestify\Tests\IntegrationTest;

class AuthorizeRestifyTest extends IntegrationTest
{
public function test_unauthorized_http_code_is_401(): void
{
Restify::$authUsing = fn () => false;

$this->getJson(UserRepository::route())
->assertStatus(401);

Restify::$authUsing = fn () => true;

$this->getJson(UserRepository::route())
->assertStatus(200);
}
}

0 comments on commit 752e1ed

Please sign in to comment.