summaryrefslogtreecommitdiffstats
path: root/tests/Modules/RebootControl/SSHKeyTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Modules/RebootControl/SSHKeyTest.php')
-rw-r--r--tests/Modules/RebootControl/SSHKeyTest.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/Modules/RebootControl/SSHKeyTest.php b/tests/Modules/RebootControl/SSHKeyTest.php
new file mode 100644
index 00000000..5cec9ac4
--- /dev/null
+++ b/tests/Modules/RebootControl/SSHKeyTest.php
@@ -0,0 +1,45 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+/**
+ * Tests for modules-available/rebootcontrol/inc/sshkey.inc.php
+ *
+ */
+class SSHKeyTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ Database::resetSchema(); // not strictly needed here
+ Property::reset();
+ $_GET = $_POST = $_REQUEST = [];
+ require_once __DIR__ . '/../../../modules-available/rebootcontrol/inc/sshkey.inc.php';
+ }
+
+ public function testGetPrivateKeyUsesExistingAndDoesNotRegen(): void
+ {
+ $existing = "-----BEGIN PRIVATE KEY-----\nTESTKEY\n-----END PRIVATE KEY-----\n";
+ Property::set('rebootcontrol-private-key', $existing);
+ $regen = null;
+ $key = SSHKey::getPrivateKey($regen);
+ $this->assertSame($existing, $key);
+ $this->assertFalse($regen);
+ }
+
+ public function testGeneratePrivateAndPublicKeyWithOpenSSLIfAvailable(): void
+ {
+ if (!function_exists('openssl_pkey_new')) {
+ $this->markTestSkipped('OpenSSL not available in this environment');
+ }
+ Property::reset();
+ $regen = null;
+ $priv = SSHKey::getPrivateKey($regen);
+ $this->assertNotNull($priv);
+ $this->assertTrue($regen);
+ $this->assertStringContainsString('BEGIN', $priv);
+
+ $pub = SSHKey::getPublicKey();
+ $this->assertNotNull($pub);
+ $this->assertStringStartsWith('ssh-rsa ', $pub);
+ }
+}