Skip to content

Commit 5a14e30

Browse files
authored
Merge pull request #342 from cultuurnet/III-6521-remove-unneeded-logging
2 parents d85887f + b22f953 commit 5a14e30

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

src/Http/Authentication/Access/CultureFeedConsumerResolver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}

src/Http/Authentication/AuthenticateRequest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use CultuurNet\UDB3\Search\Http\Authentication\Access\ConsumerResolver;
88
use CultuurNet\UDB3\Search\Http\Authentication\Access\ClientIdResolver;
99
use CultuurNet\UDB3\Search\Http\Authentication\Access\InvalidClient;
10+
use CultuurNet\UDB3\Search\Http\Authentication\Access\InvalidConsumer;
1011
use CultuurNet\UDB3\Search\Http\Authentication\ApiProblems\BlockedApiKey;
1112
use CultuurNet\UDB3\Search\Http\Authentication\ApiProblems\InvalidApiKey;
1213
use 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

tests/Http/Authentication/Access/CultureFeedConsumerResolverTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff 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
/**

tests/Http/Authentication/AuthenticateRequestTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use CultuurNet\UDB3\Search\FileReader;
99
use CultuurNet\UDB3\Search\Http\Authentication\Access\ConsumerResolver;
1010
use CultuurNet\UDB3\Search\Http\Authentication\Access\ClientIdResolver;
11+
use CultuurNet\UDB3\Search\Http\Authentication\Access\InvalidConsumer;
1112
use CultuurNet\UDB3\Search\Http\Authentication\ApiProblems\BlockedApiKey;
1213
use CultuurNet\UDB3\Search\Http\Authentication\ApiProblems\InvalidApiKey;
1314
use 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())

0 commit comments

Comments
 (0)