fluentd 1.16.5-x86-mingw32 → 1.17.1-x86-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,1102 +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_application_msgpack
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_msgpack, {"Content-Type"=>"application/msgpack"})
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_ndjson
543
- d = create_driver
544
- events = [
545
- ["tag1", 1643935663, "{\"a\":1}\n{\"b\":2}"],
546
- ["tag2", 1643935664, "{\"a\":3}\r\n{\"b\":4}"]
547
- ]
548
-
549
- expected = [
550
- ["tag1", 1643935663, {"a"=>1}],
551
- ["tag1", 1643935663, {"b"=>2}],
552
- ["tag2", 1643935664, {"a"=>3}],
553
- ["tag2", 1643935664, {"b"=>4}]
554
- ]
555
-
556
- d.run(expect_records: 1) do
557
- events.each do |tag, time, record|
558
- res = post("/#{tag}?time=#{time}", record, {"Content-Type"=>"application/x-ndjson"})
559
- assert_equal("200", res.code)
560
- end
561
- end
562
- assert_equal(expected, d.events)
563
- end
564
-
565
- def test_msgpack
566
- d = create_driver
567
- time = event_time("2011-01-02 13:14:15 UTC")
568
- time_i = time.to_i
569
-
570
- events = [
571
- ["tag1", time, {"a"=>1}],
572
- ["tag2", time, {"a"=>2}],
573
- ]
574
- res_codes = []
575
-
576
- d.run(expect_records: 2) do
577
- events.each do |tag, t, record|
578
- res = post("/#{tag}", {"msgpack"=>record.to_msgpack, "time"=>time_i.to_s})
579
- res_codes << res.code
580
- end
581
- end
582
- assert_equal ["200", "200"], res_codes
583
- assert_equal events, d.events
584
- assert_equal_event_time time, d.events[0][1]
585
- assert_equal_event_time time, d.events[1][1]
586
- end
587
-
588
- def test_multi_msgpack
589
- d = create_driver
590
-
591
- time = event_time("2011-01-02 13:14:15 UTC")
592
- time_i = time.to_i
593
-
594
- records = [{"a"=>1},{"a"=>2}]
595
- events = [
596
- ["tag1", time, records[0]],
597
- ["tag1", time, records[1]],
598
- ]
599
- tag = "tag1"
600
- res_codes = []
601
- d.run(expect_records: 2) do
602
- res = post("/#{tag}", {"msgpack"=>records.to_msgpack, "time"=>time_i.to_s})
603
- res_codes << res.code
604
- end
605
- assert_equal ["200"], res_codes
606
- assert_equal events, d.events
607
- assert_equal_event_time time, d.events[0][1]
608
- assert_equal_event_time time, d.events[1][1]
609
- end
610
-
611
- def test_with_regexp
612
- d = create_driver(config + %[
613
- format /^(?<field_1>\\d+):(?<field_2>\\w+)$/
614
- types field_1:integer
615
- ])
616
-
617
- time = event_time("2011-01-02 13:14:15 UTC")
618
- time_i = time.to_i
619
- events = [
620
- ["tag1", time, {"field_1" => 1, "field_2" => 'str'}],
621
- ["tag2", time, {"field_1" => 2, "field_2" => 'str'}],
622
- ]
623
- res_codes = []
624
-
625
- d.run(expect_records: 2) do
626
- events.each do |tag, t, record|
627
- body = record.map { |k, v|
628
- v.to_s
629
- }.join(':')
630
- res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'application/octet-stream'})
631
- res_codes << res.code
632
- end
633
- end
634
- assert_equal ["200", "200"], res_codes
635
- assert_equal events, d.events
636
- assert_equal_event_time time, d.events[0][1]
637
- assert_equal_event_time time, d.events[1][1]
638
- end
639
-
640
- def test_with_csv
641
- require 'csv'
642
-
643
- d = create_driver(config + %[
644
- format csv
645
- keys foo,bar
646
- ])
647
- time = event_time("2011-01-02 13:14:15 UTC")
648
- time_i = time.to_i
649
- events = [
650
- ["tag1", time, {"foo" => "1", "bar" => 'st"r'}],
651
- ["tag2", time, {"foo" => "2", "bar" => 'str'}],
652
- ]
653
- res_codes = []
654
-
655
- d.run(expect_records: 2) do
656
- events.each do |tag, t, record|
657
- body = record.map { |k, v| v }.to_csv
658
- res = post("/#{tag}?time=#{time_i.to_s}", body, {'Content-Type' => 'text/comma-separated-values'})
659
- res_codes << res.code
660
- end
661
- end
662
- assert_equal ["200", "200"], res_codes
663
- assert_equal events, d.events
664
- assert_equal_event_time time, d.events[0][1]
665
- assert_equal_event_time time, d.events[1][1]
666
- end
667
-
668
- def test_response_with_empty_img
669
- d = create_driver(config)
670
- assert_equal true, d.instance.respond_with_empty_img
671
-
672
- time = event_time("2011-01-02 13:14:15 UTC")
673
- time_i = time.to_i
674
- events = [
675
- ["tag1", time, {"a"=>1}],
676
- ["tag2", time, {"a"=>2}],
677
- ]
678
- res_codes = []
679
- res_bodies = []
680
-
681
- d.run do
682
- events.each do |tag, _t, record|
683
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
684
- res_codes << res.code
685
- # Ruby returns ASCII-8 encoded string for GIF.
686
- res_bodies << res.body.force_encoding("UTF-8")
687
- end
688
- end
689
- assert_equal ["200", "200"], res_codes
690
- assert_equal [Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE, Fluent::Plugin::HttpInput::EMPTY_GIF_IMAGE], res_bodies
691
- assert_equal events, d.events
692
- assert_equal_event_time time, d.events[0][1]
693
- assert_equal_event_time time, d.events[1][1]
694
- end
695
-
696
- def test_response_without_empty_img
697
- d = create_driver(config + "respond_with_empty_img false")
698
- assert_equal false, d.instance.respond_with_empty_img
699
-
700
- time = event_time("2011-01-02 13:14:15 UTC")
701
- time_i = time.to_i
702
- events = [
703
- ["tag1", time, {"a"=>1}],
704
- ["tag2", time, {"a"=>2}],
705
- ]
706
- res_codes = []
707
- res_bodies = []
708
-
709
- d.run do
710
- events.each do |tag, _t, record|
711
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
712
- res_codes << res.code
713
- end
714
- end
715
- assert_equal ["200", "200"], res_codes
716
- assert_equal [], res_bodies
717
- assert_equal events, d.events
718
- assert_equal_event_time time, d.events[0][1]
719
- assert_equal_event_time time, d.events[1][1]
720
- end
721
-
722
- def test_response_use_204_response
723
- d = create_driver(config + %[
724
- respond_with_empty_img false
725
- use_204_response true
726
- ])
727
- assert_equal true, d.instance.use_204_response
728
-
729
- time = event_time("2011-01-02 13:14:15 UTC")
730
- time_i = time.to_i
731
- events = [
732
- ["tag1", time, {"a"=>1}],
733
- ["tag2", time, {"a"=>2}],
734
- ]
735
- res_codes = []
736
- res_bodies = []
737
-
738
- d.run do
739
- events.each do |tag, _t, record|
740
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s})
741
- res_codes << res.code
742
- end
743
- end
744
- assert_equal ["204", "204"], res_codes
745
- assert_equal [], res_bodies
746
- assert_equal events, d.events
747
- assert_equal_event_time time, d.events[0][1]
748
- assert_equal_event_time time, d.events[1][1]
749
- end
750
-
751
- def test_cors_allowed
752
- d = create_driver(config + "cors_allow_origins [\"http://foo.com\"]")
753
- assert_equal ["http://foo.com"], d.instance.cors_allow_origins
754
-
755
- time = event_time("2011-01-02 13:14:15 UTC")
756
- time_i = time.to_i
757
- events = [
758
- ["tag1", time, {"a"=>1}],
759
- ["tag2", time, {"a"=>2}],
760
- ]
761
- res_codes = []
762
- res_headers = []
763
-
764
- d.run do
765
- events.each do |tag, _t, record|
766
- res = post("/#{tag}", {"json"=>record.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://foo.com"})
767
- res_codes << res.code
768
- res_headers << res["Access-Control-Allow-Origin"]
769
- end
770
- end
771
- assert_equal ["200", "200"], res_codes
772
- assert_equal ["http://foo.com", "http://foo.com"], res_headers
773
- assert_equal events, d.events
774
- assert_equal_event_time time, d.events[0][1]
775
- assert_equal_event_time time, d.events[1][1]
776
- end
777
-
778
- def test_cors_allowed_wildcard
779
- d = create_driver(config + 'cors_allow_origins ["*"]')
780
-
781
- time = event_time("2011-01-02 13:14:15 UTC")
782
- events = [
783
- ["tag1", time, {"a"=>1}],
784
- ]
785
-
786
- d.run do
787
- events.each do |tag, time, record|
788
- headers = {"Origin" => "http://foo.com"}
789
-
790
- res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
791
-
792
- assert_equal "200", res.code
793
- assert_equal "*", res["Access-Control-Allow-Origin"]
794
- end
795
- end
796
- end
797
-
798
- def test_get_request
799
- d = create_driver(config)
800
-
801
- d.run do
802
- res = get("/cors.test", {}, {})
803
- assert_equal "200", res.code
804
- end
805
- end
806
-
807
- def test_cors_preflight
808
- d = create_driver(config + 'cors_allow_origins ["*"]')
809
-
810
- d.run do
811
- header = {
812
- "Origin" => "http://foo.com",
813
- "Access-Control-Request-Method" => "POST",
814
- "Access-Control-Request-Headers" => "Content-Type",
815
- }
816
- res = options("/cors.test", {}, header)
817
-
818
- assert_equal "200", res.code
819
- assert_equal "*", res["Access-Control-Allow-Origin"]
820
- assert_equal "POST", res["Access-Control-Allow-Methods"]
821
- end
822
- end
823
-
824
- def test_cors_allowed_wildcard_for_subdomain
825
- d = create_driver(config + 'cors_allow_origins ["http://*.foo.com"]')
826
-
827
- time = event_time("2011-01-02 13:14:15 UTC")
828
- events = [
829
- ["tag1", time, {"a"=>1}],
830
- ]
831
-
832
- d.run do
833
- events.each do |tag, time, record|
834
- headers = {"Origin" => "http://subdomain.foo.com"}
835
-
836
- res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
837
-
838
- assert_equal "200", res.code
839
- assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
840
- end
841
- end
842
- end
843
-
844
- def test_cors_allowed_exclude_empty_string
845
- d = create_driver(config + 'cors_allow_origins ["", "http://*.foo.com"]')
846
-
847
- time = event_time("2011-01-02 13:14:15 UTC")
848
- events = [
849
- ["tag1", time, {"a"=>1}],
850
- ]
851
-
852
- d.run do
853
- events.each do |tag, time, record|
854
- headers = {"Origin" => "http://subdomain.foo.com"}
855
-
856
- res = post("/#{tag}", {"json" => record.to_json, "time" => time.to_i}, headers)
857
-
858
- assert_equal "200", res.code
859
- assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
860
- end
861
- end
862
- end
863
-
864
- def test_cors_allowed_wildcard_preflight_for_subdomain
865
- d = create_driver(config + 'cors_allow_origins ["http://*.foo.com"]')
866
-
867
- d.run do
868
- header = {
869
- "Origin" => "http://subdomain.foo.com",
870
- "Access-Control-Request-Method" => "POST",
871
- "Access-Control-Request-Headers" => "Content-Type",
872
- }
873
- res = options("/cors.test", {}, header)
874
-
875
- assert_equal "200", res.code
876
- assert_equal "http://subdomain.foo.com", res["Access-Control-Allow-Origin"]
877
- assert_equal "POST", res["Access-Control-Allow-Methods"]
878
- end
879
- end
880
-
881
- def test_cors_allow_credentials
882
- d = create_driver(config + %[
883
- cors_allow_origins ["http://foo.com"]
884
- cors_allow_credentials
885
- ])
886
- assert_equal true, d.instance.cors_allow_credentials
887
-
888
- time = event_time("2011-01-02 13:14:15 UTC")
889
- event = ["tag1", time, {"a"=>1}]
890
- res_code = nil
891
- res_header = nil
892
-
893
- d.run do
894
- res = post("/#{event[0]}", {"json"=>event[2].to_json, "time"=>time.to_i.to_s}, {"Origin"=>"http://foo.com"})
895
- res_code = res.code
896
- res_header = res["Access-Control-Allow-Credentials"]
897
- end
898
- assert_equal(
899
- {
900
- response_code: "200",
901
- allow_credentials_header: "true",
902
- events: [event]
903
- },
904
- {
905
- response_code: res_code,
906
- allow_credentials_header: res_header,
907
- events: d.events
908
- }
909
- )
910
- end
911
-
912
- def test_cors_allow_credentials_for_wildcard_origins
913
- assert_raise(Fluent::ConfigError) do
914
- create_driver(config + %[
915
- cors_allow_origins ["*"]
916
- cors_allow_credentials
917
- ])
918
- end
919
- end
920
-
921
- def test_content_encoding_gzip
922
- d = create_driver
923
-
924
- time = event_time("2011-01-02 13:14:15 UTC")
925
- events = [
926
- ["tag1", time, {"a"=>1}],
927
- ["tag2", time, {"a"=>2}],
928
- ]
929
- res_codes = []
930
-
931
- d.run do
932
- events.each do |tag, time, record|
933
- header = {'Content-Type'=>'application/json', 'Content-Encoding'=>'gzip'}
934
- res = post("/#{tag}?time=#{time}", compress_gzip(record.to_json), header)
935
- res_codes << res.code
936
- end
937
- end
938
- assert_equal ["200", "200"], res_codes
939
- assert_equal events, d.events
940
- assert_equal_event_time time, d.events[0][1]
941
- assert_equal_event_time time, d.events[1][1]
942
- end
943
-
944
- def test_content_encoding_deflate
945
- d = create_driver
946
-
947
- time = event_time("2011-01-02 13:14:15 UTC")
948
- events = [
949
- ["tag1", time, {"a"=>1}],
950
- ["tag2", time, {"a"=>2}],
951
- ]
952
- res_codes = []
953
-
954
- d.run do
955
- events.each do |tag, time, record|
956
- header = {'Content-Type'=>'application/msgpack', 'Content-Encoding'=>'deflate'}
957
- res = post("/#{tag}?time=#{time}", Zlib.deflate(record.to_msgpack), header)
958
- res_codes << res.code
959
- end
960
- end
961
- assert_equal ["200", "200"], res_codes
962
- assert_equal events, d.events
963
- assert_equal_event_time time, d.events[0][1]
964
- assert_equal_event_time time, d.events[1][1]
965
- end
966
-
967
- def test_cors_disallowed
968
- d = create_driver(config + "cors_allow_origins [\"http://foo.com\"]")
969
- assert_equal ["http://foo.com"], d.instance.cors_allow_origins
970
-
971
- time = event_time("2011-01-02 13:14:15 UTC")
972
- time_i = time.to_i
973
- res_codes = []
974
-
975
- d.end_if{ res_codes.size == 2 }
976
- d.run do
977
- res = post("/tag1", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
978
- res_codes << res.code
979
- res = post("/tag2", {"json"=>{"a"=>1}.to_json, "time"=>time_i.to_s}, {"Origin"=>"http://bar.com"})
980
- res_codes << res.code
981
- end
982
- assert_equal ["403", "403"], res_codes
983
- end
984
-
985
- def test_add_query_params
986
- d = create_driver(config + "add_query_params true")
987
- assert_equal true, d.instance.add_query_params
988
-
989
- time = event_time("2011-01-02 13:14:15 UTC")
990
- time_i = time.to_i
991
- events = [
992
- ["tag1", time, {"a"=>1, "QUERY_A"=>"b"}],
993
- ["tag2", time, {"a"=>2, "QUERY_A"=>"b"}],
994
- ]
995
- res_codes = []
996
- res_bodies = []
997
-
998
- d.run do
999
- events.each do |tag, _t, record|
1000
- res = post("/#{tag}?a=b", {"json"=>record.to_json, "time"=>time_i.to_s})
1001
- res_codes << res.code
1002
- end
1003
- end
1004
- assert_equal ["200", "200"], res_codes
1005
- assert_equal [], res_bodies
1006
- assert_equal events, d.events
1007
- end
1008
-
1009
- $test_in_http_connection_object_ids = []
1010
- $test_in_http_content_types = []
1011
- $test_in_http_content_types_flag = false
1012
- module ContentTypeHook
1013
- def initialize(*args)
1014
- @io_handler = nil
1015
- super
1016
- end
1017
- def on_headers_complete(headers)
1018
- super
1019
- if $test_in_http_content_types_flag
1020
- $test_in_http_content_types << self.content_type
1021
- end
1022
- end
1023
-
1024
- def on_message_begin
1025
- super
1026
- if $test_in_http_content_types_flag
1027
- $test_in_http_connection_object_ids << @io_handler.object_id
1028
- end
1029
- end
1030
- end
1031
-
1032
- class Fluent::Plugin::HttpInput::Handler
1033
- prepend ContentTypeHook
1034
- end
1035
-
1036
- def test_if_content_type_is_initialized_properly
1037
- # This test is to check if Fluent::HttpInput::Handler's @content_type is initialized properly.
1038
- # Especially when in Keep-Alive and the second request has no 'Content-Type'.
1039
-
1040
- begin
1041
- d = create_driver
1042
-
1043
- $test_in_http_content_types_flag = true
1044
- d.run do
1045
- # Send two requests the second one has no Content-Type in Keep-Alive
1046
- Net::HTTP.start("127.0.0.1", @port) do |http|
1047
- req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
1048
- http.request(req)
1049
- req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
1050
- http.request(req)
1051
- end
1052
-
1053
- end
1054
- ensure
1055
- $test_in_http_content_types_flag = false
1056
- end
1057
- assert_equal(['application/json', ''], $test_in_http_content_types)
1058
- # Asserting keepalive
1059
- assert_equal $test_in_http_connection_object_ids[0], $test_in_http_connection_object_ids[1]
1060
- end
1061
-
1062
- def get(path, params, header = {})
1063
- http = Net::HTTP.new("127.0.0.1", @port)
1064
- req = Net::HTTP::Get.new(path, header)
1065
- http.request(req)
1066
- end
1067
-
1068
- def options(path, params, header = {})
1069
- http = Net::HTTP.new("127.0.0.1", @port)
1070
- req = Net::HTTP::Options.new(path, header)
1071
- http.request(req)
1072
- end
1073
-
1074
- def post(path, params, header = {}, &block)
1075
- http = Net::HTTP.new("127.0.0.1", @port)
1076
- req = Net::HTTP::Post.new(path, header)
1077
- block.call(http, req) if block
1078
- if params.is_a?(String)
1079
- unless header.has_key?('Content-Type')
1080
- header['Content-Type'] = 'application/octet-stream'
1081
- end
1082
- req.body = params
1083
- else
1084
- unless header.has_key?('Content-Type')
1085
- header['Content-Type'] = 'application/x-www-form-urlencoded'
1086
- end
1087
- req.set_form_data(params)
1088
- end
1089
- http.request(req)
1090
- end
1091
-
1092
- def compress_gzip(data)
1093
- io = StringIO.new
1094
- io.binmode
1095
- Zlib::GzipWriter.wrap(io) { |gz| gz.write data }
1096
- return io.string
1097
- end
1098
-
1099
- def include_http_header?(record)
1100
- record.keys.find { |header| header.start_with?('HTTP_') }
1101
- end
1102
- end