diff --git a/bin/plugin/open/scp b/bin/plugin/open/scp index cc31f6e..688e0ed 100755 --- a/bin/plugin/open/scp +++ b/bin/plugin/open/scp @@ -96,6 +96,15 @@ if (not $host) { osh_exit; } +if (not $ip) { + + # use STDERR because stdout is eaten by scp itself + print STDERR "\nscp: Sorry, couldn't resolve the host you specified ('$host'), aborting.\n"; + + # note that the calling-side scp will not passthrough this exit code, but most probably "1" instead. + exit(OVH::Bastion::EXIT_HOST_NOT_FOUND); +} + my $machine = $ip; $machine = "$user\@$ip" if $user; $port ||= 22; # scp uses 22 if not specified, so we need to test access to that port and not any port (aka undef) diff --git a/tests/functional/tests.d/340-selfaccesses.sh b/tests/functional/tests.d/340-selfaccesses.sh index 384ee0a..88e18ae 100644 --- a/tests/functional/tests.d/340-selfaccesses.sh +++ b/tests/functional/tests.d/340-selfaccesses.sh @@ -195,6 +195,10 @@ testsuite_selfaccesses() contain "No such file or directory" nocontain "Permission denied" + run scp invalidhostname scp -F $mytmpdir/ssh_config -S /tmp/scphelper -i $account0key1file $shellaccount@_invalid._invalid:uptest /tmp/downloaded + retvalshouldbe 1 + contain "Sorry, couldn't resolve the host you specified" + success scp upload scp -F $mytmpdir/ssh_config -S /tmp/scphelper -i $account0key1file /etc/passwd $shellaccount@127.0.0.2:uptest contain "through the bastion to" contain "Done,"