feat: add plugin ssh key generator

This commit is contained in:
Marek Miklewicz
2026-06-30 12:52:45 +02:00
parent b23e959491
commit d43c87486c
4 changed files with 133 additions and 2 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
test('keygen script creates plugin key and direct ssh authorized keys line', function (): void {
$keyDir = TEST_TMP . '/keys-direct';
$script = PLUGIN_ROOT . '/scripts/keygen.sh';
$cmd = sprintf(
'MAIL_LOGIN_KEY_DIR=%s SERVERNAME=%s SOURCE_IP=%s %s',
escapeshellarg($keyDir),
escapeshellarg('h4'),
escapeshellarg('203.0.113.10'),
escapeshellarg($script)
);
exec($cmd, $out, $code);
assert_same(0, $code, implode("\n", $out));
assert_true(is_file($keyDir . '/mx1_ed25519'));
assert_true(is_file($keyDir . '/mx1_ed25519.pub'));
$output = implode("\n", $out);
assert_contains('from="203.0.113.10"', $output);
assert_contains('restrict,no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-pty', $output);
assert_not_contains('command=', $output);
assert_contains('KLUCZ PLUGINU mail-autologin DLA SERWERA h4', $output);
});
test('keygen script prints helper forced command line when mx login mode is helper', function (): void {
$keyDir = TEST_TMP . '/keys-helper';
$script = PLUGIN_ROOT . '/scripts/keygen.sh';
$cmd = sprintf(
'MAIL_LOGIN_KEY_DIR=%s MX_LOGIN_MODE=2 SERVERNAME=%s SOURCE_IP=%s %s',
escapeshellarg($keyDir),
escapeshellarg('h4'),
escapeshellarg('203.0.113.10'),
escapeshellarg($script)
);
exec($cmd, $out, $code);
assert_same(0, $code, implode("\n", $out));
$output = implode("\n", $out);
assert_contains('command="/usr/local/hitme_plugins/mail-login-helper/bin/create-login-url"', $output);
assert_contains('KLUCZ PLUGINU mail-autologin DLA SERWERA h4', $output);
});