fluentd 1.13.0-x64-mingw32 → 1.14.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.yaml +69 -0
- data/.github/ISSUE_TEMPLATE/feature_request.yaml +38 -0
- data/.github/workflows/linux-test.yaml +1 -1
- data/.github/workflows/windows-test.yaml +4 -4
- data/.gitlab-ci.yml +0 -22
- data/CHANGELOG.md +131 -0
- data/README.md +2 -2
- data/example/v0_12_filter.conf +2 -2
- data/fluentd.gemspec +1 -1
- data/lib/fluent/command/fluentd.rb +8 -0
- data/lib/fluent/command/plugin_generator.rb +15 -5
- data/lib/fluent/compat/output.rb +9 -6
- data/lib/fluent/config/section.rb +5 -0
- data/lib/fluent/config/types.rb +15 -0
- data/lib/fluent/config/v1_parser.rb +3 -2
- data/lib/fluent/config.rb +1 -1
- data/lib/fluent/env.rb +2 -1
- data/lib/fluent/event_router.rb +28 -1
- data/lib/fluent/oj_options.rb +62 -0
- data/lib/fluent/plugin/bare_output.rb +49 -8
- data/lib/fluent/plugin/buffer.rb +84 -22
- data/lib/fluent/plugin/file_wrapper.rb +22 -0
- data/lib/fluent/plugin/filter.rb +35 -1
- data/lib/fluent/plugin/formatter.rb +1 -0
- data/lib/fluent/plugin/formatter_json.rb +9 -7
- data/lib/fluent/plugin/in_http.rb +21 -2
- data/lib/fluent/plugin/in_monitor_agent.rb +4 -2
- data/lib/fluent/plugin/in_syslog.rb +13 -1
- data/lib/fluent/plugin/in_tail/position_file.rb +20 -18
- data/lib/fluent/plugin/in_tail.rb +45 -4
- data/lib/fluent/plugin/input.rb +39 -1
- data/lib/fluent/plugin/metrics.rb +119 -0
- data/lib/fluent/plugin/metrics_local.rb +96 -0
- data/lib/fluent/plugin/multi_output.rb +43 -6
- data/lib/fluent/plugin/out_forward.rb +1 -3
- data/lib/fluent/plugin/output.rb +74 -33
- data/lib/fluent/plugin/parser_json.rb +2 -3
- data/lib/fluent/plugin/service_discovery.rb +0 -15
- data/lib/fluent/plugin.rb +10 -1
- data/lib/fluent/plugin_helper/event_emitter.rb +8 -1
- data/lib/fluent/plugin_helper/http_server/router.rb +1 -1
- data/lib/fluent/plugin_helper/metrics.rb +129 -0
- data/lib/fluent/plugin_helper/server.rb +4 -2
- data/lib/fluent/plugin_helper.rb +1 -0
- data/lib/fluent/root_agent.rb +6 -0
- data/lib/fluent/supervisor.rb +2 -0
- data/lib/fluent/system_config.rb +9 -1
- data/lib/fluent/test/driver/storage.rb +30 -0
- data/lib/fluent/version.rb +1 -1
- data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
- data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
- data/test/command/test_cat.rb +11 -8
- data/test/command/test_plugin_generator.rb +2 -1
- data/test/config/test_section.rb +9 -0
- data/test/config/test_system_config.rb +6 -0
- data/test/config/test_types.rb +7 -0
- data/test/plugin/in_tail/test_position_file.rb +48 -8
- data/test/plugin/test_bare_output.rb +13 -0
- data/test/plugin/test_buffer.rb +8 -2
- data/test/plugin/test_file_wrapper.rb +11 -0
- data/test/plugin/test_filter.rb +11 -0
- data/test/plugin/test_in_forward.rb +59 -83
- data/test/plugin/test_in_http.rb +86 -43
- data/test/plugin/test_in_monitor_agent.rb +214 -8
- data/test/plugin/test_in_syslog.rb +101 -56
- data/test/plugin/test_in_tail.rb +149 -48
- data/test/plugin/test_in_tcp.rb +45 -32
- data/test/plugin/test_in_udp.rb +47 -33
- data/test/plugin/test_input.rb +11 -0
- data/test/plugin/test_metrics.rb +294 -0
- data/test/plugin/test_metrics_local.rb +96 -0
- data/test/plugin/test_multi_output.rb +25 -1
- data/test/plugin/test_out_forward.rb +103 -89
- data/test/plugin/test_out_stream.rb +18 -8
- data/test/plugin/test_output.rb +16 -0
- data/test/plugin_helper/http_server/test_route.rb +1 -1
- data/test/plugin_helper/test_child_process.rb +1 -1
- data/test/plugin_helper/test_event_emitter.rb +29 -0
- data/test/plugin_helper/test_http_server_helper.rb +33 -26
- data/test/plugin_helper/test_metrics.rb +137 -0
- data/test/plugin_helper/test_server.rb +137 -138
- data/test/plugin_helper/test_socket.rb +16 -9
- data/test/test_event_time.rb +2 -2
- data/test/test_oj_options.rb +55 -0
- data/test/test_plugin_classes.rb +102 -0
- data/test/test_root_agent.rb +30 -1
- metadata +22 -7
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
@@ -14,9 +14,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/plugin_helper_server")
|
16
16
|
|
17
|
-
PORT = unused_port
|
18
|
-
|
19
17
|
setup do
|
18
|
+
@port = unused_port
|
20
19
|
@socket_manager_path = ServerEngine::SocketManager::Server.generate_path
|
21
20
|
if @socket_manager_path.is_a?(String) && File.exist?(@socket_manager_path)
|
22
21
|
FileUtils.rm_f @socket_manager_path
|
@@ -75,16 +74,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
75
74
|
data(methods)
|
76
75
|
test 'raise error if title is not specified or not a symbol' do |m|
|
77
76
|
assert_raise(ArgumentError.new("BUG: title must be a symbol")) do
|
78
|
-
@d.__send__(m, nil,
|
77
|
+
@d.__send__(m, nil, @port){|x| x }
|
79
78
|
end
|
80
79
|
assert_raise(ArgumentError.new("BUG: title must be a symbol")) do
|
81
|
-
@d.__send__(m, "",
|
80
|
+
@d.__send__(m, "", @port){|x| x }
|
82
81
|
end
|
83
82
|
assert_raise(ArgumentError.new("BUG: title must be a symbol")) do
|
84
|
-
@d.__send__(m, "title",
|
83
|
+
@d.__send__(m, "title", @port){|x| x }
|
85
84
|
end
|
86
85
|
assert_nothing_raised do
|
87
|
-
@d.__send__(m, :myserver,
|
86
|
+
@d.__send__(m, :myserver, @port){|x| x }
|
88
87
|
end
|
89
88
|
end
|
90
89
|
|
@@ -100,30 +99,30 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
100
99
|
@d.__send__(m, :myserver, 1.5){|x| x }
|
101
100
|
end
|
102
101
|
assert_nothing_raised do
|
103
|
-
@d.__send__(m, :myserver,
|
102
|
+
@d.__send__(m, :myserver, @port){|x| x }
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
107
106
|
data(methods)
|
108
107
|
test 'raise error if block is not specified' do |m|
|
109
108
|
assert_raise(ArgumentError) do
|
110
|
-
@d.__send__(m, :myserver,
|
109
|
+
@d.__send__(m, :myserver, @port)
|
111
110
|
end
|
112
111
|
assert_nothing_raised do
|
113
|
-
@d.__send__(m, :myserver,
|
112
|
+
@d.__send__(m, :myserver, @port){|x| x }
|
114
113
|
end
|
115
114
|
end
|
116
115
|
|
117
116
|
data(methods)
|
118
117
|
test 'creates tcp server, binds 0.0.0.0 in default' do |m|
|
119
|
-
@d.__send__(m, :myserver,
|
118
|
+
@d.__send__(m, :myserver, @port){|x| x }
|
120
119
|
|
121
120
|
assert_equal 1, @d._servers.size
|
122
121
|
|
123
122
|
created_server_info = @d._servers.first
|
124
123
|
|
125
124
|
assert_equal :myserver, created_server_info.title
|
126
|
-
assert_equal
|
125
|
+
assert_equal @port, created_server_info.port
|
127
126
|
|
128
127
|
assert_equal :tcp, created_server_info.proto
|
129
128
|
assert_equal "0.0.0.0", created_server_info.bind
|
@@ -136,7 +135,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
136
135
|
|
137
136
|
data(methods)
|
138
137
|
test 'creates tcp server if specified in proto' do |m|
|
139
|
-
@d.__send__(m, :myserver,
|
138
|
+
@d.__send__(m, :myserver, @port, proto: :tcp){|x| x }
|
140
139
|
|
141
140
|
created_server_info = @d._servers.first
|
142
141
|
assert_equal :tcp, created_server_info.proto
|
@@ -152,7 +151,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
152
151
|
d.start
|
153
152
|
d.after_start
|
154
153
|
|
155
|
-
d.__send__(m, :myserver,
|
154
|
+
d.__send__(m, :myserver, @port){|x| x }
|
156
155
|
|
157
156
|
created_server_info = @d._servers.first
|
158
157
|
assert_equal :tcp, created_server_info.proto
|
@@ -163,9 +162,9 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
163
162
|
data(methods)
|
164
163
|
test 'creates tls server if specified in proto' do |m|
|
165
164
|
assert_raise(ArgumentError.new("BUG: TLS transport specified, but certification options are not specified")) do
|
166
|
-
@d.__send__(m, :myserver,
|
165
|
+
@d.__send__(m, :myserver, @port, proto: :tls){|x| x }
|
167
166
|
end
|
168
|
-
@d.__send__(m, :myserver,
|
167
|
+
@d.__send__(m, :myserver, @port, proto: :tls, tls_options: {insecure: true}){|x| x }
|
169
168
|
|
170
169
|
created_server_info = @d._servers.first
|
171
170
|
assert_equal :tls, created_server_info.proto
|
@@ -181,7 +180,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
181
180
|
d.start
|
182
181
|
d.after_start
|
183
182
|
|
184
|
-
d.__send__(m, :myserver,
|
183
|
+
d.__send__(m, :myserver, @port){|x| x }
|
185
184
|
|
186
185
|
created_server_info = @d._servers.first
|
187
186
|
assert_equal :tls, created_server_info.proto
|
@@ -197,7 +196,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
197
196
|
data(methods)
|
198
197
|
test 'raise error if unknown protocol specified' do |m|
|
199
198
|
assert_raise(ArgumentError.new("BUG: invalid protocol name")) do
|
200
|
-
@d.__send__(m, :myserver,
|
199
|
+
@d.__send__(m, :myserver, @port, proto: :quic){|x| x }
|
201
200
|
end
|
202
201
|
end
|
203
202
|
|
@@ -211,10 +210,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
211
210
|
)
|
212
211
|
test 'raise error if udp options specified for tcp/tls/unix' do |(m, proto)|
|
213
212
|
assert_raise ArgumentError do
|
214
|
-
@d.__send__(m, :myserver,
|
213
|
+
@d.__send__(m, :myserver, @port, proto: proto, max_bytes: 128){|x| x }
|
215
214
|
end
|
216
215
|
assert_raise ArgumentError do
|
217
|
-
@d.__send__(m, :myserver,
|
216
|
+
@d.__send__(m, :myserver, @port, proto: proto, flags: 1){|x| x }
|
218
217
|
end
|
219
218
|
end
|
220
219
|
|
@@ -223,7 +222,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
223
222
|
)
|
224
223
|
test 'raise error if tcp/tls options specified for udp' do |(m, proto)|
|
225
224
|
assert_raise(ArgumentError.new("BUG: linger_timeout is available for tcp/tls")) do
|
226
|
-
@d.__send__(m, :myserver,
|
225
|
+
@d.__send__(m, :myserver, @port, proto: proto, linger_timeout: 1, max_bytes: 128){|x| x }
|
227
226
|
end
|
228
227
|
end
|
229
228
|
|
@@ -232,7 +231,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
232
231
|
)
|
233
232
|
test 'raise error if tcp/tls/unix backlog options specified for udp' do |(m, proto)|
|
234
233
|
assert_raise(ArgumentError.new("BUG: backlog is available for tcp/tls")) do
|
235
|
-
@d.__send__(m, :myserver,
|
234
|
+
@d.__send__(m, :myserver, @port, proto: proto, backlog: 500){|x| x }
|
236
235
|
end
|
237
236
|
end
|
238
237
|
|
@@ -241,7 +240,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
241
240
|
)
|
242
241
|
test 'raise error if tcp/tls send_keepalive_packet option is specified for udp' do |(m, proto)|
|
243
242
|
assert_raise(ArgumentError.new("BUG: send_keepalive_packet is available for tcp/tls")) do
|
244
|
-
@d.__send__(m, :myserver,
|
243
|
+
@d.__send__(m, :myserver, @port, proto: proto, send_keepalive_packet: true){|x| x }
|
245
244
|
end
|
246
245
|
end
|
247
246
|
|
@@ -254,7 +253,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
254
253
|
)
|
255
254
|
test 'raise error if tls options specified for tcp/udp/unix' do |(m, proto, kwargs)|
|
256
255
|
assert_raise(ArgumentError.new("BUG: tls_options is available only for tls")) do
|
257
|
-
@d.__send__(m, :myserver,
|
256
|
+
@d.__send__(m, :myserver, @port, proto: proto, tls_options: {}, **kwargs){|x| x }
|
258
257
|
end
|
259
258
|
end
|
260
259
|
|
@@ -266,7 +265,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
266
265
|
'server_create_connection tls' => [:server_create_connection, :tls, {tls_options: {insecure: true}}],
|
267
266
|
)
|
268
267
|
test 'can bind specified IPv4 address' do |(m, proto, kwargs)|
|
269
|
-
@d.__send__(m, :myserver,
|
268
|
+
@d.__send__(m, :myserver, @port, proto: proto, bind: "127.0.0.1", **kwargs){|x| x }
|
270
269
|
assert_equal "127.0.0.1", @d._servers.first.bind
|
271
270
|
assert_equal "127.0.0.1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
|
272
271
|
end
|
@@ -280,7 +279,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
280
279
|
)
|
281
280
|
test 'can bind specified IPv6 address' do |(m, proto, kwargs)| # if available
|
282
281
|
omit "IPv6 unavailable here" unless ipv6_enabled?
|
283
|
-
@d.__send__(m, :myserver,
|
282
|
+
@d.__send__(m, :myserver, @port, proto: proto, bind: "::1", **kwargs){|x| x }
|
284
283
|
assert_equal "::1", @d._servers.first.bind
|
285
284
|
assert_equal "::1", @d._servers.first.server.instance_eval{ instance_variable_defined?(:@listen_socket) ? @listen_socket : @_io }.addr[3]
|
286
285
|
end
|
@@ -299,8 +298,8 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
299
298
|
d2 = Dummy.new; d2.start; d2.after_start
|
300
299
|
|
301
300
|
assert_nothing_raised do
|
302
|
-
@d.__send__(m, :myserver,
|
303
|
-
d2.__send__(m, :myserver,
|
301
|
+
@d.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
|
302
|
+
d2.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
|
304
303
|
end
|
305
304
|
ensure
|
306
305
|
d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
|
@@ -323,10 +322,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
323
322
|
d2 = Dummy.new; d2.start; d2.after_start
|
324
323
|
|
325
324
|
assert_nothing_raised do
|
326
|
-
@d.__send__(m, :myserver,
|
325
|
+
@d.__send__(m, :myserver, @port, proto: proto, shared: false, **kwargs){|x| x }
|
327
326
|
end
|
328
327
|
assert_raise(Errno::EADDRINUSE, Errno::EACCES) do
|
329
|
-
d2.__send__(m, :myserver,
|
328
|
+
d2.__send__(m, :myserver, @port, proto: proto, **kwargs){|x| x }
|
330
329
|
end
|
331
330
|
ensure
|
332
331
|
d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
|
@@ -343,15 +342,15 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
343
342
|
)
|
344
343
|
test 'raise error if block argument is not specified or too many' do |(proto, kwargs)|
|
345
344
|
assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
|
346
|
-
@d.server_create(:myserver,
|
345
|
+
@d.server_create(:myserver, @port, proto: proto, **kwargs){ 1 }
|
347
346
|
end
|
348
347
|
assert_raise(ArgumentError.new("BUG: block must have 1 or 2 arguments")) do
|
349
|
-
@d.server_create(:myserver,
|
348
|
+
@d.server_create(:myserver, @port, proto: proto, **kwargs){|sock, conn, what_is_this| 1 }
|
350
349
|
end
|
351
350
|
end
|
352
351
|
|
353
352
|
test 'creates udp server if specified in proto' do
|
354
|
-
@d.server_create(:myserver,
|
353
|
+
@d.server_create(:myserver, @port, proto: :udp, max_bytes: 512){|x| x }
|
355
354
|
|
356
355
|
created_server_info = @d._servers.first
|
357
356
|
assert_equal :udp, created_server_info.proto
|
@@ -363,7 +362,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
363
362
|
sub_test_case '#server_create_tcp' do
|
364
363
|
test 'can accept all keyword arguments valid for tcp server' do
|
365
364
|
assert_nothing_raised do
|
366
|
-
@d.server_create_tcp(:s,
|
365
|
+
@d.server_create_tcp(:s, @port, bind: '127.0.0.1', shared: false, resolve_name: true, linger_timeout: 10, backlog: 500, send_keepalive_packet: true) do |data, conn|
|
367
366
|
# ...
|
368
367
|
end
|
369
368
|
end
|
@@ -371,11 +370,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
371
370
|
|
372
371
|
test 'creates a tcp server just to read data' do
|
373
372
|
received = ""
|
374
|
-
@d.server_create_tcp(:s,
|
373
|
+
@d.server_create_tcp(:s, @port) do |data|
|
375
374
|
received << data
|
376
375
|
end
|
377
376
|
3.times do
|
378
|
-
sock = TCPSocket.new("127.0.0.1",
|
377
|
+
sock = TCPSocket.new("127.0.0.1", @port)
|
379
378
|
sock.puts "yay"
|
380
379
|
sock.puts "foo"
|
381
380
|
sock.close
|
@@ -387,12 +386,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
387
386
|
test 'creates a tcp server to read and write data' do
|
388
387
|
received = ""
|
389
388
|
responses = []
|
390
|
-
@d.server_create_tcp(:s,
|
389
|
+
@d.server_create_tcp(:s, @port) do |data, conn|
|
391
390
|
received << data
|
392
391
|
conn.write "ack\n"
|
393
392
|
end
|
394
393
|
3.times do
|
395
|
-
TCPSocket.open("127.0.0.1",
|
394
|
+
TCPSocket.open("127.0.0.1", @port) do |sock|
|
396
395
|
sock.puts "yay"
|
397
396
|
sock.puts "foo"
|
398
397
|
responses << sock.readline
|
@@ -408,12 +407,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
408
407
|
|
409
408
|
received = ""
|
410
409
|
responses = []
|
411
|
-
@d.server_create_tcp(:s,
|
410
|
+
@d.server_create_tcp(:s, @port, bind: "::1") do |data, conn|
|
412
411
|
received << data
|
413
412
|
conn.write "ack\n"
|
414
413
|
end
|
415
414
|
3.times do
|
416
|
-
TCPSocket.open("::1",
|
415
|
+
TCPSocket.open("::1", @port) do |sock|
|
417
416
|
sock.puts "yay"
|
418
417
|
sock.puts "foo"
|
419
418
|
responses << sock.readline
|
@@ -427,12 +426,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
427
426
|
test 'does not resolve name of client address in default' do
|
428
427
|
received = ""
|
429
428
|
sources = []
|
430
|
-
@d.server_create_tcp(:s,
|
429
|
+
@d.server_create_tcp(:s, @port) do |data, conn|
|
431
430
|
received << data
|
432
431
|
sources << conn.remote_host
|
433
432
|
end
|
434
433
|
3.times do
|
435
|
-
TCPSocket.open("127.0.0.1",
|
434
|
+
TCPSocket.open("127.0.0.1", @port) do |sock|
|
436
435
|
sock.puts "yay"
|
437
436
|
end
|
438
437
|
end
|
@@ -446,12 +445,12 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
446
445
|
|
447
446
|
received = ""
|
448
447
|
sources = []
|
449
|
-
@d.server_create_tcp(:s,
|
448
|
+
@d.server_create_tcp(:s, @port, resolve_name: true) do |data, conn|
|
450
449
|
received << data
|
451
450
|
sources << conn.remote_host
|
452
451
|
end
|
453
452
|
3.times do
|
454
|
-
TCPSocket.open("127.0.0.1",
|
453
|
+
TCPSocket.open("127.0.0.1", @port) do |sock|
|
455
454
|
sock.puts "yay"
|
456
455
|
end
|
457
456
|
end
|
@@ -467,7 +466,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
467
466
|
test 'raises error if plugin registers data callback for connection object from #server_create' do
|
468
467
|
received = ""
|
469
468
|
errors = []
|
470
|
-
@d.server_create_tcp(:s,
|
469
|
+
@d.server_create_tcp(:s, @port) do |data, conn|
|
471
470
|
received << data
|
472
471
|
begin
|
473
472
|
conn.data{|d| received << d.upcase }
|
@@ -475,7 +474,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
475
474
|
errors << e
|
476
475
|
end
|
477
476
|
end
|
478
|
-
TCPSocket.open("127.0.0.1",
|
477
|
+
TCPSocket.open("127.0.0.1", @port) do |sock|
|
479
478
|
sock.puts "foo"
|
480
479
|
end
|
481
480
|
waiting(10){ sleep 0.1 until received.bytesize == 4 || errors.size == 1 }
|
@@ -489,7 +488,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
489
488
|
lines = []
|
490
489
|
responses = []
|
491
490
|
response_completes = []
|
492
|
-
@d.server_create_tcp(:s,
|
491
|
+
@d.server_create_tcp(:s, @port) do |data, conn|
|
493
492
|
conn.on(:write_complete){|c| response_completes << true }
|
494
493
|
buffer << data
|
495
494
|
if idx = buffer.index("\n")
|
@@ -498,7 +497,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
498
497
|
end
|
499
498
|
end
|
500
499
|
3.times do
|
501
|
-
TCPSocket.open("127.0.0.1",
|
500
|
+
TCPSocket.open("127.0.0.1", @port) do |sock|
|
502
501
|
sock.write "yay"
|
503
502
|
sock.write "foo\n"
|
504
503
|
begin
|
@@ -519,7 +518,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
519
518
|
buffer = ""
|
520
519
|
lines = []
|
521
520
|
callback_results = []
|
522
|
-
@d.server_create_tcp(:s,
|
521
|
+
@d.server_create_tcp(:s, @port) do |data, conn|
|
523
522
|
conn.on(:close){|c| callback_results << "closed" }
|
524
523
|
buffer << data
|
525
524
|
if idx = buffer.index("\n")
|
@@ -528,7 +527,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
528
527
|
end
|
529
528
|
end
|
530
529
|
3.times do
|
531
|
-
TCPSocket.open("127.0.0.1",
|
530
|
+
TCPSocket.open("127.0.0.1", @port) do |sock|
|
532
531
|
sock.write "yay"
|
533
532
|
sock.write "foo\n"
|
534
533
|
begin
|
@@ -551,10 +550,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
551
550
|
omit "IPv6 unavailable here" unless ipv6_enabled?
|
552
551
|
|
553
552
|
assert_nothing_raised do
|
554
|
-
@d.server_create_tcp(:s_ipv4,
|
553
|
+
@d.server_create_tcp(:s_ipv4, @port, bind: '0.0.0.0', shared: false) do |data, conn|
|
555
554
|
# ...
|
556
555
|
end
|
557
|
-
@d.server_create_tcp(:s_ipv6,
|
556
|
+
@d.server_create_tcp(:s_ipv6, @port, bind: '::', shared: false) do |data, conn|
|
558
557
|
# ...
|
559
558
|
end
|
560
559
|
end
|
@@ -564,7 +563,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
564
563
|
sub_test_case '#server_create_udp' do
|
565
564
|
test 'can accept all keyword arguments valid for udp server' do
|
566
565
|
assert_nothing_raised do
|
567
|
-
@d.server_create_udp(:s,
|
566
|
+
@d.server_create_udp(:s, @port, bind: '127.0.0.1', shared: false, resolve_name: true, max_bytes: 100, flags: 1) do |data, conn|
|
568
567
|
# ...
|
569
568
|
end
|
570
569
|
end
|
@@ -572,14 +571,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
572
571
|
|
573
572
|
test 'creates a udp server just to read data' do
|
574
573
|
received = ""
|
575
|
-
@d.server_create_udp(:s,
|
574
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data|
|
576
575
|
received << data
|
577
576
|
end
|
578
577
|
bind_port = unused_port(protocol: :udp, bind: "127.0.0.1")
|
579
578
|
3.times do
|
580
579
|
sock = UDPSocket.new(Socket::AF_INET)
|
581
580
|
sock.bind("127.0.0.1", bind_port)
|
582
|
-
sock.connect("127.0.0.1",
|
581
|
+
sock.connect("127.0.0.1", @port)
|
583
582
|
sock.puts "yay"
|
584
583
|
sock.puts "foo"
|
585
584
|
sock.close
|
@@ -591,7 +590,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
591
590
|
test 'creates a udp server to read and write data' do
|
592
591
|
received = ""
|
593
592
|
responses = []
|
594
|
-
@d.server_create_udp(:s,
|
593
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
595
594
|
received << data
|
596
595
|
sock.write "ack\n"
|
597
596
|
end
|
@@ -600,7 +599,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
600
599
|
begin
|
601
600
|
sock = UDPSocket.new(Socket::AF_INET)
|
602
601
|
sock.bind("127.0.0.1", bind_port)
|
603
|
-
sock.connect("127.0.0.1",
|
602
|
+
sock.connect("127.0.0.1", @port)
|
604
603
|
th = Thread.new do
|
605
604
|
while true
|
606
605
|
begin
|
@@ -631,7 +630,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
631
630
|
|
632
631
|
received = ""
|
633
632
|
responses = []
|
634
|
-
@d.server_create_udp(:s,
|
633
|
+
@d.server_create_udp(:s, @port, bind: "::1", max_bytes: 128) do |data, sock|
|
635
634
|
received << data
|
636
635
|
sock.write "ack\n"
|
637
636
|
end
|
@@ -644,7 +643,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
644
643
|
responses << sock.recv(16)
|
645
644
|
true
|
646
645
|
end
|
647
|
-
sock.connect("::1",
|
646
|
+
sock.connect("::1", @port)
|
648
647
|
sock.write "yay\nfoo\n"
|
649
648
|
th.join(5)
|
650
649
|
ensure
|
@@ -659,13 +658,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
659
658
|
test 'does not resolve name of client address in default' do
|
660
659
|
received = ""
|
661
660
|
sources = []
|
662
|
-
@d.server_create_udp(:s,
|
661
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
663
662
|
received << data
|
664
663
|
sources << sock.remote_host
|
665
664
|
end
|
666
665
|
3.times do
|
667
666
|
sock = UDPSocket.new(Socket::AF_INET)
|
668
|
-
sock.connect("127.0.0.1",
|
667
|
+
sock.connect("127.0.0.1", @port)
|
669
668
|
sock.puts "yay"
|
670
669
|
sock.close
|
671
670
|
end
|
@@ -679,13 +678,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
679
678
|
|
680
679
|
received = ""
|
681
680
|
sources = []
|
682
|
-
@d.server_create_udp(:s,
|
681
|
+
@d.server_create_udp(:s, @port, resolve_name: true, max_bytes: 128) do |data, sock|
|
683
682
|
received << data
|
684
683
|
sources << sock.remote_host
|
685
684
|
end
|
686
685
|
3.times do
|
687
686
|
sock = UDPSocket.new(Socket::AF_INET)
|
688
|
-
sock.connect("127.0.0.1",
|
687
|
+
sock.connect("127.0.0.1", @port)
|
689
688
|
sock.puts "yay"
|
690
689
|
sock.close
|
691
690
|
end
|
@@ -697,7 +696,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
697
696
|
test 'raises error if plugin registers data callback for connection object from #server_create' do
|
698
697
|
received = ""
|
699
698
|
errors = []
|
700
|
-
@d.server_create_udp(:s,
|
699
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
701
700
|
received << data
|
702
701
|
begin
|
703
702
|
sock.data{|d| received << d.upcase }
|
@@ -706,7 +705,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
706
705
|
end
|
707
706
|
end
|
708
707
|
sock = UDPSocket.new(Socket::AF_INET)
|
709
|
-
sock.connect("127.0.0.1",
|
708
|
+
sock.connect("127.0.0.1", @port)
|
710
709
|
sock.write "foo\n"
|
711
710
|
sock.close
|
712
711
|
|
@@ -719,7 +718,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
719
718
|
test 'raise error if plugin registers write_complete callback for udp' do
|
720
719
|
received = ""
|
721
720
|
errors = []
|
722
|
-
@d.server_create_udp(:s,
|
721
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
723
722
|
received << data
|
724
723
|
begin
|
725
724
|
sock.on(:write_complete){|conn| "" }
|
@@ -728,7 +727,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
728
727
|
end
|
729
728
|
end
|
730
729
|
sock = UDPSocket.new(Socket::AF_INET)
|
731
|
-
sock.connect("127.0.0.1",
|
730
|
+
sock.connect("127.0.0.1", @port)
|
732
731
|
sock.write "foo\n"
|
733
732
|
sock.close
|
734
733
|
|
@@ -741,7 +740,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
741
740
|
test 'raises error if plugin registers close callback for udp' do
|
742
741
|
received = ""
|
743
742
|
errors = []
|
744
|
-
@d.server_create_udp(:s,
|
743
|
+
@d.server_create_udp(:s, @port, max_bytes: 128) do |data, sock|
|
745
744
|
received << data
|
746
745
|
begin
|
747
746
|
sock.on(:close){|d| "" }
|
@@ -750,7 +749,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
750
749
|
end
|
751
750
|
end
|
752
751
|
sock = UDPSocket.new(Socket::AF_INET)
|
753
|
-
sock.connect("127.0.0.1",
|
752
|
+
sock.connect("127.0.0.1", @port)
|
754
753
|
sock.write "foo\n"
|
755
754
|
sock.close
|
756
755
|
|
@@ -764,10 +763,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
764
763
|
omit "IPv6 unavailable here" unless ipv6_enabled?
|
765
764
|
|
766
765
|
assert_nothing_raised do
|
767
|
-
@d.server_create_udp(:s_ipv4_udp,
|
766
|
+
@d.server_create_udp(:s_ipv4_udp, @port, bind: '0.0.0.0', shared: false, max_bytes: 128) do |data, sock|
|
768
767
|
# ...
|
769
768
|
end
|
770
|
-
@d.server_create_udp(:s_ipv6_udp,
|
769
|
+
@d.server_create_udp(:s_ipv6_udp, @port, bind: '::', shared: false, max_bytes: 128) do |data, sock|
|
771
770
|
# ...
|
772
771
|
end
|
773
772
|
end
|
@@ -929,16 +928,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
929
928
|
}
|
930
929
|
|
931
930
|
received = ""
|
932
|
-
@d.server_create_tls(:s,
|
931
|
+
@d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
|
933
932
|
received << data
|
934
933
|
end
|
935
934
|
assert_raise "" do
|
936
|
-
open_tls_session('127.0.0.1',
|
935
|
+
open_tls_session('127.0.0.1', @port) do |sock|
|
937
936
|
sock.post_connection_check('myserver.testing.fluentd.org')
|
938
937
|
# cannot connect ....
|
939
938
|
end
|
940
939
|
end
|
941
|
-
open_tls_session('127.0.0.1',
|
940
|
+
open_tls_session('127.0.0.1', @port, verify: false) do |sock|
|
942
941
|
sock.puts "yay"
|
943
942
|
sock.puts "foo"
|
944
943
|
end
|
@@ -968,16 +967,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
968
967
|
}
|
969
968
|
tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
|
970
969
|
received = ""
|
971
|
-
@d.server_create_tls(:s,
|
970
|
+
@d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
|
972
971
|
received << data
|
973
972
|
end
|
974
973
|
assert_raise "" do
|
975
|
-
open_tls_session('127.0.0.1',
|
974
|
+
open_tls_session('127.0.0.1', @port) do |sock|
|
976
975
|
sock.post_connection_check('server.testing.fluentd.org')
|
977
976
|
# cannot connect by failing verification without server cert
|
978
977
|
end
|
979
978
|
end
|
980
|
-
open_tls_session('127.0.0.1',
|
979
|
+
open_tls_session('127.0.0.1', @port, cert_path: cert_path) do |sock|
|
981
980
|
sock.puts "yay"
|
982
981
|
sock.puts "foo"
|
983
982
|
end
|
@@ -1003,10 +1002,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1003
1002
|
}
|
1004
1003
|
tls_options[:ca_private_key_passphrase] = ca_key_passphrase if ca_key_passphrase
|
1005
1004
|
received = ""
|
1006
|
-
@d.server_create_tls(:s,
|
1005
|
+
@d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
|
1007
1006
|
received << data
|
1008
1007
|
end
|
1009
|
-
open_tls_session('127.0.0.1',
|
1008
|
+
open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
|
1010
1009
|
sock.puts "yay"
|
1011
1010
|
sock.puts "foo"
|
1012
1011
|
end
|
@@ -1042,10 +1041,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1042
1041
|
}
|
1043
1042
|
tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
|
1044
1043
|
received = ""
|
1045
|
-
@d.server_create_tls(:s,
|
1044
|
+
@d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
|
1046
1045
|
received << data
|
1047
1046
|
end
|
1048
|
-
open_tls_session('127.0.0.1',
|
1047
|
+
open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
|
1049
1048
|
sock.puts "yay"
|
1050
1049
|
sock.puts "foo"
|
1051
1050
|
end
|
@@ -1072,10 +1071,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1072
1071
|
}
|
1073
1072
|
tls_options[:private_key_passphrase] = private_key_passphrase if private_key_passphrase
|
1074
1073
|
received = ""
|
1075
|
-
@d.server_create_tls(:s,
|
1074
|
+
@d.server_create_tls(:s, @port, tls_options: tls_options) do |data, conn|
|
1076
1075
|
received << data
|
1077
1076
|
end
|
1078
|
-
open_tls_session('127.0.0.1',
|
1077
|
+
open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
|
1079
1078
|
sock.puts "yay"
|
1080
1079
|
sock.puts "foo"
|
1081
1080
|
end
|
@@ -1096,16 +1095,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1096
1095
|
@d.configure(conf); @d.start; @d.after_start
|
1097
1096
|
|
1098
1097
|
received = ""
|
1099
|
-
@d.server_create_tls(:s,
|
1098
|
+
@d.server_create_tls(:s, @port) do |data, conn|
|
1100
1099
|
received << data
|
1101
1100
|
end
|
1102
1101
|
assert_raise "" do
|
1103
|
-
open_tls_session('127.0.0.1',
|
1102
|
+
open_tls_session('127.0.0.1', @port) do |sock|
|
1104
1103
|
sock.post_connection_check('myserver.testing.fluentd.org')
|
1105
1104
|
# cannot connect ....
|
1106
1105
|
end
|
1107
1106
|
end
|
1108
|
-
open_tls_session('127.0.0.1',
|
1107
|
+
open_tls_session('127.0.0.1', @port, verify: false) do |sock|
|
1109
1108
|
sock.puts "yay"
|
1110
1109
|
sock.puts "foo"
|
1111
1110
|
end
|
@@ -1131,16 +1130,16 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1131
1130
|
@d.configure(conf); @d.start; @d.after_start
|
1132
1131
|
|
1133
1132
|
received = ""
|
1134
|
-
@d.server_create_tls(:s,
|
1133
|
+
@d.server_create_tls(:s, @port) do |data, conn|
|
1135
1134
|
received << data
|
1136
1135
|
end
|
1137
1136
|
assert_raise "" do
|
1138
|
-
open_tls_session('127.0.0.1',
|
1137
|
+
open_tls_session('127.0.0.1', @port) do |sock|
|
1139
1138
|
sock.post_connection_check('server.testing.fluentd.org')
|
1140
1139
|
# cannot connect by failing verification without server cert
|
1141
1140
|
end
|
1142
1141
|
end
|
1143
|
-
open_tls_session('127.0.0.1',
|
1142
|
+
open_tls_session('127.0.0.1', @port, cert_path: cert_path) do |sock|
|
1144
1143
|
sock.puts "yay"
|
1145
1144
|
sock.puts "foo"
|
1146
1145
|
end
|
@@ -1166,10 +1165,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1166
1165
|
@d.configure(conf); @d.start; @d.after_start
|
1167
1166
|
|
1168
1167
|
received = ""
|
1169
|
-
@d.server_create_tls(:s,
|
1168
|
+
@d.server_create_tls(:s, @port) do |data, conn|
|
1170
1169
|
received << data
|
1171
1170
|
end
|
1172
|
-
open_tls_session('127.0.0.1',
|
1171
|
+
open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
|
1173
1172
|
sock.puts "yay"
|
1174
1173
|
sock.puts "foo"
|
1175
1174
|
end
|
@@ -1199,10 +1198,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1199
1198
|
@d.configure(conf); @d.start; @d.after_start
|
1200
1199
|
|
1201
1200
|
received = ""
|
1202
|
-
@d.server_create_tls(:s,
|
1201
|
+
@d.server_create_tls(:s, @port) do |data, conn|
|
1203
1202
|
received << data
|
1204
1203
|
end
|
1205
|
-
open_tls_session('127.0.0.1',
|
1204
|
+
open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
|
1206
1205
|
sock.puts "yay"
|
1207
1206
|
sock.puts "foo"
|
1208
1207
|
end
|
@@ -1230,10 +1229,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1230
1229
|
@d.configure(conf); @d.start; @d.after_start
|
1231
1230
|
|
1232
1231
|
received = ""
|
1233
|
-
@d.server_create_tls(:s,
|
1232
|
+
@d.server_create_tls(:s, @port) do |data, conn|
|
1234
1233
|
received << data
|
1235
1234
|
end
|
1236
|
-
open_tls_session('127.0.0.1',
|
1235
|
+
open_tls_session('127.0.0.1', @port, cert_path: ca_cert_path) do |sock|
|
1237
1236
|
sock.puts "yay"
|
1238
1237
|
sock.puts "foo"
|
1239
1238
|
end
|
@@ -1306,7 +1305,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1306
1305
|
|
1307
1306
|
test 'can accept all keyword arguments valid for tcp/tls server' do
|
1308
1307
|
assert_nothing_raised do
|
1309
|
-
@d.server_create_tls(:s,
|
1308
|
+
@d.server_create_tls(:s, @port, bind: '127.0.0.1', shared: false, resolve_name: true, linger_timeout: 10, backlog: 500, tls_options: @tls_options, send_keepalive_packet: true) do |data, conn|
|
1310
1309
|
# ...
|
1311
1310
|
end
|
1312
1311
|
end
|
@@ -1314,11 +1313,11 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1314
1313
|
|
1315
1314
|
test 'creates a tls server just to read data' do
|
1316
1315
|
received = ""
|
1317
|
-
@d.server_create_tls(:s,
|
1316
|
+
@d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
|
1318
1317
|
received << data
|
1319
1318
|
end
|
1320
1319
|
3.times do
|
1321
|
-
open_tls_session('127.0.0.1',
|
1320
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
|
1322
1321
|
sock.puts "yay"
|
1323
1322
|
sock.puts "foo"
|
1324
1323
|
end
|
@@ -1331,13 +1330,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1331
1330
|
test 'creates a tls server to read and write data' do
|
1332
1331
|
received = ""
|
1333
1332
|
responses = []
|
1334
|
-
@d.server_create_tls(:s,
|
1333
|
+
@d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
|
1335
1334
|
received << data
|
1336
1335
|
conn.write "ack\n"
|
1337
1336
|
end
|
1338
1337
|
3.times do
|
1339
|
-
# open_tls_session('127.0.0.1',
|
1340
|
-
open_tls_session('127.0.0.1',
|
1338
|
+
# open_tls_session('127.0.0.1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
|
1339
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
|
1341
1340
|
sock.puts "yay"
|
1342
1341
|
sock.puts "foo"
|
1343
1342
|
responses << sock.readline
|
@@ -1354,13 +1353,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1354
1353
|
|
1355
1354
|
received = ""
|
1356
1355
|
responses = []
|
1357
|
-
@d.server_create_tls(:s,
|
1356
|
+
@d.server_create_tls(:s, @port, bind: "::1", tls_options: @tls_options) do |data, conn|
|
1358
1357
|
received << data
|
1359
1358
|
conn.write "ack\n"
|
1360
1359
|
end
|
1361
1360
|
3.times do
|
1362
|
-
# open_tls_session('::1',
|
1363
|
-
open_tls_session('::1',
|
1361
|
+
# open_tls_session('::1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
|
1362
|
+
open_tls_session('::1', @port, cert_path: @cert_path) do |sock|
|
1364
1363
|
sock.puts "yay"
|
1365
1364
|
sock.puts "foo"
|
1366
1365
|
responses << sock.readline
|
@@ -1375,13 +1374,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1375
1374
|
test 'does not resolve name of client address in default' do
|
1376
1375
|
received = ""
|
1377
1376
|
sources = []
|
1378
|
-
@d.server_create_tls(:s,
|
1377
|
+
@d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
|
1379
1378
|
received << data
|
1380
1379
|
sources << conn.remote_host
|
1381
1380
|
end
|
1382
1381
|
3.times do
|
1383
|
-
# open_tls_session('127.0.0.1',
|
1384
|
-
open_tls_session('127.0.0.1',
|
1382
|
+
# open_tls_session('127.0.0.1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
|
1383
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
|
1385
1384
|
sock.puts "yay"
|
1386
1385
|
end
|
1387
1386
|
end
|
@@ -1395,13 +1394,13 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1395
1394
|
|
1396
1395
|
received = ""
|
1397
1396
|
sources = []
|
1398
|
-
@d.server_create_tls(:s,
|
1397
|
+
@d.server_create_tls(:s, @port, resolve_name: true, tls_options: @tls_options) do |data, conn|
|
1399
1398
|
received << data
|
1400
1399
|
sources << conn.remote_host
|
1401
1400
|
end
|
1402
1401
|
3.times do
|
1403
|
-
# open_tls_session('127.0.0.1',
|
1404
|
-
open_tls_session('127.0.0.1',
|
1402
|
+
# open_tls_session('127.0.0.1', @port, cert_path: @cert_path, hostname: @default_hostname) do |sock|
|
1403
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
|
1405
1404
|
sock.puts "yay"
|
1406
1405
|
end
|
1407
1406
|
end
|
@@ -1417,7 +1416,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1417
1416
|
test 'raises error if plugin registers data callback for connection object from #server_create' do
|
1418
1417
|
received = ""
|
1419
1418
|
errors = []
|
1420
|
-
@d.server_create_tls(:s,
|
1419
|
+
@d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
|
1421
1420
|
received << data
|
1422
1421
|
begin
|
1423
1422
|
conn.data{|d| received << d.upcase }
|
@@ -1425,7 +1424,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1425
1424
|
errors << e
|
1426
1425
|
end
|
1427
1426
|
end
|
1428
|
-
open_tls_session('127.0.0.1',
|
1427
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
|
1429
1428
|
sock.puts "foo"
|
1430
1429
|
end
|
1431
1430
|
waiting(10){ sleep 0.1 until received.bytesize == 4 || errors.size == 1 }
|
@@ -1439,7 +1438,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1439
1438
|
lines = []
|
1440
1439
|
responses = []
|
1441
1440
|
response_completes = []
|
1442
|
-
@d.server_create_tls(:s,
|
1441
|
+
@d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
|
1443
1442
|
conn.on(:write_complete){|c| response_completes << true }
|
1444
1443
|
buffer << data
|
1445
1444
|
if idx = buffer.index("\n")
|
@@ -1448,7 +1447,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1448
1447
|
end
|
1449
1448
|
end
|
1450
1449
|
3.times do
|
1451
|
-
open_tls_session('127.0.0.1',
|
1450
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
|
1452
1451
|
sock.write "yay"
|
1453
1452
|
sock.write "foo\n"
|
1454
1453
|
begin
|
@@ -1469,7 +1468,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1469
1468
|
buffer = ""
|
1470
1469
|
lines = []
|
1471
1470
|
callback_results = []
|
1472
|
-
@d.server_create_tls(:s,
|
1471
|
+
@d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
|
1473
1472
|
conn.on(:close){|c| callback_results << "closed" }
|
1474
1473
|
buffer << data
|
1475
1474
|
if idx = buffer.index("\n")
|
@@ -1478,7 +1477,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1478
1477
|
end
|
1479
1478
|
end
|
1480
1479
|
3.times do
|
1481
|
-
open_tls_session('127.0.0.1',
|
1480
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path) do |sock|
|
1482
1481
|
sock.write "yay"
|
1483
1482
|
sock.write "foo\n"
|
1484
1483
|
begin
|
@@ -1499,7 +1498,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1499
1498
|
|
1500
1499
|
sub_test_case 'TLS version connection check' do
|
1501
1500
|
test "can't connect with different TLS version" do
|
1502
|
-
@d.server_create_tls(:s,
|
1501
|
+
@d.server_create_tls(:s, @port, tls_options: @tls_options) do |data, conn|
|
1503
1502
|
end
|
1504
1503
|
if defined?(OpenSSL::SSL::TLS1_3_VERSION)
|
1505
1504
|
version = :'TLS1_3'
|
@@ -1507,7 +1506,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1507
1506
|
version = :'TLS1_1'
|
1508
1507
|
end
|
1509
1508
|
assert_raise(OpenSSL::SSL::SSLError, Errno::ECONNRESET) {
|
1510
|
-
open_tls_session('127.0.0.1',
|
1509
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path, version: version) do |sock|
|
1511
1510
|
end
|
1512
1511
|
}
|
1513
1512
|
end
|
@@ -1523,15 +1522,15 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1523
1522
|
end
|
1524
1523
|
|
1525
1524
|
opts = @tls_options.merge(min_version: min_version, max_version: max_version)
|
1526
|
-
@d.server_create_tls(:s,
|
1525
|
+
@d.server_create_tls(:s, @port, tls_options: opts) do |data, conn|
|
1527
1526
|
end
|
1528
1527
|
assert_raise(OpenSSL::SSL::SSLError, Errno::ECONNRESET) {
|
1529
|
-
open_tls_session('127.0.0.1',
|
1528
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path, version: :'TLS1') do |sock|
|
1530
1529
|
end
|
1531
1530
|
}
|
1532
1531
|
[min_version, max_version].each { |ver|
|
1533
1532
|
assert_nothing_raised {
|
1534
|
-
open_tls_session('127.0.0.1',
|
1533
|
+
open_tls_session('127.0.0.1', @port, cert_path: @cert_path, version: ver) do |sock|
|
1535
1534
|
end
|
1536
1535
|
}
|
1537
1536
|
}
|
@@ -1571,7 +1570,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1571
1570
|
sub_test_case '#server_create_connection' do
|
1572
1571
|
test 'raise error if udp is specified in proto' do
|
1573
1572
|
assert_raise(ArgumentError.new("BUG: cannot create connection for UDP")) do
|
1574
|
-
@d.server_create_connection(:myserver,
|
1573
|
+
@d.server_create_connection(:myserver, @port, proto: :udp){|c| c }
|
1575
1574
|
end
|
1576
1575
|
end
|
1577
1576
|
|
@@ -1586,10 +1585,10 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1586
1585
|
test 'raise error if block argument is not specified or too many' do |(proto, kwargs)|
|
1587
1586
|
empty_block = ->(){}
|
1588
1587
|
assert_raise(ArgumentError.new("BUG: block must have just one argument")) do
|
1589
|
-
@d.server_create_connection(:myserver,
|
1588
|
+
@d.server_create_connection(:myserver, @port, proto: proto, **kwargs, &empty_block)
|
1590
1589
|
end
|
1591
1590
|
assert_raise(ArgumentError.new("BUG: block must have just one argument")) do
|
1592
|
-
@d.server_create_connection(:myserver,
|
1591
|
+
@d.server_create_connection(:myserver, @port, proto: proto, **kwargs){|conn, what_is_this| [conn, what_is_this] }
|
1593
1592
|
end
|
1594
1593
|
end
|
1595
1594
|
|
@@ -1597,14 +1596,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1597
1596
|
test 'does not resolve name of client address in default' do |(proto, kwargs)|
|
1598
1597
|
received = ""
|
1599
1598
|
sources = []
|
1600
|
-
@d.server_create_connection(:s,
|
1599
|
+
@d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
|
1601
1600
|
sources << conn.remote_host
|
1602
1601
|
conn.data do |d|
|
1603
1602
|
received << d
|
1604
1603
|
end
|
1605
1604
|
end
|
1606
1605
|
3.times do
|
1607
|
-
open_client(proto, "127.0.0.1",
|
1606
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1608
1607
|
sock.puts "yay"
|
1609
1608
|
end
|
1610
1609
|
end
|
@@ -1619,14 +1618,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1619
1618
|
|
1620
1619
|
received = ""
|
1621
1620
|
sources = []
|
1622
|
-
@d.server_create_connection(:s,
|
1621
|
+
@d.server_create_connection(:s, @port, proto: proto, resolve_name: true, **kwargs) do |conn|
|
1623
1622
|
sources << conn.remote_host
|
1624
1623
|
conn.data do |d|
|
1625
1624
|
received << d
|
1626
1625
|
end
|
1627
1626
|
end
|
1628
1627
|
3.times do
|
1629
|
-
open_client(proto, "127.0.0.1",
|
1628
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1630
1629
|
sock.puts "yay"
|
1631
1630
|
end
|
1632
1631
|
end
|
@@ -1639,7 +1638,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1639
1638
|
test 'creates a server to provide connection, which can read, write and close' do |(proto, kwargs)|
|
1640
1639
|
lines = []
|
1641
1640
|
buffer = ""
|
1642
|
-
@d.server_create_connection(:s,
|
1641
|
+
@d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
|
1643
1642
|
conn.data do |d|
|
1644
1643
|
buffer << d
|
1645
1644
|
if buffer == "x"
|
@@ -1655,7 +1654,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1655
1654
|
replied = []
|
1656
1655
|
disconnecteds = []
|
1657
1656
|
3.times do |i|
|
1658
|
-
open_client(proto, "127.0.0.1",
|
1657
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1659
1658
|
sock.puts "yay"
|
1660
1659
|
while line = sock.readline
|
1661
1660
|
replied << line
|
@@ -1691,7 +1690,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1691
1690
|
buffer = ""
|
1692
1691
|
written = 0
|
1693
1692
|
closed = 0
|
1694
|
-
@d.server_create_connection(:s,
|
1693
|
+
@d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
|
1695
1694
|
conn.on(:write_complete){|_conn| written += 1 }
|
1696
1695
|
conn.on(:close){|_conn| closed += 1 }
|
1697
1696
|
conn.on(:data) do |d|
|
@@ -1704,7 +1703,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1704
1703
|
end
|
1705
1704
|
replied = []
|
1706
1705
|
3.times do
|
1707
|
-
open_client(proto, "127.0.0.1",
|
1706
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1708
1707
|
sock.puts "yay"
|
1709
1708
|
while line = sock.readline
|
1710
1709
|
replied << line
|
@@ -1725,14 +1724,14 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1725
1724
|
test 'creates a server, and does not leak connections' do |(proto, kwargs)|
|
1726
1725
|
buffer = ""
|
1727
1726
|
closed = 0
|
1728
|
-
@d.server_create_connection(:s,
|
1727
|
+
@d.server_create_connection(:s, @port, proto: proto, **kwargs) do |conn|
|
1729
1728
|
conn.on(:close){|_c| closed += 1 }
|
1730
1729
|
conn.on(:data) do |d|
|
1731
1730
|
buffer << d
|
1732
1731
|
end
|
1733
1732
|
end
|
1734
1733
|
3.times do
|
1735
|
-
open_client(proto, "127.0.0.1",
|
1734
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1736
1735
|
sock.puts "yay"
|
1737
1736
|
end
|
1738
1737
|
end
|
@@ -1745,7 +1744,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1745
1744
|
test 'will refuse more connect requests after stop, but read data from sockets already connected, in non-shared server' do |(proto, kwargs)|
|
1746
1745
|
connected = false
|
1747
1746
|
begin
|
1748
|
-
open_client(proto, "127.0.0.1",
|
1747
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1749
1748
|
# expected behavior is connection refused...
|
1750
1749
|
connected = true
|
1751
1750
|
end
|
@@ -1755,7 +1754,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1755
1754
|
assert_false connected
|
1756
1755
|
|
1757
1756
|
received = ""
|
1758
|
-
@d.server_create_connection(:s,
|
1757
|
+
@d.server_create_connection(:s, @port, proto: proto, shared: false, **kwargs) do |conn|
|
1759
1758
|
conn.on(:data) do |data|
|
1760
1759
|
received << data
|
1761
1760
|
conn.write "ack\n"
|
@@ -1763,7 +1762,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1763
1762
|
end
|
1764
1763
|
|
1765
1764
|
th0 = Thread.new do
|
1766
|
-
open_client(proto, "127.0.0.1",
|
1765
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1767
1766
|
sock.puts "yay"
|
1768
1767
|
sock.readline
|
1769
1768
|
end
|
@@ -1777,7 +1776,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1777
1776
|
ending = false
|
1778
1777
|
|
1779
1778
|
th1 = Thread.new do
|
1780
|
-
open_client(proto, "127.0.0.1",
|
1779
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1781
1780
|
sleeping = true
|
1782
1781
|
sleep 0.1 until stopped
|
1783
1782
|
sock.puts "yay"
|
@@ -1800,7 +1799,7 @@ class ServerPluginHelperTest < Test::Unit::TestCase
|
|
1800
1799
|
|
1801
1800
|
th2 = Thread.new do
|
1802
1801
|
begin
|
1803
|
-
open_client(proto, "127.0.0.1",
|
1802
|
+
open_client(proto, "127.0.0.1", @port) do |sock|
|
1804
1803
|
sock.puts "foo"
|
1805
1804
|
end
|
1806
1805
|
false # failed
|