feat: add plugin ssh key generator
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ test('plugin metadata and packaging docs match project rules', function (): void
|
||||
assert_contains('name=mail-login', $conf);
|
||||
assert_contains('id=mail-login', $conf);
|
||||
assert_contains('type=user', $conf);
|
||||
assert_contains('version=1.0.2', $conf);
|
||||
assert_contains('version=1.0.3', $conf);
|
||||
assert_contains('user_run_as=root', $conf);
|
||||
assert_contains('/Users/marek/GPT/ChatGPT/da_plugins/mail-login/src', $packing);
|
||||
assert_contains('/Users/marek/GPT/ChatGPT/da_plugins/mail-login/archives/X.Y.Z/mail-login.tar.gz', $packing);
|
||||
@@ -19,6 +19,7 @@ test('package source excludes local-only files and dangerous placeholders', func
|
||||
assert_contains("--exclude='./.git'", $package);
|
||||
assert_contains("--exclude='./tests'", $package);
|
||||
assert_contains('mail-login.tar.gz', $package);
|
||||
assert_true(is_file(PLUGIN_ROOT . '/scripts/keygen.sh'));
|
||||
|
||||
$bad = [];
|
||||
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PLUGIN_ROOT, FilesystemIterator::SKIP_DOTS));
|
||||
|
||||
Reference in New Issue
Block a user