Files
SecGen/tests/helpers/vulnerability_processor_tests.rb
2016-03-08 22:42:19 +00:00

91 lines
2.9 KiB
Ruby

require 'minitest/autorun'
require '../../lib/helpers/vulnerability_processor'
require '../../lib/objects/vulnerability'
class VulnerabilityProcessorTests < MiniTest::Test
def setup
@sut = VulnerabilityProcessor.new
#Array of Vulnerabilities
@want_xml = Array.new
@all_vuln_xml = Array.new
end
def test_when_given_one_vulnerability_should_return_one_vulnerability
#arrange
vulnerability = Vulnerability.new
vulnerability.type = 'ftp'
vulnerability.access = 'remote'
@want_xml.push(vulnerability)
#act
result = @sut.process(@want_xml)
#assert
assert(result.is_a?(Array), msg = 'The returned value is not an array')
assert_equal(result.count, 1, msg= 'The returned count is less than 1')
assert(result[0].is_a?(Vulnerability), msg = 'The first value is not a type of Vulnerability')
assert_equal(result[0].type, 'ftp', msg= 'The type is not ftp')
assert_equal(result[0].access, 'remote', msg= 'The access is not remote')
end
def test_when_given_vulnerability_with_cve_should_return_full_vulnerability
#arrange
vulnerability = Vulnerability.new
vulnerability.cve = 'CVE-2004-2687'
@want_xml.push(vulnerability)
#act
result = @sut.process(@want_xml)
#assert
assert(result.is_a?(Array), msg = 'The returned value is not an array')
assert_equal(result.count, 1, msg= 'The returned count is less than 1')
assert(result[0].is_a?(Vulnerability), msg = 'The first value is not a type of vulnerability')
assert_equal(result[0].type, 'distcc', msg= 'The type is not distcc')
assert_equal(result[0].access, 'remote', msg= 'The access is not remote')
end
def test_when_given_multiple_vulnerabilities_should_return_multiple_vulnerabilities
#arrange
vulnerability = Vulnerability.new
vulnerability.type = 'ftp'
vulnerability.access = 'remote'
@want_xml.push(vulnerability)
vulnerability = Vulnerability.new
vulnerability.cve = 'CVE-2004-2687'
@want_xml.push(vulnerability)
#act
result = @sut.process(@want_xml)
#assert
assert(result.is_a?(Array), msg = 'The returned value is not an array')
assert_equal(result.count, 2, msg= 'The returned count is less than 1')
assert(result[0].is_a?(Vulnerability), msg = 'The first value is not a type of hash')
end
def test_when_given_multiple_vulnerabilities_of_same_type_should_return_single_vulnerability
#arrange
vulnerability = Vulnerability.new
vulnerability.type = 'ftp'
vulnerability.access = 'remote'
@want_xml.push(vulnerability)
@want_xml.push(vulnerability)
#act
result = @sut.process(@want_xml)
#assert
assert(result.is_a?(Array), msg = 'The returned value is not an array')
assert_equal(result.count, 1, msg= 'The returned count is less than 1')
assert(result[0].is_a?(Vulnerability), msg = 'The first value is not a type of hash')
end
end