Converted final error_and_exit in ssh.rb to exceptions
This commit is contained in:
parent
bab369e856
commit
0b03502bf2
|
@ -61,6 +61,11 @@ module Vagrant
|
|||
error_key(:ssh_authentication_failed)
|
||||
end
|
||||
|
||||
class SSHKeyBadPermissions < VagrantError
|
||||
status_code(12)
|
||||
error_key(:ssh_key_bad_permissions)
|
||||
end
|
||||
|
||||
class SSHUnavailableWindows < VagrantError
|
||||
status_code(10)
|
||||
error_key(:ssh_unavailable_windows)
|
||||
|
|
|
@ -7,8 +7,6 @@ module Vagrant
|
|||
# replace the process with SSH itself, run a specific set of commands,
|
||||
# upload files, or even check if a host is up.
|
||||
class SSH
|
||||
include Vagrant::Util
|
||||
|
||||
# Reference back up to the environment which this SSH object belongs
|
||||
# to
|
||||
attr_accessor :env
|
||||
|
@ -120,12 +118,12 @@ module Vagrant
|
|||
env.ui.info "Permissions on private key incorrect, fixing..."
|
||||
File.chmod(0600, key_path)
|
||||
|
||||
error_and_exit(:ssh_bad_permissions, :key_path => key_path) if file_perms(key_path) != "600"
|
||||
raise Errors::SSHKeyBadPermissions.new(:key_path => key_path) if file_perms(key_path) != "600"
|
||||
end
|
||||
rescue Errno::EPERM
|
||||
# This shouldn't happen since we verify we own the file, but just
|
||||
# in case.
|
||||
error_and_exit(:ssh_bad_permissions, :key_path => key_path)
|
||||
raise Errors::SSHKeyBadPermissions.new(:key_path => key_path)
|
||||
end
|
||||
|
||||
# Returns the file permissions of a given file. This is fairly unix specific
|
||||
|
|
|
@ -16,6 +16,13 @@ en:
|
|||
keypair for the SSH user not being properly set on the guest VM. Please
|
||||
verify that the guest VM is setup with the proper public key, and that
|
||||
the private key path for Vagrant is setup propery as well.
|
||||
ssh_key_bad_permissions: |-
|
||||
The private key to connect to this box via SSH has invalid permissions
|
||||
set on it. The permissions of the private key should be set to 0600, otherwise SSH will
|
||||
ignore the key. Vagrant tried to do this automatically for you but failed. Please set the
|
||||
permissions on the following file to 0600 and then try running this command again:
|
||||
|
||||
<%= key_path %>
|
||||
ssh_unavailable_windows: |-
|
||||
`vagrant ssh` isn't available on the Windows platform. The
|
||||
vagrant.ppk file for use with Putty is available at:
|
||||
|
|
|
@ -141,13 +141,6 @@
|
|||
Provisioners must be an instance of Vagrant::Provisioners::Base
|
||||
:provisioner_unknown_type: |-
|
||||
Unknown provisioner type: <%= provisioner %>
|
||||
:ssh_bad_permissions: |-
|
||||
The private key to connect to this box via SSH has invalid permissions
|
||||
set on it. The permissions of the private key should be set to 0600, otherwise SSH will
|
||||
ignore the key. Vagrant tried to do this automatically for you but failed. Please set the
|
||||
permissions on the following file to 0600 and then try running this command again:
|
||||
|
||||
<%= key_path %>
|
||||
:ssh_bad_exit_status: |-
|
||||
The following SSH command responded with a non-zero exit status.
|
||||
Vagrant assumes that this means the command failed!
|
||||
|
|
|
@ -25,7 +25,6 @@ class SshTest < Test::Unit::TestCase
|
|||
setup do
|
||||
mock_ssh
|
||||
@ssh.stubs(:check_key_permissions)
|
||||
@ssh.stubs(:error_and_exit)
|
||||
Kernel.stubs(:exec)
|
||||
|
||||
Vagrant::Util::Platform.stubs(:leopard?).returns(false)
|
||||
|
@ -285,8 +284,7 @@ class SshTest < Test::Unit::TestCase
|
|||
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
||||
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
||||
@ssh.expects(:file_perms).returns("600").in_sequence(perm_sequence)
|
||||
@ssh.expects(:error_and_exit).never
|
||||
@ssh.check_key_permissions(@key_path)
|
||||
assert_nothing_raised { @ssh.check_key_permissions(@key_path) }
|
||||
end
|
||||
|
||||
should "error and exit if the resulting chmod doesn't work" do
|
||||
|
@ -294,15 +292,13 @@ class SshTest < Test::Unit::TestCase
|
|||
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
||||
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
||||
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
||||
@ssh.expects(:error_and_exit).once.with(:ssh_bad_permissions, :key_path => @key_path).in_sequence(perm_sequence)
|
||||
@ssh.check_key_permissions(@key_path)
|
||||
assert_raises(Vagrant::Errors::SSHKeyBadPermissions) { @ssh.check_key_permissions(@key_path) }
|
||||
end
|
||||
|
||||
should "error and exit if a bad file perm is raised" do
|
||||
@ssh.expects(:file_perms).with(@key_path).returns("900")
|
||||
File.expects(:chmod).raises(Errno::EPERM)
|
||||
@ssh.expects(:error_and_exit).once.with(:ssh_bad_permissions, :key_path => @key_path)
|
||||
@ssh.check_key_permissions(@key_path)
|
||||
assert_raises(Vagrant::Errors::SSHKeyBadPermissions) { @ssh.check_key_permissions(@key_path) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue