File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77use Illuminate \Foundation \Exceptions \Handler as ExceptionHandler ;
88use Illuminate \Http \RedirectResponse ;
99use Illuminate \Http \Request ;
10+ use League \OAuth2 \Server \Exception \OAuthServerException ;
1011use Symfony \Component \HttpFoundation \Exception \SuspiciousOperationException ;
1112use Symfony \Component \HttpFoundation \Response ;
1213use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
@@ -34,6 +35,10 @@ public function register(): void
3435 //
3536 });
3637
38+ $ this ->dontReportWhen (fn (Throwable $ e ): bool => $ e instanceof OAuthServerException
39+ && $ e ->getErrorType () === 'access_denied '
40+ && $ e ->getHttpStatusCode () === 401 );
41+
3742 // A request on an untrusted host (see App\Http\Middleware\TrustHosts)
3843 // otherwise renders as a bare "Bad request." 400. Show a message that
3944 // says how to fix it instead. The framework has already converted the
Original file line number Diff line number Diff line change @@ -63,7 +63,13 @@ public static function expectedApiExceptionProvider(): iterable
6363 #[DataProvider('expectedApiExceptionProvider ' )]
6464 public function test_expected_api_exceptions_are_not_reported (ApiException $ exception ): void
6565 {
66- $ this ->assertTrue ($ exception ->report ());
66+ // Arrange: exception supplied by the data provider
67+
68+ // Act
69+ $ reportingHandled = $ exception ->report ();
70+
71+ // Assert
72+ $ this ->assertTrue ($ reportingHandled );
6773 }
6874
6975 /**
@@ -79,6 +85,12 @@ public static function operationalApiExceptionProvider(): iterable
7985 #[DataProvider('operationalApiExceptionProvider ' )]
8086 public function test_operational_api_exceptions_are_reported (ApiException $ exception ): void
8187 {
82- $ this ->assertFalse ($ exception ->report ());
88+ // Arrange: exception supplied by the data provider
89+
90+ // Act
91+ $ reportingHandled = $ exception ->report ();
92+
93+ // Assert
94+ $ this ->assertFalse ($ reportingHandled );
8395 }
8496}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Unit \Exceptions ;
6+
7+ use App \Exceptions \Handler ;
8+ use League \OAuth2 \Server \Exception \OAuthServerException ;
9+ use RuntimeException ;
10+ use Tests \TestCase ;
11+
12+ class HandlerTest extends TestCase
13+ {
14+ public function test_oauth_access_denied_exceptions_are_not_reported (): void
15+ {
16+ // Arrange
17+ $ exception = OAuthServerException::accessDenied (
18+ 'Access token could not be verified ' ,
19+ previous: new RuntimeException ('The token is expired ' )
20+ );
21+
22+ // Act
23+ $ shouldReport = app (Handler::class)->shouldReport ($ exception );
24+
25+ // Assert
26+ $ this ->assertFalse ($ shouldReport );
27+ }
28+
29+ public function test_operational_oauth_exceptions_are_reported (): void
30+ {
31+ // Arrange
32+ $ exception = OAuthServerException::serverError ('Signing key could not be read ' );
33+
34+ // Act
35+ $ shouldReport = app (Handler::class)->shouldReport ($ exception );
36+
37+ // Assert
38+ $ this ->assertTrue ($ shouldReport );
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments