fluent-plugin-sumologic-cloud-syslog 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2aea561a27d8d9487e788c66ea0663be108d8e1b
4
- data.tar.gz: 7dbdccd19c99e6ba0d819f05e516b6b15c5a08e8
3
+ metadata.gz: cc1578a36f862ac01507d453ca8350c60372efd6
4
+ data.tar.gz: 5b70bff66226ac8825fbd755905933a3cfca92ff
5
5
  SHA512:
6
- metadata.gz: 1319e8199d055e436df2945b99f08167cb193eb53cac0fd8a5e7a64764276bad8bb90828035f2b3092794c6dfc9c29862c06ec0d81db6495720b0843c2aa15da
7
- data.tar.gz: b24bd65e7710d54a4a504be9a0dd674121ad10ce91d5ce052811814a0f1252d6319f8fa9823f9fe5153a5dd1753534bda404a3de2bf6482ab9e5d83600e214e8
6
+ metadata.gz: 2bf21eb35786fcf3c0ee842afdcc5f62ae8ac668f530f7e44a9c633cb4d6a27af7ead09473cf3ae647a6545a2bfd0b4c327e33b56418fe4d1e9bab54027c5b2f
7
+ data.tar.gz: 61f2320b80887d030696e36f7931519550a32777bfb6414a8f5bb94322f816f26e7055ebe8db63aef81b24ec2f7db1aa99c15c5a66fb64e27fe37231f21f3025
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  s.add_runtime_dependency 'fluent-mixin-plaintextformatter', '~> 0.2'
37
37
 
38
38
  s.add_development_dependency 'minitest', '~> 5.8'
39
+ s.add_development_dependency 'minitest-stub_any_instance', '~> 1.0.0'
39
40
  s.add_development_dependency 'rake', '~> 10.5'
40
41
  s.add_development_dependency 'test-unit', '~> 3.1'
41
42
  s.add_development_dependency 'webmock', '~> 2.0'
@@ -35,6 +35,11 @@ module SumologicCloudSyslog
35
35
  end
36
36
 
37
37
  def connect
38
+ @socket = get_ssl_connection
39
+ @socket.connect
40
+ end
41
+
42
+ def get_ssl_connection
38
43
  tcp = TCPSocket.new(host, port)
39
44
 
40
45
  ctx = OpenSSL::SSL::SSLContext.new
@@ -43,9 +48,7 @@ module SumologicCloudSyslog
43
48
 
44
49
  ctx.cert = OpenSSL::X509::Certificate.new(File.open(cert)) if cert
45
50
  ctx.key = OpenSSL::PKey::RSA.new(File.open(key)) if key
46
-
47
- @socket = OpenSSL::SSL::SSLSocket.new(tcp, ctx)
48
- @socket.connect
51
+ OpenSSL::SSL::SSLSocket.new(tcp, ctx)
49
52
  end
50
53
 
51
54
  # Allow to retry on failed writes
@@ -54,7 +57,7 @@ module SumologicCloudSyslog
54
57
  retry_id ||= 0
55
58
  @socket.send(:write, s)
56
59
  rescue => e
57
- if (retry_id += 1) < retries
60
+ if (retry_id += 1) < @retries
58
61
  connect
59
62
  retry
60
63
  else
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module SumologicCloudSyslog
16
- VERSION = '0.1.4'
16
+ VERSION = '0.1.5'
17
17
  end
@@ -13,11 +13,12 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require 'helper'
16
+ require 'ssl'
16
17
  require 'date'
17
18
  require 'minitest/mock'
18
19
  require 'fluent/plugin/out_sumologic_cloud_syslog'
19
20
 
20
- class SumologicCloudSyslogOutput < Test::Unit::TestCase
21
+ class SumologicCloudSyslogOutput < SSLTest
21
22
  def setup
22
23
  Fluent::Test.setup
23
24
  @driver = nil
@@ -135,4 +136,39 @@ class SumologicCloudSyslogOutput < Test::Unit::TestCase
135
136
 
136
137
  assert_true logger.transport.string.start_with?("<128>1")
137
138
  end
139
+
140
+ def test_ssl
141
+ time = Time.now
142
+ record = sample_record
143
+ formatted_time = time.dup.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
144
+
145
+ server = ssl_server
146
+ st = Thread.new {
147
+ client = server.accept
148
+ assert_equal client.gets, "<134>1 #{time.to_datetime.rfc3339} host app #{$$} 1000 [1234567890] #{formatted_time}\ttest\t#{record.to_json.to_s}\n"
149
+ client.close
150
+ }
151
+
152
+ config = %{
153
+ host localhost
154
+ port #{server.addr[1]}
155
+ cert
156
+ key
157
+ token 1234567890
158
+ hostname_key hostname
159
+ procid_key procid
160
+ app_name_key app_name
161
+ msgid_key msgid
162
+ }
163
+ instance = driver('test', config).instance
164
+
165
+ chain = Minitest::Mock.new
166
+ chain.expect(:next, nil)
167
+
168
+ SumologicCloudSyslog::SSLTransport.stub_any_instance(:get_ssl_connection, ssl_client) do
169
+ instance.emit('test', {time.to_i => record}, chain)
170
+ end
171
+
172
+ st.join
173
+ end
138
174
  end
@@ -28,6 +28,7 @@ end
28
28
  require 'test/unit'
29
29
  require 'fluent/test'
30
30
  require 'minitest/pride'
31
+ require 'minitest/stub_any_instance'
31
32
 
32
33
  require 'webmock/test_unit'
33
34
  WebMock.disable_net_connect!
@@ -0,0 +1,53 @@
1
+ require 'socket'
2
+ require 'openssl'
3
+
4
+ class SSLTest < Test::Unit::TestCase
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
+ subject = "/C=BE/O=Test/OU=Test/CN=Test"
31
+
32
+ @cert = OpenSSL::X509::Certificate.new
33
+ @cert.subject = @cert.issuer = OpenSSL::X509::Name.parse(subject)
34
+ @cert.not_before = Time.now
35
+ @cert.not_after = Time.now + 365 * 24 * 60 * 60
36
+ @cert.public_key = rsa_key.public_key
37
+ @cert.serial = 0x0
38
+ @cert.version = 2
39
+
40
+ ef = OpenSSL::X509::ExtensionFactory.new
41
+ ef.subject_certificate = @cert
42
+ ef.issuer_certificate = @cert
43
+ @cert.extensions = [
44
+ ef.create_extension("basicConstraints","CA:TRUE", true),
45
+ ef.create_extension("subjectKeyIdentifier", "hash"),
46
+ # ef.create_extension("keyUsage", "cRLSign,keyCertSign", true),
47
+ ]
48
+ @cert.add_extension ef.create_extension("authorityKeyIdentifier", "keyid:always,issuer:always")
49
+ @cert.sign(rsa_key, OpenSSL::Digest::SHA1.new)
50
+ @cert
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,52 @@
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 'helper'
16
+ require 'ssl'
17
+ require 'sumologic_cloud_syslog/ssl_transport'
18
+
19
+ class SSLTransport < SSLTest
20
+ def test_ok_connection
21
+ server = ssl_server
22
+ st = Thread.new {
23
+ client = server.accept
24
+ assert_equal client.gets, "TESTTEST2\n"
25
+ client.close
26
+ }
27
+ SumologicCloudSyslog::SSLTransport.stub_any_instance(:get_ssl_connection, ssl_client) do
28
+ t = SumologicCloudSyslog::SSLTransport.new("localhost", server.addr[1], max_retries: 3)
29
+ t.write("TEST")
30
+ t.write("TEST2\n")
31
+ end
32
+ st.join
33
+ end
34
+
35
+ def test_retry
36
+ client = Object.new
37
+ client.class.module_eval { attr_accessor :retries }
38
+ def client.connect
39
+ true
40
+ end
41
+ def client.write(s)
42
+ raise "Test"
43
+ end
44
+
45
+ SumologicCloudSyslog::SSLTransport.stub_any_instance(:get_ssl_connection, client) do
46
+ assert_raises RuntimeError do
47
+ t = SumologicCloudSyslog::SSLTransport.new("localhost", 33000, max_retries: 3)
48
+ t.write("TEST\n")
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-sumologic-cloud-syslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Acquia Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-13 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-stub_any_instance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -149,8 +163,10 @@ files:
149
163
  - lib/sumologic_cloud_syslog/version.rb
150
164
  - test/fluent/test_out_sumologic_cloud_syslog.rb
151
165
  - test/helper.rb
166
+ - test/ssl.rb
152
167
  - test/sumologic_cloud_syslog/test_logger.rb
153
168
  - test/sumologic_cloud_syslog/test_protocol.rb
169
+ - test/sumologic_cloud_syslog/test_ssl_transport.rb
154
170
  homepage: https://github.com/acquia/fluent-plugin-sumologic-cloud-syslog
155
171
  licenses:
156
172
  - Apache v2
@@ -178,6 +194,7 @@ summary: Fluent Sumologic Cloud Syslog plugin
178
194
  test_files:
179
195
  - test/fluent/test_out_sumologic_cloud_syslog.rb
180
196
  - test/helper.rb
197
+ - test/ssl.rb
181
198
  - test/sumologic_cloud_syslog/test_logger.rb
182
199
  - test/sumologic_cloud_syslog/test_protocol.rb
183
- has_rdoc:
200
+ - test/sumologic_cloud_syslog/test_ssl_transport.rb