diff options
author | delano <delano@delanotes.com> | 2014-05-12 09:24:26 -0400 |
---|---|---|
committer | delano <delano@delanotes.com> | 2014-05-12 09:24:26 -0400 |
commit | e3ada3068056521126e50f7d0617ae3fa3368c0c (patch) | |
tree | 7e67306da04f34287856d9c53d483188147469be | |
parent | d0eb8b00371330d259a248402021de8eb0cf8cc9 (diff) | |
parent | 8cdbcb159f65cd06c7b38f3e460553149bd0399c (diff) | |
download | net-ssh-e3ada3068056521126e50f7d0617ae3fa3368c0c.tar.gz |
Merge branch 'master' of github.com:net-ssh/net-ssh
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | lib/net/ssh/config.rb | 14 | ||||
-rw-r--r-- | test/configs/negative_match | 6 | ||||
-rw-r--r-- | test/test_config.rb | 6 |
4 files changed, 24 insertions, 3 deletions
diff --git a/.travis.yml b/.travis.yml index 5fe80bd..cfcd613 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: ruby rvm: - "1.9.3" - "2.0.0" - - "2.1.0" install: gem install jeweler test-unit mocha diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb index fb605b2..137b8e3 100644 --- a/lib/net/ssh/config.rb +++ b/lib/net/ssh/config.rb @@ -103,8 +103,18 @@ module Net; module SSH if key == 'host' # Support "Host host1 host2 hostN". # See http://github.com/net-ssh/net-ssh/issues#issue/6 - multi_host = value.to_s.split(/\s+/) - matched_host = multi_host.select { |h| host =~ pattern2regex(h) }.first + negative_hosts, positive_hosts = value.to_s.split(/\s+/).partition { |h| h.start_with?('!') } + + # Check for negative patterns first. If the host matches, that overrules any other positive match. + # The host substring code is used to strip out the starting "!" so the regexp will be correct. + negative_match = negative_hosts.select { |h| host =~ pattern2regex(h[1..-1]) }.first + + if negative_match + matched_host = nil + else + matched_host = positive_hosts.select { |h| host =~ pattern2regex(h) }.first + end + seen_host = true settings[key] = host elsif !seen_host diff --git a/test/configs/negative_match b/test/configs/negative_match new file mode 100644 index 0000000..7a2e5ec --- /dev/null +++ b/test/configs/negative_match @@ -0,0 +1,6 @@ +Host test.* !test.host + Port 1234 + Compression no + +Host test.host + Port 9876
\ No newline at end of file diff --git a/test/test_config.rb b/test/test_config.rb index 761299d..623281e 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -35,6 +35,12 @@ class TestConfig < Test::Unit::TestCase assert !config.key?('rekeylimit') end + def test_load_with_wild_card_and_negative_pattern_does_not_match + config = Net::SSH::Config.load(config(:negative_match), "test.host") + assert_equal 9876, config['port'] + assert !config.key?('compression') + end + def test_for_should_load_all_files_and_translate_to_net_ssh_options config = Net::SSH::Config.for("test.host", [config(:exact_match), config(:wild_cards)]) assert_equal 1234, config[:port] |