fluentd 1.16.5-x64-mingw32 → 1.17.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/README.md +2 -1
  4. data/Rakefile +1 -1
  5. data/SECURITY.md +2 -2
  6. data/fluent.conf +14 -14
  7. data/lib/fluent/command/binlog_reader.rb +1 -1
  8. data/lib/fluent/command/cap_ctl.rb +4 -4
  9. data/lib/fluent/compat/call_super_mixin.rb +3 -3
  10. data/lib/fluent/compat/propagate_default.rb +4 -4
  11. data/lib/fluent/config/configure_proxy.rb +2 -2
  12. data/lib/fluent/config/types.rb +1 -1
  13. data/lib/fluent/config/yaml_parser/parser.rb +4 -0
  14. data/lib/fluent/configurable.rb +2 -2
  15. data/lib/fluent/counter/mutex_hash.rb +1 -1
  16. data/lib/fluent/fluent_log_event_router.rb +0 -2
  17. data/lib/fluent/log/console_adapter.rb +4 -2
  18. data/lib/fluent/plugin/buf_file.rb +1 -1
  19. data/lib/fluent/plugin/buffer/file_chunk.rb +1 -1
  20. data/lib/fluent/plugin/buffer/file_single_chunk.rb +2 -3
  21. data/lib/fluent/plugin/filter_parser.rb +26 -8
  22. data/lib/fluent/plugin/in_exec.rb +14 -2
  23. data/lib/fluent/plugin/in_http.rb +19 -54
  24. data/lib/fluent/plugin/in_sample.rb +13 -7
  25. data/lib/fluent/plugin/in_tail.rb +99 -25
  26. data/lib/fluent/plugin/out_copy.rb +1 -1
  27. data/lib/fluent/plugin/out_file.rb +8 -0
  28. data/lib/fluent/plugin/out_http.rb +137 -13
  29. data/lib/fluent/plugin/owned_by_mixin.rb +0 -1
  30. data/lib/fluent/plugin/parser_json.rb +26 -17
  31. data/lib/fluent/plugin/parser_msgpack.rb +24 -3
  32. data/lib/fluent/plugin_helper/http_server/server.rb +1 -1
  33. data/lib/fluent/plugin_helper/metrics.rb +2 -2
  34. data/lib/fluent/registry.rb +6 -6
  35. data/lib/fluent/test/output_test.rb +1 -1
  36. data/lib/fluent/unique_id.rb +1 -1
  37. data/lib/fluent/version.rb +1 -1
  38. data/templates/new_gem/fluent-plugin.gemspec.erb +6 -5
  39. metadata +109 -459
  40. data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -71
  41. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  42. data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -39
  43. data/.github/ISSUE_TEMPLATE.md +0 -17
  44. data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  45. data/.github/workflows/stale-actions.yml +0 -24
  46. data/.github/workflows/test.yml +0 -32
  47. data/.gitignore +0 -30
  48. data/Gemfile +0 -9
  49. data/fluentd.gemspec +0 -54
  50. data/test/command/test_binlog_reader.rb +0 -362
  51. data/test/command/test_ca_generate.rb +0 -70
  52. data/test/command/test_cap_ctl.rb +0 -100
  53. data/test/command/test_cat.rb +0 -128
  54. data/test/command/test_ctl.rb +0 -56
  55. data/test/command/test_fluentd.rb +0 -1291
  56. data/test/command/test_plugin_config_formatter.rb +0 -397
  57. data/test/command/test_plugin_generator.rb +0 -109
  58. data/test/compat/test_calls_super.rb +0 -166
  59. data/test/compat/test_parser.rb +0 -92
  60. data/test/config/assertions.rb +0 -42
  61. data/test/config/test_config_parser.rb +0 -551
  62. data/test/config/test_configurable.rb +0 -1784
  63. data/test/config/test_configure_proxy.rb +0 -604
  64. data/test/config/test_dsl.rb +0 -415
  65. data/test/config/test_element.rb +0 -518
  66. data/test/config/test_literal_parser.rb +0 -309
  67. data/test/config/test_plugin_configuration.rb +0 -56
  68. data/test/config/test_section.rb +0 -191
  69. data/test/config/test_system_config.rb +0 -195
  70. data/test/config/test_types.rb +0 -408
  71. data/test/counter/test_client.rb +0 -563
  72. data/test/counter/test_error.rb +0 -44
  73. data/test/counter/test_mutex_hash.rb +0 -179
  74. data/test/counter/test_server.rb +0 -589
  75. data/test/counter/test_store.rb +0 -258
  76. data/test/counter/test_validator.rb +0 -137
  77. data/test/helper.rb +0 -155
  78. data/test/helpers/fuzzy_assert.rb +0 -89
  79. data/test/helpers/process_extenstion.rb +0 -33
  80. data/test/log/test_console_adapter.rb +0 -110
  81. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  82. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  83. data/test/plugin/data/2010/01/20100102.log +0 -0
  84. data/test/plugin/data/log/bar +0 -0
  85. data/test/plugin/data/log/foo/bar.log +0 -0
  86. data/test/plugin/data/log/foo/bar2 +0 -0
  87. data/test/plugin/data/log/test.log +0 -0
  88. data/test/plugin/data/sd_file/config +0 -11
  89. data/test/plugin/data/sd_file/config.json +0 -17
  90. data/test/plugin/data/sd_file/config.yaml +0 -11
  91. data/test/plugin/data/sd_file/config.yml +0 -11
  92. data/test/plugin/data/sd_file/invalid_config.yml +0 -7
  93. data/test/plugin/in_tail/test_fifo.rb +0 -121
  94. data/test/plugin/in_tail/test_io_handler.rb +0 -150
  95. data/test/plugin/in_tail/test_position_file.rb +0 -346
  96. data/test/plugin/out_forward/test_ack_handler.rb +0 -140
  97. data/test/plugin/out_forward/test_connection_manager.rb +0 -145
  98. data/test/plugin/out_forward/test_handshake_protocol.rb +0 -112
  99. data/test/plugin/out_forward/test_load_balancer.rb +0 -106
  100. data/test/plugin/out_forward/test_socket_cache.rb +0 -174
  101. data/test/plugin/test_bare_output.rb +0 -131
  102. data/test/plugin/test_base.rb +0 -247
  103. data/test/plugin/test_buf_file.rb +0 -1314
  104. data/test/plugin/test_buf_file_single.rb +0 -898
  105. data/test/plugin/test_buf_memory.rb +0 -42
  106. data/test/plugin/test_buffer.rb +0 -1493
  107. data/test/plugin/test_buffer_chunk.rb +0 -209
  108. data/test/plugin/test_buffer_file_chunk.rb +0 -871
  109. data/test/plugin/test_buffer_file_single_chunk.rb +0 -611
  110. data/test/plugin/test_buffer_memory_chunk.rb +0 -339
  111. data/test/plugin/test_compressable.rb +0 -87
  112. data/test/plugin/test_file_util.rb +0 -96
  113. data/test/plugin/test_filter.rb +0 -368
  114. data/test/plugin/test_filter_grep.rb +0 -697
  115. data/test/plugin/test_filter_parser.rb +0 -731
  116. data/test/plugin/test_filter_record_transformer.rb +0 -577
  117. data/test/plugin/test_filter_stdout.rb +0 -207
  118. data/test/plugin/test_formatter_csv.rb +0 -136
  119. data/test/plugin/test_formatter_hash.rb +0 -38
  120. data/test/plugin/test_formatter_json.rb +0 -61
  121. data/test/plugin/test_formatter_ltsv.rb +0 -70
  122. data/test/plugin/test_formatter_msgpack.rb +0 -28
  123. data/test/plugin/test_formatter_out_file.rb +0 -116
  124. data/test/plugin/test_formatter_single_value.rb +0 -44
  125. data/test/plugin/test_formatter_tsv.rb +0 -76
  126. data/test/plugin/test_in_debug_agent.rb +0 -49
  127. data/test/plugin/test_in_exec.rb +0 -261
  128. data/test/plugin/test_in_forward.rb +0 -1178
  129. data/test/plugin/test_in_gc_stat.rb +0 -62
  130. data/test/plugin/test_in_http.rb +0 -1102
  131. data/test/plugin/test_in_monitor_agent.rb +0 -922
  132. data/test/plugin/test_in_object_space.rb +0 -66
  133. data/test/plugin/test_in_sample.rb +0 -190
  134. data/test/plugin/test_in_syslog.rb +0 -505
  135. data/test/plugin/test_in_tail.rb +0 -3288
  136. data/test/plugin/test_in_tcp.rb +0 -328
  137. data/test/plugin/test_in_udp.rb +0 -296
  138. data/test/plugin/test_in_unix.rb +0 -181
  139. data/test/plugin/test_input.rb +0 -137
  140. data/test/plugin/test_metadata.rb +0 -89
  141. data/test/plugin/test_metrics.rb +0 -294
  142. data/test/plugin/test_metrics_local.rb +0 -96
  143. data/test/plugin/test_multi_output.rb +0 -204
  144. data/test/plugin/test_out_copy.rb +0 -308
  145. data/test/plugin/test_out_exec.rb +0 -312
  146. data/test/plugin/test_out_exec_filter.rb +0 -606
  147. data/test/plugin/test_out_file.rb +0 -1038
  148. data/test/plugin/test_out_forward.rb +0 -1349
  149. data/test/plugin/test_out_http.rb +0 -429
  150. data/test/plugin/test_out_null.rb +0 -105
  151. data/test/plugin/test_out_relabel.rb +0 -28
  152. data/test/plugin/test_out_roundrobin.rb +0 -146
  153. data/test/plugin/test_out_secondary_file.rb +0 -458
  154. data/test/plugin/test_out_stdout.rb +0 -205
  155. data/test/plugin/test_out_stream.rb +0 -103
  156. data/test/plugin/test_output.rb +0 -1334
  157. data/test/plugin/test_output_as_buffered.rb +0 -2024
  158. data/test/plugin/test_output_as_buffered_backup.rb +0 -363
  159. data/test/plugin/test_output_as_buffered_compress.rb +0 -179
  160. data/test/plugin/test_output_as_buffered_overflow.rb +0 -250
  161. data/test/plugin/test_output_as_buffered_retries.rb +0 -966
  162. data/test/plugin/test_output_as_buffered_secondary.rb +0 -882
  163. data/test/plugin/test_output_as_standard.rb +0 -374
  164. data/test/plugin/test_owned_by.rb +0 -35
  165. data/test/plugin/test_parser.rb +0 -399
  166. data/test/plugin/test_parser_apache.rb +0 -42
  167. data/test/plugin/test_parser_apache2.rb +0 -47
  168. data/test/plugin/test_parser_apache_error.rb +0 -45
  169. data/test/plugin/test_parser_csv.rb +0 -200
  170. data/test/plugin/test_parser_json.rb +0 -138
  171. data/test/plugin/test_parser_labeled_tsv.rb +0 -160
  172. data/test/plugin/test_parser_multiline.rb +0 -111
  173. data/test/plugin/test_parser_nginx.rb +0 -88
  174. data/test/plugin/test_parser_none.rb +0 -52
  175. data/test/plugin/test_parser_regexp.rb +0 -284
  176. data/test/plugin/test_parser_syslog.rb +0 -650
  177. data/test/plugin/test_parser_tsv.rb +0 -122
  178. data/test/plugin/test_sd_file.rb +0 -228
  179. data/test/plugin/test_sd_srv.rb +0 -230
  180. data/test/plugin/test_storage.rb +0 -167
  181. data/test/plugin/test_storage_local.rb +0 -335
  182. data/test/plugin/test_string_util.rb +0 -26
  183. data/test/plugin_helper/data/cert/cert-key.pem +0 -27
  184. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +0 -19
  185. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +0 -19
  186. data/test/plugin_helper/data/cert/cert.pem +0 -19
  187. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +0 -27
  188. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +0 -20
  189. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +0 -27
  190. data/test/plugin_helper/data/cert/cert_chains/cert.pem +0 -40
  191. data/test/plugin_helper/data/cert/empty.pem +0 -0
  192. data/test/plugin_helper/data/cert/generate_cert.rb +0 -125
  193. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +0 -30
  194. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +0 -27
  195. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +0 -20
  196. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +0 -20
  197. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +0 -30
  198. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +0 -27
  199. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +0 -21
  200. data/test/plugin_helper/data/cert/with_ca/cert.pem +0 -21
  201. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +0 -30
  202. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +0 -27
  203. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +0 -20
  204. data/test/plugin_helper/data/cert/without_ca/cert.pem +0 -20
  205. data/test/plugin_helper/http_server/test_app.rb +0 -65
  206. data/test/plugin_helper/http_server/test_route.rb +0 -32
  207. data/test/plugin_helper/service_discovery/test_manager.rb +0 -93
  208. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +0 -21
  209. data/test/plugin_helper/test_cert_option.rb +0 -25
  210. data/test/plugin_helper/test_child_process.rb +0 -862
  211. data/test/plugin_helper/test_compat_parameters.rb +0 -358
  212. data/test/plugin_helper/test_event_emitter.rb +0 -80
  213. data/test/plugin_helper/test_event_loop.rb +0 -52
  214. data/test/plugin_helper/test_extract.rb +0 -194
  215. data/test/plugin_helper/test_formatter.rb +0 -255
  216. data/test/plugin_helper/test_http_server_helper.rb +0 -372
  217. data/test/plugin_helper/test_inject.rb +0 -561
  218. data/test/plugin_helper/test_metrics.rb +0 -137
  219. data/test/plugin_helper/test_parser.rb +0 -264
  220. data/test/plugin_helper/test_record_accessor.rb +0 -238
  221. data/test/plugin_helper/test_retry_state.rb +0 -1006
  222. data/test/plugin_helper/test_server.rb +0 -1895
  223. data/test/plugin_helper/test_service_discovery.rb +0 -165
  224. data/test/plugin_helper/test_socket.rb +0 -146
  225. data/test/plugin_helper/test_storage.rb +0 -542
  226. data/test/plugin_helper/test_thread.rb +0 -164
  227. data/test/plugin_helper/test_timer.rb +0 -130
  228. data/test/scripts/exec_script.rb +0 -32
  229. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +0 -7
  230. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +0 -7
  231. data/test/scripts/fluent/plugin/formatter_known.rb +0 -8
  232. data/test/scripts/fluent/plugin/out_test.rb +0 -81
  233. data/test/scripts/fluent/plugin/out_test2.rb +0 -80
  234. data/test/scripts/fluent/plugin/parser_known.rb +0 -4
  235. data/test/test_capability.rb +0 -74
  236. data/test/test_clock.rb +0 -164
  237. data/test/test_config.rb +0 -369
  238. data/test/test_configdsl.rb +0 -148
  239. data/test/test_daemonizer.rb +0 -91
  240. data/test/test_engine.rb +0 -203
  241. data/test/test_event.rb +0 -531
  242. data/test/test_event_router.rb +0 -348
  243. data/test/test_event_time.rb +0 -199
  244. data/test/test_file_wrapper.rb +0 -53
  245. data/test/test_filter.rb +0 -121
  246. data/test/test_fluent_log_event_router.rb +0 -99
  247. data/test/test_formatter.rb +0 -369
  248. data/test/test_input.rb +0 -31
  249. data/test/test_log.rb +0 -1076
  250. data/test/test_match.rb +0 -148
  251. data/test/test_mixin.rb +0 -351
  252. data/test/test_msgpack_factory.rb +0 -50
  253. data/test/test_oj_options.rb +0 -55
  254. data/test/test_output.rb +0 -278
  255. data/test/test_plugin.rb +0 -251
  256. data/test/test_plugin_classes.rb +0 -370
  257. data/test/test_plugin_helper.rb +0 -81
  258. data/test/test_plugin_id.rb +0 -119
  259. data/test/test_process.rb +0 -14
  260. data/test/test_root_agent.rb +0 -951
  261. data/test/test_static_config_analysis.rb +0 -177
  262. data/test/test_supervisor.rb +0 -821
  263. data/test/test_test_drivers.rb +0 -136
  264. data/test/test_time_formatter.rb +0 -301
  265. data/test/test_time_parser.rb +0 -362
  266. data/test/test_tls.rb +0 -65
  267. data/test/test_unique_id.rb +0 -47
  268. data/test/test_variable_store.rb +0 -65
@@ -1,255 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/plugin_helper/formatter'
3
- require 'fluent/plugin/base'
4
-
5
- class FormatterHelperTest < Test::Unit::TestCase
6
- class ExampleFormatter < Fluent::Plugin::Formatter
7
- Fluent::Plugin.register_formatter('example', self)
8
- def format(tag, time, record)
9
- "#{tag},#{time.to_i},#{record.keys.sort.join(',')}" # hey, you miss values! :P
10
- end
11
- end
12
- class Example2Formatter < Fluent::Plugin::Formatter
13
- Fluent::Plugin.register_formatter('example2', self)
14
- def format(tag, time, record)
15
- "#{tag},#{time.to_i},#{record.values.sort.join(',')}" # key...
16
- end
17
- end
18
- class Dummy < Fluent::Plugin::TestBase
19
- helpers :formatter
20
- config_section :format do
21
- config_set_default :@type, 'example'
22
- end
23
- end
24
-
25
- class Dummy2 < Fluent::Plugin::TestBase
26
- helpers :formatter
27
- config_section :format do
28
- config_set_default :@type, 'example2'
29
- end
30
- end
31
-
32
- setup do
33
- @d = nil
34
- end
35
-
36
- teardown do
37
- if @d
38
- @d.stop unless @d.stopped?
39
- @d.shutdown unless @d.shutdown?
40
- @d.close unless @d.closed?
41
- @d.terminate unless @d.terminated?
42
- end
43
- end
44
-
45
- test 'can be initialized without any formatters at first' do
46
- d = Dummy.new
47
- assert_equal 0, d._formatters.size
48
- end
49
-
50
- test 'can override default configuration parameters, but not overwrite whole definition' do
51
- d = Dummy.new
52
- assert_equal [], d.formatter_configs
53
-
54
- d = Dummy2.new
55
- d.configure(config_element('ROOT', '', {}, [config_element('format', '', {}, [])]))
56
- assert_raise NoMethodError do
57
- d.format
58
- end
59
- assert_equal 1, d.formatter_configs.size
60
- assert_equal 'example2', d.formatter_configs.first[:@type]
61
- end
62
-
63
- test 'creates instance of type specified by conf, or default_type if @type is missing in conf' do
64
- d = Dummy2.new
65
- d.configure(config_element())
66
- i = d.formatter_create(conf: config_element('format', '', {'@type' => 'example'}), default_type: 'example2')
67
- assert{ i.is_a?(ExampleFormatter) }
68
-
69
- d = Dummy2.new
70
- d.configure(config_element())
71
- i = d.formatter_create(conf: nil, default_type: 'example2')
72
- assert{ i.is_a?(Example2Formatter) }
73
- end
74
-
75
- test 'raises config error if config section is specified, but @type is not specified' do
76
- d = Dummy2.new
77
- d.configure(config_element())
78
- assert_raise Fluent::ConfigError.new("@type is required in <format>") do
79
- d.formatter_create(conf: config_element('format', '', {}), default_type: 'example2')
80
- end
81
- end
82
-
83
- test 'can be configured with default type without format sections' do
84
- d = Dummy.new
85
- assert_nothing_raised do
86
- d.configure(config_element())
87
- end
88
- assert_equal 1, d._formatters.size
89
- end
90
-
91
- test 'can be configured with a format section' do
92
- d = Dummy.new
93
- conf = config_element('ROOT', '', {}, [
94
- config_element('format', '', {'@type' => 'example'})
95
- ])
96
- assert_nothing_raised do
97
- d.configure(conf)
98
- end
99
- assert_equal 1, d._formatters.size
100
- assert{ d._formatters.values.all?{ |formatter| !formatter.started? } }
101
- end
102
-
103
- test 'can be configured with 2 or more format sections with different usages with each other' do
104
- d = Dummy.new
105
- conf = config_element('ROOT', '', {}, [
106
- config_element('format', 'default', {'@type' => 'example'}),
107
- config_element('format', 'extra', {'@type' => 'example2'}),
108
- ])
109
- assert_nothing_raised do
110
- d.configure(conf)
111
- end
112
- assert_equal 2, d._formatters.size
113
- assert{ d._formatters.values.all?{ |formatter| !formatter.started? } }
114
- end
115
-
116
- test 'cannot be configured with 2 format sections with same usage' do
117
- d = Dummy.new
118
- conf = config_element('ROOT', '', {}, [
119
- config_element('format', 'default', {'@type' => 'example'}),
120
- config_element('format', 'extra', {'@type' => 'example2'}),
121
- config_element('format', 'extra', {'@type' => 'example2'}),
122
- ])
123
- assert_raises Fluent::ConfigError do
124
- d.configure(conf)
125
- end
126
- end
127
-
128
- test 'creates a format plugin instance which is already configured without usage' do
129
- @d = d = Dummy.new
130
- conf = config_element('ROOT', '', {}, [
131
- config_element('format', '', {'@type' => 'example'})
132
- ])
133
- d.configure(conf)
134
- d.start
135
-
136
- formatter = d.formatter_create
137
- assert{ formatter.is_a? ExampleFormatter }
138
- assert formatter.started?
139
- end
140
-
141
- test 'creates a formatter plugin instance which is already configured with usage' do
142
- @d = d = Dummy.new
143
- conf = config_element('ROOT', '', {}, [
144
- config_element('format', 'mydata', {'@type' => 'example'})
145
- ])
146
- d.configure(conf)
147
- d.start
148
-
149
- formatter = d.formatter_create(usage: 'mydata')
150
- assert{ formatter.is_a? ExampleFormatter }
151
- assert formatter.started?
152
- end
153
-
154
- test 'creates a formatter plugin without configurations' do
155
- @d = d = Dummy.new
156
- d.configure(config_element())
157
- d.start
158
-
159
- formatter = d.formatter_create(usage: 'mydata', type: 'example', conf: config_element('format', 'mydata'))
160
- assert{ formatter.is_a? ExampleFormatter }
161
- assert formatter.started?
162
- end
163
-
164
- test 'creates 2 or more formatter plugin instances' do
165
- @d = d = Dummy.new
166
- conf = config_element('ROOT', '', {}, [
167
- config_element('format', 'mydata', {'@type' => 'example'}),
168
- config_element('format', 'secret', {'@type' => 'example2'})
169
- ])
170
- d.configure(conf)
171
- d.start
172
-
173
- p1 = d.formatter_create(usage: 'mydata')
174
- p2 = d.formatter_create(usage: 'secret')
175
- assert{ p1.is_a? ExampleFormatter }
176
- assert p1.started?
177
- assert{ p2.is_a? Example2Formatter }
178
- assert p2.started?
179
- end
180
-
181
- test 'calls lifecycle methods for all plugin instances via owner plugin' do
182
- @d = d = Dummy.new
183
- conf = config_element('ROOT', '', {}, [ config_element('format', '', {'@type' => 'example'}), config_element('format', 'e2', {'@type' => 'example'}) ])
184
- d.configure(conf)
185
- d.start
186
-
187
- i1 = d.formatter_create(usage: '')
188
- i2 = d.formatter_create(usage: 'e2')
189
- i3 = d.formatter_create(usage: 'e3', type: 'example2')
190
-
191
- assert i1.started?
192
- assert i2.started?
193
- assert i3.started?
194
-
195
- assert !i1.stopped?
196
- assert !i2.stopped?
197
- assert !i3.stopped?
198
-
199
- d.stop
200
-
201
- assert i1.stopped?
202
- assert i2.stopped?
203
- assert i3.stopped?
204
-
205
- assert !i1.before_shutdown?
206
- assert !i2.before_shutdown?
207
- assert !i3.before_shutdown?
208
-
209
- d.before_shutdown
210
-
211
- assert i1.before_shutdown?
212
- assert i2.before_shutdown?
213
- assert i3.before_shutdown?
214
-
215
- assert !i1.shutdown?
216
- assert !i2.shutdown?
217
- assert !i3.shutdown?
218
-
219
- d.shutdown
220
-
221
- assert i1.shutdown?
222
- assert i2.shutdown?
223
- assert i3.shutdown?
224
-
225
- assert !i1.after_shutdown?
226
- assert !i2.after_shutdown?
227
- assert !i3.after_shutdown?
228
-
229
- d.after_shutdown
230
-
231
- assert i1.after_shutdown?
232
- assert i2.after_shutdown?
233
- assert i3.after_shutdown?
234
-
235
- assert !i1.closed?
236
- assert !i2.closed?
237
- assert !i3.closed?
238
-
239
- d.close
240
-
241
- assert i1.closed?
242
- assert i2.closed?
243
- assert i3.closed?
244
-
245
- assert !i1.terminated?
246
- assert !i2.terminated?
247
- assert !i3.terminated?
248
-
249
- d.terminate
250
-
251
- assert i1.terminated?
252
- assert i2.terminated?
253
- assert i3.terminated?
254
- end
255
- end
@@ -1,372 +0,0 @@
1
- require_relative '../helper'
2
- require 'flexmock/test_unit'
3
- require 'fluent/plugin_helper/http_server'
4
- require 'fluent/plugin/output'
5
- require 'fluent/event'
6
- require 'net/http'
7
- require 'uri'
8
- require 'openssl'
9
- require 'async'
10
-
11
- class HttpHelperTest < Test::Unit::TestCase
12
- NULL_LOGGER = Logger.new(nil)
13
- CERT_DIR = File.expand_path(File.dirname(__FILE__) + '/data/cert/without_ca')
14
- CERT_CA_DIR = File.expand_path(File.dirname(__FILE__) + '/data/cert/with_ca')
15
-
16
- def setup
17
- @port = unused_port
18
- end
19
-
20
- def teardown
21
- @port = nil
22
- end
23
-
24
- class Dummy < Fluent::Plugin::TestBase
25
- helpers :http_server
26
- end
27
-
28
- def on_driver(config = nil)
29
- config ||= Fluent::Config.parse(config || '', '(name)', '')
30
- Fluent::Test.setup
31
- driver = Dummy.new
32
- driver.configure(config)
33
- driver.start
34
- driver.after_start
35
-
36
- yield(driver)
37
- ensure
38
- unless driver.stopped?
39
- driver.stop rescue nil
40
- end
41
-
42
- unless driver.before_shutdown?
43
- driver.before_shutdown rescue nil
44
- end
45
-
46
- unless driver.shutdown?
47
- driver.shutdown rescue nil
48
- end
49
-
50
- unless driver.after_shutdown?
51
- driver.after_shutdown rescue nil
52
- end
53
-
54
- unless driver.closed?
55
- driver.close rescue nil
56
- end
57
-
58
- unless driver.terminated?
59
- driver.terminated rescue nil
60
- end
61
- end
62
-
63
- def on_driver_transport(opts = {}, &block)
64
- transport_conf = config_element('transport', 'tls', opts)
65
- c = config_element('ROOT', '', {}, [transport_conf])
66
- on_driver(c, &block)
67
- end
68
-
69
- %w[get head].each do |n|
70
- define_method(n) do |uri, header = {}|
71
- url = URI.parse(uri)
72
- headers = { 'Content-Type' => 'application/x-www-form-urlencoded/' }.merge(header)
73
- req = Net::HTTP.const_get(n.capitalize).new(url, headers)
74
- Net::HTTP.start(url.host, url.port) do |http|
75
- http.request(req)
76
- end
77
- end
78
-
79
- define_method("secure_#{n}") do |uri, header = {}, verify: true, cert_path: nil, selfsigned: true, hostname: false|
80
- url = URI.parse(uri)
81
- headers = { 'Content-Type' => 'application/x-www-form-urlencoded/' }.merge(header)
82
- start_https_request(url.host, url.port, verify: verify, cert_path: cert_path, selfsigned: selfsigned) do |https|
83
- https.send(n, url.path, headers.to_a)
84
- end
85
- end
86
- end
87
-
88
- %w[post put patch delete options trace].each do |n|
89
- define_method(n) do |uri, body = '', header = {}|
90
- url = URI.parse(uri)
91
- headers = { 'Content-Type' => 'application/x-www-form-urlencoded/' }.merge(header)
92
- req = Net::HTTP.const_get(n.capitalize).new(url, headers)
93
- req.body = body
94
- Net::HTTP.start(url.host, url.port) do |http|
95
- http.request(req)
96
- end
97
- end
98
- end
99
-
100
- # wrapper for net/http
101
- Response = Struct.new(:code, :body, :headers)
102
-
103
- # Use async-http as http client since net/http can't be set verify_hostname= now
104
- # will be replaced when net/http supports verify_hostname=
105
- def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: true, hostname: nil)
106
- context = OpenSSL::SSL::SSLContext.new
107
- context.set_params({})
108
- if verify
109
- cert_store = OpenSSL::X509::Store.new
110
- cert_store.set_default_paths
111
- if selfsigned && OpenSSL::X509.const_defined?('V_FLAG_CHECK_SS_SIGNATURE')
112
- cert_store.flags = OpenSSL::X509::V_FLAG_CHECK_SS_SIGNATURE
113
- end
114
-
115
- if cert_path
116
- cert_store.add_file(cert_path)
117
- end
118
-
119
- context.cert_store = cert_store
120
- if !hostname
121
- context.verify_hostname = false # In test code, using hostname to be connected is very difficult
122
- end
123
-
124
- context.verify_mode = OpenSSL::SSL::VERIFY_PEER
125
- else
126
- context.verify_mode = OpenSSL::SSL::VERIFY_NONE
127
- end
128
-
129
- client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse("https://#{addr}:#{port}", ssl_context: context))
130
- reactor = Async::Reactor.new(nil, logger: Fluent::Log::ConsoleAdapter.wrap(NULL_LOGGER))
131
-
132
- resp = nil
133
- error = nil
134
-
135
- reactor.run do
136
- begin
137
- response = yield(client)
138
- rescue => e # Async::Reactor rescue all error. handle it by myself
139
- error = e
140
- end
141
-
142
- if response
143
- resp = Response.new(response.status.to_s, response.body.read, response.headers)
144
- end
145
- end
146
-
147
- if error
148
- raise error
149
- else
150
- resp
151
- end
152
- end
153
-
154
- sub_test_case 'Create a HTTP server' do
155
- test 'monunt given path' do
156
- on_driver do |driver|
157
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
158
- s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
159
- s.post('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello post'] }
160
- s.head('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello head'] }
161
- s.put('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello put'] }
162
- s.patch('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello patch'] }
163
- s.delete('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello delete'] }
164
- s.trace('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello trace'] }
165
- s.options('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello options'] }
166
- end
167
-
168
- resp = head("http://127.0.0.1:#{@port}/example/hello")
169
- assert_equal('200', resp.code)
170
- assert_equal(nil, resp.body)
171
- assert_equal('text/plain', resp['Content-Type'])
172
-
173
- %w[get put post put delete options trace].each do |n|
174
- resp = send(n, "http://127.0.0.1:#{@port}/example/hello")
175
- assert_equal('200', resp.code)
176
- assert_equal("hello #{n}", resp.body)
177
- assert_equal('text/plain', resp['Content-Type'])
178
- end
179
- end
180
- end
181
-
182
- test 'when path does not start with `/` or ends with `/`' do
183
- on_driver do |driver|
184
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
185
- s.get('example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
186
- s.get('/example/hello2/') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
187
- end
188
-
189
- resp = get("http://127.0.0.1:#{@port}/example/hello")
190
- assert_equal('404', resp.code)
191
-
192
- resp = get("http://127.0.0.1:#{@port}/example/hello2")
193
- assert_equal('200', resp.code)
194
- end
195
- end
196
-
197
- test 'when error raised' do
198
- on_driver do |driver|
199
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
200
- s.get('/example/hello') { raise 'error!' }
201
- end
202
-
203
- resp = get("http://127.0.0.1:#{@port}/example/hello")
204
- assert_equal('500', resp.code)
205
- end
206
- end
207
-
208
- test 'when path is not found' do
209
- on_driver do |driver|
210
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
211
- s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
212
- end
213
-
214
- resp = get("http://127.0.0.1:#{@port}/example/hello/not_found")
215
- assert_equal('404', resp.code)
216
- end
217
- end
218
-
219
- test 'params and body' do
220
- on_driver do |driver|
221
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
222
- s.get('/example/hello') do |req|
223
- assert_equal(req.query_string, nil)
224
- assert_equal(req.body, nil)
225
- [200, { 'Content-Type' => 'text/plain' }, 'hello get']
226
- end
227
-
228
- s.post('/example/hello') do |req|
229
- assert_equal(req.query_string, nil)
230
- assert_equal(req.body, 'this is body')
231
- [200, { 'Content-Type' => 'text/plain' }, 'hello post']
232
- end
233
-
234
- s.get('/example/hello/params') do |req|
235
- assert_equal(req.query_string, 'test=true')
236
- assert_equal(req.body, nil)
237
- [200, { 'Content-Type' => 'text/plain' }, 'hello get']
238
- end
239
-
240
- s.post('/example/hello/params') do |req|
241
- assert_equal(req.query_string, 'test=true')
242
- assert_equal(req.body, 'this is body')
243
- [200, { 'Content-Type' => 'text/plain' }, 'hello post']
244
- end
245
- end
246
-
247
- resp = get("http://127.0.0.1:#{@port}/example/hello")
248
- assert_equal('200', resp.code)
249
-
250
- resp = post("http://127.0.0.1:#{@port}/example/hello", 'this is body')
251
- assert_equal('200', resp.code)
252
-
253
- resp = get("http://127.0.0.1:#{@port}/example/hello/params?test=true")
254
- assert_equal('200', resp.code)
255
-
256
- resp = post("http://127.0.0.1:#{@port}/example/hello/params?test=true", 'this is body')
257
- assert_equal('200', resp.code)
258
- end
259
- end
260
-
261
- sub_test_case 'create a HTTPS server' do
262
- test '#configure' do
263
- driver = Dummy.new
264
-
265
- transport_conf = config_element('transport', 'tls', { 'version' => 'TLSv1_1' })
266
- driver.configure(config_element('ROOT', '', {}, [transport_conf]))
267
- assert_equal :tls, driver.transport_config.protocol
268
- assert_equal :TLSv1_1, driver.transport_config.version
269
- end
270
-
271
- sub_test_case '#http_server_create_https_server' do
272
- test 'can overwrite settings by using tls_context' do
273
- on_driver_transport({ 'insecure' => 'false' }) do |driver|
274
- tls = { 'insecure' => 'true' } # overwrite
275
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER, tls_opts: tls) do |s|
276
- s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
277
- end
278
-
279
- resp = secure_get("https://127.0.0.1:#{@port}/example/hello", verify: false)
280
- assert_equal('200', resp.code)
281
- assert_equal('hello get', resp.body)
282
- end
283
- end
284
-
285
- test 'with insecure in transport section' do
286
- on_driver_transport({ 'insecure' => 'true' }) do |driver|
287
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
288
- s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
289
- end
290
- omit "TLS connection should be aborted due to `Errno::ECONNABORTED`. Need to debug." if Fluent.windows?
291
-
292
- resp = secure_get("https://127.0.0.1:#{@port}/example/hello", verify: false)
293
- assert_equal('200', resp.code)
294
- assert_equal('hello get', resp.body)
295
-
296
- assert_raise OpenSSL::SSL::SSLError do
297
- secure_get("https://127.0.0.1:#{@port}/example/hello")
298
- end
299
- end
300
- end
301
-
302
- data(
303
- 'with passphrase' => ['apple', 'cert-pass.pem', 'cert-key-pass.pem'],
304
- 'without passphrase' => [nil, 'cert.pem', 'cert-key.pem'])
305
- test 'load self-signed cert/key pair, verified from clients using cert files' do |(passphrase, cert, private_key)|
306
- omit "Self signed certificate blocks TLS connection. Need to debug." if Fluent.windows?
307
-
308
- cert_path = File.join(CERT_DIR, cert)
309
- private_key_path = File.join(CERT_DIR, private_key)
310
- opt = { 'insecure' => 'false', 'private_key_path' => private_key_path, 'cert_path' => cert_path }
311
- if passphrase
312
- opt['private_key_passphrase'] = passphrase
313
- end
314
-
315
- on_driver_transport(opt) do |driver|
316
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
317
- s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
318
- end
319
-
320
- resp = secure_get("https://127.0.0.1:#{@port}/example/hello", cert_path: cert_path)
321
- assert_equal('200', resp.code)
322
- assert_equal('hello get', resp.body)
323
- end
324
- end
325
-
326
- data(
327
- 'with passphrase' => ['apple', 'cert-pass.pem', 'cert-key-pass.pem', 'ca-cert-pass.pem'],
328
- 'without passphrase' => [nil, 'cert.pem', 'cert-key.pem', 'ca-cert.pem'])
329
- test 'load cert by private CA cert file, verified from clients using CA cert file' do |(passphrase, cert, cert_key, ca_cert)|
330
- omit "Self signed certificate blocks TLS connection. Need to debug." if Fluent.windows?
331
-
332
- cert_path = File.join(CERT_CA_DIR, cert)
333
- private_key_path = File.join(CERT_CA_DIR, cert_key)
334
-
335
- ca_cert_path = File.join(CERT_CA_DIR, ca_cert)
336
-
337
- opt = { 'insecure' => 'false', 'cert_path' => cert_path, 'private_key_path' => private_key_path }
338
- if passphrase
339
- opt['private_key_passphrase'] = passphrase
340
- end
341
-
342
- on_driver_transport(opt) do |driver|
343
- driver.http_server_create_https_server(:http_server_helper_test_tls, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do |s|
344
- s.get('/example/hello') { [200, { 'Content-Type' => 'text/plain' }, 'hello get'] }
345
- end
346
-
347
- resp = secure_get("https://127.0.0.1:#{@port}/example/hello", cert_path: ca_cert_path)
348
- assert_equal('200', resp.code)
349
- assert_equal('hello get', resp.body)
350
- end
351
- end
352
- end
353
- end
354
-
355
- test 'must be called #start and #stop' do
356
- on_driver do |driver|
357
- server = flexmock('Server') do |watcher|
358
- watcher.should_receive(:start).once.and_return do |que|
359
- que.push(:start)
360
- end
361
- watcher.should_receive(:stop).once
362
- end
363
-
364
- stub(Fluent::PluginHelper::HttpServer::Server).new(addr: anything, port: anything, logger: anything, default_app: anything) { server }
365
- driver.http_server_create_http_server(:http_server_helper_test, addr: '127.0.0.1', port: @port, logger: NULL_LOGGER) do
366
- # nothing
367
- end
368
- driver.stop
369
- end
370
- end
371
- end
372
- end