diff options
| author | Simon Rettberg | 2025-11-26 10:46:51 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2025-12-12 15:16:59 +0100 |
| commit | 7c173411785f959d250d3dfbd7d4cfcb0e20f0e0 (patch) | |
| tree | 242157791a76afb7af23ec2cd3d22b599e54ce9d /tests/Modules/RebootControl/SSHKeyTest.php | |
| parent | [exams] Fix incorrect count() clause (diff) | |
| download | slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.gz slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.tar.xz slx-admin-7c173411785f959d250d3dfbd7d4cfcb0e20f0e0.zip | |
Add tests using PHPUnit
Tests generated by Junie AI. Might not have the best possible quality
but at least we got something, and if it turns out to be complete
rubbish, we can just throw it out again without any issues, as this is
independent of the actual code base.
Diffstat (limited to 'tests/Modules/RebootControl/SSHKeyTest.php')
| -rw-r--r-- | tests/Modules/RebootControl/SSHKeyTest.php | 45 |
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); + } +} |
