summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklós Fazekas <mfazekas@szemafor.com>2016-04-20 21:24:31 +0200
committerMiklós Fazekas <mfazekas@szemafor.com>2016-04-20 21:24:31 +0200
commite0ca4a97439357307210cf46ab7376de0d9affbd (patch)
tree399be16bfad257874d84db1f4caab4dc99c8716d
parent0ceca8f39a74daa96d9675147abbe70036904519 (diff)
parent915b0866737b9b1f035b3d7091ee2205dcaf98fc (diff)
downloadnet-ssh-e0ca4a97439357307210cf46ab7376de0d9affbd.tar.gz
Merge pull request #355 from KaneMorgan/nil-start-options
Prevents users explicitly passing in nils in options by accident whic…
-rw-r--r--lib/net/ssh.rb7
-rw-r--r--test/start/test_options.rb14
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/net/ssh.rb b/lib/net/ssh.rb
index 4e97b06..27e5847 100644
--- a/lib/net/ssh.rb
+++ b/lib/net/ssh.rb
@@ -178,7 +178,7 @@ module Net
# * :user_known_hosts_file => the location of the user known hosts file.
# Set to an array to specify multiple user known hosts files.
# Defaults to %w(~/.ssh/known_hosts ~/.ssh/known_hosts2).
- # * :use_agent => Set false to disable the use of ssh-agent. Defaults to
+ # * :use_agent => Set false to disable the use of ssh-agent. Defaults to
# true
# * :non_interactive => set to true if your app is non interactive and prefers
# authentication failure vs password prompt
@@ -203,6 +203,11 @@ module Net
raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
end
+ if options.values.include? nil
+ nil_options = options.keys.select { |k| options[k].nil? }
+ raise ArgumentError, "Value(s) have been set to nil: #{nil_options.join(', ')}"
+ end
+
options[:user] = user if user
options = configuration_for(host, options.fetch(:config, true)).merge(options)
host = options.fetch(:host_name, host)
diff --git a/test/start/test_options.rb b/test/start/test_options.rb
index fa8a40d..ce911b5 100644
--- a/test/start/test_options.rb
+++ b/test/start/test_options.rb
@@ -52,6 +52,20 @@ module NetSSH
Net::SSH.start('localhost', 'testuser', options)
end
end
+
+ def test_constructor_should_reject_options_set_to_nil
+ assert_raises(ArgumentError) do
+ options = { :remote_user => nil}
+ Net::SSH.start('localhost', 'testuser', options)
+ end
+ end
+
+ def test_constructor_should_reject_invalid_options
+ assert_raises(ArgumentError) do
+ options = { :some_invalid_option => "some setting"}
+ Net::SSH.start('localhost', 'testuser', options)
+ end
+ end
end
end