fluent-plugin-syslog-tls-long-timeout 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'coveralls'
16
+ require 'simplecov'
17
+
18
+ SimpleCov.start
19
+
20
+ Coveralls.wear! if ENV['TRAVIS']
21
+
22
+ # Fluentd sets default encoding to ASCII-8BIT, but coverall can load git data which can contain UTF-8 characters
23
+ at_exit do
24
+ Encoding.default_internal = 'UTF-8' if defined?(Encoding) && Encoding.respond_to?(:default_internal)
25
+ Encoding.default_external = 'UTF-8' if defined?(Encoding) && Encoding.respond_to?(:default_external)
26
+ end
27
+
28
+ require 'test/unit'
29
+ require 'fluent/test'
30
+ require 'minitest/pride'
31
+ require 'minitest/stub_any_instance'
32
+
33
+ require 'webmock/test_unit'
34
+ WebMock.disable_net_connect!
data/test/ssl.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'socket'
2
+ require 'openssl'
3
+
4
+ module SSLTestHelper
5
+ def ssl_server
6
+ @ssl_server ||= begin
7
+ tcp_server = TCPServer.new("localhost", 33000 + Random.rand(1000))
8
+ ssl_context = OpenSSL::SSL::SSLContext.new
9
+ ssl_context.cert = certificate
10
+ ssl_context.key = rsa_key
11
+ OpenSSL::SSL::SSLServer.new(tcp_server, ssl_context)
12
+ end
13
+ end
14
+
15
+ def ssl_client
16
+ tcp = TCPSocket.new("localhost", ssl_server.addr[1])
17
+ ctx = OpenSSL::SSL::SSLContext.new
18
+ ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_NONE)
19
+ ctx.cert = certificate
20
+ ctx.key = rsa_key
21
+ OpenSSL::SSL::SSLSocket.new(tcp, ctx)
22
+ end
23
+
24
+ def rsa_key
25
+ @rsa_key ||= OpenSSL::PKey::RSA.new(2048)
26
+ end
27
+
28
+ def certificate
29
+ @cert ||= begin
30
+ cert = OpenSSL::X509::Certificate.new
31
+ cert.subject = cert.issuer = OpenSSL::X509::Name.parse("/C=BE/O=Test/OU=Test/CN=Test")
32
+ cert.not_before = Time.now
33
+ cert.not_after = Time.now + 365 * 24 * 60 * 60
34
+ cert.public_key = rsa_key.public_key
35
+ cert.serial = 0x0
36
+ cert.version = 2
37
+
38
+ ef = OpenSSL::X509::ExtensionFactory.new
39
+ ef.subject_certificate = cert
40
+ ef.issuer_certificate = cert
41
+ cert.extensions = [
42
+ ef.create_extension("basicConstraints","CA:TRUE", true),
43
+ ef.create_extension("subjectKeyIdentifier", "hash"),
44
+ # ef.create_extension("keyUsage", "cRLSign,keyCertSign", true),
45
+ ]
46
+ cert.add_extension ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
47
+ cert.sign(rsa_key, OpenSSL::Digest::SHA1.new)
48
+ cert
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016 t.e.morgan.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'helper'
17
+ require 'date'
18
+ require 'syslog_tls/logger'
19
+
20
+ class LoggerTest < Test::Unit::TestCase
21
+ def test_logger_defaults
22
+ io = StringIO.new
23
+ l = SyslogTls::Logger.new(io, "TOKEN")
24
+ time = Time.now
25
+ l.log(:WARN, "MESSAGE", time: time)
26
+ assert_equal "<132>1 #{time.to_datetime.rfc3339} - - - - [TOKEN] MESSAGE\n", io.string
27
+ end
28
+
29
+ def test_logger_default_headers
30
+ io = StringIO.new
31
+ l = SyslogTls::Logger.new(io, "TOKEN")
32
+ l.hostname("hostname")
33
+ l.app_name("appname")
34
+ l.procid($$)
35
+ l.facility("SYSLOG")
36
+ time = Time.now
37
+ l.log(:WARN, "MESSAGE", time: time)
38
+ assert_equal "<44>1 #{time.to_datetime.rfc3339} hostname appname #{$$} - [TOKEN] MESSAGE\n", io.string
39
+ end
40
+
41
+ def test_logger_closed
42
+ io = StringIO.new
43
+ l = SyslogTls::Logger.new(io, "TOKEN")
44
+ assert_false l.closed?
45
+ l.close
46
+ assert_true l.closed?
47
+ end
48
+ end
@@ -0,0 +1,150 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016 t.e.morgan.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'helper'
17
+ require 'date'
18
+ require 'syslog_tls/protocol'
19
+
20
+ class ProtocolTest < Test::Unit::TestCase
21
+ def test_header_defaults
22
+ h = SyslogTls::Header.new
23
+
24
+ # Check defaults
25
+ assert_equal 'INFO', h.severity
26
+ assert_equal 'LOCAL0', h.facility
27
+ assert_equal 1, h.version
28
+ assert_equal SyslogTls::NIL_VALUE, h.hostname
29
+ assert_equal SyslogTls::NIL_VALUE, h.app_name
30
+ assert_equal SyslogTls::NIL_VALUE, h.procid
31
+ assert_equal SyslogTls::NIL_VALUE, h.msgid
32
+
33
+ assert_equal "<#{h.pri}>1 #{h.timestamp.to_datetime.rfc3339} - - - -", h.to_s
34
+ end
35
+
36
+ def test_header_facility_setter
37
+ h = SyslogTls::Header.new
38
+ assert_raise do
39
+ h.facility = "NON_EXISTING"
40
+ end
41
+ SyslogTls::Header::FACILITIES.each do |facility, _|
42
+ assert_nothing_raised do
43
+ h.facility = facility
44
+ end
45
+ end
46
+ end
47
+
48
+ def test_header_severity_setter
49
+ h = SyslogTls::Header.new
50
+ assert_raise do
51
+ h.severity = "NON_EXISTING"
52
+ end
53
+ SyslogTls::Header::SEVERITIES.each do |severity, _|
54
+ assert_nothing_raised do
55
+ h.severity = severity
56
+ end
57
+ end
58
+ end
59
+
60
+ def test_header_timestamp_setter
61
+ h = SyslogTls::Header.new
62
+ assert_raise do
63
+ h.timestamp = Time.now.to_i
64
+ end
65
+ assert_nothing_raised do
66
+ h.timestamp = Time.now
67
+ end
68
+ end
69
+
70
+ def test_header_hostname
71
+ h = SyslogTls::Header.new
72
+ h.hostname = "hostname"
73
+ assert_equal "<#{h.pri}>1 #{h.timestamp.to_datetime.rfc3339} hostname - - -", h.to_s
74
+ end
75
+
76
+ def test_header_appname
77
+ h = SyslogTls::Header.new
78
+ h.app_name = "appname"
79
+ assert_equal "<#{h.pri}>1 #{h.timestamp.to_datetime.rfc3339} - appname - -", h.to_s
80
+ end
81
+
82
+ def test_header_procid
83
+ h = SyslogTls::Header.new
84
+ h.procid = $$
85
+ assert_equal "<#{h.pri}>1 #{h.timestamp.to_datetime.rfc3339} - - #{$$} -", h.to_s
86
+ end
87
+
88
+ def test_header_msgid
89
+ h = SyslogTls::Header.new
90
+ h.msgid = "msgid"
91
+ assert_equal "<#{h.pri}>1 #{h.timestamp.to_datetime.rfc3339} - - - msgid", h.to_s
92
+ end
93
+
94
+ def test_structured_data_defaults
95
+ id = "hash@IANA-ID"
96
+ sd = SyslogTls::StructuredData.new(id)
97
+ assert_equal "[#{id}]", sd.to_s
98
+ end
99
+
100
+ def test_structured_data_key
101
+ id = "hash@IANA-ID"
102
+ sd = SyslogTls::StructuredData.new(id)
103
+ sd.data["key"] = "val"
104
+ assert_equal "[#{id} key=\"val\"]", sd.to_s
105
+ end
106
+
107
+ def test_structured_data_escaping
108
+ id = "hash@IANA-ID"
109
+ sd = SyslogTls::StructuredData.new(id)
110
+ sd.data["key"] = '\]"'
111
+ assert_equal "[#{id} key=\"\\\\\\]\\\"\"]", sd.to_s
112
+ end
113
+
114
+ def test_messsage_defaults
115
+ m = SyslogTls::Message.new
116
+ assert_not_nil m.header
117
+ assert_true m.structured_data.is_a? Array
118
+ assert_equal 0, m.structured_data.length
119
+ assert_equal "", m.msg
120
+
121
+ assert_equal "<134>1 #{m.header.timestamp.to_datetime.rfc3339} - - - - -\n", m.to_s
122
+ end
123
+
124
+ def test_message_msg
125
+ m = SyslogTls::Message.new
126
+ m.msg = "TEST"
127
+ assert_equal "<134>1 #{m.header.timestamp.to_datetime.rfc3339} - - - - - TEST\n", m.to_s
128
+ end
129
+
130
+ def test_message_sd
131
+ m = SyslogTls::Message.new
132
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID")
133
+ assert_equal "<134>1 #{m.header.timestamp.to_datetime.rfc3339} - - - - [TEST_ID]\n", m.to_s
134
+ end
135
+
136
+ def test_message_multiple_sd
137
+ m = SyslogTls::Message.new
138
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID")
139
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID2")
140
+ assert_equal "<134>1 #{m.header.timestamp.to_datetime.rfc3339} - - - - [TEST_ID][TEST_ID2]\n", m.to_s
141
+ end
142
+
143
+ def test_message_multiple_sd_msg
144
+ m = SyslogTls::Message.new
145
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID")
146
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID2")
147
+ m.msg = "MSG"
148
+ assert_equal "<134>1 #{m.header.timestamp.to_datetime.rfc3339} - - - - [TEST_ID][TEST_ID2] MSG\n", m.to_s
149
+ end
150
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016 t.e.morgan.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'helper'
17
+ require 'ssl'
18
+ require 'syslog_tls/ssl_transport'
19
+
20
+ class SSLTransportTest < Test::Unit::TestCase
21
+ include SSLTestHelper
22
+
23
+ def test_ok_connection
24
+ server = ssl_server
25
+ st = Thread.new {
26
+ client = server.accept
27
+ assert_equal "TESTTEST2\n", client.gets
28
+ client.close
29
+ }
30
+ SyslogTls::SSLTransport.stub_any_instance(:get_ssl_connection, ssl_client) do
31
+ t = SyslogTls::SSLTransport.new("localhost", server.addr[1], max_retries: 3)
32
+ t.write("TEST")
33
+ t.write("TEST2\n")
34
+ end
35
+ st.join
36
+ end
37
+
38
+ def test_retry
39
+ client = Object.new
40
+ def client.connect
41
+ true
42
+ end
43
+ def client.write(s)
44
+ raise "Test"
45
+ end
46
+
47
+ SyslogTls::SSLTransport.stub_any_instance(:get_ssl_connection, client) do
48
+ assert_raises RuntimeError do
49
+ t = SyslogTls::SSLTransport.new("localhost", 33000, max_retries: 3)
50
+ t.write("TEST\n")
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-syslog-tls-long-timeout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - thomas morgan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: fluent-mixin-config-placeholders
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-stub_any_instance
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.11'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.11'
125
+ description: Syslog TLS output plugin with formatting support, for Fluentd
126
+ email:
127
+ - tm@iprog.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - CHANGELOG.md
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - docs/configuration.md
142
+ - fluent-plugin-syslog-tls.gemspec
143
+ - lib/fluent/plugin/out_syslog_tls.rb
144
+ - lib/syslog_tls/facility.rb
145
+ - lib/syslog_tls/logger.rb
146
+ - lib/syslog_tls/lookup_from_const.rb
147
+ - lib/syslog_tls/protocol.rb
148
+ - lib/syslog_tls/severity.rb
149
+ - lib/syslog_tls/ssl_transport.rb
150
+ - lib/syslog_tls/version.rb
151
+ - test/fluent/test_out_syslog_tls.rb
152
+ - test/helper.rb
153
+ - test/ssl.rb
154
+ - test/syslog_tls/test_logger.rb
155
+ - test/syslog_tls/test_protocol.rb
156
+ - test/syslog_tls/test_ssl_transport.rb
157
+ homepage: https://github.com/zarqman/fluent-plugin-syslog-tls
158
+ licenses:
159
+ - Apache v2
160
+ metadata: {}
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: 2.0.0
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 2.5.2.3
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: Fluent Syslog TLS output plugin
181
+ test_files:
182
+ - test/fluent/test_out_syslog_tls.rb
183
+ - test/helper.rb
184
+ - test/ssl.rb
185
+ - test/syslog_tls/test_logger.rb
186
+ - test/syslog_tls/test_protocol.rb
187
+ - test/syslog_tls/test_ssl_transport.rb