callApi(self::METHOD_GET, '/short-urls'); $payload = $this->getJsonResponsePayload($resp); $this->assertEquals(self::STATUS_UNAUTHORIZED, $resp->getStatusCode()); $this->assertEquals(self::STATUS_UNAUTHORIZED, $payload['status']); $this->assertEquals('INVALID_AUTHORIZATION', $payload['type']); $this->assertEquals($expectedDetail, $payload['detail']); $this->assertEquals('Invalid authorization', $payload['title']); } /** * @test * @dataProvider provideInvalidApiKeys */ public function apiKeyErrorIsReturnedWhenProvidedApiKeyIsInvalid(string $apiKey): void { $expectedDetail = 'Provided API key does not exist or is invalid.'; $resp = $this->callApi(self::METHOD_GET, '/short-urls', [ 'headers' => [ Plugin\ApiKeyHeaderPlugin::HEADER_NAME => $apiKey, ], ]); $payload = $this->getJsonResponsePayload($resp); $this->assertEquals(self::STATUS_UNAUTHORIZED, $resp->getStatusCode()); $this->assertEquals(self::STATUS_UNAUTHORIZED, $payload['status']); $this->assertEquals('INVALID_API_KEY', $payload['type']); $this->assertEquals($expectedDetail, $payload['detail']); $this->assertEquals('Invalid API key', $payload['title']); } public function provideInvalidApiKeys(): iterable { yield 'key which does not exist' => ['invalid']; yield 'key which is expired' => ['expired_api_key']; yield 'key which is disabled' => ['disabled_api_key']; } }