summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklós Fazekas <mfazekas@szemafor.com>2018-02-28 09:10:43 +0100
committerGitHub <noreply@github.com>2018-02-28 09:10:43 +0100
commitb8fdd0a7fc4f283f0d87a4e603b3db94a91b335f (patch)
tree92b06c5c73ee380c4c3db953cb4665a6b194b0f9
parent0d008be966b04016d3e6bbed0987421d0102a92c (diff)
parent28965db543361aa703821a07ba33a19dea1ffc13 (diff)
downloadnet-ssh-b8fdd0a7fc4f283f0d87a4e603b3db94a91b335f.tar.gz
Merge pull request #540 from fl0at/default_files_sideeffects
Fixed side-effects caused by passing by reference
-rw-r--r--lib/net/ssh/config.rb4
-rw-r--r--test/test_config.rb18
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb
index 2c98b5b..b5e360e 100644
--- a/lib/net/ssh/config.rb
+++ b/lib/net/ssh/config.rb
@@ -49,11 +49,11 @@ module Net; module SSH
# Returns an array of locations of OpenSSH configuration files
# to parse by default.
def default_files
- @@default_files
+ @@default_files.clone
end
def default_auth_methods
- @@default_auth_methods
+ @@default_auth_methods.clone
end
# Loads the configuration data for the given +host+ from all of the
diff --git a/test/test_config.rb b/test/test_config.rb
index 662a01d..13270c0 100644
--- a/test/test_config.rb
+++ b/test/test_config.rb
@@ -286,6 +286,24 @@ class TestConfig < NetSSHTest
assert_equal %w(~/.ssh/id.pem ~/.ssh/id2.pem ~/.ssh/id3.pem), net_ssh[:keys]
end
+ def test_default_files_not_mutable
+ original_default_files = Net::SSH::Config.default_files.clone
+
+ default_files = Net::SSH::Config.default_files
+ default_files.push('garbage')
+
+ assert_equal(original_default_files, Net::SSH::Config.default_files)
+ end
+
+ def test_default_auth_methods_not_mutable
+ original_default_auth_methods = Net::SSH::Config.default_auth_methods.clone
+
+ default_auth_methods = Net::SSH::Config.default_auth_methods
+ default_auth_methods.push('garbage')
+
+ assert_equal(original_default_auth_methods, Net::SSH::Config.default_auth_methods)
+ end
+
def test_load_with_match_block
config = Net::SSH::Config.load(config(:match), "test.host")
net_ssh = Net::SSH::Config.translate(config)