fluent-plugin-devo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,49 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016 t.e.morgan.
3
+ # Copyright 2021 Devo .Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'helper'
18
+ require 'date'
19
+ require 'syslog_tls/logger'
20
+
21
+ class LoggerTest < Test::Unit::TestCase
22
+ def test_logger_defaults
23
+ io = StringIO.new
24
+ l = SyslogTls::Logger.new(io, "TOKEN")
25
+ time = Time.now
26
+ l.log(:WARN, "MESSAGE", time: time)
27
+ assert_equal "<132>#{time.to_datetime.strftime("%b %d %H:%M:%S")} MESSAGE\n", io.string
28
+ end
29
+
30
+ def test_logger_default_headers
31
+ io = StringIO.new
32
+ l = SyslogTls::Logger.new(io, "TOKEN")
33
+ l.hostname("hostname")
34
+ l.app_name("appname")
35
+ l.procid($$)
36
+ l.facility("SYSLOG")
37
+ time = Time.now
38
+ l.log(:WARN, "MESSAGE", time: time)
39
+ assert_equal "<44>#{time.to_datetime.strftime("%b %d %H:%M:%S")} hostname appname MESSAGE\n", io.string
40
+ end
41
+
42
+ def test_logger_closed
43
+ io = StringIO.new
44
+ l = SyslogTls::Logger.new(io, "TOKEN")
45
+ assert_false l.closed?
46
+ l.close
47
+ assert_true l.closed?
48
+ end
49
+ end
@@ -0,0 +1,151 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016 t.e.morgan.
3
+ # Copyright 2021 Devo .Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'helper'
18
+ require 'date'
19
+ require 'syslog_tls/protocol'
20
+
21
+ class ProtocolTest < Test::Unit::TestCase
22
+ def test_header_defaults
23
+ h = SyslogTls::Header.new
24
+
25
+ # Check defaults
26
+ assert_equal 'INFO', h.severity
27
+ assert_equal 'LOCAL0', h.facility
28
+ assert_equal 1, h.version
29
+ assert_equal SyslogTls::NIL_VALUE, h.hostname
30
+ assert_equal SyslogTls::NIL_VALUE, h.app_name
31
+ assert_equal SyslogTls::NIL_VALUE, h.procid
32
+ assert_equal SyslogTls::NIL_VALUE, h.msgid
33
+
34
+ assert_equal "<#{h.pri}>#{h.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} ", h.to_s
35
+ end
36
+
37
+ def test_header_facility_setter
38
+ h = SyslogTls::Header.new
39
+ assert_raise do
40
+ h.facility = "NON_EXISTING"
41
+ end
42
+ SyslogTls::Header::FACILITIES.each do |facility, _|
43
+ assert_nothing_raised do
44
+ h.facility = facility
45
+ end
46
+ end
47
+ end
48
+
49
+ def test_header_severity_setter
50
+ h = SyslogTls::Header.new
51
+ assert_raise do
52
+ h.severity = "NON_EXISTING"
53
+ end
54
+ SyslogTls::Header::SEVERITIES.each do |severity, _|
55
+ assert_nothing_raised do
56
+ h.severity = severity
57
+ end
58
+ end
59
+ end
60
+
61
+ def test_header_timestamp_setter
62
+ h = SyslogTls::Header.new
63
+ assert_raise do
64
+ h.timestamp = Time.now.to_i
65
+ end
66
+ assert_nothing_raised do
67
+ h.timestamp = Time.now
68
+ end
69
+ end
70
+
71
+ def test_header_hostname
72
+ h = SyslogTls::Header.new
73
+ h.hostname = "hostname"
74
+ assert_equal "<#{h.pri}>#{h.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} hostname ", h.to_s
75
+ end
76
+
77
+ def test_header_appname
78
+ h = SyslogTls::Header.new
79
+ h.app_name = "appname"
80
+ assert_equal "<#{h.pri}>#{h.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} appname", h.to_s
81
+ end
82
+
83
+ def test_header_procid
84
+ h = SyslogTls::Header.new
85
+ h.procid = $$
86
+ assert_equal "<#{h.pri}>#{h.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} ", h.to_s
87
+ end
88
+
89
+ def test_header_msgid
90
+ h = SyslogTls::Header.new
91
+ h.msgid = "msgid"
92
+ assert_equal "<#{h.pri}>#{h.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} ", h.to_s
93
+ end
94
+
95
+ def test_structured_data_defaults
96
+ id = "hash@IANA-ID"
97
+ sd = SyslogTls::StructuredData.new(id)
98
+ assert_equal "[#{id}]", sd.to_s
99
+ end
100
+
101
+ def test_structured_data_key
102
+ id = "hash@IANA-ID"
103
+ sd = SyslogTls::StructuredData.new(id)
104
+ sd.data["key"] = "val"
105
+ assert_equal "[#{id} key=\"val\"]", sd.to_s
106
+ end
107
+
108
+ def test_structured_data_escaping
109
+ id = "hash@IANA-ID"
110
+ sd = SyslogTls::StructuredData.new(id)
111
+ sd.data["key"] = '\]"'
112
+ assert_equal "[#{id} key=\"\\\\\\]\\\"\"]", sd.to_s
113
+ end
114
+
115
+ def test_messsage_defaults
116
+ m = SyslogTls::Message.new
117
+ assert_not_nil m.header
118
+ assert_true m.structured_data.is_a? Array
119
+ assert_equal 0, m.structured_data.length
120
+ assert_equal "", m.msg
121
+
122
+ assert_equal "<134>#{m.header.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} \n", m.to_s
123
+ end
124
+
125
+ def test_message_msg
126
+ m = SyslogTls::Message.new
127
+ m.msg = "TEST"
128
+ assert_equal "<134>#{m.header.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} TEST\n", m.to_s
129
+ end
130
+
131
+ def test_message_sd
132
+ m = SyslogTls::Message.new
133
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID")
134
+ assert_equal "<134>#{m.header.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} \n", m.to_s
135
+ end
136
+
137
+ def test_message_multiple_sd
138
+ m = SyslogTls::Message.new
139
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID")
140
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID2")
141
+ assert_equal "<134>#{m.header.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} \n", m.to_s
142
+ end
143
+
144
+ def test_message_multiple_sd_msg
145
+ m = SyslogTls::Message.new
146
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID")
147
+ m.structured_data << SyslogTls::StructuredData.new("TEST_ID2")
148
+ m.msg = "MSG"
149
+ assert_equal "<134>#{m.header.timestamp.to_datetime.strftime("%b %d %H:%M:%S")} MSG\n", m.to_s
150
+ end
151
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016 t.e.morgan.
3
+ # Copyright 2021 Devo .Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'helper'
18
+ require 'ssl'
19
+ require 'syslog_tls/ssl_transport'
20
+
21
+ class SSLTransportTest < Test::Unit::TestCase
22
+ include SSLTestHelper
23
+
24
+ def test_ok_connection
25
+ server = ssl_server
26
+ st = Thread.new {
27
+ client = server.accept
28
+ assert_equal "TESTTEST2\n", client.gets
29
+ client.close
30
+ }
31
+ SyslogTls::SSLTransport.stub_any_instance(:get_ssl_connection, ssl_client) do
32
+ t = SyslogTls::SSLTransport.new("localhost", server.addr[1], max_retries: 3)
33
+ t.write("TEST")
34
+ t.write("TEST2\n")
35
+ end
36
+ st.join
37
+ end
38
+
39
+ def test_retry
40
+ client = Object.new
41
+ def client.connect_nonblock
42
+ true
43
+ end
44
+ def client.write_nonblock(s)
45
+ raise "Test"
46
+ end
47
+
48
+ SyslogTls::SSLTransport.stub_any_instance(:get_ssl_connection, client) do
49
+ assert_raises RuntimeError do
50
+ t = SyslogTls::SSLTransport.new("localhost", 33000, max_retries: 3)
51
+ t.write("TEST\n")
52
+ end
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-devo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Devo Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-14 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.14.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.14.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: minitest
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.8'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.8'
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest-stub_any_instance
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.1'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.1'
89
+ - !ruby/object:Gem::Dependency
90
+ name: webmock
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: simplecov
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.11'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.11'
117
+ description: Syslog TLS output plugin with formatting support, for Fluentd
118
+ email:
119
+ - support@devo.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - CHANGELOG.md
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE
128
+ - README.md
129
+ - Rakefile
130
+ - lib/fluent/plugin/out_devo.rb
131
+ - lib/syslog_tls/facility.rb
132
+ - lib/syslog_tls/logger.rb
133
+ - lib/syslog_tls/lookup_from_const.rb
134
+ - lib/syslog_tls/protocol.rb
135
+ - lib/syslog_tls/severity.rb
136
+ - lib/syslog_tls/ssl_transport.rb
137
+ - lib/syslog_tls/version.rb
138
+ - test/fluent/test_out_devo.rb
139
+ - test/helper.rb
140
+ - test/ssl.rb
141
+ - test/syslog_tls/test_logger.rb
142
+ - test/syslog_tls/test_protocol.rb
143
+ - test/syslog_tls/test_ssl_transport.rb
144
+ homepage: https://github.com/DevoInc/fluent-plugin-devo
145
+ licenses:
146
+ - Apache v2
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '2.4'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubygems_version: 3.1.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Fluent Syslog TLS output plugin for Devo
167
+ test_files:
168
+ - test/fluent/test_out_devo.rb
169
+ - test/helper.rb
170
+ - test/ssl.rb
171
+ - test/syslog_tls/test_logger.rb
172
+ - test/syslog_tls/test_protocol.rb
173
+ - test/syslog_tls/test_ssl_transport.rb