eventmachine-mkroman 1.3.0.dev.1
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +179 -0
- data/GNU +281 -0
- data/LICENSE +60 -0
- data/README.md +110 -0
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +520 -0
- data/docs/old/ChangeLog +211 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/old/EPOLL +141 -0
- data/docs/old/INSTALL +13 -0
- data/docs/old/KEYBOARD +42 -0
- data/docs/old/LEGAL +25 -0
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/PURE_RUBY +75 -0
- data/docs/old/RELEASE_NOTES +94 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/docs/old/TODO +8 -0
- data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
- data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
- data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
- data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
- data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
- data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
- data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
- data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
- data/examples/old/ex_channel.rb +43 -0
- data/examples/old/ex_queue.rb +2 -0
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/examples/old/helper.rb +2 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +52 -0
- data/ext/cmain.cpp +1046 -0
- data/ext/ed.cpp +2243 -0
- data/ext/ed.h +463 -0
- data/ext/em.cpp +2378 -0
- data/ext/em.h +266 -0
- data/ext/eventmachine.h +152 -0
- data/ext/extconf.rb +291 -0
- data/ext/fastfilereader/extconf.rb +120 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +126 -0
- data/ext/kb.cpp +79 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +354 -0
- data/ext/project.h +174 -0
- data/ext/rubymain.cpp +1643 -0
- data/ext/ssl.cpp +701 -0
- data/ext/ssl.h +103 -0
- data/ext/wait_for_single_fd.h +36 -0
- data/java/.classpath +8 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
- data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
- data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
- data/lib/em/buftok.rb +59 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +69 -0
- data/lib/em/completion.rb +307 -0
- data/lib/em/connection.rb +802 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/io_streamer.rb +68 -0
- data/lib/em/iterator.rb +252 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/pool.rb +151 -0
- data/lib/em/process_watch.rb +45 -0
- data/lib/em/processes.rb +123 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +303 -0
- data/lib/em/protocols/httpclient2.rb +602 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +33 -0
- data/lib/em/protocols/linetext2.rb +179 -0
- data/lib/em/protocols/memcache.rb +331 -0
- data/lib/em/protocols/object_protocol.rb +46 -0
- data/lib/em/protocols/postgres3.rb +246 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +394 -0
- data/lib/em/protocols/smtpserver.rb +666 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +205 -0
- data/lib/em/protocols/tcptest.rb +54 -0
- data/lib/em/protocols.rb +37 -0
- data/lib/em/pure_ruby.rb +1300 -0
- data/lib/em/queue.rb +80 -0
- data/lib/em/resolver.rb +232 -0
- data/lib/em/spawnable.rb +84 -0
- data/lib/em/streamer.rb +118 -0
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +61 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1602 -0
- data/lib/jeventmachine.rb +319 -0
- data/rakelib/package.rake +120 -0
- data/rakelib/test.rake +6 -0
- data/rakelib/test_pure.rake +11 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/dhparam.pem +13 -0
- data/tests/em_ssl_handlers.rb +165 -0
- data/tests/em_test_helper.rb +198 -0
- data/tests/encoded_client.key +54 -0
- data/tests/jruby/test_jeventmachine.rb +38 -0
- data/tests/test_attach.rb +199 -0
- data/tests/test_basic.rb +321 -0
- data/tests/test_channel.rb +75 -0
- data/tests/test_completion.rb +178 -0
- data/tests/test_connection_count.rb +83 -0
- data/tests/test_connection_write.rb +35 -0
- data/tests/test_defer.rb +35 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +141 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +37 -0
- data/tests/test_file_watch.rb +86 -0
- data/tests/test_fork.rb +75 -0
- data/tests/test_futures.rb +170 -0
- data/tests/test_handler_check.rb +35 -0
- data/tests/test_hc.rb +155 -0
- data/tests/test_httpclient.rb +238 -0
- data/tests/test_httpclient2.rb +132 -0
- data/tests/test_idle_connection.rb +31 -0
- data/tests/test_inactivity_timeout.rb +102 -0
- data/tests/test_io_streamer.rb +48 -0
- data/tests/test_ipv4.rb +96 -0
- data/tests/test_ipv6.rb +107 -0
- data/tests/test_iterator.rb +122 -0
- data/tests/test_kb.rb +28 -0
- data/tests/test_keepalive.rb +113 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +155 -0
- data/tests/test_ltp2.rb +332 -0
- data/tests/test_many_fds.rb +21 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +109 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +196 -0
- data/tests/test_process_watch.rb +50 -0
- data/tests/test_processes.rb +147 -0
- data/tests/test_proxy_connection.rb +180 -0
- data/tests/test_pure.rb +156 -0
- data/tests/test_queue.rb +64 -0
- data/tests/test_resolver.rb +129 -0
- data/tests/test_running.rb +14 -0
- data/tests/test_sasl.rb +46 -0
- data/tests/test_send_file.rb +217 -0
- data/tests/test_servers.rb +32 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +75 -0
- data/tests/test_smtpserver.rb +90 -0
- data/tests/test_sock_opt.rb +53 -0
- data/tests/test_spawn.rb +290 -0
- data/tests/test_ssl_args.rb +70 -0
- data/tests/test_ssl_dhparam.rb +57 -0
- data/tests/test_ssl_ecdh_curve.rb +57 -0
- data/tests/test_ssl_extensions.rb +24 -0
- data/tests/test_ssl_inline_cert.rb +222 -0
- data/tests/test_ssl_methods.rb +31 -0
- data/tests/test_ssl_protocols.rb +190 -0
- data/tests/test_ssl_verify.rb +108 -0
- data/tests/test_stomp.rb +38 -0
- data/tests/test_system.rb +46 -0
- data/tests/test_threaded_resource.rb +68 -0
- data/tests/test_tick_loop.rb +58 -0
- data/tests/test_timers.rb +150 -0
- data/tests/test_ud.rb +8 -0
- data/tests/test_unbind_reason.rb +40 -0
- metadata +389 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'em_test_helper'
|
|
4
|
+
|
|
5
|
+
class TestSSLInlineCert < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
require_relative 'em_ssl_handlers'
|
|
8
|
+
include EMSSLHandlers
|
|
9
|
+
|
|
10
|
+
CERT_FILE="#{__dir__}/client.crt"
|
|
11
|
+
PRIVATE_KEY_FILE="#{__dir__}/client.key"
|
|
12
|
+
ENCODED_KEY_FILE="#{__dir__}/encoded_client.key"
|
|
13
|
+
|
|
14
|
+
CERT = File.read CERT_FILE
|
|
15
|
+
PRIVATE_KEY = File.read PRIVATE_KEY_FILE
|
|
16
|
+
ENCODED_KEY = File.read ENCODED_KEY_FILE
|
|
17
|
+
|
|
18
|
+
ENCODED_KEY_PASS = 'nicercat'
|
|
19
|
+
|
|
20
|
+
def test_proper_key_required_for_client
|
|
21
|
+
# an assert in ssl.ccp code make this fail
|
|
22
|
+
# with no way of catching the error
|
|
23
|
+
omit_if(rbx?)
|
|
24
|
+
|
|
25
|
+
bad_key=PRIVATE_KEY.dup
|
|
26
|
+
assert(bad_key[100]!=4)
|
|
27
|
+
bad_key[100]='4'
|
|
28
|
+
|
|
29
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
30
|
+
|
|
31
|
+
assert_raises EM::InvalidPrivateKey do
|
|
32
|
+
client_server Client, Server,
|
|
33
|
+
client: { private_key: bad_key,
|
|
34
|
+
cert: CERT },
|
|
35
|
+
server: server
|
|
36
|
+
end
|
|
37
|
+
refute Client.handshake_completed?
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_proper_key_required_for_server
|
|
41
|
+
# an assert in ssl.ccp code make this fail
|
|
42
|
+
# with no way of catching the error
|
|
43
|
+
omit_if(rbx?)
|
|
44
|
+
|
|
45
|
+
bad_key=PRIVATE_KEY.dup
|
|
46
|
+
assert(bad_key[100]!=4)
|
|
47
|
+
bad_key[100]='4'
|
|
48
|
+
|
|
49
|
+
server = { verify_peer: true, ssl_verify_result: true,
|
|
50
|
+
private_key: bad_key, cert: CERT }
|
|
51
|
+
|
|
52
|
+
assert_raises EM::InvalidPrivateKey do
|
|
53
|
+
client_server Client, Server,
|
|
54
|
+
server: server
|
|
55
|
+
end
|
|
56
|
+
refute Server.handshake_completed?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_accept_client_key_inline_cert_inline
|
|
60
|
+
omit_if(rbx?)
|
|
61
|
+
|
|
62
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
63
|
+
client = { private_key: PRIVATE_KEY,
|
|
64
|
+
cert: CERT }
|
|
65
|
+
|
|
66
|
+
client_server Client, Server,
|
|
67
|
+
client: client,
|
|
68
|
+
server: server
|
|
69
|
+
|
|
70
|
+
assert Client.handshake_completed?
|
|
71
|
+
assert Server.handshake_completed?
|
|
72
|
+
assert_equal CERT, Server.cert
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_accept_server_key_inline_cert_inline
|
|
76
|
+
omit_if(rbx?)
|
|
77
|
+
|
|
78
|
+
client = { verify_peer: true, ssl_verify_result: true }
|
|
79
|
+
server = { private_key: PRIVATE_KEY,
|
|
80
|
+
cert: CERT }
|
|
81
|
+
|
|
82
|
+
client_server Client, Server,
|
|
83
|
+
client: client,
|
|
84
|
+
server: server
|
|
85
|
+
|
|
86
|
+
assert Client.handshake_completed?
|
|
87
|
+
assert Server.handshake_completed?
|
|
88
|
+
assert_equal CERT, Client.cert
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_accept_client_encoded_key_inline_cert_inlince
|
|
92
|
+
omit_if(rbx?)
|
|
93
|
+
|
|
94
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
95
|
+
client = { private_key: ENCODED_KEY,
|
|
96
|
+
private_key_pass: ENCODED_KEY_PASS,
|
|
97
|
+
cert: CERT }
|
|
98
|
+
|
|
99
|
+
client_server Client, Server,
|
|
100
|
+
client: client,
|
|
101
|
+
server: server
|
|
102
|
+
|
|
103
|
+
assert Client.handshake_completed?
|
|
104
|
+
assert Server.handshake_completed?
|
|
105
|
+
assert_equal CERT, Server.cert
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_accept_server_encoded_key_inline_cert_inlince
|
|
109
|
+
omit_if(rbx?)
|
|
110
|
+
|
|
111
|
+
client = { verify_peer: true, ssl_verify_result: true }
|
|
112
|
+
server = { private_key: ENCODED_KEY,
|
|
113
|
+
private_key_pass: ENCODED_KEY_PASS,
|
|
114
|
+
cert: CERT }
|
|
115
|
+
|
|
116
|
+
client_server Client, Server,
|
|
117
|
+
client: client,
|
|
118
|
+
server: server
|
|
119
|
+
|
|
120
|
+
assert Client.handshake_completed?
|
|
121
|
+
assert Server.handshake_completed?
|
|
122
|
+
assert_equal CERT, Client.cert
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_accept_client_key_from_file_cert_inline
|
|
126
|
+
omit_if(rbx?)
|
|
127
|
+
|
|
128
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
129
|
+
client = { private_key_file: PRIVATE_KEY_FILE,
|
|
130
|
+
cert: CERT }
|
|
131
|
+
|
|
132
|
+
client_server Client, Server,
|
|
133
|
+
client: client,
|
|
134
|
+
server: server
|
|
135
|
+
|
|
136
|
+
assert Client.handshake_completed?
|
|
137
|
+
assert Server.handshake_completed?
|
|
138
|
+
assert_equal CERT, Server.cert
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_accept_server_key_from_file_cert_inline
|
|
142
|
+
omit_if(rbx?)
|
|
143
|
+
|
|
144
|
+
client = { verify_peer: true, ssl_verify_result: true }
|
|
145
|
+
server = { private_key_file: PRIVATE_KEY_FILE,
|
|
146
|
+
cert: CERT }
|
|
147
|
+
|
|
148
|
+
client_server Client, Server,
|
|
149
|
+
client: client,
|
|
150
|
+
server: server
|
|
151
|
+
|
|
152
|
+
assert Client.handshake_completed?
|
|
153
|
+
assert Server.handshake_completed?
|
|
154
|
+
assert_equal CERT, Client.cert
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_accept_client_key_inline_cert_from_file
|
|
158
|
+
omit_if(rbx?)
|
|
159
|
+
|
|
160
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
161
|
+
client = { private_key: PRIVATE_KEY,
|
|
162
|
+
cert_chain_file: CERT_FILE }
|
|
163
|
+
|
|
164
|
+
client_server Client, Server,
|
|
165
|
+
client: client,
|
|
166
|
+
server: server
|
|
167
|
+
|
|
168
|
+
assert Client.handshake_completed?
|
|
169
|
+
assert Server.handshake_completed?
|
|
170
|
+
assert_equal CERT, Server.cert
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def test_accept_server_key_inline_cert_from_file
|
|
174
|
+
omit_if(rbx?)
|
|
175
|
+
|
|
176
|
+
client = { verify_peer: true, ssl_verify_result: true }
|
|
177
|
+
server = { private_key: PRIVATE_KEY,
|
|
178
|
+
cert_chain_file: CERT_FILE }
|
|
179
|
+
|
|
180
|
+
client_server Client, Server,
|
|
181
|
+
client: client,
|
|
182
|
+
server: server
|
|
183
|
+
|
|
184
|
+
assert Client.handshake_completed?
|
|
185
|
+
assert Server.handshake_completed?
|
|
186
|
+
assert_equal CERT, Client.cert
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def test_accept_client_encoded_key_inline_cert_from_file
|
|
190
|
+
omit_if(rbx?)
|
|
191
|
+
|
|
192
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
193
|
+
client = { private_key: ENCODED_KEY,
|
|
194
|
+
private_key_pass: ENCODED_KEY_PASS,
|
|
195
|
+
cert_chain_file: CERT_FILE }
|
|
196
|
+
|
|
197
|
+
client_server Client, Server,
|
|
198
|
+
client: client,
|
|
199
|
+
server: server
|
|
200
|
+
|
|
201
|
+
assert Client.handshake_completed?
|
|
202
|
+
assert Server.handshake_completed?
|
|
203
|
+
assert_equal CERT, Server.cert
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def test_accept_server_encoded_key_inline_cert_from_file
|
|
207
|
+
omit_if(rbx?)
|
|
208
|
+
|
|
209
|
+
client = { verify_peer: true, ssl_verify_result: true}
|
|
210
|
+
server = { private_key: ENCODED_KEY,
|
|
211
|
+
private_key_pass: ENCODED_KEY_PASS,
|
|
212
|
+
cert_chain_file: CERT_FILE }
|
|
213
|
+
|
|
214
|
+
client_server Client, Server,
|
|
215
|
+
client: client,
|
|
216
|
+
server: server
|
|
217
|
+
|
|
218
|
+
assert Client.handshake_completed?
|
|
219
|
+
assert Server.handshake_completed?
|
|
220
|
+
assert_equal CERT, Client.cert
|
|
221
|
+
end
|
|
222
|
+
end if EM.ssl?
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'em_test_helper'
|
|
4
|
+
|
|
5
|
+
class TestSSLMethods < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
require_relative 'em_ssl_handlers'
|
|
8
|
+
include EMSSLHandlers
|
|
9
|
+
|
|
10
|
+
def test_ssl_methods
|
|
11
|
+
omit_if(rbx?)
|
|
12
|
+
|
|
13
|
+
client_server
|
|
14
|
+
|
|
15
|
+
assert Server.handshake_completed?
|
|
16
|
+
assert Client.handshake_completed?
|
|
17
|
+
|
|
18
|
+
assert Server.cert_value.is_a? NilClass
|
|
19
|
+
assert Client.cert_value.is_a? String
|
|
20
|
+
|
|
21
|
+
assert Client.cipher_bits > 0
|
|
22
|
+
assert_equal Client.cipher_bits, Server.cipher_bits
|
|
23
|
+
|
|
24
|
+
assert Client.cipher_name.length > 0
|
|
25
|
+
assert_match(/AES/, Client.cipher_name)
|
|
26
|
+
assert_equal Client.cipher_name, Server.cipher_name
|
|
27
|
+
|
|
28
|
+
assert Client.cipher_protocol.start_with? "TLS"
|
|
29
|
+
assert_equal Client.cipher_protocol, Server.cipher_protocol
|
|
30
|
+
end
|
|
31
|
+
end if EM.ssl?
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'em_test_helper'
|
|
4
|
+
|
|
5
|
+
# For OpenSSL 1.1.0 and later, cipher_protocol returns single cipher, older
|
|
6
|
+
# versions return "TLSv1/SSLv3"
|
|
7
|
+
# TLSv1.1 handshake_completed Server/Client callback order is reversed from
|
|
8
|
+
# older protocols
|
|
9
|
+
|
|
10
|
+
class TestSSLProtocols < Test::Unit::TestCase
|
|
11
|
+
|
|
12
|
+
require_relative 'em_ssl_handlers'
|
|
13
|
+
include EMSSLHandlers
|
|
14
|
+
|
|
15
|
+
# We're checking for whether Context min_version= & max_version= are defined, but
|
|
16
|
+
# JRuby has a bug where they're defined, but the private method they call isn't
|
|
17
|
+
RUBY_SSL_GE_2_1 = OpenSSL::SSL::SSLContext.private_instance_methods(false).include?(:set_minmax_proto_version)
|
|
18
|
+
|
|
19
|
+
def test_invalid_ssl_version
|
|
20
|
+
assert_raises(RuntimeError, "Unrecognized SSL/TLS Version: badinput") do
|
|
21
|
+
client = { ssl_version: %w(tlsv1 badinput) }
|
|
22
|
+
server = { ssl_version: %w(tlsv1 badinput) }
|
|
23
|
+
client_server client: client, server: server
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_any_to_v3
|
|
28
|
+
omit("SSLv3 is (correctly) unavailable") if EM::OPENSSL_NO_SSL3
|
|
29
|
+
client_server client: TLS_ALL, server: SSL_3
|
|
30
|
+
assert Client.handshake_completed?
|
|
31
|
+
assert Server.handshake_completed?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_any_to_tlsv1_2
|
|
35
|
+
client_server client: TLS_ALL, server: TLS_1_2
|
|
36
|
+
assert Client.handshake_completed?
|
|
37
|
+
assert Server.handshake_completed?
|
|
38
|
+
if IS_SSL_GE_1_1
|
|
39
|
+
assert_equal "TLSv1.2", Client.cipher_protocol
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_case_insensitivity
|
|
44
|
+
lower_case = SSL_AVAIL.map { |p| p.downcase }
|
|
45
|
+
client = { ssl_version: %w(tlsv1_2) }
|
|
46
|
+
server = { ssl_version: lower_case }
|
|
47
|
+
client_server client: client, server: server
|
|
48
|
+
assert Client.handshake_completed?
|
|
49
|
+
assert Server.handshake_completed?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_v3_to_any
|
|
53
|
+
omit("SSLv3 is (correctly) unavailable") if EM::OPENSSL_NO_SSL3
|
|
54
|
+
client_server client: SSL_3, server: TLS_ALL
|
|
55
|
+
assert Client.handshake_completed?
|
|
56
|
+
assert Server.handshake_completed?
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_tlsv1_2_to_any
|
|
60
|
+
client_server client: TLS_1_2, server: TLS_ALL
|
|
61
|
+
assert Client.handshake_completed?
|
|
62
|
+
assert Server.handshake_completed?
|
|
63
|
+
if IS_SSL_GE_1_1
|
|
64
|
+
assert_equal "TLSv1.2", Server.cipher_protocol
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_v3_to_v3
|
|
69
|
+
omit("SSLv3 is (correctly) unavailable") if EM::OPENSSL_NO_SSL3
|
|
70
|
+
client_server client: SSL_3, server: SSL_3
|
|
71
|
+
assert Client.handshake_completed?
|
|
72
|
+
assert Server.handshake_completed?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_tlsv1_2_to_tlsv1_2
|
|
76
|
+
client_server client: TLS_1_2, server: TLS_1_2
|
|
77
|
+
assert Client.handshake_completed?
|
|
78
|
+
assert Server.handshake_completed?
|
|
79
|
+
if IS_SSL_GE_1_1
|
|
80
|
+
assert_equal "TLSv1.2", Client.cipher_protocol
|
|
81
|
+
assert_equal "TLSv1.2", Server.cipher_protocol
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_tlsv1_3_to_tlsv1_3
|
|
86
|
+
omit("TLSv1_3 is unavailable") unless EM.const_defined? :EM_PROTO_TLSv1_3
|
|
87
|
+
client_server client: TLS_1_3, server: TLS_1_3
|
|
88
|
+
assert Client.handshake_completed?
|
|
89
|
+
assert Server.handshake_completed?
|
|
90
|
+
assert_equal "TLSv1.3", Client.cipher_protocol
|
|
91
|
+
assert_equal "TLSv1.3", Server.cipher_protocol
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def test_any_to_any
|
|
95
|
+
client_server client: TLS_ALL, server: TLS_ALL
|
|
96
|
+
assert Client.handshake_completed?
|
|
97
|
+
assert Server.handshake_completed?
|
|
98
|
+
if IS_SSL_GE_1_1
|
|
99
|
+
best_protocol = SSL_AVAIL.last.tr "_", "."
|
|
100
|
+
assert_equal best_protocol, Client.cipher_protocol
|
|
101
|
+
assert_equal best_protocol, Server.cipher_protocol
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_default_to_default
|
|
106
|
+
client_server
|
|
107
|
+
assert Client.handshake_completed?
|
|
108
|
+
assert Server.handshake_completed?
|
|
109
|
+
if IS_SSL_GE_1_1
|
|
110
|
+
best_protocol = SSL_AVAIL.last.tr "_", "."
|
|
111
|
+
assert_equal best_protocol, Client.cipher_protocol
|
|
112
|
+
assert_equal best_protocol, Server.cipher_protocol
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def external_client(ext_min, ext_max, ext_ssl, server)
|
|
117
|
+
EM.run do
|
|
118
|
+
# setup_timeout 2
|
|
119
|
+
EM.start_server IP, PORT, Server, server.merge( { stop_after_handshake: true} )
|
|
120
|
+
EM.defer do
|
|
121
|
+
sock = TCPSocket.new IP, PORT
|
|
122
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
|
123
|
+
if RUBY_SSL_GE_2_1
|
|
124
|
+
ctx.min_version = ext_min if ext_min
|
|
125
|
+
ctx.max_version = ext_max if ext_max
|
|
126
|
+
else
|
|
127
|
+
ctx.ssl_version = ext_ssl
|
|
128
|
+
end
|
|
129
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
|
|
130
|
+
ssl.connect
|
|
131
|
+
ssl.close rescue nil
|
|
132
|
+
sock.close rescue nil
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
assert Server.handshake_completed?
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_v3_with_external_client
|
|
139
|
+
omit("SSLv3 is (correctly) unavailable") if EM::OPENSSL_NO_SSL3
|
|
140
|
+
external_client nil, nil, :SSLv3_client, SSL_3
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Fixed Server
|
|
144
|
+
def test_tlsv1_2_with_external_client
|
|
145
|
+
external_client nil, nil, :SSLv23_client, TLS_1_2
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_tlsv1_3_with_external_client
|
|
149
|
+
omit("TLSv1_3 is unavailable") unless EM.const_defined?(:EM_PROTO_TLSv1_3) &&
|
|
150
|
+
OpenSSL::SSL.const_defined?(:TLS1_3_VERSION)
|
|
151
|
+
external_client nil, nil, :SSLv23_client, TLS_1_3
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Fixed Client
|
|
155
|
+
def test_any_with_external_client_tlsv1_2
|
|
156
|
+
external_client :TLS1_2, :TLS1_2, :TLSv1_2_client, TLS_ALL
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def test_any_with_external_client_tlsv1_3
|
|
160
|
+
omit("TLSv1_3 is unavailable") unless EM.const_defined? :EM_PROTO_TLSv1_3
|
|
161
|
+
external_client :TLS1_3, :TLS1_3, :TLSv1_2_client, TLS_ALL
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Refuse a client?
|
|
165
|
+
def test_tlsv1_2_required_with_external_client
|
|
166
|
+
EM.run do
|
|
167
|
+
n = 0
|
|
168
|
+
EM.add_periodic_timer(0.5) do
|
|
169
|
+
n += 1
|
|
170
|
+
(EM.stop rescue nil) if n == 2
|
|
171
|
+
end
|
|
172
|
+
EM.start_server IP, PORT, Server, TLS_1_2.merge( { stop_after_handshake: true} )
|
|
173
|
+
EM.defer do
|
|
174
|
+
sock = TCPSocket.new IP, PORT
|
|
175
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
|
176
|
+
if RUBY_SSL_GE_2_1
|
|
177
|
+
ctx.max_version = :TLS1_1
|
|
178
|
+
else
|
|
179
|
+
ctx.ssl_version = :TLSv1_client
|
|
180
|
+
end
|
|
181
|
+
ssl = OpenSSL::SSL::SSLSocket.new sock, ctx
|
|
182
|
+
assert_raise(OpenSSL::SSL::SSLError) { ssl.connect }
|
|
183
|
+
ssl.close rescue nil
|
|
184
|
+
sock.close rescue nil
|
|
185
|
+
EM.stop rescue nil
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
refute Server.handshake_completed?
|
|
189
|
+
end
|
|
190
|
+
end if EM.ssl?
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'em_test_helper'
|
|
4
|
+
|
|
5
|
+
class TestSSLVerify < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
require_relative 'em_ssl_handlers'
|
|
8
|
+
include EMSSLHandlers
|
|
9
|
+
|
|
10
|
+
CERT_FROM_FILE = File.read "#{__dir__}/client.crt"
|
|
11
|
+
|
|
12
|
+
CERT_CONFIG = { private_key_file: "#{__dir__}/client.key",
|
|
13
|
+
cert_chain_file: "#{__dir__}/client.crt" }
|
|
14
|
+
|
|
15
|
+
ENCODED_CERT_CONFIG = { private_key_file: "#{__dir__}/encoded_client.key",
|
|
16
|
+
private_key_pass: 'nicercat',
|
|
17
|
+
cert_chain_file: "#{__dir__}/client.crt" }
|
|
18
|
+
|
|
19
|
+
def test_fail_no_peer_cert
|
|
20
|
+
omit_if(rbx?)
|
|
21
|
+
|
|
22
|
+
server = { verify_peer: true, fail_if_no_peer_cert: true,
|
|
23
|
+
ssl_verify_result: "|RAISE|Verify peer should not get called for a client without a certificate" }
|
|
24
|
+
|
|
25
|
+
client_server Client, Server, server: server
|
|
26
|
+
|
|
27
|
+
refute Client.handshake_completed? unless "TLSv1.3" == Client.cipher_protocol
|
|
28
|
+
refute Server.handshake_completed?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_accept_server
|
|
32
|
+
omit_if(EM.library_type == :pure_ruby) # Server has a default cert chain
|
|
33
|
+
omit_if(rbx?)
|
|
34
|
+
|
|
35
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
36
|
+
|
|
37
|
+
client_server Client, Server, client: CERT_CONFIG, server: server
|
|
38
|
+
|
|
39
|
+
assert_equal CERT_FROM_FILE, Server.cert
|
|
40
|
+
assert Client.handshake_completed?
|
|
41
|
+
assert Server.handshake_completed?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_accept_client
|
|
45
|
+
omit_if(EM.library_type == :pure_ruby) # Server has a default cert chain
|
|
46
|
+
omit_if(rbx?)
|
|
47
|
+
|
|
48
|
+
client = { verify_peer: true, ssl_verify_result: true }
|
|
49
|
+
|
|
50
|
+
client_server Client, Server, server: CERT_CONFIG, client: client
|
|
51
|
+
|
|
52
|
+
assert_equal CERT_FROM_FILE, Client.cert
|
|
53
|
+
assert Client.handshake_completed?
|
|
54
|
+
assert Server.handshake_completed?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_encoded_accept_server
|
|
58
|
+
omit_if(EM.library_type == :pure_ruby) # Server has a default cert chain
|
|
59
|
+
omit_if(rbx?)
|
|
60
|
+
|
|
61
|
+
server = { verify_peer: true, ssl_verify_result: true }
|
|
62
|
+
|
|
63
|
+
client_server Client, Server, client: ENCODED_CERT_CONFIG, server: server
|
|
64
|
+
|
|
65
|
+
assert Client.handshake_completed?
|
|
66
|
+
assert Server.handshake_completed?
|
|
67
|
+
assert_equal CERT_FROM_FILE, Server.cert
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_encoded_accept_client
|
|
71
|
+
omit_if(EM.library_type == :pure_ruby) # Server has a default cert chain
|
|
72
|
+
omit_if(rbx?)
|
|
73
|
+
|
|
74
|
+
client = { verify_peer: true, ssl_verify_result: true }
|
|
75
|
+
|
|
76
|
+
client_server Client, Server, server: ENCODED_CERT_CONFIG, client: client
|
|
77
|
+
|
|
78
|
+
assert Client.handshake_completed?
|
|
79
|
+
assert Server.handshake_completed?
|
|
80
|
+
assert_equal CERT_FROM_FILE, Client.cert
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_deny_server
|
|
84
|
+
omit_if(EM.library_type == :pure_ruby) # Server has a default cert chain
|
|
85
|
+
omit_if(rbx?)
|
|
86
|
+
|
|
87
|
+
server = { verify_peer: true, ssl_verify_result: false }
|
|
88
|
+
|
|
89
|
+
client_server Client, Server, client: CERT_CONFIG, server: server
|
|
90
|
+
|
|
91
|
+
assert_equal CERT_FROM_FILE, Server.cert
|
|
92
|
+
refute Client.handshake_completed? unless "TLSv1.3" == Client.cipher_protocol
|
|
93
|
+
refute Server.handshake_completed?
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_deny_client
|
|
97
|
+
omit_if(EM.library_type == :pure_ruby) # Server has a default cert chain
|
|
98
|
+
omit_if(rbx?)
|
|
99
|
+
|
|
100
|
+
client = { verify_peer: true, ssl_verify_result: false }
|
|
101
|
+
|
|
102
|
+
client_server Client, Server, server: CERT_CONFIG, client: client
|
|
103
|
+
|
|
104
|
+
refute Client.handshake_completed? unless "TLSv1.3" == Client.cipher_protocol
|
|
105
|
+
refute Server.handshake_completed?
|
|
106
|
+
assert_equal CERT_FROM_FILE, Client.cert
|
|
107
|
+
end
|
|
108
|
+
end if EM.ssl?
|
data/tests/test_stomp.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_relative 'em_test_helper'
|
|
2
|
+
|
|
3
|
+
class TestStomp < Test::Unit::TestCase
|
|
4
|
+
CONTENT_LENGTH_REGEX = /^content-length: (\d+)$/
|
|
5
|
+
|
|
6
|
+
def bytesize(str)
|
|
7
|
+
str = str.to_s
|
|
8
|
+
size = str.bytesize if str.respond_to?(:bytesize) # bytesize added in 1.9
|
|
9
|
+
size || str.size
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class TStomp
|
|
13
|
+
include EM::P::Stomp
|
|
14
|
+
|
|
15
|
+
def last_sent_content_length
|
|
16
|
+
@sent && Integer(@sent[CONTENT_LENGTH_REGEX, 1])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def send_data(string)
|
|
20
|
+
@sent = string
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_content_length_in_bytes
|
|
25
|
+
connection = TStomp.new
|
|
26
|
+
|
|
27
|
+
queue = "queue"
|
|
28
|
+
failure_message = "header content-length is not the byte size of last sent body"
|
|
29
|
+
|
|
30
|
+
body = "test"
|
|
31
|
+
connection.send queue, body
|
|
32
|
+
assert_equal bytesize(body), connection.last_sent_content_length, failure_message
|
|
33
|
+
|
|
34
|
+
body = "test\u221A"
|
|
35
|
+
connection.send queue, body
|
|
36
|
+
assert_equal bytesize(body), connection.last_sent_content_length, failure_message
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
require_relative 'em_test_helper'
|
|
3
|
+
|
|
4
|
+
class TestSystem < Test::Unit::TestCase
|
|
5
|
+
def setup
|
|
6
|
+
@filename = File.expand_path("../я манал dump.txt", __FILE__)
|
|
7
|
+
@test_data = 'a' * 100
|
|
8
|
+
File.open(@filename, 'w'){|f| f.write(@test_data)}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_system
|
|
12
|
+
omit_if(windows?)
|
|
13
|
+
|
|
14
|
+
result = nil
|
|
15
|
+
status = nil
|
|
16
|
+
EM.run {
|
|
17
|
+
EM.system('cat', @filename){|out, state|
|
|
18
|
+
result = out
|
|
19
|
+
status = state.exitstatus
|
|
20
|
+
EM.stop
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
assert_equal(0, status)
|
|
24
|
+
assert_equal(@test_data, result)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_system_with_string
|
|
28
|
+
omit_if(windows?)
|
|
29
|
+
|
|
30
|
+
result = nil
|
|
31
|
+
status = nil
|
|
32
|
+
EM.run {
|
|
33
|
+
EM.system("cat '#@filename'"){|out, state|
|
|
34
|
+
result = out
|
|
35
|
+
status = state.exitstatus
|
|
36
|
+
EM.stop
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
assert_equal(0, status)
|
|
40
|
+
assert_equal(@test_data, result)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def teardown
|
|
44
|
+
File.unlink(@filename)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require_relative 'em_test_helper'
|
|
2
|
+
|
|
3
|
+
class TestThreadedResource < Test::Unit::TestCase
|
|
4
|
+
def object
|
|
5
|
+
@object ||= {}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def resource
|
|
9
|
+
@resource = EM::ThreadedResource.new do
|
|
10
|
+
object
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def teardown
|
|
15
|
+
resource.shutdown
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_dispatch_completion
|
|
19
|
+
EM.run do
|
|
20
|
+
EM.add_timer(3) do
|
|
21
|
+
EM.stop
|
|
22
|
+
if ENV['CI'].casecmp('true').zero? and RUBY_PLATFORM[/darwin/]
|
|
23
|
+
notify "Intermittent Travis MacOS: Resource dispatch timed out"
|
|
24
|
+
return
|
|
25
|
+
else
|
|
26
|
+
assert false, 'Resource dispatch timed out'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
completion = resource.dispatch do |o|
|
|
30
|
+
o[:foo] = :bar
|
|
31
|
+
:foo
|
|
32
|
+
end
|
|
33
|
+
completion.callback do |result|
|
|
34
|
+
assert_equal :foo, result
|
|
35
|
+
EM.stop
|
|
36
|
+
end
|
|
37
|
+
completion.errback do |error|
|
|
38
|
+
EM.stop
|
|
39
|
+
assert false, "Unexpected error: #{error.message}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
assert_equal :bar, object[:foo]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_dispatch_failure
|
|
46
|
+
completion = resource.dispatch do |o|
|
|
47
|
+
raise 'boom'
|
|
48
|
+
end
|
|
49
|
+
completion.errback do |error|
|
|
50
|
+
assert_kind_of RuntimeError, error
|
|
51
|
+
assert_equal 'boom', error.message
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_dispatch_threading
|
|
56
|
+
main = Thread.current
|
|
57
|
+
resource.dispatch do |o|
|
|
58
|
+
o[:dispatch_thread] = Thread.current
|
|
59
|
+
end
|
|
60
|
+
assert_not_equal main, object[:dispatch_thread]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_shutdown
|
|
64
|
+
# This test should get improved sometime. The method returning thread is
|
|
65
|
+
# NOT an api that will be maintained.
|
|
66
|
+
assert !resource.shutdown.alive?
|
|
67
|
+
end
|
|
68
|
+
end
|