|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Keboola\JobQueueInternalClient\Tests\DataPlane\Config; |
| 6 | + |
| 7 | +use Keboola\JobQueueInternalClient\DataPlane\Config\KubernetesConfig; |
| 8 | +use Keboola\ObjectEncryptor\EncryptorOptions; |
| 9 | +use Keboola\ObjectEncryptor\ObjectEncryptorFactory; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class KubernetesConfigTest extends TestCase |
| 13 | +{ |
| 14 | + public function testCreateAndGetData(): void |
| 15 | + { |
| 16 | + $config = new KubernetesConfig( |
| 17 | + 'apiUrl', |
| 18 | + 'token', |
| 19 | + 'cert', |
| 20 | + 'namespace' |
| 21 | + ); |
| 22 | + |
| 23 | + self::assertSame('apiUrl', $config->getApiUrl()); |
| 24 | + self::assertSame('token', $config->getToken()); |
| 25 | + self::assertSame('cert', $config->getCertificateAuthority()); |
| 26 | + self::assertSame('namespace', $config->getNamespace()); |
| 27 | + } |
| 28 | + |
| 29 | + public function testGetDecryptedToken(): void |
| 30 | + { |
| 31 | + $objectEncryptor = ObjectEncryptorFactory::getEncryptor(new EncryptorOptions( |
| 32 | + (string) parse_url((string) getenv('TEST_STORAGE_API_URL'), PHP_URL_HOST), |
| 33 | + (string) getenv('TEST_KMS_KEY_ID'), |
| 34 | + (string) getenv('TEST_KMS_REGION'), |
| 35 | + null, |
| 36 | + (string) getenv('TEST_AZURE_KEY_VAULT_URL'), |
| 37 | + )); |
| 38 | + |
| 39 | + $encryptedToken = $objectEncryptor->encryptGeneric('tokenValue'); |
| 40 | + self::assertStringStartsWith('KBC::Secure', $encryptedToken); |
| 41 | + |
| 42 | + $config = new KubernetesConfig( |
| 43 | + 'apiUrl', |
| 44 | + $encryptedToken, |
| 45 | + 'cert', |
| 46 | + 'namespace' |
| 47 | + ); |
| 48 | + |
| 49 | + $decryptedToken = $config->getTokenDecrypted($objectEncryptor); |
| 50 | + self::assertSame('tokenValue', $decryptedToken); |
| 51 | + } |
| 52 | +} |
0 commit comments