Browse Source

Restore status unit tests

new-scoring
aeris 2 years ago
parent
commit
34cc29b2a5
5 changed files with 39 additions and 46 deletions
  1. 1
    1
      cryptcheck.gemspec
  2. 3
    4
      lib/cryptcheck/tls/host.rb
  3. 1
    1
      lib/cryptcheck/tls/https.rb
  4. 28
    31
      spec/cryptcheck/status_spec.rb
  5. 6
    9
      spec/helpers.rb

+ 1
- 1
cryptcheck.gemspec View File

@@ -30,11 +30,11 @@ Gem::Specification.new do |spec|
30 30
 	spec.add_development_dependency 'rake', '~> 11.2', '>= 11.2.2'
31 31
 	spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
32 32
 	spec.add_development_dependency 'ffi', '~> 1.9', '>= 1.9.17'
33
-	spec.add_development_dependency 'awesome_print', '~> 1.7.0', '>= 1.7.0'
34 33
 
35 34
 	spec.add_dependency 'httparty', '~> 0.13', '>= 0.13.3'
36 35
 	spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.6'
37 36
 	spec.add_dependency 'parallel', '~> 1.3', '>= 1.3.4'
38 37
 	spec.add_dependency 'ruby-progressbar', '~> 1.7', '>= 1.7.1'
39 38
 	spec.add_dependency 'colorize', '~> 0.7', '>= 0.7.7'
39
+	spec.add_dependency 'awesome_print', '~> 1.7.0', '>= 1.7.0'
40 40
 end

+ 3
- 4
lib/cryptcheck/tls/host.rb View File

@@ -38,6 +38,7 @@ module CryptCheck
38 38
 						end
39 39
 						Logger.info ''
40 40
 						Logger.info { "Grade : #{server.grade.to_s.colorize server.grade_status}" }
41
+						Logger.info { server.states.ai }
41 42
 						server
42 43
 					rescue Engine::TLSException, Engine::ConnectionError, Engine::Timeout => e
43 44
 						AnalysisFailure.new e
@@ -46,8 +47,6 @@ module CryptCheck
46 47
 					end
47 48
 					[[@hostname, ip, @port], result]
48 49
 				end.to_h
49
-			rescue StandardError
50
-				raise
51 50
 			rescue => e
52 51
 				@error = e
53 52
 			end
@@ -69,8 +68,8 @@ module CryptCheck
69 68
 						case server
70 69
 							when Server
71 70
 								host[:handshakes] = server.to_h
72
-								host[:states]   = server.states
73
-								host[:grade]   = server.grade
71
+								host[:states]     = server.states
72
+								host[:grade]     = server.grade
74 73
 							else
75 74
 								host[:error] = server.message
76 75
 						end

+ 1
- 1
lib/cryptcheck/tls/https.rb View File

@@ -2,7 +2,7 @@ module CryptCheck
2 2
 	module Tls
3 3
 		module Https
4 4
 			def self.analyze(host, port=443)
5
-				::CryptCheck.analyze host, port, Server, Grade
5
+				::CryptCheck.analyze host, port, Server
6 6
 			end
7 7
 
8 8
 			def self.analyze_file(input, output)

+ 28
- 31
spec/cryptcheck/status_spec.rb View File

@@ -132,10 +132,12 @@ describe CryptCheck::State do
132 132
 	end
133 133
 
134 134
 	describe '#states' do
135
-		def match_states(actual, **expected)
136
-			expect(actual.states).to eq expected
135
+		def match_states(obj, **expected)
136
+			expected = CryptCheck::State.empty.merge expected
137
+			expect(obj.states).to eq expected
137 138
 		end
138 139
 
140
+
139 141
 		let(:empty) do
140 142
 			Class.new do
141 143
 				include ::CryptCheck::State
@@ -215,7 +217,7 @@ describe CryptCheck::State do
215 217
 					[[:foo, :critical, -> (_) { true }]]
216 218
 				end
217 219
 			end.new
218
-			expect(obj.states).to eq({ critical: { foo: true } })
220
+			match_states obj, critical: { foo: true }
219 221
 
220 222
 			obj = Class.new do
221 223
 				include ::CryptCheck::State
@@ -224,7 +226,7 @@ describe CryptCheck::State do
224 226
 					[[:foo, :critical, -> (_) { false }]]
225 227
 				end
226 228
 			end.new
227
-			expect(obj.states).to eq({ critical: { foo: false } })
229
+			match_states obj, critical: { foo: false }
228 230
 
229 231
 			obj = Class.new do
230 232
 				include ::CryptCheck::State
@@ -233,7 +235,7 @@ describe CryptCheck::State do
233 235
 					[[:foo, :critical, -> (_) { nil }]]
234 236
 				end
235 237
 			end.new
236
-			expect(obj.states).to eq({ critical: { foo: nil } })
238
+			match_states obj, critical: { foo: nil }
237 239
 		end
238 240
 
239 241
 		it 'must return all levels if multiple levels specified' do
@@ -244,11 +246,10 @@ describe CryptCheck::State do
244 246
 					[[:foo, %i(critical error good great), -> (_) { :critical }]]
245 247
 				end
246 248
 			end.new
247
-			expect(obj.states).to eq({
248
-											 critical: { foo: true },
249
-											 error:    { foo: true },
250
-											 good:     { foo: false },
251
-											 great:    { foo: false } })
249
+			match_states obj, critical: { foo: true },
250
+						 error:         { foo: true },
251
+						 good:          { foo: false },
252
+						 great:         { foo: false }
252 253
 
253 254
 			obj = Class.new do
254 255
 				include ::CryptCheck::State
@@ -257,11 +258,10 @@ describe CryptCheck::State do
257 258
 					[[:foo, %i(critical error good great), -> (_) { :error }]]
258 259
 				end
259 260
 			end.new
260
-			expect(obj.states).to eq({
261
-											 critical: { foo: false },
262
-											 error:    { foo: true },
263
-											 good:     { foo: false },
264
-											 great:    { foo: false } })
261
+			match_states obj, critical: { foo: false },
262
+						 error:         { foo: true },
263
+						 good:          { foo: false },
264
+						 great:         { foo: false }
265 265
 
266 266
 
267 267
 			obj = Class.new do
@@ -271,11 +271,10 @@ describe CryptCheck::State do
271 271
 					[[:foo, %i(critical error good great), -> (_) { :great }]]
272 272
 				end
273 273
 			end.new
274
-			expect(obj.states).to eq({
275
-											 critical: { foo: false },
276
-											 error:    { foo: false },
277
-											 good:     { foo: true },
278
-											 great:    { foo: true } })
274
+			match_states obj, critical: { foo: false },
275
+						 error:         { foo: false },
276
+						 good:          { foo: true },
277
+						 great:         { foo: true }
279 278
 
280 279
 
281 280
 			obj = Class.new do
@@ -285,11 +284,10 @@ describe CryptCheck::State do
285 284
 					[[:foo, %i(critical error good great), -> (_) { :good }]]
286 285
 				end
287 286
 			end.new
288
-			expect(obj.states).to eq({
289
-											 critical: { foo: false },
290
-											 error:    { foo: false },
291
-											 good:     { foo: true },
292
-											 great:    { foo: false } })
287
+			match_states obj, critical: { foo: false },
288
+						 error:         { foo: false },
289
+						 good:          { foo: true },
290
+						 great:         { foo: false }
293 291
 
294 292
 			obj = Class.new do
295 293
 				include ::CryptCheck::State
@@ -298,11 +296,10 @@ describe CryptCheck::State do
298 296
 					[[:foo, %i(critical error good great), -> (_) { nil }]]
299 297
 				end
300 298
 			end.new
301
-			expect(obj.states).to eq({
302
-											 critical: { foo: nil },
303
-											 error:    { foo: nil },
304
-											 good:     { foo: nil },
305
-											 great:    { foo: nil } })
299
+			match_states obj, critical: { foo: nil },
300
+						 error:         { foo: nil },
301
+						 good:          { foo: nil },
302
+						 great:         { foo: nil }
306 303
 		end
307 304
 
308 305
 		it 'must return empty if no check nor child' do
@@ -314,7 +311,7 @@ describe CryptCheck::State do
314 311
 		end
315 312
 
316 313
 		it 'must return personal and children statuses' do
317
-			match_states parent, critical: { foo: true }, error: { bar: true}
314
+			match_states parent, critical: { foo: true }, error: { bar: true }
318 315
 		end
319 316
 
320 317
 		it 'must return remove duplicated status' do

+ 6
- 9
spec/helpers.rb View File

@@ -226,14 +226,12 @@ module Helpers
226 226
 		end
227 227
 	end
228 228
 
229
-	def grade(grades, host, ip, port)
230
-		grades[[host, ip, port]]
229
+	def server(servers, host, ip, port)
230
+		servers[[host, ip, port]]
231 231
 	end
232 232
 
233
-	def expect_grade(grades, host, ip, port, family)
234
-		grade = grade grades, host, ip, port
235
-		expect(grade).to be_a CryptCheck::Tls::Grade
236
-		server = grade.server
233
+	def expect_grade(servers, host, ip, port, family)
234
+		server = server servers, host, ip, port
237 235
 		expect(server).to be_a CryptCheck::Tls::Server
238 236
 		expect(server.hostname).to eq host
239 237
 		expect(server.ip).to eq ip
@@ -244,11 +242,10 @@ module Helpers
244 242
 										when :ipv6
245 243
 											Socket::AF_INET6
246 244
 									end
247
-		[grade, server]
248 245
 	end
249 246
 
250
-	def expect_grade_error(grades, host, ip, port, error)
251
-		server = grades[[host, ip, port]]
247
+	def expect_grade_error(servers, host, ip, port, error)
248
+		server = servers[[host, ip, port]]
252 249
 		expect(server).to be_a CryptCheck::Tls::AnalysisFailure
253 250
 		expect(server.to_s).to eq error
254 251
 	end

Loading…
Cancel
Save