fluent-plugin-syslog-tls-with-backoff-test 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,71 @@
1
+ # Copyright 2016 Acquia, Inc.
2
+ # Copyright 2016-2023 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
+ # srvr-min srvr-max clnt-min should-raise?
24
+ [ [:TLS1_2, :TLS1_2, :TLS1_2],
25
+ [:TLS1_2, :TLS1_3, :TLS1_2],
26
+ [:TLS1_3, :TLS1_3, :TLS1_2],
27
+ [:TLS1_2, :TLS1_2, :TLS1_3, true],
28
+ [:TLS1_2, :TLS1_3, :TLS1_3],
29
+ [:TLS1_3, :TLS1_3, :TLS1_3],
30
+ ].each do |(server_min, server_max, client_min, should_raise)|
31
+ define_method "test_#{server_min}-#{server_max}_server_#{client_min}_client" do
32
+ Thread.report_on_exception = false
33
+ blk = lambda do
34
+ server = ssl_server(min_version: server_min, max_version: server_max)
35
+ st = Thread.new {
36
+ client = server.accept
37
+ assert_equal "TESTTEST2\n", client.gets
38
+ client.close
39
+ }
40
+ t = SyslogTls::SSLTransport.new("localhost", server.addr[1], ca_cert: false, ssl_version: client_min)
41
+ t.write("TEST")
42
+ t.write("TEST2\n")
43
+ st.join
44
+ end
45
+ if should_raise
46
+ assert_raises OpenSSL::SSL::SSLError, &blk
47
+ else
48
+ blk.call
49
+ end
50
+ ensure
51
+ Thread.report_on_exception = true
52
+ end
53
+ end
54
+
55
+ def test_retry
56
+ client = Object.new
57
+ def client.connect_nonblock
58
+ true
59
+ end
60
+ def client.write_nonblock(s)
61
+ raise "Test"
62
+ end
63
+
64
+ SyslogTls::SSLTransport.stub_any_instance(:get_ssl_connection, client) do
65
+ assert_raises RuntimeError do
66
+ t = SyslogTls::SSLTransport.new("localhost", 33000, max_retries: 3)
67
+ t.write("TEST\n")
68
+ end
69
+ end
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-syslog-tls-with-backoff-test
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - thomas morgan
8
+ - muhammad adil ghaffar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.14.0
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '2'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: 0.14.0
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ - !ruby/object:Gem::Dependency
35
+ name: minitest
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.8'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ - !ruby/object:Gem::Dependency
49
+ name: minitest-stub_any_instance
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: test-unit
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.1'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ - !ruby/object:Gem::Dependency
91
+ name: webmock
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ - !ruby/object:Gem::Dependency
105
+ name: simplecov
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.11'
118
+ description: Syslog TLS output plugin with formatting support, for Fluentd. This is
119
+ cutom version backoff.
120
+ email:
121
+ - tm@iprog.com
122
+ - muhammad.sdil.ghaffar@est.tech
123
+ executables: []
124
+ extensions: []
125
+ extra_rdoc_files: []
126
+ files:
127
+ - ".coveralls.yml"
128
+ - ".gitignore"
129
+ - ".travis.yml"
130
+ - CHANGELOG.md
131
+ - Gemfile
132
+ - Gemfile.lock
133
+ - LICENSE
134
+ - README.md
135
+ - Rakefile
136
+ - docs/configuration.md
137
+ - fluent-plugin-syslog-tls.gemspec
138
+ - lib/fluent/plugin/out_syslog_tls.rb
139
+ - lib/syslog_tls/facility.rb
140
+ - lib/syslog_tls/host_backoff_specs.rb
141
+ - lib/syslog_tls/logger.rb
142
+ - lib/syslog_tls/lookup_from_const.rb
143
+ - lib/syslog_tls/protocol.rb
144
+ - lib/syslog_tls/severity.rb
145
+ - lib/syslog_tls/ssl_transport.rb
146
+ - lib/syslog_tls/version.rb
147
+ - test/fluent/test_out_syslog_tls.rb
148
+ - test/helper.rb
149
+ - test/ssl.rb
150
+ - test/syslog_tls/test_logger.rb
151
+ - test/syslog_tls/test_protocol.rb
152
+ - test/syslog_tls/test_ssl_transport.rb
153
+ homepage: https://github.com/Nordix/fluent-plugin-syslog-tls/tree/add-expo-backoff/adil
154
+ licenses:
155
+ - Apache v2
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '2.5'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubygems_version: 3.1.2
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Fluent Syslog TLS output plugin
176
+ test_files:
177
+ - test/fluent/test_out_syslog_tls.rb
178
+ - test/helper.rb
179
+ - test/ssl.rb
180
+ - test/syslog_tls/test_logger.rb
181
+ - test/syslog_tls/test_protocol.rb
182
+ - test/syslog_tls/test_ssl_transport.rb