fix: make keygen autodetect source ip

This commit is contained in:
Marek Miklewicz
2026-06-30 13:03:22 +02:00
parent d43c87486c
commit b27c5c774a
4 changed files with 52 additions and 6 deletions
+23 -1
View File
@@ -24,6 +24,29 @@ test('keygen script creates plugin key and direct ssh authorized keys line', fun
assert_contains('KLUCZ PLUGINU mail-autologin DLA SERWERA h4', $output);
});
test('keygen script detects source ip without parameters', function (): void {
$keyDir = TEST_TMP . '/keys-auto';
$binDir = TEST_TMP . '/fake-bin';
mkdir($binDir, 0700, true);
test_write($binDir . '/ip', "#!/bin/sh\nif [ \"$1 $2 $3\" = 'route get 1.1.1.1' ]; then echo '1.1.1.1 via 203.0.113.1 dev eth0 src 203.0.113.55 uid 0'; exit 0; fi\nexit 1\n");
chmod($binDir . '/ip', 0755);
$script = PLUGIN_ROOT . '/scripts/keygen.sh';
$cmd = sprintf(
'PATH=%s:$PATH MAIL_LOGIN_KEY_DIR=%s %s',
escapeshellarg($binDir),
escapeshellarg($keyDir),
escapeshellarg($script)
);
exec($cmd, $out, $code);
assert_same(0, $code, implode("\n", $out));
$output = implode("\n", $out);
assert_contains('from="203.0.113.55"', $output);
assert_not_contains('SOURCE_SERVER_PUBLIC_IP', $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';
@@ -42,4 +65,3 @@ test('keygen script prints helper forced command line when mx login mode is help
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);
});
+1 -1
View File
@@ -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.3', $conf);
assert_contains('version=1.0.4', $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);