fix: make keygen autodetect source ip
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user