r7insight 2.7.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/r7insight.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+
5
+ lib = File.expand_path('lib', __dir__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require 'r7_insight'
8
+
9
+ Gem::Specification.new do |gem|
10
+ gem.name = 'r7insight'
11
+ gem.version = '3.0.0'
12
+ gem.date = Time.now
13
+ gem.summary = 'Rapid7 Insight Platform logging plugin'
14
+ gem.licenses = ['MIT']
15
+ gem.description = <<DESC
16
+ Rapid7 Insight Platform Ruby library for logging
17
+ DESC
18
+
19
+ gem.authors = ['Rapid7']
20
+ gem.email = 'support@rapid7.com'
21
+ gem.homepage = 'https://github.com/rapid7/r7insight_ruby'
22
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
23
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
24
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
25
+ gem.require_paths = ['lib']
26
+
27
+ gem.add_development_dependency 'activesupport', '~> 6.0.0'
28
+ gem.add_development_dependency 'bundler', '~> 2.0.0'
29
+ gem.add_development_dependency 'minitest', '~> 5.12.2'
30
+ gem.add_development_dependency 'rake', '~> 13.0.0'
31
+ end
data/test/host_spec.rb CHANGED
@@ -1,23 +1,27 @@
1
- require 'spec_helper'
2
-
1
+ # frozen_string_literal: true
3
2
 
4
- describe Le::Host do
3
+ require 'spec_helper'
5
4
 
5
+ describe R7Insight::Host do
6
6
  let(:token) { '11111111-2222-3333-aaaa-bbbbbbbbbbbb' }
7
+ let(:region) { 'eu' }
7
8
  let(:local) { false }
8
9
  let(:debug) { false }
9
10
  let(:ssl) { true }
10
11
  let(:udp) { nil }
11
12
 
12
-
13
-
14
- let(:datahub_endpoint) { ["", 10000] }
15
- let(:host_id) { ""}
16
- let(:custom_host) { [false, ""]}
17
- let(:data_endpoint) {true}
18
-
19
- #let(:host) { Le::Host.new(token, local, debug, ssl) }
20
- let(:host) { Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp, data_endpoint) }
21
- specify { host.must_be_instance_of Le::Host::HTTP }
22
-
13
+ let(:datahub_endpoint) { ['', 10_000] }
14
+ let(:host_id) { '' }
15
+ let(:custom_host) { [false, ''] }
16
+ let(:use_data_endpoint) { true }
17
+
18
+ let(:host) do
19
+ R7Insight::Host::CONNECTION.new(token, region, local, debug, ssl, datahub_endpoint,
20
+ host_id, custom_host, udp, use_data_endpoint)
21
+ end
22
+ describe 'host' do
23
+ it 'is an instance of CONNECTION' do
24
+ assert_instance_of(R7Insight::Host::CONNECTION, host)
25
+ end
26
+ end
23
27
  end
data/test/http_spec.rb CHANGED
@@ -1,33 +1,52 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'pathname'
3
5
 
4
- describe Le::Host::HTTP do
5
-
6
+ describe R7Insight::Host::CONNECTION do
6
7
  let(:token) { '11111111-2222-3333-aaaa-bbbbbbbbbbbb' }
8
+ let(:region) { 'eu' }
7
9
  let(:local) { false }
8
10
  let(:debug) { false }
9
11
  let(:ssl) { false }
10
12
  let(:udp) { nil }
11
13
 
12
- let(:datahub_endpoint) { ["", 10000]}
13
- let(:host_id) {""}
14
- let(:custom_host) {[false, ""]}
15
- let(:endpoint) {false}
16
-
17
-
18
-
19
- # let(:host) { Le::Host::HTTP.new(token, local, debug, ssl) }
20
- let(:host) { Le::Host::HTTP.new(token, local, debug, ssl, datahub_endpoint, host_id, custom_host, udp, endpoint) }
21
-
22
- let(:logger_console) { host.instance_variable_get(:@logger_console) }
23
- let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
24
-
25
- specify { host.must_be_instance_of Le::Host::HTTP }
26
- specify { host.local.must_equal false }
27
- specify { host.debug.must_equal false }
28
- specify { host.ssl.must_equal false }
29
- specify { host.udp_port.must_equal nil }
30
- specify {host_id.must_equal ""}
31
- specify {custom_host.must_equal [false, ""]}
32
-
14
+ let(:datahub_endpoint) { ['', 10_000] }
15
+ let(:host_id) { '' }
16
+ let(:custom_host) { [false, ''] }
17
+ let(:endpoint) { false }
18
+
19
+ let(:host) do
20
+ R7Insight::Host::CONNECTION.new(token, region, local, debug, ssl, datahub_endpoint,
21
+ host_id, custom_host, udp, endpoint)
22
+ end
23
+
24
+ let(:logger_console) { host.instance_variable_get(:@logger_console) }
25
+
26
+ describe 'host' do
27
+ it 'is an instance of CONNECTION' do
28
+ assert_instance_of(R7Insight::Host::CONNECTION, host)
29
+ end
30
+ it 'region is expected value' do
31
+ assert_equal(host.region, 'eu')
32
+ end
33
+ it 'local is expected value' do
34
+ refute(host.local)
35
+ end
36
+ it 'debug is expected value' do
37
+ refute(host.debug)
38
+ end
39
+ it 'ssl is expected value' do
40
+ refute(host.ssl)
41
+ end
42
+ it 'udp port is expected value' do
43
+ assert_nil(host.udp_port)
44
+ end
45
+ it 'id is expected value' do
46
+ assert_equal(host_id, '')
47
+ end
48
+ it 'custom_host is expected value' do
49
+ assert_equal(custom_host, [false, ''])
50
+ end
51
+ end
33
52
  end
@@ -0,0 +1,312 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe R7Insight do
6
+ let(:token) { '11111111-2222-3333-aaaa-bbbbbbbbbbbb' }
7
+ let(:local) { false }
8
+ let(:region) { 'eu' }
9
+ let(:logger) { R7Insight.new(token, region, local: local) }
10
+ let(:logdev) { logger.instance_variable_get(:@logdev).dev }
11
+ let(:logger_console) { logdev.instance_variable_get(:@logger_console) }
12
+ let(:logger_console_dev) { logger_console.instance_variable_get(:@logdev).dev }
13
+
14
+ describe 'when non-Rails environment' do
15
+ describe 'is initialised with just a token' do
16
+ let(:logger) { R7Insight.new(token, region) }
17
+
18
+ describe 'logger' do
19
+ it 'should be a Logger instance' do
20
+ assert_instance_of(Logger, logger)
21
+ end
22
+ end
23
+
24
+ describe 'logger device' do
25
+ it 'is an instance of R7Insight::Host::CONNECTION' do
26
+ assert_instance_of(R7Insight::Host::CONNECTION, logdev)
27
+ end
28
+ it 'local is false' do
29
+ refute(logdev.local)
30
+ end
31
+ it 'ssl is true' do
32
+ assert(logdev.ssl)
33
+ end
34
+ end
35
+
36
+ describe 'logger console' do
37
+ it 'is nil' do
38
+ assert_nil(logger_console)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe 'is initialized with :ssl => true' do
44
+ let(:logger) { R7Insight.new(token, region, ssl: true) }
45
+
46
+ describe 'logger device' do
47
+ it 'ssl is true' do
48
+ assert(logdev.ssl)
49
+ end
50
+ end
51
+ end
52
+
53
+ describe 'is initialized with :ssl => false' do
54
+ let(:logger) { R7Insight.new(token, region, ssl: false) }
55
+
56
+ describe 'logger device' do
57
+ it 'ssl is false' do
58
+ refute(logdev.ssl)
59
+ end
60
+ end
61
+ end
62
+
63
+ it 'logger device local is false' do
64
+ refute(logdev.local)
65
+ end
66
+
67
+ it 'logger console is nil' do
68
+ assert_nil(logger_console)
69
+ end
70
+
71
+ describe 'local is set to true' do
72
+ let(:local) { true }
73
+
74
+ it 'logger device local is true' do
75
+ assert(logdev.local)
76
+ end
77
+
78
+ it 'logger console is instance of Logger' do
79
+ assert_instance_of(Logger, logger_console)
80
+ end
81
+
82
+ it 'logger console device instance of IO' do
83
+ assert_instance_of(IO, logger_console_dev)
84
+ end
85
+ end
86
+
87
+ describe 'and :local => ' do
88
+ let(:local_test_log) do
89
+ Pathname.new(File.dirname(__FILE__))
90
+ .join('fixtures', 'log', 'local_log.log')
91
+ end
92
+ let(:local) { log_file }
93
+
94
+ describe 'Pathname' do
95
+ let(:log_file) { local_test_log }
96
+
97
+ describe 'logger device' do
98
+ it 'is an instance of our CONNECTION' do
99
+ assert_instance_of(R7Insight::Host::CONNECTION, logdev)
100
+ end
101
+ it 'local is true' do
102
+ assert(logdev.local)
103
+ end
104
+ end
105
+
106
+ describe 'logger console' do
107
+ it 'is an instance of Logger' do
108
+ assert_instance_of(Logger, logger_console)
109
+ end
110
+ end
111
+
112
+ describe 'logger console device' do
113
+ it 'is an instance of File' do
114
+ assert_instance_of(File, logger_console_dev)
115
+ end
116
+ it 'path matches specified log file' do
117
+ assert_match('local_log.log', logger_console_dev.path)
118
+ end
119
+ end
120
+ end
121
+
122
+ describe 'path string' do
123
+ let(:log_file) { local_test_log.to_s }
124
+
125
+ describe 'logger device' do
126
+ it 'is an instance of CONNECTION' do
127
+ assert_instance_of(R7Insight::Host::CONNECTION, logdev)
128
+ end
129
+ it 'local is true' do
130
+ assert(logdev.local)
131
+ end
132
+ end
133
+
134
+ describe 'logger console' do
135
+ it 'is an instance of Logger' do
136
+ assert_instance_of(Logger, logger_console)
137
+ end
138
+ end
139
+
140
+ describe 'logger console device' do
141
+ it 'is an instance of File' do
142
+ assert_instance_of(File, logger_console_dev)
143
+ end
144
+ it 'path matches expected log filename' do
145
+ assert_match('local_log.log', logger_console_dev.path)
146
+ end
147
+ end
148
+ end
149
+
150
+ describe 'File' do
151
+ let(:log_file) { File.new(local_test_log, 'w') }
152
+
153
+ describe 'logger device' do
154
+ it 'is an instance of CONNECTION' do
155
+ assert_instance_of(R7Insight::Host::CONNECTION, logdev)
156
+ end
157
+ it 'local is true' do
158
+ assert(logdev.local)
159
+ end
160
+ end
161
+ describe 'logger console' do
162
+ it 'is an instance of Logger' do
163
+ assert_instance_of(Logger, logger_console)
164
+ end
165
+ end
166
+ describe 'logger console device' do
167
+ it 'is an instance of File' do
168
+ assert_instance_of(File, logger_console_dev)
169
+ end
170
+ it 'path matches expected log location' do
171
+ assert_match('local_log.log', logger_console_dev.path)
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+
178
+ describe 'when Rails environment' do
179
+ before do
180
+ class Rails
181
+ def self.root
182
+ Pathname.new(File.dirname(__FILE__)).join('fixtures')
183
+ end
184
+
185
+ def self.env
186
+ 'test'
187
+ end
188
+ end
189
+ end
190
+ after do
191
+ Object.send(:remove_const, :Rails)
192
+ end
193
+
194
+ it 'ssl is true' do
195
+ assert(logdev.ssl)
196
+ end
197
+
198
+ it 'local is false' do
199
+ refute(logdev.local)
200
+ assert_nil(logger_console)
201
+ end
202
+
203
+ describe 'and :local is true' do
204
+ let(:local) { true }
205
+
206
+ describe 'logger device' do
207
+ it 'local is true' do
208
+ assert(logdev.local)
209
+ end
210
+ end
211
+ describe 'logger console' do
212
+ it 'is an instance of Logger' do
213
+ assert_instance_of(Logger, logger_console)
214
+ end
215
+ end
216
+ describe 'logger console device' do
217
+ it 'is an instance of File' do
218
+ assert_instance_of(File, logger_console_dev)
219
+ end
220
+ it 'path matches expected log filename' do
221
+ assert_match('test.log', logger_console_dev.path)
222
+ end
223
+ end
224
+ end
225
+
226
+ describe 'and :local => ' do
227
+ let(:local_test_log) do
228
+ Pathname.new(File.dirname(__FILE__))
229
+ .join('fixtures', 'log', 'local_log.log')
230
+ end
231
+ let(:local) { log_file }
232
+
233
+ describe 'Pathname' do
234
+ let(:log_file) { local_test_log }
235
+
236
+ describe 'logger device' do
237
+ it 'is an instance of CONNECTION' do
238
+ assert_instance_of(R7Insight::Host::CONNECTION, logdev)
239
+ end
240
+ it 'local is true' do
241
+ assert(logdev.local)
242
+ end
243
+ end
244
+ describe 'logger console' do
245
+ it 'is an instance of Logger' do
246
+ assert_instance_of(Logger, logger_console)
247
+ end
248
+ end
249
+ describe 'logger console device' do
250
+ it 'is an instance of File' do
251
+ assert_instance_of(File, logger_console_dev)
252
+ end
253
+ it 'path matches expected log filename' do
254
+ assert_match('local_log.log', logger_console_dev.path)
255
+ end
256
+ end
257
+ end
258
+
259
+ describe 'path string' do
260
+ let(:log_file) { local_test_log.to_s }
261
+
262
+ describe 'logger device' do
263
+ it 'is an instance of CONNECTION' do
264
+ assert_instance_of(R7Insight::Host::CONNECTION, logdev)
265
+ end
266
+ it 'local is true' do
267
+ assert(logdev.local)
268
+ end
269
+ end
270
+ describe 'logger console' do
271
+ it 'is an instance of Logger' do
272
+ assert_instance_of(Logger, logger_console)
273
+ end
274
+ end
275
+ describe 'logger console device' do
276
+ it 'is an instance of File' do
277
+ assert_instance_of(File, logger_console_dev)
278
+ end
279
+ it 'path matches expected log filename' do
280
+ assert_match('local_log.log', logger_console_dev.path)
281
+ end
282
+ end
283
+ end
284
+
285
+ describe 'File' do
286
+ let(:log_file) { File.new(local_test_log, 'w') }
287
+
288
+ describe 'logger device' do
289
+ it 'is an instance of CONNECTION' do
290
+ assert_instance_of(R7Insight::Host::CONNECTION, logdev)
291
+ end
292
+ it 'local is true' do
293
+ assert(logdev.local)
294
+ end
295
+ end
296
+ describe 'logger console' do
297
+ it 'is an instance of Logger' do
298
+ assert_instance_of(Logger, logger_console)
299
+ end
300
+ end
301
+ describe 'logger console device' do
302
+ it 'is an instance of File' do
303
+ assert_instance_of(File, logger_console_dev)
304
+ end
305
+ it 'path matches expected log filename' do
306
+ assert_match('local_log.log', logger_console_dev.path)
307
+ end
308
+ end
309
+ end
310
+ end
311
+ end
312
+ end