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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
require_relative '../common'
require 'net/ssh'
module NetSSH
class TestStartOptions < NetSSHTest
def setup
authentication_session = mock('authentication_session')
authentication_session.stubs(:authenticate).returns(true)
Net::SSH::Authentication::Session.stubs(:new).returns(authentication_session)
Net::SSH::Transport::Session.stubs(:new).returns(mock('transport_session'))
Net::SSH::Connection::Session.stubs(:new).returns(mock('connection_session'))
end
def test_start_should_accept_keepalive_option
assert_nothing_raised do
options = { keepalive: true }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_start_should_accept_keepalive_interval_option
assert_nothing_raised do
options = { keepalive_interval: 10 }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_start_should_accept_send_env_option
assert_nothing_raised do
options = { send_env: [/^LC_.*$/, "LANG"] }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_start_should_accept_set_env_option
assert_nothing_raised do
options = { set_env: { foo: 'bar', baz: 'whale will' } }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_start_should_accept_number_of_password_prompts_option
assert_nothing_raised do
options = { number_of_password_prompts: 2 }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_start_should_accept_append_all_supported_algorithms_option
assert_nothing_raised do
options = { append_all_supported_algorithms: true }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_start_should_accept_non_interactive_option
assert_nothing_raised do
options = { non_interactive: true }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_start_should_accept_remote_user_option
assert_nothing_raised do
options = { remote_user: 'foo' }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_constructor_should_reject_options_set_to_nil
Kernel.expects(:warn).with { |message| message =~ /remote_user/ }.once
options = { remote_user: nil }
Net::SSH.start('localhost', 'testuser', options)
end
def test_constructor_should_reject_options_set_to_array_of_nil
Kernel.expects(:warn).with { |message| message =~ /keys/ }.once
ENV.delete('no-such-env-variable')
Net::SSH.start('localhost', 'testuser', keys: [ENV['no-such-env-variable']])
end
def test_constructor_should_not_reject_nil_password_options_for_cap_v2_compatibility
assert_nothing_raised do
options = { password: nil }
Net::SSH.start('localhost', 'testuser', options)
end
end
def test_constructor_should_not_reject_nil_passpharse
assert_nothing_raised do
options = { passphrase: 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
def test_constructor_should_set_default_options
options = { logger: nil, password_prompt: nil }
Net::SSH.start('localhost', 'testuser', options)
assert !options[:logger].nil?
assert !options[:password_prompt].nil?
end
end
end
|