eventmachine 1.2.0.dev.2-x64-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +105 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +108 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/ChangeLog +211 -0
  9. data/docs/old/DEFERRABLES +246 -0
  10. data/docs/old/EPOLL +141 -0
  11. data/docs/old/INSTALL +13 -0
  12. data/docs/old/KEYBOARD +42 -0
  13. data/docs/old/LEGAL +25 -0
  14. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  15. data/docs/old/PURE_RUBY +75 -0
  16. data/docs/old/RELEASE_NOTES +94 -0
  17. data/docs/old/SMTP +4 -0
  18. data/docs/old/SPAWNED_PROCESSES +148 -0
  19. data/docs/old/TODO +8 -0
  20. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  21. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  22. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  23. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  24. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  25. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  26. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  27. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  28. data/examples/old/ex_channel.rb +43 -0
  29. data/examples/old/ex_queue.rb +2 -0
  30. data/examples/old/ex_tick_loop_array.rb +15 -0
  31. data/examples/old/ex_tick_loop_counter.rb +32 -0
  32. data/examples/old/helper.rb +2 -0
  33. data/ext/binder.cpp +124 -0
  34. data/ext/binder.h +46 -0
  35. data/ext/cmain.cpp +988 -0
  36. data/ext/ed.cpp +2111 -0
  37. data/ext/ed.h +442 -0
  38. data/ext/em.cpp +2379 -0
  39. data/ext/em.h +308 -0
  40. data/ext/eventmachine.h +143 -0
  41. data/ext/extconf.rb +270 -0
  42. data/ext/fastfilereader/extconf.rb +110 -0
  43. data/ext/fastfilereader/mapper.cpp +216 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +127 -0
  46. data/ext/kb.cpp +79 -0
  47. data/ext/page.cpp +107 -0
  48. data/ext/page.h +51 -0
  49. data/ext/pipe.cpp +354 -0
  50. data/ext/project.h +176 -0
  51. data/ext/rubymain.cpp +1504 -0
  52. data/ext/ssl.cpp +615 -0
  53. data/ext/ssl.h +103 -0
  54. data/java/.classpath +8 -0
  55. data/java/.project +17 -0
  56. data/java/src/com/rubyeventmachine/EmReactor.java +591 -0
  57. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  58. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  59. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  60. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  61. data/lib/2.0/fastfilereaderext.so +0 -0
  62. data/lib/2.0/rubyeventmachine.so +0 -0
  63. data/lib/2.1/fastfilereaderext.so +0 -0
  64. data/lib/2.1/rubyeventmachine.so +0 -0
  65. data/lib/2.2/fastfilereaderext.so +0 -0
  66. data/lib/2.2/rubyeventmachine.so +0 -0
  67. data/lib/2.3/fastfilereaderext.so +0 -0
  68. data/lib/2.3/rubyeventmachine.so +0 -0
  69. data/lib/em/buftok.rb +59 -0
  70. data/lib/em/callback.rb +58 -0
  71. data/lib/em/channel.rb +69 -0
  72. data/lib/em/completion.rb +304 -0
  73. data/lib/em/connection.rb +770 -0
  74. data/lib/em/deferrable.rb +210 -0
  75. data/lib/em/deferrable/pool.rb +2 -0
  76. data/lib/em/file_watch.rb +73 -0
  77. data/lib/em/future.rb +61 -0
  78. data/lib/em/iterator.rb +252 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/pool.rb +151 -0
  81. data/lib/em/process_watch.rb +45 -0
  82. data/lib/em/processes.rb +123 -0
  83. data/lib/em/protocols.rb +37 -0
  84. data/lib/em/protocols/header_and_content.rb +138 -0
  85. data/lib/em/protocols/httpclient.rb +299 -0
  86. data/lib/em/protocols/httpclient2.rb +600 -0
  87. data/lib/em/protocols/line_and_text.rb +125 -0
  88. data/lib/em/protocols/line_protocol.rb +29 -0
  89. data/lib/em/protocols/linetext2.rb +166 -0
  90. data/lib/em/protocols/memcache.rb +331 -0
  91. data/lib/em/protocols/object_protocol.rb +46 -0
  92. data/lib/em/protocols/postgres3.rb +246 -0
  93. data/lib/em/protocols/saslauth.rb +175 -0
  94. data/lib/em/protocols/smtpclient.rb +394 -0
  95. data/lib/em/protocols/smtpserver.rb +666 -0
  96. data/lib/em/protocols/socks4.rb +66 -0
  97. data/lib/em/protocols/stomp.rb +205 -0
  98. data/lib/em/protocols/tcptest.rb +54 -0
  99. data/lib/em/pure_ruby.rb +1022 -0
  100. data/lib/em/queue.rb +80 -0
  101. data/lib/em/resolver.rb +232 -0
  102. data/lib/em/spawnable.rb +84 -0
  103. data/lib/em/streamer.rb +118 -0
  104. data/lib/em/threaded_resource.rb +90 -0
  105. data/lib/em/tick_loop.rb +85 -0
  106. data/lib/em/timers.rb +61 -0
  107. data/lib/em/version.rb +3 -0
  108. data/lib/eventmachine.rb +1584 -0
  109. data/lib/fastfilereaderext.rb +2 -0
  110. data/lib/jeventmachine.rb +301 -0
  111. data/lib/rubyeventmachine.rb +2 -0
  112. data/rakelib/package.rake +120 -0
  113. data/rakelib/test.rake +8 -0
  114. data/tests/client.crt +31 -0
  115. data/tests/client.key +51 -0
  116. data/tests/dhparam.pem +13 -0
  117. data/tests/em_test_helper.rb +151 -0
  118. data/tests/test_attach.rb +151 -0
  119. data/tests/test_basic.rb +283 -0
  120. data/tests/test_channel.rb +75 -0
  121. data/tests/test_completion.rb +178 -0
  122. data/tests/test_connection_count.rb +54 -0
  123. data/tests/test_connection_write.rb +35 -0
  124. data/tests/test_defer.rb +35 -0
  125. data/tests/test_deferrable.rb +35 -0
  126. data/tests/test_epoll.rb +142 -0
  127. data/tests/test_error_handler.rb +38 -0
  128. data/tests/test_exc.rb +28 -0
  129. data/tests/test_file_watch.rb +66 -0
  130. data/tests/test_fork.rb +75 -0
  131. data/tests/test_futures.rb +170 -0
  132. data/tests/test_get_sock_opt.rb +37 -0
  133. data/tests/test_handler_check.rb +35 -0
  134. data/tests/test_hc.rb +155 -0
  135. data/tests/test_httpclient.rb +233 -0
  136. data/tests/test_httpclient2.rb +128 -0
  137. data/tests/test_idle_connection.rb +25 -0
  138. data/tests/test_inactivity_timeout.rb +54 -0
  139. data/tests/test_ipv4.rb +125 -0
  140. data/tests/test_ipv6.rb +131 -0
  141. data/tests/test_iterator.rb +115 -0
  142. data/tests/test_kb.rb +28 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +138 -0
  145. data/tests/test_ltp2.rb +308 -0
  146. data/tests/test_many_fds.rb +22 -0
  147. data/tests/test_next_tick.rb +104 -0
  148. data/tests/test_object_protocol.rb +36 -0
  149. data/tests/test_pause.rb +107 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +196 -0
  152. data/tests/test_process_watch.rb +50 -0
  153. data/tests/test_processes.rb +128 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +88 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +104 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +47 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +33 -0
  162. data/tests/test_set_sock_opt.rb +39 -0
  163. data/tests/test_shutdown_hooks.rb +23 -0
  164. data/tests/test_smtpclient.rb +75 -0
  165. data/tests/test_smtpserver.rb +57 -0
  166. data/tests/test_spawn.rb +293 -0
  167. data/tests/test_ssl_args.rb +78 -0
  168. data/tests/test_ssl_dhparam.rb +83 -0
  169. data/tests/test_ssl_ecdh_curve.rb +79 -0
  170. data/tests/test_ssl_extensions.rb +49 -0
  171. data/tests/test_ssl_methods.rb +65 -0
  172. data/tests/test_ssl_protocols.rb +246 -0
  173. data/tests/test_ssl_verify.rb +126 -0
  174. data/tests/test_stomp.rb +37 -0
  175. data/tests/test_system.rb +46 -0
  176. data/tests/test_threaded_resource.rb +61 -0
  177. data/tests/test_tick_loop.rb +59 -0
  178. data/tests/test_timers.rb +123 -0
  179. data/tests/test_ud.rb +8 -0
  180. data/tests/test_unbind_reason.rb +52 -0
  181. metadata +381 -0
@@ -0,0 +1,78 @@
1
+ require "test/unit"
2
+ require 'tempfile'
3
+
4
+ require 'em_test_helper'
5
+
6
+ module EM
7
+ def self._set_mocks
8
+ class <<self
9
+ alias set_tls_parms_old set_tls_parms
10
+ alias start_tls_old start_tls
11
+ begin
12
+ old, $VERBOSE = $VERBOSE, nil
13
+ def set_tls_parms *args; end
14
+ def start_tls *args; end
15
+ ensure
16
+ $VERBOSE = old
17
+ end
18
+ end
19
+ end
20
+
21
+ def self._clear_mocks
22
+ class <<self
23
+ begin
24
+ old, $VERBOSE = $VERBOSE, nil
25
+ alias set_tls_parms set_tls_parms_old
26
+ alias start_tls start_tls_old
27
+ ensure
28
+ $VERBOSE = old
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+
36
+ class TestSslArgs < Test::Unit::TestCase
37
+ def setup
38
+ EM._set_mocks
39
+ end
40
+
41
+ def teardown
42
+ EM._clear_mocks
43
+ end
44
+
45
+ def test_tls_params_file_doesnt_exist
46
+ priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
47
+ [priv_file, cert_file].all? do |f|
48
+ assert(!File.exist?(f), "Cert file #{f} seems to exist, and should not for the tests")
49
+ end
50
+
51
+ # associate_callback_target is a pain! (build!)
52
+ conn = EM::Connection.new('foo')
53
+
54
+ assert_raises(EM::FileNotFoundException) do
55
+ conn.start_tls(:private_key_file => priv_file)
56
+ end
57
+ assert_raises(EM::FileNotFoundException) do
58
+ conn.start_tls(:cert_chain_file => cert_file)
59
+ end
60
+ assert_raises(EM::FileNotFoundException) do
61
+ conn.start_tls(:private_key_file => priv_file, :cert_chain_file => cert_file)
62
+ end
63
+ end
64
+
65
+ def test_tls_params_file_does_exist
66
+ priv_file = Tempfile.new('em_test')
67
+ cert_file = Tempfile.new('em_test')
68
+ priv_file_path = priv_file.path
69
+ cert_file_path = cert_file.path
70
+ conn = EM::Connection.new('foo')
71
+ params = {:private_key_file => priv_file_path, :cert_chain_file => cert_file_path}
72
+ begin
73
+ conn.start_tls params
74
+ rescue Object
75
+ assert(false, 'should not have raised an exception')
76
+ end
77
+ end
78
+ end if EM.ssl?
@@ -0,0 +1,83 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestSslDhParam < Test::Unit::TestCase
4
+ def setup
5
+ $dir = File.dirname(File.expand_path(__FILE__)) + '/'
6
+ $dhparam_file = File.join($dir, 'dhparam.pem')
7
+ end
8
+
9
+ module Client
10
+ def connection_completed
11
+ start_tls
12
+ end
13
+
14
+ def ssl_handshake_completed
15
+ $client_handshake_completed = true
16
+ $client_cipher_name = get_cipher_name
17
+ close_connection
18
+ end
19
+
20
+ def unbind
21
+ EM.stop_event_loop
22
+ end
23
+ end
24
+
25
+ module Server
26
+ def post_init
27
+ start_tls(:dhparam => $dhparam_file, :cipher_list => "DHE,EDH")
28
+ end
29
+
30
+ def ssl_handshake_completed
31
+ $server_handshake_completed = true
32
+ $server_cipher_name = get_cipher_name
33
+ end
34
+ end
35
+
36
+ module NoDhServer
37
+ def post_init
38
+ start_tls(:cipher_list => "DHE,EDH")
39
+ end
40
+
41
+ def ssl_handshake_completed
42
+ $server_handshake_completed = true
43
+ $server_cipher_name = get_cipher_name
44
+ end
45
+ end
46
+
47
+ def test_no_dhparam
48
+ omit_unless(EM.ssl?)
49
+ omit_if(rbx?)
50
+
51
+ $client_handshake_completed, $server_handshake_completed = false, false
52
+ $server_cipher_name, $client_cipher_name = nil, nil
53
+
54
+ EM.run {
55
+ EM.start_server("127.0.0.1", 16784, NoDhServer)
56
+ EM.connect("127.0.0.1", 16784, Client)
57
+ }
58
+
59
+ assert(!$client_handshake_completed)
60
+ assert(!$server_handshake_completed)
61
+ end
62
+
63
+ def test_dhparam
64
+ omit_unless(EM.ssl?)
65
+ omit_if(rbx?)
66
+
67
+ $client_handshake_completed, $server_handshake_completed = false, false
68
+ $server_cipher_name, $client_cipher_name = nil, nil
69
+
70
+ EM.run {
71
+ EM.start_server("127.0.0.1", 16784, Server)
72
+ EM.connect("127.0.0.1", 16784, Client)
73
+ }
74
+
75
+ assert($client_handshake_completed)
76
+ assert($server_handshake_completed)
77
+
78
+ assert($client_cipher_name.length > 0)
79
+ assert_equal($client_cipher_name, $server_cipher_name)
80
+
81
+ assert_match(/^(DHE|EDH)/, $client_cipher_name)
82
+ end
83
+ end
@@ -0,0 +1,79 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestSslEcdhCurve < Test::Unit::TestCase
4
+ module Client
5
+ def connection_completed
6
+ start_tls
7
+ end
8
+
9
+ def ssl_handshake_completed
10
+ $client_handshake_completed = true
11
+ $client_cipher_name = get_cipher_name
12
+ close_connection
13
+ end
14
+
15
+ def unbind
16
+ EM.stop_event_loop
17
+ end
18
+ end
19
+
20
+ module Server
21
+ def post_init
22
+ start_tls(:ecdh_curve => "prime256v1", :cipher_list => "ECDH")
23
+ end
24
+
25
+ def ssl_handshake_completed
26
+ $server_handshake_completed = true
27
+ $server_cipher_name = get_cipher_name
28
+ end
29
+ end
30
+
31
+ module NoCurveServer
32
+ def post_init
33
+ start_tls(:cipher_list => "ECDH")
34
+ end
35
+
36
+ def ssl_handshake_completed
37
+ $server_handshake_completed = true
38
+ $server_cipher_name = get_cipher_name
39
+ end
40
+ end
41
+
42
+ def test_no_ecdh_curve
43
+ omit_unless(EM.ssl?)
44
+ omit_if(rbx?)
45
+
46
+ $client_handshake_completed, $server_handshake_completed = false, false
47
+
48
+ EM.run {
49
+ EM.start_server("127.0.0.1", 16784, NoCurveServer)
50
+ EM.connect("127.0.0.1", 16784, Client)
51
+ }
52
+
53
+ assert(!$client_handshake_completed)
54
+ assert(!$server_handshake_completed)
55
+ end
56
+
57
+ def test_ecdh_curve
58
+ omit_unless(EM.ssl?)
59
+ omit_if(rbx?)
60
+
61
+ $client_handshake_completed, $server_handshake_completed = false, false
62
+ $server_cipher_name, $client_cipher_name = nil, nil
63
+
64
+ EM.run {
65
+ EM.start_server("127.0.0.1", 16784, Server)
66
+ EM.connect("127.0.0.1", 16784, Client)
67
+ }
68
+
69
+ assert($client_handshake_completed)
70
+ assert($server_handshake_completed)
71
+
72
+ assert($client_cipher_name.length > 0)
73
+ assert_equal($client_cipher_name, $server_cipher_name)
74
+
75
+ assert_match(/^(AECDH|ECDHE)/, $client_cipher_name)
76
+ end
77
+
78
+
79
+ end
@@ -0,0 +1,49 @@
1
+ require 'em_test_helper'
2
+
3
+ require 'socket'
4
+ require 'openssl'
5
+
6
+ if EM.ssl?
7
+ class TestSslExtensions < Test::Unit::TestCase
8
+
9
+ module Client
10
+ def ssl_handshake_completed
11
+ $client_handshake_completed = true
12
+ close_connection
13
+ end
14
+
15
+ def unbind
16
+ EM.stop_event_loop
17
+ end
18
+
19
+ def connection_completed
20
+ start_tls(:ssl_version => :tlsv1, :sni_hostname => 'example.com')
21
+ end
22
+ end
23
+
24
+ module Server
25
+ def ssl_handshake_completed
26
+ $server_handshake_completed = true
27
+ $server_sni_hostname = get_sni_hostname
28
+ end
29
+
30
+ def post_init
31
+ start_tls(:ssl_version => :TLSv1)
32
+ end
33
+ end
34
+
35
+ def test_tlsext_sni_hostname
36
+ $server_handshake_completed = false
37
+
38
+ EM.run do
39
+ EM.start_server("127.0.0.1", 16784, Server)
40
+ EM.connect("127.0.0.1", 16784, Client)
41
+ end
42
+
43
+ assert($server_handshake_completed)
44
+ assert_equal('example.com', $server_sni_hostname)
45
+ end
46
+ end
47
+ else
48
+ warn "EM built without SSL support, skipping tests in #{__FILE__}"
49
+ end
@@ -0,0 +1,65 @@
1
+ require 'em_test_helper'
2
+
3
+ class TestSSLMethods < Test::Unit::TestCase
4
+
5
+ module ServerHandler
6
+ def post_init
7
+ start_tls
8
+ end
9
+
10
+ def ssl_handshake_completed
11
+ $server_called_back = true
12
+ $server_cert_value = get_peer_cert
13
+ $server_cipher_bits = get_cipher_bits
14
+ $server_cipher_name = get_cipher_name
15
+ $server_cipher_protocol = get_cipher_protocol
16
+ end
17
+ end
18
+
19
+ module ClientHandler
20
+ def post_init
21
+ start_tls
22
+ end
23
+
24
+ def ssl_handshake_completed
25
+ $client_called_back = true
26
+ $client_cert_value = get_peer_cert
27
+ $client_cipher_bits = get_cipher_bits
28
+ $client_cipher_name = get_cipher_name
29
+ $client_cipher_protocol = get_cipher_protocol
30
+ EM.stop_event_loop
31
+ end
32
+ end
33
+
34
+ def test_ssl_methods
35
+ omit_unless(EM.ssl?)
36
+ omit_if(rbx?)
37
+ $server_called_back, $client_called_back = false, false
38
+ $server_cert_value, $client_cert_value = nil, nil
39
+ $server_cipher_bits, $client_cipher_bits = nil, nil
40
+ $server_cipher_name, $client_cipher_name = nil, nil
41
+ $server_cipher_protocol, $client_cipher_protocol = nil, nil
42
+
43
+ EM.run {
44
+ EM.start_server("127.0.0.1", 9999, ServerHandler)
45
+ EM.connect("127.0.0.1", 9999, ClientHandler)
46
+ }
47
+
48
+ assert($server_called_back)
49
+ assert($client_called_back)
50
+
51
+ assert($server_cert_value.is_a?(NilClass))
52
+ assert($client_cert_value.is_a?(String))
53
+
54
+ assert($client_cipher_bits > 0)
55
+ assert_equal($client_cipher_bits, $server_cipher_bits)
56
+
57
+ assert($client_cipher_name.length > 0)
58
+ assert_match(/AES/, $client_cipher_name)
59
+ assert_equal($client_cipher_name, $server_cipher_name)
60
+
61
+ assert_match(/TLS/, $client_cipher_protocol)
62
+ assert_equal($client_cipher_protocol, $server_cipher_protocol)
63
+ end
64
+
65
+ end
@@ -0,0 +1,246 @@
1
+ require 'em_test_helper'
2
+
3
+ require 'socket'
4
+ require 'openssl'
5
+
6
+ if EM.ssl?
7
+ class TestSslProtocols < Test::Unit::TestCase
8
+
9
+ module Client
10
+ def ssl_handshake_completed
11
+ $client_handshake_completed = true
12
+ close_connection
13
+ end
14
+
15
+ def unbind
16
+ EM.stop_event_loop
17
+ end
18
+ end
19
+
20
+ module Server
21
+ def ssl_handshake_completed
22
+ $server_handshake_completed = true
23
+ end
24
+ end
25
+
26
+ module ClientAny
27
+ include Client
28
+ def connection_completed
29
+ start_tls(:ssl_version => %w(sslv2 sslv3 tlsv1 tlsv1_1 tlsv1_2))
30
+ end
31
+ end
32
+
33
+ module ClientDefault
34
+ include Client
35
+ def connection_completed
36
+ start_tls
37
+ end
38
+ end
39
+
40
+ module ClientSSLv3
41
+ include Client
42
+ def connection_completed
43
+ start_tls(:ssl_version => %w(SSLv3))
44
+ end
45
+ end
46
+
47
+ module ServerSSLv3
48
+ include Server
49
+ def post_init
50
+ start_tls(:ssl_version => %w(SSLv3))
51
+ end
52
+ end
53
+
54
+ module ServerTLSv1CaseInsensitive
55
+ include Server
56
+ def post_init
57
+ start_tls(:ssl_version => %w(tlsv1))
58
+ end
59
+ end
60
+
61
+ module ServerAny
62
+ include Server
63
+ def post_init
64
+ start_tls(:ssl_version => %w(sslv2 sslv3 tlsv1 tlsv1_1 tlsv1_2))
65
+ end
66
+ end
67
+
68
+ module ServerDefault
69
+ include Server
70
+ def post_init
71
+ start_tls
72
+ end
73
+ end
74
+
75
+ module InvalidProtocol
76
+ include Client
77
+ def post_init
78
+ start_tls(:ssl_version => %w(tlsv1 badinput))
79
+ end
80
+ end
81
+
82
+ def test_invalid_ssl_version
83
+ assert_raises(RuntimeError, "Unrecognized SSL/TLS Version: badinput") do
84
+ EM.run do
85
+ EM.start_server("127.0.0.1", 16784, InvalidProtocol)
86
+ EM.connect("127.0.0.1", 16784, InvalidProtocol)
87
+ end
88
+ end
89
+ end
90
+
91
+ def test_any_to_v3
92
+ $client_handshake_completed, $server_handshake_completed = false, false
93
+ EM.run do
94
+ EM.start_server("127.0.0.1", 16784, ServerSSLv3)
95
+ EM.connect("127.0.0.1", 16784, ClientAny)
96
+ end
97
+
98
+ assert($client_handshake_completed)
99
+ assert($server_handshake_completed)
100
+ end
101
+
102
+ def test_case_insensitivity
103
+ $client_handshake_completed, $server_handshake_completed = false, false
104
+ EM.run do
105
+ EM.start_server("127.0.0.1", 16784, ServerTLSv1CaseInsensitive)
106
+ EM.connect("127.0.0.1", 16784, ClientAny)
107
+ end
108
+
109
+ assert($client_handshake_completed)
110
+ assert($server_handshake_completed)
111
+ end
112
+
113
+ def test_v3_to_any
114
+ $client_handshake_completed, $server_handshake_completed = false, false
115
+ EM.run do
116
+ EM.start_server("127.0.0.1", 16784, ServerAny)
117
+ EM.connect("127.0.0.1", 16784, ClientSSLv3)
118
+ end
119
+
120
+ assert($client_handshake_completed)
121
+ assert($server_handshake_completed)
122
+ end
123
+
124
+ def test_v3_to_v3
125
+ $client_handshake_completed, $server_handshake_completed = false, false
126
+ EM.run do
127
+ EM.start_server("127.0.0.1", 16784, ServerSSLv3)
128
+ EM.connect("127.0.0.1", 16784, ClientSSLv3)
129
+ end
130
+
131
+ assert($client_handshake_completed)
132
+ assert($server_handshake_completed)
133
+ end
134
+
135
+ def test_any_to_any
136
+ $client_handshake_completed, $server_handshake_completed = false, false
137
+ EM.run do
138
+ EM.start_server("127.0.0.1", 16784, ServerAny)
139
+ EM.connect("127.0.0.1", 16784, ClientAny)
140
+ end
141
+
142
+ assert($client_handshake_completed)
143
+ assert($server_handshake_completed)
144
+ end
145
+
146
+ def test_default_to_default
147
+ $client_handshake_completed, $server_handshake_completed = false, false
148
+ EM.run do
149
+ EM.start_server("127.0.0.1", 16784, ServerDefault)
150
+ EM.connect("127.0.0.1", 16784, ClientDefault)
151
+ end
152
+
153
+ assert($client_handshake_completed)
154
+ assert($server_handshake_completed)
155
+ end
156
+
157
+ module ServerV3StopAfterHandshake
158
+ def post_init
159
+ start_tls(:ssl_version => %w(SSLv3))
160
+ end
161
+
162
+ def ssl_handshake_completed
163
+ $server_handshake_completed = true
164
+ EM.stop_event_loop
165
+ end
166
+ end
167
+
168
+ module ServerTLSv1StopAfterHandshake
169
+ def post_init
170
+ start_tls(:ssl_version => %w(TLSv1))
171
+ end
172
+
173
+ def ssl_handshake_completed
174
+ $server_handshake_completed = true
175
+ EM.stop_event_loop
176
+ end
177
+ end
178
+
179
+ def test_v3_with_external_client
180
+ $server_handshake_completed = false
181
+ EM.run do
182
+ setup_timeout(2)
183
+ EM.start_server("127.0.0.1", 16784, ServerV3StopAfterHandshake)
184
+ EM.defer do
185
+ sock = TCPSocket.new("127.0.0.1", 16784)
186
+ ctx = OpenSSL::SSL::SSLContext.new
187
+ ctx.ssl_version = :SSLv3_client
188
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
189
+ ssl.connect
190
+ ssl.close rescue nil
191
+ sock.close rescue nil
192
+ end
193
+ end
194
+
195
+ assert($server_handshake_completed)
196
+ end
197
+
198
+ def test_tlsv1_with_external_client
199
+ $server_handshake_completed = false
200
+ EM.run do
201
+ setup_timeout(2)
202
+ EM.start_server("127.0.0.1", 16784, ServerTLSv1StopAfterHandshake)
203
+ EM.defer do
204
+ sock = TCPSocket.new("127.0.0.1", 16784)
205
+ ctx = OpenSSL::SSL::SSLContext.new
206
+ ctx.ssl_version = :TLSv1_client
207
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
208
+ ssl.connect
209
+ ssl.close rescue nil
210
+ sock.close rescue nil
211
+ end
212
+ end
213
+
214
+ assert($server_handshake_completed)
215
+ end
216
+
217
+ def test_tlsv1_required_with_external_client
218
+ $server_handshake_completed = false
219
+
220
+ EM.run do
221
+ n = 0
222
+ EM.add_periodic_timer(0.5) do
223
+ n += 1
224
+ (EM.stop rescue nil) if n == 2
225
+ end
226
+ EM.start_server("127.0.0.1", 16784, ServerTLSv1StopAfterHandshake)
227
+ EM.defer do
228
+ sock = TCPSocket.new("127.0.0.1", 16784)
229
+ ctx = OpenSSL::SSL::SSLContext.new
230
+ ctx.ssl_version = :SSLv3_client
231
+ ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
232
+ assert_raise OpenSSL::SSL::SSLError do
233
+ ssl.connect
234
+ end
235
+ ssl.close rescue nil
236
+ sock.close rescue nil
237
+ EM.stop rescue nil
238
+ end
239
+ end
240
+
241
+ assert(!$server_handshake_completed)
242
+ end
243
+ end
244
+ else
245
+ warn "EM built without SSL support, skipping tests in #{__FILE__}"
246
+ end