From 236a77142ced9130275fa200ed502bc7553b2f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6nig?= Date: Tue, 4 Jan 2022 12:11:25 +0100 Subject: [PATCH] Fix KubeConfig temp certificate filename extension .pem --- src/Traits/Cluster/LoadsFromKubeConfig.php | 2 +- tests/KubeConfigTest.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Traits/Cluster/LoadsFromKubeConfig.php b/src/Traits/Cluster/LoadsFromKubeConfig.php index aab4bba8..60f8948e 100644 --- a/src/Traits/Cluster/LoadsFromKubeConfig.php +++ b/src/Traits/Cluster/LoadsFromKubeConfig.php @@ -244,7 +244,7 @@ protected function writeTempFileForContext( /** @var \RenokiCo\PhpK8s\KubernetesCluster $this */ $tempFolder = static::$tempFolder ?: sys_get_temp_dir(); - $tempFilePath = $tempFolder.DIRECTORY_SEPARATOR.Str::slug("ctx-{$context}-{$userName}-{$url}-{$fileName}"); + $tempFilePath = $tempFolder.DIRECTORY_SEPARATOR.Str::slug("ctx-{$context}-{$userName}-{$url}")."-{$fileName}"; if (file_exists($tempFilePath)) { return $tempFilePath; diff --git a/tests/KubeConfigTest.php b/tests/KubeConfigTest.php index a69a5457..b98a3ff9 100644 --- a/tests/KubeConfigTest.php +++ b/tests/KubeConfigTest.php @@ -11,6 +11,8 @@ class KubeConfigTest extends TestCase { + private $tempFolder; + /** * {@inheritdoc} */ @@ -18,7 +20,8 @@ public function setUp(): void { parent::setUp(); - KubernetesCluster::setTempFolder(__DIR__.DIRECTORY_SEPARATOR.'temp'); + $this->tempFolder = __DIR__.DIRECTORY_SEPARATOR.'temp'; + KubernetesCluster::setTempFolder($this->tempFolder); } /** @@ -41,6 +44,12 @@ public function test_kube_config_from_yaml_file_with_base64_encoded_ssl() 'ssl_key' => $keyPath, ] = $cluster->getClient()->getConfig(); + $tempFilePath = $this->tempFolder.DIRECTORY_SEPARATOR.'ctx-minikube-minikube-httpsminikube8443-'; + + $this->assertSame($tempFilePath.'ca-cert.pem', $caPath); + $this->assertSame($tempFilePath.'client-cert.pem', $certPath); + $this->assertSame($tempFilePath.'client-key.pem', $keyPath); + $this->assertEquals("some-ca\n", file_get_contents($caPath)); $this->assertEquals("some-cert\n", file_get_contents($certPath)); $this->assertEquals("some-key\n", file_get_contents($keyPath));