summaryrefslogtreecommitdiff
path: root/test/test_proxy_jump.rb
blob: 38363033eb6777e1e0f77a614cd96b24b76515ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require_relative 'common'
require 'net/ssh/proxy/jump'

class TestProxyJump < NetSSHTest
  def test_is_a_proxy_command
    proxy = Net::SSH::Proxy::Jump.new("user@jumphost")
    assert proxy.is_a?(Net::SSH::Proxy::Command)
  end

  def test_host
    proxy = Net::SSH::Proxy::Jump.new("jumphost")
    proxy.build_proxy_command_equivalent
    assert_equal "ssh -W %h:%p jumphost", proxy.command_line_template
  end

  def test_user_host
    proxy = Net::SSH::Proxy::Jump.new("sally@proxy")
    proxy.build_proxy_command_equivalent
    assert_equal "ssh -l sally -W %h:%p proxy", proxy.command_line_template
  end

  def test_user_host_port
    proxy = Net::SSH::Proxy::Jump.new("bob@jump:2222")
    proxy.build_proxy_command_equivalent
    assert_equal "ssh -l bob -p 2222 -W %h:%p jump", proxy.command_line_template
  end

  def test_multiple_jump_proxies
    proxy = Net::SSH::Proxy::Jump.new("user1@proxy1,user2@proxy2,user3@proxy3")
    proxy.build_proxy_command_equivalent
    assert_equal "ssh -l user1 -J user2@proxy2,user3@proxy3 -W %h:%p proxy1", proxy.command_line_template
  end

  def test_config_override
    proxy = Net::SSH::Proxy::Jump.new("proxy")
    proxy.build_proxy_command_equivalent(config: "/home/user/.ssh/config2")
    assert_equal "ssh -F /home/user/.ssh/config2 -W %h:%p proxy", proxy.command_line_template
  end

  def test_config_false
    proxy = Net::SSH::Proxy::Jump.new("proxy")
    proxy.build_proxy_command_equivalent(config: false)
    assert_equal "ssh -W %h:%p proxy", proxy.command_line_template
  end

  def test_config_true
    proxy = Net::SSH::Proxy::Jump.new("proxy")
    proxy.build_proxy_command_equivalent(config: true)
    assert_equal "ssh -W %h:%p proxy", proxy.command_line_template
  end
end