File tree Expand file tree Collapse file tree 5 files changed +18
-10
lines changed
tests/Http/Authentication Expand file tree Collapse file tree 5 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,7 @@ public function getStatus(string $apiKey): string
3030 /** @var CultureFeed_Consumer $cultureFeedConsumer */
3131 $ cultureFeedConsumer = $ this ->cultureFeed ->getServiceConsumerByApiKey ($ apiKey , true );
3232 } catch (Exception $ exception ) {
33- $ this ->logger ->error ($ exception ->getMessage ());
34- return 'INVALID ' ;
33+ throw new InvalidConsumer ();
3534 }
3635 return $ cultureFeedConsumer ->status ;
3736 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace CultuurNet \UDB3 \Search \Http \Authentication \Access ;
6+
7+ final class InvalidConsumer extends \Exception
8+ {
9+ }
Original file line number Diff line number Diff line change 77use CultuurNet \UDB3 \Search \Http \Authentication \Access \ConsumerResolver ;
88use CultuurNet \UDB3 \Search \Http \Authentication \Access \ClientIdResolver ;
99use CultuurNet \UDB3 \Search \Http \Authentication \Access \InvalidClient ;
10+ use CultuurNet \UDB3 \Search \Http \Authentication \Access \InvalidConsumer ;
1011use CultuurNet \UDB3 \Search \Http \Authentication \ApiProblems \BlockedApiKey ;
1112use CultuurNet \UDB3 \Search \Http \Authentication \ApiProblems \InvalidApiKey ;
1213use CultuurNet \UDB3 \Search \Http \Authentication \ApiProblems \InvalidClientId ;
@@ -151,9 +152,9 @@ private function handleApiKey(
151152 RequestHandlerInterface $ handler ,
152153 string $ apiKey
153154 ): ResponseInterface {
154- $ status = $ this -> consumerResolver -> getStatus ( $ apiKey );
155-
156- if ( $ status === ' INVALID ' ) {
155+ try {
156+ $ status = $ this -> consumerResolver -> getStatus ( $ apiKey );
157+ } catch ( InvalidConsumer $ invalidConsumer ) {
157158 return (new InvalidApiKey ($ apiKey ))->toResponse ();
158159 }
159160
Original file line number Diff line number Diff line change @@ -34,11 +34,9 @@ public function it_handles_invalid_api_keys(): void
3434 ->method ('getServiceConsumerByApiKey ' )
3535 ->with ('my_invalid_api_key ' , true )
3636 ->willThrowException (new Exception ('Invalid API key ' ));
37+ $ this ->expectException (InvalidConsumer::class);
3738
38- $ this ->assertEquals (
39- 'INVALID ' ,
40- $ this ->consumerResolver ->getStatus ('my_invalid_api_key ' )
41- );
39+ $ this ->consumerResolver ->getStatus ('my_invalid_api_key ' );
4240 }
4341
4442 /**
Original file line number Diff line number Diff line change 88use CultuurNet \UDB3 \Search \FileReader ;
99use CultuurNet \UDB3 \Search \Http \Authentication \Access \ConsumerResolver ;
1010use CultuurNet \UDB3 \Search \Http \Authentication \Access \ClientIdResolver ;
11+ use CultuurNet \UDB3 \Search \Http \Authentication \Access \InvalidConsumer ;
1112use CultuurNet \UDB3 \Search \Http \Authentication \ApiProblems \BlockedApiKey ;
1213use CultuurNet \UDB3 \Search \Http \Authentication \ApiProblems \InvalidApiKey ;
1314use CultuurNet \UDB3 \Search \Http \Authentication \ApiProblems \InvalidToken ;
@@ -140,7 +141,7 @@ public function it_handles_invalid_api_keys(): void
140141 $ this ->consumerResolver ->expects ($ this ->once ())
141142 ->method ('getStatus ' )
142143 ->with ('my_invalid_api_key ' )
143- ->willReturn ( ' INVALID ' );
144+ ->willThrowException ( new InvalidConsumer () );
144145
145146 $ response = $ this ->authenticateRequest ->process (
146147 (new ServerRequestFactory ())
You can’t perform that action at this time.
0 commit comments