fluentd 1.17.0-x64-mingw-ucrt → 1.17.1-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +1 -0
  4. data/SECURITY.md +2 -2
  5. data/fluent.conf +14 -14
  6. data/lib/fluent/command/cap_ctl.rb +4 -4
  7. data/lib/fluent/compat/call_super_mixin.rb +3 -3
  8. data/lib/fluent/compat/propagate_default.rb +4 -4
  9. data/lib/fluent/config/yaml_parser/parser.rb +4 -0
  10. data/lib/fluent/log/console_adapter.rb +4 -2
  11. data/lib/fluent/plugin/in_exec.rb +14 -2
  12. data/lib/fluent/plugin/in_http.rb +1 -1
  13. data/lib/fluent/plugin/in_sample.rb +13 -7
  14. data/lib/fluent/plugin/in_tail.rb +65 -23
  15. data/lib/fluent/plugin/out_copy.rb +1 -1
  16. data/lib/fluent/plugin/out_file.rb +8 -0
  17. data/lib/fluent/plugin/out_http.rb +12 -0
  18. data/lib/fluent/plugin/parser_json.rb +4 -12
  19. data/lib/fluent/plugin_helper/http_server/server.rb +1 -1
  20. data/lib/fluent/version.rb +1 -1
  21. data/templates/new_gem/fluent-plugin.gemspec.erb +6 -5
  22. metadata +25 -472
  23. data/.github/DISCUSSION_TEMPLATE/q-a-japanese.yml +0 -50
  24. data/.github/DISCUSSION_TEMPLATE/q-a.yml +0 -47
  25. data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -71
  26. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  27. data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -39
  28. data/.github/ISSUE_TEMPLATE.md +0 -17
  29. data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  30. data/.github/workflows/stale-actions.yml +0 -24
  31. data/.github/workflows/test-ruby-head.yml +0 -31
  32. data/.github/workflows/test.yml +0 -32
  33. data/.gitignore +0 -30
  34. data/Gemfile +0 -9
  35. data/fluentd.gemspec +0 -62
  36. data/test/command/test_binlog_reader.rb +0 -362
  37. data/test/command/test_ca_generate.rb +0 -70
  38. data/test/command/test_cap_ctl.rb +0 -100
  39. data/test/command/test_cat.rb +0 -128
  40. data/test/command/test_ctl.rb +0 -56
  41. data/test/command/test_fluentd.rb +0 -1291
  42. data/test/command/test_plugin_config_formatter.rb +0 -397
  43. data/test/command/test_plugin_generator.rb +0 -109
  44. data/test/compat/test_calls_super.rb +0 -166
  45. data/test/compat/test_parser.rb +0 -92
  46. data/test/config/assertions.rb +0 -42
  47. data/test/config/test_config_parser.rb +0 -551
  48. data/test/config/test_configurable.rb +0 -1784
  49. data/test/config/test_configure_proxy.rb +0 -604
  50. data/test/config/test_dsl.rb +0 -415
  51. data/test/config/test_element.rb +0 -518
  52. data/test/config/test_literal_parser.rb +0 -309
  53. data/test/config/test_plugin_configuration.rb +0 -56
  54. data/test/config/test_section.rb +0 -191
  55. data/test/config/test_system_config.rb +0 -195
  56. data/test/config/test_types.rb +0 -408
  57. data/test/counter/test_client.rb +0 -563
  58. data/test/counter/test_error.rb +0 -44
  59. data/test/counter/test_mutex_hash.rb +0 -179
  60. data/test/counter/test_server.rb +0 -589
  61. data/test/counter/test_store.rb +0 -258
  62. data/test/counter/test_validator.rb +0 -137
  63. data/test/helper.rb +0 -155
  64. data/test/helpers/fuzzy_assert.rb +0 -89
  65. data/test/helpers/process_extenstion.rb +0 -33
  66. data/test/log/test_console_adapter.rb +0 -117
  67. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  68. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  69. data/test/plugin/data/2010/01/20100102.log +0 -0
  70. data/test/plugin/data/log/bar +0 -0
  71. data/test/plugin/data/log/foo/bar.log +0 -0
  72. data/test/plugin/data/log/foo/bar2 +0 -0
  73. data/test/plugin/data/log/test.log +0 -0
  74. data/test/plugin/data/log_numeric/01.log +0 -0
  75. data/test/plugin/data/log_numeric/02.log +0 -0
  76. data/test/plugin/data/log_numeric/12.log +0 -0
  77. data/test/plugin/data/log_numeric/14.log +0 -0
  78. data/test/plugin/data/sd_file/config +0 -11
  79. data/test/plugin/data/sd_file/config.json +0 -17
  80. data/test/plugin/data/sd_file/config.yaml +0 -11
  81. data/test/plugin/data/sd_file/config.yml +0 -11
  82. data/test/plugin/data/sd_file/invalid_config.yml +0 -7
  83. data/test/plugin/in_tail/test_fifo.rb +0 -121
  84. data/test/plugin/in_tail/test_io_handler.rb +0 -150
  85. data/test/plugin/in_tail/test_position_file.rb +0 -346
  86. data/test/plugin/out_forward/test_ack_handler.rb +0 -140
  87. data/test/plugin/out_forward/test_connection_manager.rb +0 -145
  88. data/test/plugin/out_forward/test_handshake_protocol.rb +0 -112
  89. data/test/plugin/out_forward/test_load_balancer.rb +0 -106
  90. data/test/plugin/out_forward/test_socket_cache.rb +0 -174
  91. data/test/plugin/test_bare_output.rb +0 -131
  92. data/test/plugin/test_base.rb +0 -247
  93. data/test/plugin/test_buf_file.rb +0 -1314
  94. data/test/plugin/test_buf_file_single.rb +0 -898
  95. data/test/plugin/test_buf_memory.rb +0 -42
  96. data/test/plugin/test_buffer.rb +0 -1493
  97. data/test/plugin/test_buffer_chunk.rb +0 -209
  98. data/test/plugin/test_buffer_file_chunk.rb +0 -871
  99. data/test/plugin/test_buffer_file_single_chunk.rb +0 -611
  100. data/test/plugin/test_buffer_memory_chunk.rb +0 -339
  101. data/test/plugin/test_compressable.rb +0 -87
  102. data/test/plugin/test_file_util.rb +0 -96
  103. data/test/plugin/test_filter.rb +0 -368
  104. data/test/plugin/test_filter_grep.rb +0 -697
  105. data/test/plugin/test_filter_parser.rb +0 -731
  106. data/test/plugin/test_filter_record_transformer.rb +0 -577
  107. data/test/plugin/test_filter_stdout.rb +0 -207
  108. data/test/plugin/test_formatter_csv.rb +0 -136
  109. data/test/plugin/test_formatter_hash.rb +0 -38
  110. data/test/plugin/test_formatter_json.rb +0 -61
  111. data/test/plugin/test_formatter_ltsv.rb +0 -70
  112. data/test/plugin/test_formatter_msgpack.rb +0 -28
  113. data/test/plugin/test_formatter_out_file.rb +0 -116
  114. data/test/plugin/test_formatter_single_value.rb +0 -44
  115. data/test/plugin/test_formatter_tsv.rb +0 -76
  116. data/test/plugin/test_in_debug_agent.rb +0 -49
  117. data/test/plugin/test_in_exec.rb +0 -261
  118. data/test/plugin/test_in_forward.rb +0 -1178
  119. data/test/plugin/test_in_gc_stat.rb +0 -62
  120. data/test/plugin/test_in_http.rb +0 -1124
  121. data/test/plugin/test_in_monitor_agent.rb +0 -922
  122. data/test/plugin/test_in_object_space.rb +0 -66
  123. data/test/plugin/test_in_sample.rb +0 -190
  124. data/test/plugin/test_in_syslog.rb +0 -505
  125. data/test/plugin/test_in_tail.rb +0 -3429
  126. data/test/plugin/test_in_tcp.rb +0 -328
  127. data/test/plugin/test_in_udp.rb +0 -296
  128. data/test/plugin/test_in_unix.rb +0 -181
  129. data/test/plugin/test_input.rb +0 -137
  130. data/test/plugin/test_metadata.rb +0 -89
  131. data/test/plugin/test_metrics.rb +0 -294
  132. data/test/plugin/test_metrics_local.rb +0 -96
  133. data/test/plugin/test_multi_output.rb +0 -204
  134. data/test/plugin/test_out_copy.rb +0 -308
  135. data/test/plugin/test_out_exec.rb +0 -312
  136. data/test/plugin/test_out_exec_filter.rb +0 -606
  137. data/test/plugin/test_out_file.rb +0 -1038
  138. data/test/plugin/test_out_forward.rb +0 -1349
  139. data/test/plugin/test_out_http.rb +0 -557
  140. data/test/plugin/test_out_null.rb +0 -105
  141. data/test/plugin/test_out_relabel.rb +0 -28
  142. data/test/plugin/test_out_roundrobin.rb +0 -146
  143. data/test/plugin/test_out_secondary_file.rb +0 -458
  144. data/test/plugin/test_out_stdout.rb +0 -205
  145. data/test/plugin/test_out_stream.rb +0 -103
  146. data/test/plugin/test_output.rb +0 -1334
  147. data/test/plugin/test_output_as_buffered.rb +0 -2024
  148. data/test/plugin/test_output_as_buffered_backup.rb +0 -363
  149. data/test/plugin/test_output_as_buffered_compress.rb +0 -179
  150. data/test/plugin/test_output_as_buffered_overflow.rb +0 -250
  151. data/test/plugin/test_output_as_buffered_retries.rb +0 -966
  152. data/test/plugin/test_output_as_buffered_secondary.rb +0 -882
  153. data/test/plugin/test_output_as_standard.rb +0 -374
  154. data/test/plugin/test_owned_by.rb +0 -34
  155. data/test/plugin/test_parser.rb +0 -399
  156. data/test/plugin/test_parser_apache.rb +0 -42
  157. data/test/plugin/test_parser_apache2.rb +0 -47
  158. data/test/plugin/test_parser_apache_error.rb +0 -45
  159. data/test/plugin/test_parser_csv.rb +0 -200
  160. data/test/plugin/test_parser_json.rb +0 -244
  161. data/test/plugin/test_parser_labeled_tsv.rb +0 -160
  162. data/test/plugin/test_parser_msgpack.rb +0 -127
  163. data/test/plugin/test_parser_multiline.rb +0 -111
  164. data/test/plugin/test_parser_nginx.rb +0 -88
  165. data/test/plugin/test_parser_none.rb +0 -52
  166. data/test/plugin/test_parser_regexp.rb +0 -284
  167. data/test/plugin/test_parser_syslog.rb +0 -650
  168. data/test/plugin/test_parser_tsv.rb +0 -122
  169. data/test/plugin/test_sd_file.rb +0 -228
  170. data/test/plugin/test_sd_srv.rb +0 -230
  171. data/test/plugin/test_storage.rb +0 -166
  172. data/test/plugin/test_storage_local.rb +0 -335
  173. data/test/plugin/test_string_util.rb +0 -26
  174. data/test/plugin_helper/data/cert/cert-key.pem +0 -27
  175. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +0 -19
  176. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +0 -19
  177. data/test/plugin_helper/data/cert/cert.pem +0 -19
  178. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +0 -27
  179. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +0 -20
  180. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +0 -27
  181. data/test/plugin_helper/data/cert/cert_chains/cert.pem +0 -40
  182. data/test/plugin_helper/data/cert/empty.pem +0 -0
  183. data/test/plugin_helper/data/cert/generate_cert.rb +0 -125
  184. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +0 -30
  185. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +0 -27
  186. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +0 -20
  187. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +0 -20
  188. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +0 -30
  189. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +0 -27
  190. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +0 -21
  191. data/test/plugin_helper/data/cert/with_ca/cert.pem +0 -21
  192. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +0 -30
  193. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +0 -27
  194. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +0 -20
  195. data/test/plugin_helper/data/cert/without_ca/cert.pem +0 -20
  196. data/test/plugin_helper/http_server/test_app.rb +0 -65
  197. data/test/plugin_helper/http_server/test_route.rb +0 -32
  198. data/test/plugin_helper/service_discovery/test_manager.rb +0 -93
  199. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +0 -21
  200. data/test/plugin_helper/test_cert_option.rb +0 -25
  201. data/test/plugin_helper/test_child_process.rb +0 -862
  202. data/test/plugin_helper/test_compat_parameters.rb +0 -358
  203. data/test/plugin_helper/test_event_emitter.rb +0 -80
  204. data/test/plugin_helper/test_event_loop.rb +0 -52
  205. data/test/plugin_helper/test_extract.rb +0 -194
  206. data/test/plugin_helper/test_formatter.rb +0 -255
  207. data/test/plugin_helper/test_http_server_helper.rb +0 -372
  208. data/test/plugin_helper/test_inject.rb +0 -561
  209. data/test/plugin_helper/test_metrics.rb +0 -137
  210. data/test/plugin_helper/test_parser.rb +0 -264
  211. data/test/plugin_helper/test_record_accessor.rb +0 -238
  212. data/test/plugin_helper/test_retry_state.rb +0 -1006
  213. data/test/plugin_helper/test_server.rb +0 -1895
  214. data/test/plugin_helper/test_service_discovery.rb +0 -165
  215. data/test/plugin_helper/test_socket.rb +0 -146
  216. data/test/plugin_helper/test_storage.rb +0 -542
  217. data/test/plugin_helper/test_thread.rb +0 -164
  218. data/test/plugin_helper/test_timer.rb +0 -130
  219. data/test/scripts/exec_script.rb +0 -32
  220. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +0 -7
  221. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +0 -7
  222. data/test/scripts/fluent/plugin/formatter_known.rb +0 -8
  223. data/test/scripts/fluent/plugin/out_test.rb +0 -81
  224. data/test/scripts/fluent/plugin/out_test2.rb +0 -80
  225. data/test/scripts/fluent/plugin/parser_known.rb +0 -4
  226. data/test/test_capability.rb +0 -74
  227. data/test/test_clock.rb +0 -164
  228. data/test/test_config.rb +0 -369
  229. data/test/test_configdsl.rb +0 -148
  230. data/test/test_daemonizer.rb +0 -91
  231. data/test/test_engine.rb +0 -203
  232. data/test/test_event.rb +0 -531
  233. data/test/test_event_router.rb +0 -348
  234. data/test/test_event_time.rb +0 -199
  235. data/test/test_file_wrapper.rb +0 -53
  236. data/test/test_filter.rb +0 -121
  237. data/test/test_fluent_log_event_router.rb +0 -99
  238. data/test/test_formatter.rb +0 -369
  239. data/test/test_input.rb +0 -31
  240. data/test/test_log.rb +0 -1076
  241. data/test/test_match.rb +0 -148
  242. data/test/test_mixin.rb +0 -351
  243. data/test/test_msgpack_factory.rb +0 -50
  244. data/test/test_oj_options.rb +0 -55
  245. data/test/test_output.rb +0 -278
  246. data/test/test_plugin.rb +0 -251
  247. data/test/test_plugin_classes.rb +0 -370
  248. data/test/test_plugin_helper.rb +0 -81
  249. data/test/test_plugin_id.rb +0 -119
  250. data/test/test_process.rb +0 -14
  251. data/test/test_root_agent.rb +0 -951
  252. data/test/test_static_config_analysis.rb +0 -177
  253. data/test/test_supervisor.rb +0 -821
  254. data/test/test_test_drivers.rb +0 -136
  255. data/test/test_time_formatter.rb +0 -301
  256. data/test/test_time_parser.rb +0 -362
  257. data/test/test_tls.rb +0 -65
  258. data/test/test_unique_id.rb +0 -47
  259. data/test/test_variable_store.rb +0 -65
@@ -1,1124 +0,0 @@
1
- require_relative '../helper'
2
- require 'fluent/test/driver/input'
3
- require 'fluent/plugin/in_http'
4
- require 'net/http'
5
- require 'timecop'
6
-
7
- class HttpInputTest < Test::Unit::TestCase
8
- class << self
9
- def startup
10
- @server = ServerEngine::SocketManager::Server.open
11
- ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = @server.path.to_s
12
- end
13
-
14
- def shutdown
15
- @server.close
16
- end
17
- end
18
-
19
- def setup
20
- Fluent::Test.setup
21
- @port = unused_port
22
- end
23
-
24
- def teardown
25
- Timecop.return
26
- @port = nil
27
- end
28
-
29
- def config
30
- %[
31
- port #{@port}
32
- bind "127.0.0.1"
33
- body_size_limit 10m
34
- keepalive_timeout 5
35
- respond_with_empty_img true
36
- use_204_response false
37
- ]
38
- end
39
-
40
- def create_driver(conf=config)
41
- Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpInput).configure(conf)
42
- end
43
-
44
- def test_configure
45
- d = create_driver
46
- assert_equal @port, d.instance.port
47
- assert_equal '127.0.0.1', d.instance.bind
48
- assert_equal 10*1024*1024, d.instance.body_size_limit
49
- assert_equal 5, d.instance.keepalive_timeout
50
- assert_equal false, d.instance.add_http_headers
51
- assert_equal false, d.instance.add_query_params
52
- end
53
-
54
- def test_time
55
- d = create_driver
56
- time = event_time("2011-01-02 13:14:15.123 UTC")
57
- Timecop.freeze(Time.at(time))
58
-
59
- events = [
60
- ["tag1", time, {"a" => 1}],
61
- ["tag2", time, {"a" => 2}],
62
- ]
63
- res_codes = []
64
-
65
- d.run(expect_records: 2) do
66
- events.each do |tag, _time, record|
67
- res = post("/#{tag}", {"json"=>record.to_json})
68
- res_codes << res.code
69
- end
70
- end
71
-
72
- assert_equal ["200", "200"], res_codes
73
- assert_equal events, d.events
74
- assert_equal_event_time time, d.events[0][1]
75
- assert_equal_event_time time, d.events[1][1]
76
- end
77
-
78
- def test_time_as_float
79
- d = create_driver
80
- time = event_time("2011-01-02 13:14:15.123 UTC")
81
- float_time = time.to_f
82
-
83
- events = [
84
- ["tag1", time, {"a"=>1}],
85
- ]
86
- res_codes = []
87
-
88
- d.run(expect_records: 1) do
89
- events.each do |tag, t, record|
90
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s})
91
- res_codes << res.code
92
- end
93
- end
94
- assert_equal ["200"], res_codes
95
- assert_equal events, d.events
96
- assert_equal_event_time time, d.events[0][1]
97
- end
98
-
99
- def test_json
100
- d = create_driver
101
- time = event_time("2011-01-02 13:14:15 UTC")
102
- time_i = time.to_i
103
-
104
- events = [
105
- ["tag1", time_i, {"a"=>1}],
106
- ["tag2", time_i, {"a"=>2}],
107
- ]
108
- res_codes = []
109
-
110
- d.run(expect_records: 2) do
111
- events.each do |tag, t, record|
112
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>t.to_s})
113
- res_codes << res.code
114
- end
115
- end
116
- assert_equal ["200", "200"], res_codes
117
- assert_equal events, d.events
118
- assert_equal_event_time time, d.events[0][1]
119
- assert_equal_event_time time, d.events[1][1]
120
- end
121
-
122
- data('json' => ['json', :to_json],
123
- 'msgpack' => ['msgpack', :to_msgpack])
124
- def test_default_with_time_format(data)
125
- param, method_name = data
126
- d = create_driver(config + %[
127
- <parse>
128
- keep_time_key
129
- time_format %iso8601
130
- </parse>
131
- ])
132
-
133
- time = event_time("2020-06-10T01:14:27+00:00")
134
- events = [
135
- ["tag1", time, {"a" => 1, "time" => '2020-06-10T01:14:27+00:00'}],
136
- ["tag2", time, {"a" => 2, "time" => '2020-06-10T01:14:27+00:00'}],
137
- ]
138
- res_codes = []
139
-
140
- d.run(expect_records: 2) do
141
- events.each do |tag, t, record|
142
- res = post("/#{tag}", {param => record.__send__(method_name)})
143
- res_codes << res.code
144
- end
145
- end
146
- assert_equal ["200", "200"], res_codes
147
- assert_equal events, d.events
148
- assert_equal_event_time time, d.events[0][1]
149
- assert_equal_event_time time, d.events[1][1]
150
- end
151
-
152
- def test_multi_json
153
- d = create_driver
154
- time = event_time("2011-01-02 13:14:15 UTC")
155
- time_i = time.to_i
156
-
157
- records = [{"a"=>1},{"a"=>2}]
158
- events = [
159
- ["tag1", time_i, records[0]],
160
- ["tag1", time_i, records[1]],
161
- ]
162
- tag = "tag1"
163
- res_codes = []
164
- d.run(expect_records: 2, timeout: 5) do
165
- res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
166
- res_codes << res.code
167
- end
168
- assert_equal ["200"], res_codes
169
- assert_equal events, d.events
170
- assert_equal_event_time time, d.events[0][1]
171
- assert_equal_event_time time, d.events[1][1]
172
- end
173
-
174
- def test_multi_json_with_time_field
175
- d = create_driver
176
- time = event_time("2011-01-02 13:14:15 UTC")
177
- time_i = time.to_i
178
- time_f = time.to_f
179
-
180
- records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
181
- events = [
182
- ["tag1", time, {'a' => 1}],
183
- ["tag1", time, {'a' => 2}],
184
- ]
185
- tag = "tag1"
186
- res_codes = []
187
- d.run(expect_records: 2, timeout: 5) do
188
- res = post("/#{tag}", {"json" => records.to_json})
189
- res_codes << res.code
190
- end
191
- assert_equal ["200"], res_codes
192
- assert_equal events, d.events
193
- assert_instance_of Fluent::EventTime, d.events[0][1]
194
- assert_instance_of Fluent::EventTime, d.events[1][1]
195
- assert_equal_event_time time, d.events[0][1]
196
- assert_equal_event_time time, d.events[1][1]
197
- end
198
-
199
- data('json' => ['json', :to_json],
200
- 'msgpack' => ['msgpack', :to_msgpack])
201
- def test_default_multi_with_time_format(data)
202
- param, method_name = data
203
- d = create_driver(config + %[
204
- <parse>
205
- keep_time_key
206
- time_format %iso8601
207
- </parse>
208
- ])
209
- time = event_time("2020-06-10T01:14:27+00:00")
210
- events = [
211
- ["tag1", time, {'a' => 1, 'time' => "2020-06-10T01:14:27+00:00"}],
212
- ["tag1", time, {'a' => 2, 'time' => "2020-06-10T01:14:27+00:00"}],
213
- ]
214
- tag = "tag1"
215
- res_codes = []
216
- d.run(expect_records: 2, timeout: 5) do
217
- res = post("/#{tag}", {param => events.map { |e| e[2] }.__send__(method_name)})
218
- res_codes << res.code
219
- end
220
- assert_equal ["200"], res_codes
221
- assert_equal events, d.events
222
- assert_equal_event_time time, d.events[0][1]
223
- assert_equal_event_time time, d.events[1][1]
224
- end
225
-
226
- def test_multi_json_with_nonexistent_time_key
227
- d = create_driver(config + %[
228
- <parse>
229
- time_key missing
230
- </parse>
231
- ])
232
- time = event_time("2011-01-02 13:14:15 UTC")
233
- time_i = time.to_i
234
- time_f = time.to_f
235
-
236
- records = [{"a" => 1, 'time' => time_i},{"a" => 2, 'time' => time_f}]
237
- tag = "tag1"
238
- res_codes = []
239
- d.run(expect_records: 2, timeout: 5) do
240
- res = post("/#{tag}", {"json" => records.to_json})
241
- res_codes << res.code
242
- end
243
- assert_equal ["200"], res_codes
244
- assert_equal 2, d.events.size
245
- assert_not_equal time_i, d.events[0][1].sec # current time is used because "missing" field doesn't exist
246
- assert_not_equal time_i, d.events[1][1].sec
247
- end
248
-
249
- def test_json_with_add_remote_addr
250
- d = create_driver(config + "add_remote_addr true")
251
- time = event_time("2011-01-02 13:14:15 UTC")
252
- time_i = time.to_i
253
-
254
- events = [
255
- ["tag1", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>1}],
256
- ["tag2", time, {"REMOTE_ADDR"=>"127.0.0.1", "a"=>2}],
257
- ]
258
- res_codes = []
259
- d.run(expect_records: 2) do
260
- events.each do |tag, _t, record|
261
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
262
- res_codes << res.code
263
- end
264
- end
265
- assert_equal ["200", "200"], res_codes
266
- assert_equal events, d.events
267
- assert_equal_event_time time, d.events[0][1]
268
- assert_equal_event_time time, d.events[1][1]
269
- end
270
-
271
- def test_exact_match_for_expect
272
- d = create_driver(config)
273
- records = [{ "a" => 1}, { "a" => 2 }]
274
- tag = "tag1"
275
- res_codes = []
276
-
277
- d.run(expect_records: 0, timeout: 5) do
278
- res = post("/#{tag}", { "json" => records.to_json }, { 'Expect' => 'something' })
279
- res_codes << res.code
280
- end
281
- assert_equal ["417"], res_codes
282
- end
283
-
284
- def test_exact_match_for_expect_with_other_header
285
- d = create_driver(config)
286
-
287
- records = [{ "a" => 1}, { "a" => 2 }]
288
- tag = "tag1"
289
- res_codes = []
290
-
291
- d.run(expect_records: 2, timeout: 5) do
292
- res = post("/#{tag}", { "json" => records.to_json, 'x-envoy-expected-rq-timeout-ms' => 4 })
293
- res_codes << res.code
294
- end
295
- assert_equal ["200"], res_codes
296
-
297
- assert_equal "tag1", d.events[0][0]
298
- assert_equal 1, d.events[0][2]["a"]
299
- assert_equal "tag1", d.events[1][0]
300
- assert_equal 2, d.events[1][2]["a"]
301
- end
302
-
303
- def test_multi_json_with_add_remote_addr
304
- d = create_driver(config + "add_remote_addr true")
305
- time = event_time("2011-01-02 13:14:15 UTC")
306
- time_i = time.to_i
307
-
308
- records = [{"a"=>1},{"a"=>2}]
309
- tag = "tag1"
310
- res_codes = []
311
-
312
- d.run(expect_records: 2, timeout: 5) do
313
- res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
314
- res_codes << res.code
315
- end
316
- assert_equal ["200"], res_codes
317
-
318
- assert_equal "tag1", d.events[0][0]
319
- assert_equal_event_time time, d.events[0][1]
320
- assert_equal 1, d.events[0][2]["a"]
321
- assert{ d.events[0][2].has_key?("REMOTE_ADDR") && d.events[0][2]["REMOTE_ADDR"] =~ /^\d{1,4}(\.\d{1,4}){3}$/ }
322
-
323
- assert_equal "tag1", d.events[1][0]
324
- assert_equal_event_time time, d.events[1][1]
325
- assert_equal 2, d.events[1][2]["a"]
326
- end
327
-
328
- def test_json_with_add_remote_addr_given_x_forwarded_for
329
- d = create_driver(config + "add_remote_addr true")
330
- time = event_time("2011-01-02 13:14:15 UTC")
331
- time_i = time.to_i
332
-
333
- events = [
334
- ["tag1", time, {"a"=>1}],
335
- ["tag2", time, {"a"=>2}],
336
- ]
337
- res_codes = []
338
-
339
- d.run(expect_records: 2) do
340
- events.each do |tag, _t, record|
341
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
342
- res_codes << res.code
343
- end
344
- end
345
- assert_equal ["200", "200"], res_codes
346
-
347
- assert_equal "tag1", d.events[0][0]
348
- assert_equal_event_time time, d.events[0][1]
349
- assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}, d.events[0][2])
350
-
351
- assert_equal "tag2", d.events[1][0]
352
- assert_equal_event_time time, d.events[1][1]
353
- assert_equal({"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}, d.events[1][2])
354
- end
355
-
356
- def test_multi_json_with_add_remote_addr_given_x_forwarded_for
357
- d = create_driver(config + "add_remote_addr true")
358
-
359
- tag = "tag1"
360
- time = event_time("2011-01-02 13:14:15 UTC")
361
- time_i = time.to_i
362
- records = [{"a"=>1},{"a"=>2}]
363
- events = [
364
- [tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>1}],
365
- [tag, time, {"REMOTE_ADDR"=>"129.78.138.66", "a"=>2}],
366
- ]
367
- res_codes = []
368
-
369
- d.run(expect_records: 2, timeout: 5) do
370
- res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s}, {"X-Forwarded-For"=>"129.78.138.66, 127.0.0.1"})
371
- res_codes << res.code
372
- end
373
- assert_equal ["200"], res_codes
374
- assert_equal events, d.events
375
- assert_equal_event_time time, d.events[0][1]
376
- assert_equal_event_time time, d.events[1][1]
377
- end
378
-
379
- def test_add_remote_addr_given_multi_x_forwarded_for
380
- d = create_driver(config + "add_remote_addr true")
381
-
382
- tag = "tag1"
383
- time = event_time("2011-01-02 13:14:15 UTC")
384
- time_i = time.to_i
385
- record = {"a" => 1}
386
- event = ["tag1", time, {"REMOTE_ADDR" => "129.78.138.66", "a" => 1}]
387
- res_code = nil
388
-
389
- d.run(expect_records: 1, timeout: 5) do
390
- res = post("/#{tag}", {"json" => record.to_json, "time" => time_i.to_s}) { |http, req|
391
- # net/http can't send multiple headers so overwrite it.
392
- def req.each_capitalized
393
- block_given? or return enum_for(__method__) { @header.size }
394
- @header.each do |k, vs|
395
- vs.each { |v|
396
- yield capitalize(k), v
397
- }
398
- end
399
- end
400
- req.add_field("X-Forwarded-For", "129.78.138.66, 127.0.0.1")
401
- req.add_field("X-Forwarded-For", "8.8.8.8")
402
- }
403
- res_code = res.code
404
- end
405
- assert_equal "200", res_code
406
- assert_equal event, d.events.first
407
- assert_equal_event_time time, d.events.first[1]
408
- end
409
-
410
- def test_multi_json_with_add_http_headers
411
- d = create_driver(config + "add_http_headers true")
412
- time = event_time("2011-01-02 13:14:15 UTC")
413
- time_i = time.to_i
414
- records = [{"a"=>1},{"a"=>2}]
415
- tag = "tag1"
416
- res_codes = []
417
-
418
- d.run(expect_records: 2, timeout: 5) do
419
- res = post("/#{tag}", {"json"=>records.to_json, "time"=>time_i.to_s})
420
- res_codes << res.code
421
- end
422
- assert_equal ["200"], res_codes
423
-
424
- assert_equal "tag1", d.events[0][0]
425
- assert_equal_event_time time, d.events[0][1]
426
- assert_equal 1, d.events[0][2]["a"]
427
-
428
- assert_equal "tag1", d.events[1][0]
429
- assert_equal_event_time time, d.events[1][1]
430
- assert_equal 2, d.events[1][2]["a"]
431
-
432
- assert include_http_header?(d.events[0][2])
433
- assert include_http_header?(d.events[1][2])
434
- end
435
-
436
- def test_json_with_add_http_headers
437
- d = create_driver(config + "add_http_headers true")
438
- time = event_time("2011-01-02 13:14:15 UTC")
439
- time_i = time.to_i
440
- events = [
441
- ["tag1", time, {"a"=>1}],
442
- ["tag2", time, {"a"=>2}],
443
- ]
444
- res_codes = []
445
-
446
- d.run(expect_records: 2) do
447
- events.each do |tag, t, record|
448
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
449
- res_codes << res.code
450
- end
451
- end
452
- assert_equal ["200", "200"], res_codes
453
-
454
- assert_equal "tag1", d.events[0][0]
455
- assert_equal_event_time time, d.events[0][1]
456
- assert_equal 1, d.events[0][2]["a"]
457
-
458
- assert_equal "tag2", d.events[1][0]
459
- assert_equal_event_time time, d.events[1][1]
460
- assert_equal 2, d.events[1][2]["a"]
461
-
462
- assert include_http_header?(d.events[0][2])
463
- assert include_http_header?(d.events[1][2])
464
- end
465
-
466
- def test_multi_json_with_custom_parser
467
- d = create_driver(config + %[
468
- <parse>
469
- @type json
470
- keep_time_key true
471
- time_key foo
472
- time_format %iso8601
473
- </parse>
474
- ])
475
-
476
- time = event_time("2011-01-02 13:14:15 UTC")
477
- time_s = Time.at(time).iso8601
478
-
479
- records = [{"foo"=>time_s,"bar"=>"test1"},{"foo"=>time_s,"bar"=>"test2"}]
480
- tag = "tag1"
481
- res_codes = []
482
-
483
- d.run(expect_records: 2, timeout: 5) do
484
- res = post("/#{tag}", records.to_json, {"Content-Type"=>"application/octet-stream"})
485
- res_codes << res.code
486
- end
487
- assert_equal ["200"], res_codes
488
-
489
- assert_equal "tag1", d.events[0][0]
490
- assert_equal_event_time time, d.events[0][1]
491
- assert_equal d.events[0][2], records[0]
492
-
493
- assert_equal "tag1", d.events[1][0]
494
- assert_equal_event_time time, d.events[1][1]
495
- assert_equal d.events[1][2], records[1]
496
- end
497
-
498
- def test_application_json
499
- d = create_driver
500
- time = event_time("2011-01-02 13:14:15 UTC")
501
- time_i = time.to_i
502
- events = [
503
- ["tag1", time, {"a"=>1}],
504
- ["tag2", time, {"a"=>2}],
505
- ]
506
- res_codes = []
507
-
508
- d.run(expect_records: 2) do
509
- events.each do |tag, t, record|
510
- res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/json; charset=utf-8"})
511
- res_codes << res.code
512
- end
513
- end
514
- assert_equal ["200", "200"], res_codes
515
- assert_equal events, d.events
516
- assert_equal_event_time time, d.events[0][1]
517
- assert_equal_event_time time, d.events[1][1]
518
- end
519
-
520
- def test_csp_report
521
- d = create_driver
522
- time = event_time("2011-01-02 13:14:15 UTC")
523
- time_i = time.to_i
524
- events = [
525
- ["tag1", time, {"a"=>1}],
526
- ["tag2", time, {"a"=>2}],
527
- ]
528
- res_codes = []
529
-
530
- d.run(expect_records: 2) do
531
- events.each do |tag, t, record|
532
- res = post("/#{tag}?time=#{time_i.to_s}", record.to_json, {"Content-Type"=>"application/csp-report; charset=utf-8"})
533
- res_codes << res.code
534
- end
535
- end
536
- assert_equal ["200", "200"], res_codes
537
- assert_equal events, d.events
538
- assert_equal_event_time time, d.events[0][1]
539
- assert_equal_event_time time, d.events[1][1]
540
- end
541
-
542
- def test_application_msgpack
543
- d = create_driver
544
- time = event_time("2011-01-02 13:14:15 UTC")
545
- time_i = time.to_i
546
- events = [
547
- ["tag1", time, {"a"=>1}],
548
- ["tag2", time, {"a"=>2}],
549
- ]
550
- res_codes = []
551
-
552
- d.run(expect_records: 2) do
553
- events.each do |tag, t, record|
554
- res = post("/#{tag}?time=#{time_i.to_s}", record.to_msgpack, {"Content-Type"=>"application/msgpack"})
555
- res_codes << res.code
556
- end
557
- end
558
- assert_equal ["200", "200"], res_codes
559
- assert_equal events, d.events
560
- assert_equal_event_time time, d.events[0][1]
561
- assert_equal_event_time time, d.events[1][1]
562
- end
563
-
564
- def test_application_ndjson
565
- d = create_driver
566
- events = [
567
- ["tag1", 1643935663, "{\"a\":1}\n{\"b\":2}"],
568
- ["tag2", 1643935664, "{\"a\":3}\r\n{\"b\":4}"]
569
- ]
570
-
571
- expected = [
572
- ["tag1", 1643935663, {"a"=>1}],
573
- ["tag1", 1643935663, {"b"=>2}],
574
- ["tag2", 1643935664, {"a"=>3}],
575
- ["tag2", 1643935664, {"b"=>4}]
576
- ]
577
-
578
- d.run(expect_records: 1) do
579
- events.each do |tag, time, record|
580
- res = post("/#{tag}?time=#{time}", record, {"Content-Type"=>"application/x-ndjson"})
581
- assert_equal("200", res.code)
582
- end
583
- end
584
- assert_equal(expected, d.events)
585
- end
586
-
587
- def test_msgpack
588
- d = create_driver
589
- time = event_time("2011-01-02 13:14:15 UTC")
590
- time_i = time.to_i
591
-
592
- events = [
593
- ["tag1", time, {"a"=>1}],
594
- ["tag2", time, {"a"=>2}],
595
- ]
596
- res_codes = []
597
-
598
- d.run(expect_records: 2) do
599
- events.each do |tag, t, record|
600
- res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time_i.to_s})
601
- res_codes << res.code
602
- end
603
- end
604
- assert_equal ["200", "200"], res_codes
605
- assert_equal events, d.events
606
- assert_equal_event_time time, d.events[0][1]
607
- assert_equal_event_time time, d.events[1][1]
608
- end
609
-
610
- def test_multi_msgpack
611
- d = create_driver
612
-
613
- time = event_time("2011-01-02 13:14:15 UTC")
614
- time_i = time.to_i
615
-
616
- records = [{"a"=>1},{"a"=>2}]
617
- events = [
618
- ["tag1", time, records[0]],
619
- ["tag1", time, records[1]],
620
- ]
621
- tag = "tag1"
622
- res_codes = []
623
- d.run(expect_records: 2) do
624
- res = post("/#{tag}", {"msgpack"=>records.to_msgpack, "time"=>time_i.to_s})
625
- res_codes << res.code
626
- end
627
- assert_equal ["200"], res_codes
628
- assert_equal events, d.events
629
- assert_equal_event_time time, d.events[0][1]
630
- assert_equal_event_time time, d.events[1][1]
631
- end
632
-
633
- def test_with_regexp
634
- d = create_driver(config + %[
635
- format /^(?<field_1>\\d+):(?<field_2>\\w+)$/
636
- types field_1:integer
637
- ])
638
-
639
- time = event_time("2011-01-02 13:14:15 UTC")
640
- time_i = time.to_i
641
- events = [
642
- ["tag1", time, {"field_1" => 1, "field_2" => 'str'}],
643
- ["tag2", time, {"field_1" => 2, "field_2" => 'str'}],
644
- ]
645
- res_codes = []
646
-
647
- d.run(expect_records: 2) do
648
- events.each do |tag, t, record|
649
- body = record.map { |k, v|
650
- v.to_s
651
- }.join(':')
652
- res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'application/octet-stream'})
653
- res_codes << res.code
654
- end
655
- end
656
- assert_equal ["200", "200"], res_codes
657
- assert_equal events, d.events
658
- assert_equal_event_time time, d.events[0][1]
659
- assert_equal_event_time time, d.events[1][1]
660
- end
661
-
662
- def test_with_csv
663
- require 'csv'
664
-
665
- d = create_driver(config + %[
666
- format csv
667
- keys foo,bar
668
- ])
669
- time = event_time("2011-01-02 13:14:15 UTC")
670
- time_i = time.to_i
671
- events = [
672
- ["tag1", time, {"foo" => "1", "bar" => 'st"r'}],
673
- ["tag2", time, {"foo" => "2", "bar" => 'str'}],
674
- ]
675
- res_codes = []
676
-
677
- d.run(expect_records: 2) do
678
- events.each do |tag, t, record|
679
- body = record.map { |k, v| v }.to_csv
680
- res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
681
- res_codes << res.code
682
- end
683
- end
684
- assert_equal ["200", "200"], res_codes
685
- assert_equal events, d.events
686
- assert_equal_event_time time, d.events[0][1]
687
- assert_equal_event_time time, d.events[1][1]
688
- end
689
-
690
- def test_response_with_empty_img
691
- d = create_driver(config)
692
- assert_equal true, d.instance.respond_with_empty_img
693
-
694
- time = event_time("2011-01-02 13:14:15 UTC")
695
- time_i = time.to_i
696
- events = [
697
- ["tag1", time, {"a"=>1}],
698
- ["tag2", time, {"a"=>2}],
699
- ]
700
- res_codes = []
701
- res_bodies = []
702
-
703
- d.run do
704
- events.each do |tag, _t, record|
705
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
706
- res_codes << res.code
707
- # Ruby returns ASCII-8 encoded string for GIF.
708
- res_bodies << res.body.force_encoding("UTF-8")
709
- end
710
- end
711
- assert_equal ["200", "200"], res_codes
712
- assert_equal [Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE, Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE], res_bodies
713
- assert_equal events, d.events
714
- assert_equal_event_time time, d.events[0][1]
715
- assert_equal_event_time time, d.events[1][1]
716
- end
717
-
718
- def test_response_without_empty_img
719
- d = create_driver(config + "respond_with_empty_img false")
720
- assert_equal false, d.instance.respond_with_empty_img
721
-
722
- time = event_time("2011-01-02 13:14:15 UTC")
723
- time_i = time.to_i
724
- events = [
725
- ["tag1", time, {"a"=>1}],
726
- ["tag2", time, {"a"=>2}],
727
- ]
728
- res_codes = []
729
- res_bodies = []
730
-
731
- d.run do
732
- events.each do |tag, _t, record|
733
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
734
- res_codes << res.code
735
- end
736
- end
737
- assert_equal ["200", "200"], res_codes
738
- assert_equal [], res_bodies
739
- assert_equal events, d.events
740
- assert_equal_event_time time, d.events[0][1]
741
- assert_equal_event_time time, d.events[1][1]
742
- end
743
-
744
- def test_response_use_204_response
745
- d = create_driver(config + %[
746
- respond_with_empty_img false
747
- use_204_response true
748
- ])
749
- assert_equal true, d.instance.use_204_response
750
-
751
- time = event_time("2011-01-02 13:14:15 UTC")
752
- time_i = time.to_i
753
- events = [
754
- ["tag1", time, {"a"=>1}],
755
- ["tag2", time, {"a"=>2}],
756
- ]
757
- res_codes = []
758
- res_bodies = []
759
-
760
- d.run do
761
- events.each do |tag, _t, record|
762
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
763
- res_codes << res.code
764
- end
765
- end
766
- assert_equal ["204", "204"], res_codes
767
- assert_equal [], res_bodies
768
- assert_equal events, d.events
769
- assert_equal_event_time time, d.events[0][1]
770
- assert_equal_event_time time, d.events[1][1]
771
- end
772
-
773
- def test_cors_allowed
774
- d = create_driver(config + "cors_allow_origins [\"http://foo.com\"]")
775
- assert_equal ["http://foo.com"], d.instance.cors_allow_origins
776
-
777
- time = event_time("2011-01-02 13:14:15 UTC")
778
- time_i = time.to_i
779
- events = [
780
- ["tag1", time, {"a"=>1}],
781
- ["tag2", time, {"a"=>2}],
782
- ]
783
- res_codes = []
784
- res_headers = []
785
-
786
- d.run do
787
- events.each do |tag, _t, record|
788
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://foo.com"})
789
- res_codes << res.code
790
- res_headers << res["Access-Control-Allow-Origin"]
791
- end
792
- end
793
- assert_equal ["200", "200"], res_codes
794
- assert_equal ["http://foo.com", "http://foo.com"], res_headers
795
- assert_equal events, d.events
796
- assert_equal_event_time time, d.events[0][1]
797
- assert_equal_event_time time, d.events[1][1]
798
- end
799
-
800
- def test_cors_allowed_wildcard
801
- d = create_driver(config + 'cors_allow_origins ["*"]')
802
-
803
- time = event_time("2011-01-02 13:14:15 UTC")
804
- events = [
805
- ["tag1", time, {"a"=>1}],
806
- ]
807
-
808
- d.run do
809
- events.each do |tag, time, record|
810
- headers = {"Origin" => "http://foo.com"}
811
-
812
- res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
813
-
814
- assert_equal "200", res.code
815
- assert_equal "*", res["Access-Control-Allow-Origin"]
816
- end
817
- end
818
- end
819
-
820
- def test_get_request
821
- d = create_driver(config)
822
-
823
- d.run do
824
- res = get("/cors.test", {}, {})
825
- assert_equal "200", res.code
826
- end
827
- end
828
-
829
- def test_cors_preflight
830
- d = create_driver(config + 'cors_allow_origins ["*"]')
831
-
832
- d.run do
833
- header = {
834
- "Origin" => "http://foo.com",
835
- "Access-Control-Request-Method" => "POST",
836
- "Access-Control-Request-Headers" => "Content-Type",
837
- }
838
- res = options("/cors.test", {}, header)
839
-
840
- assert_equal "200", res.code
841
- assert_equal "*", res["Access-Control-Allow-Origin"]
842
- assert_equal "POST", res["Access-Control-Allow-Methods"]
843
- end
844
- end
845
-
846
- def test_cors_allowed_wildcard_for_subdomain
847
- d = create_driver(config + 'cors_allow_origins ["http://*.foo.com"]')
848
-
849
- time = event_time("2011-01-02 13:14:15 UTC")
850
- events = [
851
- ["tag1", time, {"a"=>1}],
852
- ]
853
-
854
- d.run do
855
- events.each do |tag, time, record|
856
- headers = {"Origin" => "http://subdomain.foo.com"}
857
-
858
- res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
859
-
860
- assert_equal "200", res.code
861
- assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
862
- end
863
- end
864
- end
865
-
866
- def test_cors_allowed_exclude_empty_string
867
- d = create_driver(config + 'cors_allow_origins ["", "http://*.foo.com"]')
868
-
869
- time = event_time("2011-01-02 13:14:15 UTC")
870
- events = [
871
- ["tag1", time, {"a"=>1}],
872
- ]
873
-
874
- d.run do
875
- events.each do |tag, time, record|
876
- headers = {"Origin" => "http://subdomain.foo.com"}
877
-
878
- res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
879
-
880
- assert_equal "200", res.code
881
- assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
882
- end
883
- end
884
- end
885
-
886
- def test_cors_allowed_wildcard_preflight_for_subdomain
887
- d = create_driver(config + 'cors_allow_origins ["http://*.foo.com"]')
888
-
889
- d.run do
890
- header = {
891
- "Origin" => "http://subdomain.foo.com",
892
- "Access-Control-Request-Method" => "POST",
893
- "Access-Control-Request-Headers" => "Content-Type",
894
- }
895
- res = options("/cors.test", {}, header)
896
-
897
- assert_equal "200", res.code
898
- assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
899
- assert_equal "POST", res["Access-Control-Allow-Methods"]
900
- end
901
- end
902
-
903
- def test_cors_allow_credentials
904
- d = create_driver(config + %[
905
- cors_allow_origins ["http://foo.com"]
906
- cors_allow_credentials
907
- ])
908
- assert_equal true, d.instance.cors_allow_credentials
909
-
910
- time = event_time("2011-01-02 13:14:15 UTC")
911
- event = ["tag1", time, {"a"=>1}]
912
- res_code = nil
913
- res_header = nil
914
-
915
- d.run do
916
- res = post("/#{event[0]}", {"json"=>event[2].to_json, "time"=>time.to_i.to_s}, {"Origin"=>"http://foo.com"})
917
- res_code = res.code
918
- res_header = res["Access-Control-Allow-Credentials"]
919
- end
920
- assert_equal(
921
- {
922
- response_code: "200",
923
- allow_credentials_header: "true",
924
- events: [event]
925
- },
926
- {
927
- response_code: res_code,
928
- allow_credentials_header: res_header,
929
- events: d.events
930
- }
931
- )
932
- end
933
-
934
- def test_cors_allow_credentials_for_wildcard_origins
935
- assert_raise(Fluent::ConfigError) do
936
- create_driver(config + %[
937
- cors_allow_origins ["*"]
938
- cors_allow_credentials
939
- ])
940
- end
941
- end
942
-
943
- def test_content_encoding_gzip
944
- d = create_driver
945
-
946
- time = event_time("2011-01-02 13:14:15 UTC")
947
- events = [
948
- ["tag1", time, {"a"=>1}],
949
- ["tag2", time, {"a"=>2}],
950
- ]
951
- res_codes = []
952
-
953
- d.run do
954
- events.each do |tag, time, record|
955
- header = {'Content-Type'=>'application/json', 'Content-Encoding'=>'gzip'}
956
- res = post("/#{tag}?time=#{time}", compress_gzip(record.to_json), header)
957
- res_codes << res.code
958
- end
959
- end
960
- assert_equal ["200", "200"], res_codes
961
- assert_equal events, d.events
962
- assert_equal_event_time time, d.events[0][1]
963
- assert_equal_event_time time, d.events[1][1]
964
- end
965
-
966
- def test_content_encoding_deflate
967
- d = create_driver
968
-
969
- time = event_time("2011-01-02 13:14:15 UTC")
970
- events = [
971
- ["tag1", time, {"a"=>1}],
972
- ["tag2", time, {"a"=>2}],
973
- ]
974
- res_codes = []
975
-
976
- d.run do
977
- events.each do |tag, time, record|
978
- header = {'Content-Type'=>'application/msgpack', 'Content-Encoding'=>'deflate'}
979
- res = post("/#{tag}?time=#{time}", Zlib.deflate(record.to_msgpack), header)
980
- res_codes << res.code
981
- end
982
- end
983
- assert_equal ["200", "200"], res_codes
984
- assert_equal events, d.events
985
- assert_equal_event_time time, d.events[0][1]
986
- assert_equal_event_time time, d.events[1][1]
987
- end
988
-
989
- def test_cors_disallowed
990
- d = create_driver(config + "cors_allow_origins [\"http://foo.com\"]")
991
- assert_equal ["http://foo.com"], d.instance.cors_allow_origins
992
-
993
- time = event_time("2011-01-02 13:14:15 UTC")
994
- time_i = time.to_i
995
- res_codes = []
996
-
997
- d.end_if{ res_codes.size == 2 }
998
- d.run do
999
- res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
1000
- res_codes << res.code
1001
- res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
1002
- res_codes << res.code
1003
- end
1004
- assert_equal ["403", "403"], res_codes
1005
- end
1006
-
1007
- def test_add_query_params
1008
- d = create_driver(config + "add_query_params true")
1009
- assert_equal true, d.instance.add_query_params
1010
-
1011
- time = event_time("2011-01-02 13:14:15 UTC")
1012
- time_i = time.to_i
1013
- events = [
1014
- ["tag1", time, {"a"=>1, "QUERY_A"=>"b"}],
1015
- ["tag2", time, {"a"=>2, "QUERY_A"=>"b"}],
1016
- ]
1017
- res_codes = []
1018
- res_bodies = []
1019
-
1020
- d.run do
1021
- events.each do |tag, _t, record|
1022
- res = post("/#{tag}?a=b", {"json"=>record.to_json, "time"=>time_i.to_s})
1023
- res_codes << res.code
1024
- end
1025
- end
1026
- assert_equal ["200", "200"], res_codes
1027
- assert_equal [], res_bodies
1028
- assert_equal events, d.events
1029
- end
1030
-
1031
- $test_in_http_connection_object_ids = []
1032
- $test_in_http_content_types = []
1033
- $test_in_http_content_types_flag = false
1034
- module ContentTypeHook
1035
- def initialize(*args)
1036
- @io_handler = nil
1037
- super
1038
- end
1039
- def on_headers_complete(headers)
1040
- super
1041
- if $test_in_http_content_types_flag
1042
- $test_in_http_content_types << self.content_type
1043
- end
1044
- end
1045
-
1046
- def on_message_begin
1047
- super
1048
- if $test_in_http_content_types_flag
1049
- $test_in_http_connection_object_ids << @io_handler.object_id
1050
- end
1051
- end
1052
- end
1053
-
1054
- class Fluent::Plugin::HttpInput::Handler
1055
- prepend ContentTypeHook
1056
- end
1057
-
1058
- def test_if_content_type_is_initialized_properly
1059
- # This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly.
1060
- # Especially when in Keep-Alive and the second request has no 'Content-Type'.
1061
-
1062
- begin
1063
- d = create_driver
1064
-
1065
- $test_in_http_content_types_flag = true
1066
- d.run do
1067
- # Send two requests the second one has no Content-Type in Keep-Alive
1068
- Net::HTTP.start("127.0.0.1", @port) do |http|
1069
- req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
1070
- http.request(req)
1071
- req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
1072
- http.request(req)
1073
- end
1074
-
1075
- end
1076
- ensure
1077
- $test_in_http_content_types_flag = false
1078
- end
1079
- assert_equal(['application/json', ''], $test_in_http_content_types)
1080
- # Asserting keepalive
1081
- assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
1082
- end
1083
-
1084
- def get(path, params, header = {})
1085
- http = Net::HTTP.new("127.0.0.1", @port)
1086
- req = Net::HTTP::Get.new(path, header)
1087
- http.request(req)
1088
- end
1089
-
1090
- def options(path, params, header = {})
1091
- http = Net::HTTP.new("127.0.0.1", @port)
1092
- req = Net::HTTP::Options.new(path, header)
1093
- http.request(req)
1094
- end
1095
-
1096
- def post(path, params, header = {}, &block)
1097
- http = Net::HTTP.new("127.0.0.1", @port)
1098
- req = Net::HTTP::Post.new(path, header)
1099
- block.call(http, req) if block
1100
- if params.is_a?(String)
1101
- unless header.has_key?('Content-Type')
1102
- header['Content-Type'] = 'application/octet-stream'
1103
- end
1104
- req.body = params
1105
- else
1106
- unless header.has_key?('Content-Type')
1107
- header['Content-Type'] = 'application/x-www-form-urlencoded'
1108
- end
1109
- req.set_form_data(params)
1110
- end
1111
- http.request(req)
1112
- end
1113
-
1114
- def compress_gzip(data)
1115
- io = StringIO.new
1116
- io.binmode
1117
- Zlib::GzipWriter.wrap(io) { |gz| gz.write data }
1118
- return io.string
1119
- end
1120
-
1121
- def include_http_header?(record)
1122
- record.keys.find { |header| header.start_with?('HTTP_') }
1123
- end
1124
- end