auser-poolparty 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/bin/cloud-bootstrap +1 -0
- data/bin/cloud-configure +1 -0
- data/bin/cloud-contract +1 -0
- data/bin/poolparty-setup +36 -0
- data/examples/vmware.rb +18 -0
- data/lib/cloud_providers/cloud_provider_instance.rb +1 -1
- data/lib/core/object.rb +2 -2
- data/lib/dependency_resolvers/chef.rb +2 -2
- data/lib/mixins/askable.rb +16 -7
- data/lib/poolparty/base.rb +9 -7
- data/lib/poolparty/cloud.rb +57 -2
- data/lib/poolparty/installer.rb +8 -4
- data/lib/poolparty/installers/ec2.rb +75 -5
- data/lib/poolparty/installers/vmware.rb +17 -5
- data/lib/poolparty/plugins/apache.rb +3 -2
- data/lib/poolparty/plugins/apache2/base.conf.erb +2 -2
- data/lib/poolparty/plugins/apache2/browser_fixes.conf.erb +1 -1
- data/lib/poolparty/plugins/apache2/passenger_site.rb +2 -2
- data/lib/poolparty/pool.rb +9 -2
- data/lib/poolparty/resource.rb +20 -7
- data/lib/poolparty/resources/directory.rb +5 -1
- data/lib/poolparty/resources/exec.rb +2 -2
- data/lib/poolparty/resources/file.rb +8 -2
- data/lib/poolparty/resources/gem_package.rb +2 -2
- data/lib/poolparty/resources/line.rb +23 -6
- data/lib/poolparty/resources/mount.rb +2 -2
- data/lib/poolparty/resources/package.rb +2 -2
- data/lib/poolparty/resources/service.rb +2 -2
- data/lib/poolparty/resources/user.rb +2 -2
- data/lib/poolparty.rb +2 -2
- data/test/lib/poolparty/base_test.rb +13 -0
- data/test/lib/poolparty/resources/line_test.rb +3 -3
- data/test/lib/poolparty/resources/service_test.rb +1 -1
- data/vendor/gems/net-ssh/CHANGELOG.rdoc +127 -0
- data/vendor/gems/net-ssh/Manifest +104 -0
- data/vendor/gems/net-ssh/README.rdoc +110 -0
- data/vendor/gems/net-ssh/Rakefile +26 -0
- data/vendor/gems/net-ssh/THANKS.rdoc +16 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/agent.rb +176 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/constants.rb +18 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/key_manager.rb +193 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/pageant.rb +183 -0
- data/vendor/gems/net-ssh/lib/net/ssh/authentication/session.rb +134 -0
- data/vendor/gems/net-ssh/lib/net/ssh/buffer.rb +340 -0
- data/vendor/gems/net-ssh/lib/net/ssh/buffered_io.rb +149 -0
- data/vendor/gems/net-ssh/lib/net/ssh/config.rb +181 -0
- data/vendor/gems/net-ssh/lib/net/ssh/connection/channel.rb +625 -0
- data/vendor/gems/net-ssh/lib/net/ssh/connection/constants.rb +33 -0
- data/vendor/gems/net-ssh/lib/net/ssh/connection/session.rb +596 -0
- data/vendor/gems/net-ssh/lib/net/ssh/connection/term.rb +178 -0
- data/vendor/gems/net-ssh/lib/net/ssh/errors.rb +85 -0
- data/vendor/gems/net-ssh/lib/net/ssh/key_factory.rb +102 -0
- data/vendor/gems/net-ssh/lib/net/ssh/known_hosts.rb +129 -0
- data/vendor/gems/net-ssh/lib/net/ssh/loggable.rb +61 -0
- data/vendor/gems/net-ssh/lib/net/ssh/packet.rb +102 -0
- data/vendor/gems/net-ssh/lib/net/ssh/prompt.rb +93 -0
- data/vendor/gems/net-ssh/lib/net/ssh/proxy/errors.rb +14 -0
- data/vendor/gems/net-ssh/lib/net/ssh/proxy/http.rb +94 -0
- data/vendor/gems/net-ssh/lib/net/ssh/proxy/socks4.rb +70 -0
- data/vendor/gems/net-ssh/lib/net/ssh/proxy/socks5.rb +129 -0
- data/vendor/gems/net-ssh/lib/net/ssh/ruby_compat.rb +7 -0
- data/vendor/gems/net-ssh/lib/net/ssh/service/forward.rb +267 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/channel.rb +129 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/extensions.rb +152 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/kex.rb +44 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/local_packet.rb +51 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/packet.rb +81 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/remote_packet.rb +38 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/script.rb +157 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test/socket.rb +59 -0
- data/vendor/gems/net-ssh/lib/net/ssh/test.rb +89 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/algorithms.rb +384 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/cipher_factory.rb +80 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/constants.rb +30 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/abstract.rb +78 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/hmac.rb +31 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/kex.rb +13 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/openssl.rb +128 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/packet_stream.rb +230 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/server_version.rb +60 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/session.rb +276 -0
- data/vendor/gems/net-ssh/lib/net/ssh/transport/state.rb +201 -0
- data/vendor/gems/net-ssh/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/vendor/gems/net-ssh/lib/net/ssh/verifiers/null.rb +12 -0
- data/vendor/gems/net-ssh/lib/net/ssh/verifiers/strict.rb +53 -0
- data/vendor/gems/net-ssh/lib/net/ssh/version.rb +62 -0
- data/vendor/gems/net-ssh/lib/net/ssh.rb +215 -0
- data/vendor/gems/net-ssh/net-ssh.gemspec +33 -0
- data/vendor/gems/net-ssh/setup.rb +1585 -0
- data/vendor/gems/net-ssh/test/authentication/methods/common.rb +28 -0
- data/vendor/gems/net-ssh/test/authentication/methods/test_abstract.rb +51 -0
- data/vendor/gems/net-ssh/test/authentication/methods/test_hostbased.rb +114 -0
- data/vendor/gems/net-ssh/test/authentication/methods/test_keyboard_interactive.rb +98 -0
- data/vendor/gems/net-ssh/test/authentication/methods/test_password.rb +50 -0
- data/vendor/gems/net-ssh/test/authentication/methods/test_publickey.rb +127 -0
- data/vendor/gems/net-ssh/test/authentication/test_agent.rb +205 -0
- data/vendor/gems/net-ssh/test/authentication/test_key_manager.rb +105 -0
- data/vendor/gems/net-ssh/test/authentication/test_session.rb +93 -0
- data/vendor/gems/net-ssh/test/common.rb +106 -0
- data/vendor/gems/net-ssh/test/configs/eqsign +3 -0
- data/vendor/gems/net-ssh/test/configs/exact_match +8 -0
- data/vendor/gems/net-ssh/test/configs/wild_cards +14 -0
- data/vendor/gems/net-ssh/test/connection/test_channel.rb +452 -0
- data/vendor/gems/net-ssh/test/connection/test_session.rb +488 -0
- data/vendor/gems/net-ssh/test/test_all.rb +6 -0
- data/vendor/gems/net-ssh/test/test_buffer.rb +336 -0
- data/vendor/gems/net-ssh/test/test_buffered_io.rb +63 -0
- data/vendor/gems/net-ssh/test/test_config.rb +84 -0
- data/vendor/gems/net-ssh/test/test_key_factory.rb +67 -0
- data/vendor/gems/net-ssh/test/transport/hmac/test_md5.rb +39 -0
- data/vendor/gems/net-ssh/test/transport/hmac/test_md5_96.rb +25 -0
- data/vendor/gems/net-ssh/test/transport/hmac/test_none.rb +34 -0
- data/vendor/gems/net-ssh/test/transport/hmac/test_sha1.rb +34 -0
- data/vendor/gems/net-ssh/test/transport/hmac/test_sha1_96.rb +25 -0
- data/vendor/gems/net-ssh/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
- data/vendor/gems/net-ssh/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
- data/vendor/gems/net-ssh/test/transport/test_algorithms.rb +302 -0
- data/vendor/gems/net-ssh/test/transport/test_cipher_factory.rb +171 -0
- data/vendor/gems/net-ssh/test/transport/test_hmac.rb +34 -0
- data/vendor/gems/net-ssh/test/transport/test_identity_cipher.rb +40 -0
- data/vendor/gems/net-ssh/test/transport/test_packet_stream.rb +435 -0
- data/vendor/gems/net-ssh/test/transport/test_server_version.rb +57 -0
- data/vendor/gems/net-ssh/test/transport/test_session.rb +315 -0
- data/vendor/gems/net-ssh/test/transport/test_state.rb +173 -0
- metadata +109 -4
- data/bin/install-poolparty +0 -20
@@ -0,0 +1,28 @@
|
|
1
|
+
module Authentication; module Methods
|
2
|
+
|
3
|
+
module Common
|
4
|
+
include Net::SSH::Authentication::Constants
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def socket(options={})
|
9
|
+
@socket ||= stub("socket", :client_name => "me.ssh.test")
|
10
|
+
end
|
11
|
+
|
12
|
+
def transport(options={})
|
13
|
+
@transport ||= MockTransport.new(options.merge(:socket => socket))
|
14
|
+
end
|
15
|
+
|
16
|
+
def session(options={})
|
17
|
+
@session ||= begin
|
18
|
+
sess = stub("auth-session", :logger => nil, :transport => transport(options))
|
19
|
+
def sess.next_message
|
20
|
+
transport.next_message
|
21
|
+
end
|
22
|
+
sess
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end; end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'authentication/methods/common'
|
3
|
+
require 'net/ssh/authentication/methods/abstract'
|
4
|
+
|
5
|
+
module Authentication; module Methods
|
6
|
+
|
7
|
+
class TestAbstract < Test::Unit::TestCase
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def test_constructor_should_set_defaults
|
11
|
+
assert_nil subject.key_manager
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_constructor_should_honor_options
|
15
|
+
assert_equal :manager, subject(:key_manager => :manager).key_manager
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_session_id_should_query_session_id_from_key_exchange
|
19
|
+
transport.stubs(:algorithms).returns(stub("algorithms", :session_id => "abcxyz123"))
|
20
|
+
assert_equal "abcxyz123", subject.session_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_send_message_should_delegate_to_transport
|
24
|
+
transport.expects(:send_message).with("abcxyz123")
|
25
|
+
subject.send_message("abcxyz123")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_userauth_request_should_build_well_formed_userauth_packet
|
29
|
+
packet = subject.userauth_request("jamis", "ssh-connection", "password")
|
30
|
+
assert_equal "\062\0\0\0\005jamis\0\0\0\016ssh-connection\0\0\0\010password", packet.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_userauth_request_should_translate_extra_booleans_onto_end
|
34
|
+
packet = subject.userauth_request("jamis", "ssh-connection", "password", true, false)
|
35
|
+
assert_equal "\062\0\0\0\005jamis\0\0\0\016ssh-connection\0\0\0\010password\1\0", packet.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_userauth_request_should_translate_extra_strings_onto_end
|
39
|
+
packet = subject.userauth_request("jamis", "ssh-connection", "password", "foo", "bar")
|
40
|
+
assert_equal "\062\0\0\0\005jamis\0\0\0\016ssh-connection\0\0\0\010password\0\0\0\3foo\0\0\0\3bar", packet.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def subject(options={})
|
46
|
+
@subject ||= Net::SSH::Authentication::Methods::Abstract.new(session(options), options)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end; end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'net/ssh/authentication/methods/hostbased'
|
3
|
+
require 'authentication/methods/common'
|
4
|
+
|
5
|
+
module Authentication; module Methods
|
6
|
+
|
7
|
+
class TestHostbased < Test::Unit::TestCase
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def test_authenticate_should_return_false_when_no_key_manager_has_been_set
|
11
|
+
assert_equal false, subject(:key_manager => nil).authenticate("ssh-connection", "jamis")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_authenticate_should_return_false_when_key_manager_has_no_keys
|
15
|
+
assert_equal false, subject(:keys => []).authenticate("ssh-connection", "jamis")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_authenticate_should_return_false_if_no_keys_can_authenticate
|
19
|
+
ENV.stubs(:[]).with('USER').returns(nil)
|
20
|
+
key_manager.expects(:sign).with(&signature_parameters(keys.first)).returns("sig-one")
|
21
|
+
key_manager.expects(:sign).with(&signature_parameters(keys.last)).returns("sig-two")
|
22
|
+
|
23
|
+
transport.expect do |t, packet|
|
24
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
25
|
+
assert verify_userauth_request_packet(packet, keys.first)
|
26
|
+
assert_equal "sig-one", packet.read_string
|
27
|
+
t.return(USERAUTH_FAILURE, :string, "hostbased,password")
|
28
|
+
|
29
|
+
t.expect do |t2, packet2|
|
30
|
+
assert_equal USERAUTH_REQUEST, packet2.type
|
31
|
+
assert verify_userauth_request_packet(packet2, keys.last)
|
32
|
+
assert_equal "sig-two", packet2.read_string
|
33
|
+
t2.return(USERAUTH_FAILURE, :string, "hostbased,password")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal false, subject.authenticate("ssh-connection", "jamis")
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_authenticate_should_return_true_if_any_key_can_authenticate
|
41
|
+
ENV.stubs(:[]).with('USER').returns(nil)
|
42
|
+
key_manager.expects(:sign).with(&signature_parameters(keys.first)).returns("sig-one")
|
43
|
+
|
44
|
+
transport.expect do |t, packet|
|
45
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
46
|
+
assert verify_userauth_request_packet(packet, keys.first)
|
47
|
+
assert_equal "sig-one", packet.read_string
|
48
|
+
t.return(USERAUTH_SUCCESS)
|
49
|
+
end
|
50
|
+
|
51
|
+
assert subject.authenticate("ssh-connection", "jamis")
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def signature_parameters(key)
|
57
|
+
Proc.new do |given_key, data|
|
58
|
+
next false unless given_key.to_blob == key.to_blob
|
59
|
+
buffer = Net::SSH::Buffer.new(data)
|
60
|
+
buffer.read_string == "abcxyz123" && # session-id
|
61
|
+
buffer.read_byte == USERAUTH_REQUEST && # type
|
62
|
+
verify_userauth_request_packet(buffer, key)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def verify_userauth_request_packet(packet, key)
|
67
|
+
packet.read_string == "jamis" && # user-name
|
68
|
+
packet.read_string == "ssh-connection" && # next service
|
69
|
+
packet.read_string == "hostbased" && # auth-method
|
70
|
+
packet.read_string == key.ssh_type && # key type
|
71
|
+
packet.read_buffer.read_key.to_blob == key.to_blob && # key
|
72
|
+
packet.read_string == "me.ssh.test." && # client hostname
|
73
|
+
packet.read_string == "jamis" # client username
|
74
|
+
end
|
75
|
+
|
76
|
+
@@keys = nil
|
77
|
+
def keys
|
78
|
+
@@keys ||= [OpenSSL::PKey::RSA.new(32), OpenSSL::PKey::DSA.new(32)]
|
79
|
+
end
|
80
|
+
|
81
|
+
def key_manager(options={})
|
82
|
+
@key_manager ||= begin
|
83
|
+
manager = stub("key_manager")
|
84
|
+
manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys))
|
85
|
+
manager
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def subject(options={})
|
90
|
+
options[:key_manager] = key_manager(options) unless options.key?(:key_manager)
|
91
|
+
@subject ||= Net::SSH::Authentication::Methods::Hostbased.new(session(options), options)
|
92
|
+
end
|
93
|
+
|
94
|
+
def socket(options={})
|
95
|
+
@socket ||= stub("socket", :client_name => "me.ssh.test")
|
96
|
+
end
|
97
|
+
|
98
|
+
def transport(options={})
|
99
|
+
@transport ||= MockTransport.new(options.merge(:socket => socket))
|
100
|
+
end
|
101
|
+
|
102
|
+
def session(options={})
|
103
|
+
@session ||= begin
|
104
|
+
sess = stub("auth-session", :logger => nil, :transport => transport(options))
|
105
|
+
def sess.next_message
|
106
|
+
transport.next_message
|
107
|
+
end
|
108
|
+
sess
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end; end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'net/ssh/authentication/methods/keyboard_interactive'
|
3
|
+
require 'authentication/methods/common'
|
4
|
+
|
5
|
+
module Authentication; module Methods
|
6
|
+
|
7
|
+
class TestKeyboardInteractive < Test::Unit::TestCase
|
8
|
+
include Common
|
9
|
+
|
10
|
+
USERAUTH_INFO_REQUEST = 60
|
11
|
+
USERAUTH_INFO_RESPONSE = 61
|
12
|
+
|
13
|
+
def test_authenticate_should_be_false_when_server_does_not_support_this_method
|
14
|
+
transport.expect do |t,packet|
|
15
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
16
|
+
assert_equal "jamis", packet.read_string
|
17
|
+
assert_equal "ssh-connection", packet.read_string
|
18
|
+
assert_equal "keyboard-interactive", packet.read_string
|
19
|
+
assert_equal "", packet.read_string # language tags
|
20
|
+
assert_equal "", packet.read_string # submethods
|
21
|
+
|
22
|
+
t.return(USERAUTH_FAILURE, :string, "password")
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_equal false, subject.authenticate("ssh-connection", "jamis")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_authenticate_should_be_false_if_given_password_is_not_accepted
|
29
|
+
transport.expect do |t,packet|
|
30
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
31
|
+
t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 1, :string, "Password:", :bool, false)
|
32
|
+
t.expect do |t2,packet2|
|
33
|
+
assert_equal USERAUTH_INFO_RESPONSE, packet2.type
|
34
|
+
assert_equal 1, packet2.read_long
|
35
|
+
assert_equal "the-password", packet2.read_string
|
36
|
+
t2.return(USERAUTH_FAILURE, :string, "publickey")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_equal false, subject.authenticate("ssh-connection", "jamis", "the-password")
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_authenticate_should_be_true_if_given_password_is_accepted
|
44
|
+
transport.expect do |t,packet|
|
45
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
46
|
+
t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 1, :string, "Password:", :bool, false)
|
47
|
+
t.expect do |t2,packet2|
|
48
|
+
assert_equal USERAUTH_INFO_RESPONSE, packet2.type
|
49
|
+
t2.return(USERAUTH_SUCCESS)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
assert subject.authenticate("ssh-connection", "jamis", "the-password")
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_authenticate_should_duplicate_password_as_needed_to_fill_request
|
57
|
+
transport.expect do |t,packet|
|
58
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
59
|
+
t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 2, :string, "Password:", :bool, false, :string, "Again:", :bool, false)
|
60
|
+
t.expect do |t2,packet2|
|
61
|
+
assert_equal USERAUTH_INFO_RESPONSE, packet2.type
|
62
|
+
assert_equal 2, packet2.read_long
|
63
|
+
assert_equal "the-password", packet2.read_string
|
64
|
+
assert_equal "the-password", packet2.read_string
|
65
|
+
t2.return(USERAUTH_SUCCESS)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
assert subject.authenticate("ssh-connection", "jamis", "the-password")
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_authenticate_should_prompt_for_input_when_password_is_not_given
|
73
|
+
subject.expects(:prompt).with("Name:", true).returns("name")
|
74
|
+
subject.expects(:prompt).with("Password:", false).returns("password")
|
75
|
+
|
76
|
+
transport.expect do |t,packet|
|
77
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
78
|
+
t.return(USERAUTH_INFO_REQUEST, :string, "", :string, "", :string, "", :long, 2, :string, "Name:", :bool, true, :string, "Password:", :bool, false)
|
79
|
+
t.expect do |t2,packet2|
|
80
|
+
assert_equal USERAUTH_INFO_RESPONSE, packet2.type
|
81
|
+
assert_equal 2, packet2.read_long
|
82
|
+
assert_equal "name", packet2.read_string
|
83
|
+
assert_equal "password", packet2.read_string
|
84
|
+
t2.return(USERAUTH_SUCCESS)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
assert subject.authenticate("ssh-connection", "jamis", nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def subject(options={})
|
94
|
+
@subject ||= Net::SSH::Authentication::Methods::KeyboardInteractive.new(session(options), options)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end; end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'net/ssh/authentication/methods/password'
|
3
|
+
require 'authentication/methods/common'
|
4
|
+
|
5
|
+
module Authentication; module Methods
|
6
|
+
|
7
|
+
class TestPassword < Test::Unit::TestCase
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def test_authenticate_when_password_is_unacceptible_should_return_false
|
11
|
+
transport.expect do |t,packet|
|
12
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
13
|
+
assert_equal "jamis", packet.read_string
|
14
|
+
assert_equal "ssh-connection", packet.read_string
|
15
|
+
assert_equal "password", packet.read_string
|
16
|
+
assert_equal false, packet.read_bool
|
17
|
+
assert_equal "the-password", packet.read_string
|
18
|
+
|
19
|
+
t.return(USERAUTH_FAILURE, :string, "publickey")
|
20
|
+
end
|
21
|
+
|
22
|
+
assert !subject.authenticate("ssh-connection", "jamis", "the-password")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_authenticate_when_password_is_acceptible_should_return_true
|
26
|
+
transport.expect do |t,packet|
|
27
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
28
|
+
t.return(USERAUTH_SUCCESS)
|
29
|
+
end
|
30
|
+
|
31
|
+
assert subject.authenticate("ssh-connection", "jamis", "the-password")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_authenticate_should_return_false_if_password_change_request_is_received
|
35
|
+
transport.expect do |t,packet|
|
36
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
37
|
+
t.return(USERAUTH_PASSWD_CHANGEREQ, :string, "Change your password:", :string, "")
|
38
|
+
end
|
39
|
+
|
40
|
+
assert !subject.authenticate("ssh-connection", "jamis", "the-password")
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def subject(options={})
|
46
|
+
@subject ||= Net::SSH::Authentication::Methods::Password.new(session(options), options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end; end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'net/ssh/authentication/methods/publickey'
|
3
|
+
require 'authentication/methods/common'
|
4
|
+
|
5
|
+
module Authentication; module Methods
|
6
|
+
|
7
|
+
class TestPublickey < Test::Unit::TestCase
|
8
|
+
include Common
|
9
|
+
|
10
|
+
def test_authenticate_should_return_false_when_no_key_manager_has_been_set
|
11
|
+
assert_equal false, subject(:key_manager => nil).authenticate("ssh-connection", "jamis")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_authenticate_should_return_false_when_key_manager_has_no_keys
|
15
|
+
assert_equal false, subject(:keys => []).authenticate("ssh-connection", "jamis")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_authenticate_should_return_false_if_no_keys_can_authenticate
|
19
|
+
transport.expect do |t, packet|
|
20
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
21
|
+
assert verify_userauth_request_packet(packet, keys.first, false)
|
22
|
+
t.return(USERAUTH_FAILURE, :string, "hostbased,password")
|
23
|
+
|
24
|
+
t.expect do |t2, packet2|
|
25
|
+
assert_equal USERAUTH_REQUEST, packet2.type
|
26
|
+
assert verify_userauth_request_packet(packet2, keys.last, false)
|
27
|
+
t2.return(USERAUTH_FAILURE, :string, "hostbased,password")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_equal false, subject.authenticate("ssh-connection", "jamis")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_authenticate_should_return_false_if_signature_exchange_fails
|
35
|
+
key_manager.expects(:sign).with(&signature_parameters(keys.first)).returns("sig-one")
|
36
|
+
key_manager.expects(:sign).with(&signature_parameters(keys.last)).returns("sig-two")
|
37
|
+
|
38
|
+
transport.expect do |t, packet|
|
39
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
40
|
+
assert verify_userauth_request_packet(packet, keys.first, false)
|
41
|
+
t.return(USERAUTH_PK_OK, :string, keys.first.ssh_type, :string, Net::SSH::Buffer.from(:key, keys.first))
|
42
|
+
|
43
|
+
t.expect do |t2,packet2|
|
44
|
+
assert_equal USERAUTH_REQUEST, packet2.type
|
45
|
+
assert verify_userauth_request_packet(packet2, keys.first, true)
|
46
|
+
assert_equal "sig-one", packet2.read_string
|
47
|
+
t2.return(USERAUTH_FAILURE, :string, "hostbased,password")
|
48
|
+
|
49
|
+
t2.expect do |t3, packet3|
|
50
|
+
assert_equal USERAUTH_REQUEST, packet3.type
|
51
|
+
assert verify_userauth_request_packet(packet3, keys.last, false)
|
52
|
+
t3.return(USERAUTH_PK_OK, :string, keys.last.ssh_type, :string, Net::SSH::Buffer.from(:key, keys.last))
|
53
|
+
|
54
|
+
t3.expect do |t4,packet4|
|
55
|
+
assert_equal USERAUTH_REQUEST, packet4.type
|
56
|
+
assert verify_userauth_request_packet(packet4, keys.last, true)
|
57
|
+
assert_equal "sig-two", packet4.read_string
|
58
|
+
t4.return(USERAUTH_FAILURE, :string, "hostbased,password")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
assert !subject.authenticate("ssh-connection", "jamis")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_authenticate_should_return_true_if_any_key_can_authenticate
|
68
|
+
key_manager.expects(:sign).with(&signature_parameters(keys.first)).returns("sig-one")
|
69
|
+
|
70
|
+
transport.expect do |t, packet|
|
71
|
+
assert_equal USERAUTH_REQUEST, packet.type
|
72
|
+
assert verify_userauth_request_packet(packet, keys.first, false)
|
73
|
+
t.return(USERAUTH_PK_OK, :string, keys.first.ssh_type, :string, Net::SSH::Buffer.from(:key, keys.first))
|
74
|
+
|
75
|
+
t.expect do |t2,packet2|
|
76
|
+
assert_equal USERAUTH_REQUEST, packet2.type
|
77
|
+
assert verify_userauth_request_packet(packet2, keys.first, true)
|
78
|
+
assert_equal "sig-one", packet2.read_string
|
79
|
+
t2.return(USERAUTH_SUCCESS)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
assert subject.authenticate("ssh-connection", "jamis")
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def signature_parameters(key)
|
89
|
+
Proc.new do |given_key, data|
|
90
|
+
next false unless given_key.to_blob == key.to_blob
|
91
|
+
buffer = Net::SSH::Buffer.new(data)
|
92
|
+
buffer.read_string == "abcxyz123" && # session-id
|
93
|
+
buffer.read_byte == USERAUTH_REQUEST && # type
|
94
|
+
verify_userauth_request_packet(buffer, key, true)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def verify_userauth_request_packet(packet, key, has_sig)
|
99
|
+
packet.read_string == "jamis" && # user-name
|
100
|
+
packet.read_string == "ssh-connection" && # next service
|
101
|
+
packet.read_string == "publickey" && # auth-method
|
102
|
+
packet.read_bool == has_sig && # whether a signature is appended
|
103
|
+
packet.read_string == key.ssh_type && # ssh key type
|
104
|
+
packet.read_buffer.read_key.to_blob == key.to_blob # key
|
105
|
+
end
|
106
|
+
|
107
|
+
@@keys = nil
|
108
|
+
def keys
|
109
|
+
@@keys ||= [OpenSSL::PKey::RSA.new(32), OpenSSL::PKey::DSA.new(32)]
|
110
|
+
end
|
111
|
+
|
112
|
+
def key_manager(options={})
|
113
|
+
@key_manager ||= begin
|
114
|
+
manager = stub("key_manager")
|
115
|
+
manager.stubs(:each_identity).multiple_yields(*(options[:keys] || keys))
|
116
|
+
manager
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def subject(options={})
|
121
|
+
options[:key_manager] = key_manager(options) unless options.key?(:key_manager)
|
122
|
+
@subject ||= Net::SSH::Authentication::Methods::Publickey.new(session(options), options)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end; end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'net/ssh/authentication/agent'
|
3
|
+
|
4
|
+
module Authentication
|
5
|
+
|
6
|
+
class TestAgent < Test::Unit::TestCase
|
7
|
+
|
8
|
+
SSH2_AGENT_REQUEST_VERSION = 1
|
9
|
+
SSH2_AGENT_REQUEST_IDENTITIES = 11
|
10
|
+
SSH2_AGENT_IDENTITIES_ANSWER = 12
|
11
|
+
SSH2_AGENT_SIGN_REQUEST = 13
|
12
|
+
SSH2_AGENT_SIGN_RESPONSE = 14
|
13
|
+
SSH2_AGENT_FAILURE = 30
|
14
|
+
SSH2_AGENT_VERSION_RESPONSE = 103
|
15
|
+
|
16
|
+
SSH_COM_AGENT2_FAILURE = 102
|
17
|
+
|
18
|
+
SSH_AGENT_REQUEST_RSA_IDENTITIES = 1
|
19
|
+
SSH_AGENT_RSA_IDENTITIES_ANSWER = 2
|
20
|
+
SSH_AGENT_FAILURE = 5
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@original, ENV['SSH_AUTH_SOCK'] = ENV['SSH_AUTH_SOCK'], "/path/to/ssh.agent.sock"
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
ENV['SSH_AUTH_SOCK'] = @original
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_connect_should_use_agent_factory_to_determine_connection_type
|
31
|
+
factory.expects(:open).with("/path/to/ssh.agent.sock").returns(socket)
|
32
|
+
agent(false).connect!
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_connect_should_raise_error_if_connection_could_not_be_established
|
36
|
+
factory.expects(:open).raises(SocketError)
|
37
|
+
assert_raises(Net::SSH::Authentication::AgentNotAvailable) { agent(false).connect! }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_negotiate_should_raise_error_if_ssh2_agent_response_recieved
|
41
|
+
socket.expect do |s, type, buffer|
|
42
|
+
assert_equal SSH2_AGENT_REQUEST_VERSION, type
|
43
|
+
assert_equal Net::SSH::Transport::ServerVersion::PROTO_VERSION, buffer.read_string
|
44
|
+
s.return(SSH2_AGENT_VERSION_RESPONSE)
|
45
|
+
end
|
46
|
+
assert_raises(NotImplementedError) { agent.negotiate! }
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_negotiate_should_raise_error_if_response_was_unexpected
|
50
|
+
socket.expect do |s, type, buffer|
|
51
|
+
assert_equal SSH2_AGENT_REQUEST_VERSION, type
|
52
|
+
s.return(255)
|
53
|
+
end
|
54
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.negotiate! }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_negotiate_should_be_successful_with_expected_response
|
58
|
+
socket.expect do |s, type, buffer|
|
59
|
+
assert_equal SSH2_AGENT_REQUEST_VERSION, type
|
60
|
+
s.return(SSH_AGENT_RSA_IDENTITIES_ANSWER)
|
61
|
+
end
|
62
|
+
assert_nothing_raised { agent(:connect).negotiate! }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_identities_should_fail_if_SSH_AGENT_FAILURE_recieved
|
66
|
+
socket.expect do |s, type, buffer|
|
67
|
+
assert_equal SSH2_AGENT_REQUEST_IDENTITIES, type
|
68
|
+
s.return(SSH_AGENT_FAILURE)
|
69
|
+
end
|
70
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.identities }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_identities_should_fail_if_SSH2_AGENT_FAILURE_recieved
|
74
|
+
socket.expect do |s, type, buffer|
|
75
|
+
assert_equal SSH2_AGENT_REQUEST_IDENTITIES, type
|
76
|
+
s.return(SSH2_AGENT_FAILURE)
|
77
|
+
end
|
78
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.identities }
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_identities_should_fail_if_SSH_COM_AGENT2_FAILURE_recieved
|
82
|
+
socket.expect do |s, type, buffer|
|
83
|
+
assert_equal SSH2_AGENT_REQUEST_IDENTITIES, type
|
84
|
+
s.return(SSH_COM_AGENT2_FAILURE)
|
85
|
+
end
|
86
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.identities }
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_identities_should_fail_if_response_is_not_SSH2_AGENT_IDENTITIES_ANSWER
|
90
|
+
socket.expect do |s, type, buffer|
|
91
|
+
assert_equal SSH2_AGENT_REQUEST_IDENTITIES, type
|
92
|
+
s.return(255)
|
93
|
+
end
|
94
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.identities }
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_identities_should_augment_identities_with_comment_field
|
98
|
+
key1 = key
|
99
|
+
key2 = OpenSSL::PKey::DSA.new(32)
|
100
|
+
|
101
|
+
socket.expect do |s, type, buffer|
|
102
|
+
assert_equal SSH2_AGENT_REQUEST_IDENTITIES, type
|
103
|
+
s.return(SSH2_AGENT_IDENTITIES_ANSWER, :long, 2, :string, Net::SSH::Buffer.from(:key, key1), :string, "My favorite key", :string, Net::SSH::Buffer.from(:key, key2), :string, "Okay, but not the best")
|
104
|
+
end
|
105
|
+
|
106
|
+
result = agent.identities
|
107
|
+
assert_equal key1.to_blob, result.first.to_blob
|
108
|
+
assert_equal key2.to_blob, result.last.to_blob
|
109
|
+
assert_equal "My favorite key", result.first.comment
|
110
|
+
assert_equal "Okay, but not the best", result.last.comment
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_close_should_close_socket
|
114
|
+
socket.expects(:close)
|
115
|
+
agent.close
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_sign_should_fail_if_response_is_SSH_AGENT_FAILURE
|
119
|
+
socket.expect { |s,| s.return(SSH_AGENT_FAILURE) }
|
120
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.sign(key, "hello world") }
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_sign_should_fail_if_response_is_SSH2_AGENT_FAILURE
|
124
|
+
socket.expect { |s,| s.return(SSH2_AGENT_FAILURE) }
|
125
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.sign(key, "hello world") }
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_sign_should_fail_if_response_is_SSH_COM_AGENT2_FAILURE
|
129
|
+
socket.expect { |s,| s.return(SSH_COM_AGENT2_FAILURE) }
|
130
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.sign(key, "hello world") }
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_sign_should_fail_if_response_is_not_SSH2_AGENT_SIGN_RESPONSE
|
134
|
+
socket.expect { |s,| s.return(255) }
|
135
|
+
assert_raises(Net::SSH::Authentication::AgentError) { agent.sign(key, "hello world") }
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_sign_should_return_signed_data_from_agent
|
139
|
+
socket.expect do |s,type,buffer|
|
140
|
+
assert_equal SSH2_AGENT_SIGN_REQUEST, type
|
141
|
+
assert_equal key.to_blob, Net::SSH::Buffer.new(buffer.read_string).read_key.to_blob
|
142
|
+
assert_equal "hello world", buffer.read_string
|
143
|
+
assert_equal 0, buffer.read_long
|
144
|
+
|
145
|
+
s.return(SSH2_AGENT_SIGN_RESPONSE, :string, "abcxyz123")
|
146
|
+
end
|
147
|
+
|
148
|
+
assert_equal "abcxyz123", agent.sign(key, "hello world")
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
class MockSocket
|
154
|
+
def initialize
|
155
|
+
@expectation = nil
|
156
|
+
@buffer = Net::SSH::Buffer.new
|
157
|
+
end
|
158
|
+
|
159
|
+
def expect(&block)
|
160
|
+
@expectation = block
|
161
|
+
end
|
162
|
+
|
163
|
+
def return(type, *args)
|
164
|
+
data = Net::SSH::Buffer.from(*args)
|
165
|
+
@buffer.append([data.length+1, type, data.to_s].pack("NCA*"))
|
166
|
+
end
|
167
|
+
|
168
|
+
def send(data, flags)
|
169
|
+
raise "got #{data.inspect} but no packet was expected" unless @expectation
|
170
|
+
buffer = Net::SSH::Buffer.new(data)
|
171
|
+
buffer.read_long # skip the length
|
172
|
+
type = buffer.read_byte
|
173
|
+
@expectation.call(self, type, buffer)
|
174
|
+
@expectation = nil
|
175
|
+
end
|
176
|
+
|
177
|
+
def read(length)
|
178
|
+
@buffer.read(length)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def key
|
183
|
+
@key ||= OpenSSL::PKey::RSA.new(32)
|
184
|
+
end
|
185
|
+
|
186
|
+
def socket
|
187
|
+
@socket ||= MockSocket.new
|
188
|
+
end
|
189
|
+
|
190
|
+
def factory
|
191
|
+
@factory ||= stub("socket factory", :open => socket)
|
192
|
+
end
|
193
|
+
|
194
|
+
def agent(auto=:connect)
|
195
|
+
@agent ||= begin
|
196
|
+
agent = Net::SSH::Authentication::Agent.new
|
197
|
+
agent.stubs(:agent_socket_factory).returns(factory)
|
198
|
+
agent.connect! if auto == :connect
|
199
|
+
agent
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|