Skip to content

Commit

Permalink
UHF-9239: Remove VaultAuthorizer
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Jan 12, 2024
1 parent 2d33ff2 commit 56a718e
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 232 deletions.
7 changes: 0 additions & 7 deletions helfi_api_base.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,3 @@ services:
- '@cache.default'
- '@datetime.time'
- '@helfi_api_base.environment_resolver'

helfi_api_base.vault_authorizer:
class: Drupal\helfi_api_base\ApiClient\VaultAuthorizer
abstract: true
arguments:
- '@config.factory'
- '@helfi_api_base.vault_manager'
20 changes: 0 additions & 20 deletions src/ApiClient/ApiAuthorizerInterface.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/ApiClient/ApiClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ abstract class ApiClientBase {
* The environment resolver.
* @param \Psr\Log\LoggerInterface $logger
* Logger channel.
* @param \Drupal\helfi_api_base\ApiClient\ApiAuthorizerInterface|null $authorizer
* The authorization plugin.
* @param array $defaultOptions
* Default request options.
*/
Expand All @@ -63,7 +61,6 @@ public function __construct(
protected readonly TimeInterface $time,
protected readonly EnvironmentResolverInterface $environmentResolver,
protected readonly LoggerInterface $logger,
protected readonly ?ApiAuthorizerInterface $authorizer = NULL,
private readonly array $defaultOptions = [],
) {
}
Expand All @@ -80,16 +77,6 @@ public function withBypassCache() : self {
return $instance;
}

/**
* Is the authorizer configured.
*
* @return bool
* True if the requests contain authorization header.
*/
public function hasAuthorization(): bool {
return (bool) $this->authorizer?->getAuthorization();
}

/**
* Gets the default request options.
*
Expand All @@ -109,10 +96,6 @@ protected function getRequestOptions(string $environmentName, array $options = [
'curl' => [CURLOPT_TCP_KEEPALIVE => TRUE],
];

if ($this->hasAuthorization()) {
$default['headers']['Authorization'] = $this->authorizer?->getAuthorization();
}

if ($environmentName === 'local') {
// Disable SSL verification in local environment.
$default['verify'] = FALSE;
Expand Down
72 changes: 0 additions & 72 deletions src/ApiClient/VaultAuthorizer.php

This file was deleted.

46 changes: 0 additions & 46 deletions tests/src/Unit/ApiClient/ApiClientBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ private function getTimeMock(int $expectedTime) : ObjectProphecy {
* The time prophecy.
* @param \Psr\Log\LoggerInterface|null $logger
* The logger.
* @param \Drupal\helfi_api_base\ApiClient\ApiAuthorizerInterface|null $authorizer
* The api authorizer.
* @param \Drupal\helfi_api_base\Environment\EnvironmentResolverInterface|null $environmentResolver
* The environment resolver.
* @param array $requestOptions
Expand All @@ -107,7 +105,6 @@ private function getSut(
ClientInterface $client = NULL,
TimeInterface $time = NULL,
LoggerInterface $logger = NULL,
ApiAuthorizerInterface $authorizer = NULL,
EnvironmentResolverInterface $environmentResolver = NULL,
array $requestOptions = [],
) : ApiClient {
Expand All @@ -134,53 +131,10 @@ private function getSut(
$time,
$environmentResolver,
$logger,
$authorizer,
$requestOptions,
);
}

/**
* Tests authorization.
*
* @covers ::__construct
* @covers ::makeRequest
* @covers ::getRequestOptions
* @covers ::hasAuthorization
* @covers \Drupal\helfi_api_base\ApiClient\ApiResponse::__construct
* @covers \Drupal\helfi_api_base\ApiClient\VaultAuthorizer::__construct
* @covers \Drupal\helfi_api_base\ApiClient\VaultAuthorizer::getAuthorization
* @covers \Drupal\helfi_api_base\ApiClient\VaultAuthorizer::getToken
*/
public function testAuthorization() : void {
$requests = [];
$client = $this->createMockHistoryMiddlewareHttpClient($requests, [
new Response(200, body: json_encode(['key' => 'value'])),
]);

$sut = $this->getSut(
$client,
authorizer: new VaultAuthorizer(
$this->getConfigFactoryStub([]),
new VaultManager([
new AuthorizationToken('vault_key', '123'),
]),
'vault_key',
),
requestOptions: [
'headers' => ['X-Custom-Header' => '1'],
],
);

$sut->exposedMakeRequest('GET', '/foo');

$this->assertCount(1, $requests);
// Make sure SSL verification is disabled on local.
$this->assertFalse($requests[0]['options']['verify']);
// Make sure headers are set.
$this->assertEquals('Basic 123', $requests[0]['request']->getHeader('Authorization')[0]);
$this->assertEquals('1', $requests[0]['request']->getHeader('X-Custom-Header')[0]);
}

/**
* Test makeRequest().
*
Expand Down
70 changes: 0 additions & 70 deletions tests/src/Unit/ApiClient/VaultAuthorizerTest.php

This file was deleted.

0 comments on commit 56a718e

Please sign in to comment.