diff options
author | Kane Morgan <kane.a.s.morgan@gmail.com> | 2016-04-17 15:30:44 +0100 |
---|---|---|
committer | Kane Morgan <kane.a.s.morgan@gmail.com> | 2016-04-17 15:30:44 +0100 |
commit | 915b0866737b9b1f035b3d7091ee2205dcaf98fc (patch) | |
tree | 399be16bfad257874d84db1f4caab4dc99c8716d | |
parent | 0ceca8f39a74daa96d9675147abbe70036904519 (diff) | |
download | net-ssh-915b0866737b9b1f035b3d7091ee2205dcaf98fc.tar.gz |
Prevent nils being explicitly passed in at start up time
-rw-r--r-- | lib/net/ssh.rb | 7 | ||||
-rw-r--r-- | test/start/test_options.rb | 14 |
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 |