eventmachine-mkroman 1.3.0.dev.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +179 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +110 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +520 -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 +52 -0
  35. data/ext/cmain.cpp +1046 -0
  36. data/ext/ed.cpp +2243 -0
  37. data/ext/ed.h +463 -0
  38. data/ext/em.cpp +2378 -0
  39. data/ext/em.h +266 -0
  40. data/ext/eventmachine.h +152 -0
  41. data/ext/extconf.rb +291 -0
  42. data/ext/fastfilereader/extconf.rb +120 -0
  43. data/ext/fastfilereader/mapper.cpp +214 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +126 -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 +174 -0
  51. data/ext/rubymain.cpp +1643 -0
  52. data/ext/ssl.cpp +701 -0
  53. data/ext/ssl.h +103 -0
  54. data/ext/wait_for_single_fd.h +36 -0
  55. data/java/.classpath +8 -0
  56. data/java/.project +17 -0
  57. data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
  58. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  59. data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
  60. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  61. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  62. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  63. data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
  64. data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
  65. data/lib/em/buftok.rb +59 -0
  66. data/lib/em/callback.rb +58 -0
  67. data/lib/em/channel.rb +69 -0
  68. data/lib/em/completion.rb +307 -0
  69. data/lib/em/connection.rb +802 -0
  70. data/lib/em/deferrable/pool.rb +2 -0
  71. data/lib/em/deferrable.rb +210 -0
  72. data/lib/em/file_watch.rb +73 -0
  73. data/lib/em/future.rb +61 -0
  74. data/lib/em/io_streamer.rb +68 -0
  75. data/lib/em/iterator.rb +252 -0
  76. data/lib/em/messages.rb +66 -0
  77. data/lib/em/pool.rb +151 -0
  78. data/lib/em/process_watch.rb +45 -0
  79. data/lib/em/processes.rb +123 -0
  80. data/lib/em/protocols/header_and_content.rb +138 -0
  81. data/lib/em/protocols/httpclient.rb +303 -0
  82. data/lib/em/protocols/httpclient2.rb +602 -0
  83. data/lib/em/protocols/line_and_text.rb +125 -0
  84. data/lib/em/protocols/line_protocol.rb +33 -0
  85. data/lib/em/protocols/linetext2.rb +179 -0
  86. data/lib/em/protocols/memcache.rb +331 -0
  87. data/lib/em/protocols/object_protocol.rb +46 -0
  88. data/lib/em/protocols/postgres3.rb +246 -0
  89. data/lib/em/protocols/saslauth.rb +175 -0
  90. data/lib/em/protocols/smtpclient.rb +394 -0
  91. data/lib/em/protocols/smtpserver.rb +666 -0
  92. data/lib/em/protocols/socks4.rb +66 -0
  93. data/lib/em/protocols/stomp.rb +205 -0
  94. data/lib/em/protocols/tcptest.rb +54 -0
  95. data/lib/em/protocols.rb +37 -0
  96. data/lib/em/pure_ruby.rb +1300 -0
  97. data/lib/em/queue.rb +80 -0
  98. data/lib/em/resolver.rb +232 -0
  99. data/lib/em/spawnable.rb +84 -0
  100. data/lib/em/streamer.rb +118 -0
  101. data/lib/em/threaded_resource.rb +90 -0
  102. data/lib/em/tick_loop.rb +85 -0
  103. data/lib/em/timers.rb +61 -0
  104. data/lib/em/version.rb +3 -0
  105. data/lib/eventmachine.rb +1602 -0
  106. data/lib/jeventmachine.rb +319 -0
  107. data/rakelib/package.rake +120 -0
  108. data/rakelib/test.rake +6 -0
  109. data/rakelib/test_pure.rake +11 -0
  110. data/tests/client.crt +31 -0
  111. data/tests/client.key +51 -0
  112. data/tests/dhparam.pem +13 -0
  113. data/tests/em_ssl_handlers.rb +165 -0
  114. data/tests/em_test_helper.rb +198 -0
  115. data/tests/encoded_client.key +54 -0
  116. data/tests/jruby/test_jeventmachine.rb +38 -0
  117. data/tests/test_attach.rb +199 -0
  118. data/tests/test_basic.rb +321 -0
  119. data/tests/test_channel.rb +75 -0
  120. data/tests/test_completion.rb +178 -0
  121. data/tests/test_connection_count.rb +83 -0
  122. data/tests/test_connection_write.rb +35 -0
  123. data/tests/test_defer.rb +35 -0
  124. data/tests/test_deferrable.rb +35 -0
  125. data/tests/test_epoll.rb +141 -0
  126. data/tests/test_error_handler.rb +38 -0
  127. data/tests/test_exc.rb +37 -0
  128. data/tests/test_file_watch.rb +86 -0
  129. data/tests/test_fork.rb +75 -0
  130. data/tests/test_futures.rb +170 -0
  131. data/tests/test_handler_check.rb +35 -0
  132. data/tests/test_hc.rb +155 -0
  133. data/tests/test_httpclient.rb +238 -0
  134. data/tests/test_httpclient2.rb +132 -0
  135. data/tests/test_idle_connection.rb +31 -0
  136. data/tests/test_inactivity_timeout.rb +102 -0
  137. data/tests/test_io_streamer.rb +48 -0
  138. data/tests/test_ipv4.rb +96 -0
  139. data/tests/test_ipv6.rb +107 -0
  140. data/tests/test_iterator.rb +122 -0
  141. data/tests/test_kb.rb +28 -0
  142. data/tests/test_keepalive.rb +113 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +155 -0
  145. data/tests/test_ltp2.rb +332 -0
  146. data/tests/test_many_fds.rb +21 -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 +109 -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 +147 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +156 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +129 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +46 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +32 -0
  162. data/tests/test_shutdown_hooks.rb +23 -0
  163. data/tests/test_smtpclient.rb +75 -0
  164. data/tests/test_smtpserver.rb +90 -0
  165. data/tests/test_sock_opt.rb +53 -0
  166. data/tests/test_spawn.rb +290 -0
  167. data/tests/test_ssl_args.rb +70 -0
  168. data/tests/test_ssl_dhparam.rb +57 -0
  169. data/tests/test_ssl_ecdh_curve.rb +57 -0
  170. data/tests/test_ssl_extensions.rb +24 -0
  171. data/tests/test_ssl_inline_cert.rb +222 -0
  172. data/tests/test_ssl_methods.rb +31 -0
  173. data/tests/test_ssl_protocols.rb +190 -0
  174. data/tests/test_ssl_verify.rb +108 -0
  175. data/tests/test_stomp.rb +38 -0
  176. data/tests/test_system.rb +46 -0
  177. data/tests/test_threaded_resource.rb +68 -0
  178. data/tests/test_tick_loop.rb +58 -0
  179. data/tests/test_timers.rb +150 -0
  180. data/tests/test_ud.rb +8 -0
  181. data/tests/test_unbind_reason.rb +40 -0
  182. metadata +389 -0
@@ -0,0 +1,53 @@
1
+ require_relative 'em_test_helper'
2
+
3
+ class TestSockOpt < Test::Unit::TestCase
4
+ def setup
5
+ assert(!EM.reactor_running?)
6
+ @port = next_port
7
+ end
8
+
9
+ def teardown
10
+ assert(!EM.reactor_running?)
11
+ end
12
+
13
+ def test_set_sock_opt
14
+ omit_if(windows?)
15
+ omit_if(!EM.respond_to?(:set_sock_opt))
16
+
17
+ val = nil
18
+ test_module = Module.new do
19
+ define_method :post_init do
20
+ val = set_sock_opt Socket::SOL_SOCKET, Socket::SO_BROADCAST, true
21
+ EM.stop
22
+ end
23
+ end
24
+
25
+ EM.run do
26
+ EM.start_server '127.0.0.1', @port
27
+ EM.connect '127.0.0.1', @port, test_module
28
+ end
29
+
30
+ assert_equal 0, val
31
+ end
32
+
33
+ def test_get_sock_opt
34
+ omit_if(windows?)
35
+ omit_if(!EM.respond_to?(:set_sock_opt))
36
+
37
+ val = nil
38
+ test_module = Module.new do
39
+ define_method :connection_completed do
40
+ val = get_sock_opt Socket::SOL_SOCKET, Socket::SO_ERROR
41
+ EM.stop
42
+ end
43
+ end
44
+
45
+ EM.run do
46
+ EM.start_server '127.0.0.1', @port
47
+ EM.connect '127.0.0.1', @port, test_module
48
+ end
49
+
50
+ assert_equal "\0\0\0\0", val
51
+ end
52
+
53
+ end
@@ -0,0 +1,290 @@
1
+ require_relative 'em_test_helper'
2
+
3
+ class TestSpawn < Test::Unit::TestCase
4
+
5
+ # Spawn a process that simply stops the reactor.
6
+ # Assert that the notification runs after the block that calls it.
7
+ #
8
+ def test_stop
9
+ x = nil
10
+ EM.run {
11
+ s = EM.spawn {EM.stop}
12
+ s.notify
13
+ x = true
14
+ }
15
+ assert x
16
+ end
17
+
18
+
19
+ # Pass a parameter to a spawned process.
20
+ #
21
+ def test_parms
22
+ val = 5
23
+ EM.run {
24
+ s = EM.spawn {|v| val *= v; EM.stop}
25
+ s.notify 3
26
+ }
27
+ assert_equal( 15, val )
28
+ end
29
+
30
+ # Pass multiple parameters to a spawned process.
31
+ #
32
+ def test_multiparms
33
+ val = 5
34
+ EM.run {
35
+ s = EM.spawn {|v1,v2| val *= (v1 + v2); EM.stop}
36
+ s.notify 3,4
37
+ }
38
+ assert_equal( 35, val )
39
+ end
40
+
41
+
42
+ # This test demonstrates that a notification does not happen immediately,
43
+ # but rather is scheduled sometime after the current code path completes.
44
+ #
45
+ def test_race
46
+ x = 0
47
+ EM.run {
48
+ s = EM.spawn {x *= 2; EM.stop}
49
+ s.notify
50
+ x = 2
51
+ }
52
+ assert_equal( 4, x)
53
+ end
54
+
55
+
56
+ # Spawn a process and notify it 25 times to run fibonacci
57
+ # on a pair of global variables.
58
+ #
59
+ def test_fibonacci
60
+ x = 1
61
+ y = 1
62
+ EM.run {
63
+ s = EM.spawn {x,y = y,x+y}
64
+ 25.times {s.notify}
65
+
66
+ t = EM.spawn {EM.stop}
67
+ t.notify
68
+ }
69
+ assert_equal( 121393, x)
70
+ assert_equal( 196418, y)
71
+ end
72
+
73
+ # This one spawns 25 distinct processes, and notifies each one once,
74
+ # rather than notifying a single process 25 times.
75
+ #
76
+ def test_another_fibonacci
77
+ x = 1
78
+ y = 1
79
+ EM.run {
80
+ 25.times {
81
+ s = EM.spawn {x,y = y,x+y}
82
+ s.notify
83
+ }
84
+
85
+ t = EM.spawn {EM.stop}
86
+ t.notify
87
+ }
88
+ assert_equal( 121393, x)
89
+ assert_equal( 196418, y)
90
+ end
91
+
92
+
93
+ # Make a chain of processes that notify each other in turn
94
+ # with intermediate fibonacci results. The final process in
95
+ # the chain stops the loop and returns the result.
96
+ #
97
+ def test_fibonacci_chain
98
+ a,b = nil
99
+
100
+ EM.run {
101
+ nextpid = EM.spawn {|x,y|
102
+ a,b = x,y
103
+ EM.stop
104
+ }
105
+
106
+ 25.times {
107
+ n = nextpid
108
+ nextpid = EM.spawn {|x,y| n.notify( y, x+y )}
109
+ }
110
+
111
+ nextpid.notify( 1, 1 )
112
+ }
113
+
114
+ assert_equal( 121393, a)
115
+ assert_equal( 196418, b)
116
+ end
117
+
118
+
119
+ # EM#yield gives a spawed process to yield control to other processes
120
+ # (in other words, to stop running), and to specify a different code block
121
+ # that will run on its next notification.
122
+ #
123
+ def test_yield
124
+ a = 0
125
+ EM.run {
126
+ n = EM.spawn {
127
+ a += 10
128
+ EM.yield {
129
+ a += 20
130
+ EM.yield {
131
+ a += 30
132
+ EM.stop
133
+ }
134
+ }
135
+ }
136
+ n.notify
137
+ n.notify
138
+ n.notify
139
+ }
140
+ assert_equal( 60, a )
141
+ end
142
+
143
+ # EM#yield_and_notify behaves like EM#yield, except that it also notifies the
144
+ # yielding process. This may sound trivial, since the yield block will run very
145
+ # shortly after with no action by the program, but this actually can be very useful,
146
+ # because it causes the reactor core to execute once before the yielding process
147
+ # gets control back. So it can be used to allow heavily-used network connections
148
+ # to clear buffers, or allow other processes to process their notifications.
149
+ #
150
+ # Notice in this test code that only a simple notify is needed at the bottom
151
+ # of the initial block. Even so, all of the yielded blocks will execute.
152
+ #
153
+ def test_yield_and_notify
154
+ a = 0
155
+ EM.run {
156
+ n = EM.spawn {
157
+ a += 10
158
+ EM.yield_and_notify {
159
+ a += 20
160
+ EM.yield_and_notify {
161
+ a += 30
162
+ EM.stop
163
+ }
164
+ }
165
+ }
166
+ n.notify
167
+ }
168
+ assert_equal( 60, a )
169
+ end
170
+
171
+ # resume is an alias for notify.
172
+ #
173
+ def test_resume
174
+ EM.run {
175
+ n = EM.spawn {EM.stop}
176
+ n.resume
177
+ }
178
+ assert true
179
+ end
180
+
181
+ # run is an idiomatic alias for notify.
182
+ #
183
+ def test_run
184
+ EM.run {
185
+ (EM.spawn {EM.stop}).run
186
+ }
187
+ assert true
188
+ end
189
+
190
+
191
+ # Clones the ping-pong example from the Erlang tutorial, in much less code.
192
+ # Illustrates that a spawned block executes in the context of a SpawnableObject.
193
+ # (Meaning, we can pass self as a parameter to another process that can then
194
+ # notify us.)
195
+ #
196
+ def test_ping_pong
197
+ n_pongs = 0
198
+ EM.run {
199
+ pong = EM.spawn {|x, ping|
200
+ n_pongs += 1
201
+ ping.notify( x-1 )
202
+ }
203
+ ping = EM.spawn {|x|
204
+ if x > 0
205
+ pong.notify x, self
206
+ else
207
+ EM.stop
208
+ end
209
+ }
210
+ ping.notify 3
211
+ }
212
+ assert_equal( 3, n_pongs )
213
+ end
214
+
215
+ # Illustrates that you can call notify inside a notification, and it will cause
216
+ # the currently-executing process to be re-notified. Of course, the new notification
217
+ # won't run until sometime after the current one completes.
218
+ #
219
+ def test_self_notify
220
+ n = 0
221
+ EM.run {
222
+ pid = EM.spawn {|x|
223
+ if x > 0
224
+ n += x
225
+ notify( x-1 )
226
+ else
227
+ EM.stop
228
+ end
229
+ }
230
+ pid.notify 3
231
+ }
232
+ assert_equal( 6, n )
233
+ end
234
+
235
+
236
+ # Illustrates that the block passed to #spawn executes in the context of a
237
+ # SpawnedProcess object, NOT in the local context. This can often be deceptive.
238
+ #
239
+ class BlockScopeTest
240
+ attr_reader :var
241
+ def run
242
+ # The following line correctly raises a NameError.
243
+ # The problem is that the programmer expected the spawned block to
244
+ # execute in the local context, but it doesn't.
245
+ #
246
+ # (EM.spawn { do_something }).notify ### NO! BAD!
247
+
248
+
249
+
250
+ # The following line correctly passes self as a parameter to the
251
+ # notified process.
252
+ #
253
+ (EM.spawn {|obj| obj.do_something }).notify(self)
254
+
255
+
256
+
257
+ # Here's another way to do it. This works because "myself" is bound
258
+ # in the local scope, unlike "self," so the spawned block sees it.
259
+ #
260
+ myself = self
261
+ (EM.spawn { myself.do_something }).notify
262
+
263
+
264
+
265
+ # And we end the loop.
266
+ # This is a tangential point, but observe that #notify never blocks.
267
+ # It merely appends a message to the internal queue of a spawned process
268
+ # and returns. As it turns out, the reactor processes notifications for ALL
269
+ # spawned processes in the order that #notify is called. So there is a
270
+ # reasonable expectation that the process which stops the reactor will
271
+ # execute after the previous ones in this method. HOWEVER, this is NOT
272
+ # a documented behavior and is subject to change.
273
+ #
274
+ (EM.spawn {EM.stop}).notify
275
+ end
276
+ def do_something
277
+ @var ||= 0
278
+ @var += 100
279
+ end
280
+ end
281
+
282
+ def test_block_scope
283
+ bs = BlockScopeTest.new
284
+ EM.run {
285
+ bs.run
286
+ }
287
+ assert_equal( 200, bs.var )
288
+ end
289
+
290
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'em_test_helper'
4
+ require 'tempfile'
5
+
6
+ class TestSSLArgs < Test::Unit::TestCase
7
+
8
+ require_relative 'em_ssl_handlers'
9
+ include EMSSLHandlers
10
+
11
+ def test_tls_params_file_doesnt_exist
12
+ priv_file, cert_file = 'foo_priv_key', 'bar_cert_file'
13
+ [priv_file, cert_file].all? do |f|
14
+ assert(!File.exist?(f), "Cert file #{f} seems to exist, and should not for the tests")
15
+ end
16
+
17
+ assert_raises EM::FileNotFoundException do
18
+ client_server client: { private_key_file: priv_file }
19
+ end
20
+
21
+ assert_raises EM::FileNotFoundException do
22
+ client_server client: { cert_chain_file: cert_file }
23
+ end
24
+
25
+ assert_raises EM::FileNotFoundException do
26
+ client_server client: { private_key_file: priv_file, cert_chain_file: cert_file }
27
+ end
28
+ end
29
+
30
+ def test_tls_cert_not_defined_twice
31
+ cert_file_path="#{__dir__}/client.crt"
32
+ cert=File.read "#{__dir__}/client.crt"
33
+
34
+ assert_raises EM::BadCertParams do
35
+ client_server client: {cert: cert, cert_chain_file: cert_file_path}
36
+ end
37
+ end
38
+
39
+ def test_tls_key_not_defined_twice
40
+ cert_file_path="#{__dir__}/client.crt"
41
+ key_file_path="#{__dir__}/client.key"
42
+ key=File.read "#{__dir__}/client.key"
43
+
44
+ assert_raises EM::BadPrivateKeyParams do
45
+ client_server client: {private_key_file: key_file_path, private_key: key, cert_chain_file: cert_file_path}
46
+ end
47
+ end
48
+
49
+ def test_tls_key_requires_cert
50
+ #specifying a key but no cert will generate an error at SSL level
51
+ #with a misleading text
52
+ #140579476657920:error:1417A0C1:SSL routines:tls_post_process_client_hello:no shared cipher
53
+
54
+ assert_raises EM::BadParams do
55
+ client_server client: {private_key_file: "#{__dir__}/client.key"}
56
+ end
57
+ end
58
+
59
+ def _test_tls_params_file_improper
60
+ priv_file_path = Tempfile.new('em_test').path
61
+ cert_file_path = Tempfile.new('em_test').path
62
+ params = { private_key_file: priv_file_path,
63
+ cert_chain_file: cert_file_path }
64
+ begin
65
+ client_server client: params
66
+ rescue Object
67
+ assert false, 'should not have raised an exception'
68
+ end
69
+ end
70
+ end if EM.ssl?
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'em_test_helper'
4
+
5
+ class TestSSLDhParam < Test::Unit::TestCase
6
+
7
+ require_relative 'em_ssl_handlers'
8
+ include EMSSLHandlers
9
+
10
+ DH_PARAM_FILE = File.join(__dir__, 'dhparam.pem')
11
+
12
+ DH_1_2 = { cipher_list: "DHE,EDH", ssl_version: %w(TLSv1_2) }
13
+ CLIENT_1_2 = { client_unbind: true, ssl_version: %w(TLSv1_2) }
14
+
15
+ def test_no_dhparam
16
+ omit_if(EM.library_type == :pure_ruby) # DH will work with defaults
17
+ omit_if(rbx?)
18
+
19
+ client_server client: CLIENT_1_2, server: DH_1_2
20
+
21
+ refute Client.handshake_completed?
22
+ refute Server.handshake_completed?
23
+ end
24
+
25
+ def test_dhparam_1_2
26
+ omit_if(rbx?)
27
+
28
+ client_server client: CLIENT_1_2, server: DH_1_2.merge(dhparam: DH_PARAM_FILE)
29
+
30
+ assert Client.handshake_completed?
31
+ assert Server.handshake_completed?
32
+
33
+ assert Client.cipher_name.length > 0
34
+ assert_equal Client.cipher_name, Server.cipher_name
35
+
36
+ assert_match(/^(DHE|EDH)/, Client.cipher_name)
37
+ end
38
+
39
+ def test_dhparam_1_3
40
+ omit_if(rbx?)
41
+ omit("TLSv1_3 is unavailable") unless EM.const_defined? :EM_PROTO_TLSv1_3
42
+
43
+ client = { client_unbind: true, ssl_version: %w(TLSv1_3) }
44
+ server = { dhparam: DH_PARAM_FILE, cipher_list: "DHE,EDH", ssl_version: %w(TLSv1_3) }
45
+ client_server client: client, server: server
46
+
47
+ assert Client.handshake_completed?
48
+ assert Server.handshake_completed?
49
+
50
+ assert Client.cipher_name.length > 0
51
+ assert_equal Client.cipher_name, Server.cipher_name
52
+
53
+ # see https://wiki.openssl.org/index.php/TLS1.3#Ciphersuites
54
+ # may depend on OpenSSL build options
55
+ assert_equal "TLS_AES_256_GCM_SHA384", Client.cipher_name
56
+ end
57
+ end if EM.ssl?
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'em_test_helper'
4
+
5
+ class TestSSLEcdhCurve < Test::Unit::TestCase
6
+
7
+ require_relative 'em_ssl_handlers'
8
+ include EMSSLHandlers
9
+
10
+ def test_no_ecdh_curve
11
+ omit_if(rbx?)
12
+ omit("OpenSSL 1.1.x (and later) auto selects curve") if IS_SSL_GE_1_1
13
+
14
+ client_server server: { cipher_list: "ECDH", ssl_version: %w(TLSv1_2) }
15
+
16
+ refute Client.handshake_completed?
17
+ refute Server.handshake_completed?
18
+ end
19
+
20
+ def test_ecdh_curve_tlsv1_2
21
+ omit_if(EM.library_type == :pure_ruby && RUBY_VERSION < "2.3.0")
22
+ omit_if(rbx?)
23
+
24
+ server = { cipher_list: "ECDH", ssl_version: %w(TLSv1_2) }
25
+ server.merge!(ecdh_curve: "prime256v1") unless IS_SSL_GE_1_1
26
+
27
+ client_server server: server
28
+
29
+ assert Client.handshake_completed?
30
+ assert Server.handshake_completed?
31
+
32
+ assert Client.cipher_name.length > 0
33
+ assert_equal Client.cipher_name, Server.cipher_name
34
+
35
+ assert_match(/^(AECDH|ECDHE)/, Client.cipher_name)
36
+ end
37
+
38
+ def test_ecdh_curve_tlsv1_3
39
+ omit_if(EM.library_type == :pure_ruby && RUBY_VERSION < "2.3.0")
40
+ omit_if(rbx?)
41
+ omit("TLSv1_3 is unavailable") unless EM.const_defined? :EM_PROTO_TLSv1_3
42
+
43
+ tls = { cipher_list: "ECDH", ssl_version: %w(TLSv1_3) }
44
+
45
+ client_server server: tls
46
+
47
+ assert Client.handshake_completed?
48
+ assert Server.handshake_completed?
49
+
50
+ assert Client.cipher_name.length > 0
51
+ assert_equal Client.cipher_name, Server.cipher_name
52
+
53
+ # see https://wiki.openssl.org/index.php/TLS1.3#Ciphersuites
54
+ # may depend on OpenSSL build options
55
+ assert_equal "TLS_AES_256_GCM_SHA384", Client.cipher_name
56
+ end
57
+ end if EM.ssl?
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'em_test_helper'
4
+
5
+ class TestSSLExtensions < Test::Unit::TestCase
6
+
7
+ require_relative 'em_ssl_handlers'
8
+ include EMSSLHandlers
9
+
10
+ def test_tlsext_sni_hostname_1_2
11
+ client = { sni_hostname: 'example.com', ssl_version: %w(TLSv1_2) }
12
+ client_server client: client
13
+ assert Server.handshake_completed?
14
+ assert_equal 'example.com', Server.sni_hostname
15
+ end
16
+
17
+ def test_tlsext_sni_hostname_1_3
18
+ omit("TLSv1_3 is unavailable") unless EM.const_defined? :EM_PROTO_TLSv1_3
19
+ client = { sni_hostname: 'example.com', ssl_version: %w(TLSv1_3) }
20
+ client_server client: client
21
+ assert Server.handshake_completed?
22
+ assert_equal 'example.com', Server.sni_hostname
23
+ end
24
+ end if EM.ssl?