fix: report direct ssh login failures
This commit is contained in:
@@ -96,7 +96,7 @@ final class RemoteLoginUrlClient
|
||||
throw new RuntimeException('Invalid process runner result');
|
||||
}
|
||||
if ($result->exitCode !== 0) {
|
||||
throw new RuntimeException('MX helper failed');
|
||||
throw new RuntimeException(self::failureMessage($settings, $result));
|
||||
}
|
||||
if (!preg_match('/https:\/\/\S+/', $result->stdout, $match)) {
|
||||
throw new RuntimeException('MX helper did not return a login URL');
|
||||
@@ -108,6 +108,24 @@ final class RemoteLoginUrlClient
|
||||
}
|
||||
}
|
||||
|
||||
private static function failureMessage(Settings $settings, ProcessResult $result): string
|
||||
{
|
||||
$message = $settings->mxLoginMode() === 1 ? 'MX direct SSH command failed' : 'MX helper failed';
|
||||
$message .= ' (exit ' . $result->exitCode . ')';
|
||||
$detail = self::safeDiagnostic($result->stderr);
|
||||
if ($detail !== '') {
|
||||
$message .= ': ' . $detail;
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
private static function safeDiagnostic(string $text): string
|
||||
{
|
||||
$text = preg_replace('/https?:\/\/\S+/i', '[redacted-url]', $text) ?? '';
|
||||
$text = preg_replace('/\s+/', ' ', trim($text)) ?? '';
|
||||
return substr($text, 0, 512);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $command
|
||||
*/
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ name=mail-login
|
||||
id=mail-login
|
||||
type=user
|
||||
author=HITME.PL
|
||||
version=1.0.5
|
||||
version=1.0.6
|
||||
active=no
|
||||
installed=no
|
||||
user_run_as=root
|
||||
|
||||
@@ -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.5', $conf);
|
||||
assert_contains('version=1.0.6', $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);
|
||||
|
||||
@@ -73,6 +73,26 @@ test('remote login url client validates helper output before returning it', func
|
||||
}
|
||||
});
|
||||
|
||||
test('remote login url client reports direct ssh failure diagnostics', function (): void {
|
||||
$settings = Settings::fromArray([
|
||||
'MAIL_LOGIN_TARGET_BASE_URL' => 'https://mx1.domena.pl:2222',
|
||||
'MX_LOGIN_MODE' => '1',
|
||||
]);
|
||||
$request = new LoginUrlRequest('mxtest', 'h4.domena.pl', 'h4', 30, true, '198.51.100.10', '/', 1782810000);
|
||||
$client = new RemoteLoginUrlClient(function (array $command, int $timeout): ProcessResult {
|
||||
return new ProcessResult(255, '', "Host key verification failed.\n");
|
||||
});
|
||||
|
||||
try {
|
||||
$client->create($settings, $request);
|
||||
throw new RuntimeException('Expected direct ssh failure to fail');
|
||||
} catch (RuntimeException $e) {
|
||||
assert_contains('MX direct SSH command failed', $e->getMessage());
|
||||
assert_contains('exit 255', $e->getMessage());
|
||||
assert_contains('Host key verification failed.', $e->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
test('process runner returns stdout and exit code from real command', function (): void {
|
||||
$result = RemoteLoginUrlClient::runProcess(['php', '-r', 'echo "ok\n";'], 5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user