Browse Source

Restore status unit tests

new-scoring
aeris 5 years ago
parent
commit
34cc29b2a5
  1. 2
      cryptcheck.gemspec
  2. 7
      lib/cryptcheck/tls/host.rb
  3. 2
      lib/cryptcheck/tls/https.rb
  4. 59
      spec/cryptcheck/status_spec.rb
  5. 15
      spec/helpers.rb

2
cryptcheck.gemspec

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

7
lib/cryptcheck/tls/host.rb

@ -38,6 +38,7 @@ module CryptCheck
end
Logger.info ''
Logger.info { "Grade : #{server.grade.to_s.colorize server.grade_status}" }
Logger.info { server.states.ai }
server
rescue Engine::TLSException, Engine::ConnectionError, Engine::Timeout => e
AnalysisFailure.new e
@ -46,8 +47,6 @@ module CryptCheck
end
[[@hostname, ip, @port], result]
end.to_h
rescue StandardError
raise
rescue => e
@error = e
end
@ -69,8 +68,8 @@ module CryptCheck
case server
when Server
host[:handshakes] = server.to_h
host[:states] = server.states
host[:grade] = server.grade
host[:states] = server.states
host[:grade] = server.grade
else
host[:error] = server.message
end

2
lib/cryptcheck/tls/https.rb

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

59
spec/cryptcheck/status_spec.rb

@ -132,10 +132,12 @@ describe CryptCheck::State do
end
describe '#states' do
def match_states(actual, **expected)
expect(actual.states).to eq expected
def match_states(obj, **expected)
expected = CryptCheck::State.empty.merge expected
expect(obj.states).to eq expected
end
let(:empty) do
Class.new do
include ::CryptCheck::State
@ -215,7 +217,7 @@ describe CryptCheck::State do
[[:foo, :critical, -> (_) { true }]]
end
end.new
expect(obj.states).to eq({ critical: { foo: true } })
match_states obj, critical: { foo: true }
obj = Class.new do
include ::CryptCheck::State
@ -224,7 +226,7 @@ describe CryptCheck::State do
[[:foo, :critical, -> (_) { false }]]
end
end.new
expect(obj.states).to eq({ critical: { foo: false } })
match_states obj, critical: { foo: false }
obj = Class.new do
include ::CryptCheck::State
@ -233,7 +235,7 @@ describe CryptCheck::State do
[[:foo, :critical, -> (_) { nil }]]
end
end.new
expect(obj.states).to eq({ critical: { foo: nil } })
match_states obj, critical: { foo: nil }
end
it 'must return all levels if multiple levels specified' do
@ -244,11 +246,10 @@ describe CryptCheck::State do
[[:foo, %i(critical error good great), -> (_) { :critical }]]
end
end.new
expect(obj.states).to eq({
critical: { foo: true },
error: { foo: true },
good: { foo: false },
great: { foo: false } })
match_states obj, critical: { foo: true },
error: { foo: true },
good: { foo: false },
great: { foo: false }
obj = Class.new do
include ::CryptCheck::State
@ -257,11 +258,10 @@ describe CryptCheck::State do
[[:foo, %i(critical error good great), -> (_) { :error }]]
end
end.new
expect(obj.states).to eq({
critical: { foo: false },
error: { foo: true },
good: { foo: false },
great: { foo: false } })
match_states obj, critical: { foo: false },
error: { foo: true },
good: { foo: false },
great: { foo: false }
obj = Class.new do
@ -271,11 +271,10 @@ describe CryptCheck::State do
[[:foo, %i(critical error good great), -> (_) { :great }]]
end
end.new
expect(obj.states).to eq({
critical: { foo: false },
error: { foo: false },
good: { foo: true },
great: { foo: true } })
match_states obj, critical: { foo: false },
error: { foo: false },
good: { foo: true },
great: { foo: true }
obj = Class.new do
@ -285,11 +284,10 @@ describe CryptCheck::State do
[[:foo, %i(critical error good great), -> (_) { :good }]]
end
end.new
expect(obj.states).to eq({
critical: { foo: false },
error: { foo: false },
good: { foo: true },
great: { foo: false } })
match_states obj, critical: { foo: false },
error: { foo: false },
good: { foo: true },
great: { foo: false }
obj = Class.new do
include ::CryptCheck::State
@ -298,11 +296,10 @@ describe CryptCheck::State do
[[:foo, %i(critical error good great), -> (_) { nil }]]
end
end.new
expect(obj.states).to eq({
critical: { foo: nil },
error: { foo: nil },
good: { foo: nil },
great: { foo: nil } })
match_states obj, critical: { foo: nil },
error: { foo: nil },
good: { foo: nil },
great: { foo: nil }
end
it 'must return empty if no check nor child' do
@ -314,7 +311,7 @@ describe CryptCheck::State do
end
it 'must return personal and children statuses' do
match_states parent, critical: { foo: true }, error: { bar: true}
match_states parent, critical: { foo: true }, error: { bar: true }
end
it 'must return remove duplicated status' do

15
spec/helpers.rb

@ -226,14 +226,12 @@ module Helpers
end
end
def grade(grades, host, ip, port)
grades[[host, ip, port]]
def server(servers, host, ip, port)
servers[[host, ip, port]]
end
def expect_grade(grades, host, ip, port, family)
grade = grade grades, host, ip, port
expect(grade).to be_a CryptCheck::Tls::Grade
server = grade.server
def expect_grade(servers, host, ip, port, family)
server = server servers, host, ip, port
expect(server).to be_a CryptCheck::Tls::Server
expect(server.hostname).to eq host
expect(server.ip).to eq ip
@ -244,11 +242,10 @@ module Helpers
when :ipv6
Socket::AF_INET6
end
[grade, server]
end
def expect_grade_error(grades, host, ip, port, error)
server = grades[[host, ip, port]]
def expect_grade_error(servers, host, ip, port, error)
server = servers[[host, ip, port]]
expect(server).to be_a CryptCheck::Tls::AnalysisFailure
expect(server.to_s).to eq error
end

Loading…
Cancel
Save