def test_vulnerability_dependency_add(): provides = 'test' version = '3.0.1' vuln = vulnerability(name, desc, provides, version) vuln.add_dependency(("app1", ">=1.0.0")) dep_list = vuln.get_dependencies() assert dep_list[0].get_links()[0][0] == "app1" assert dep_list[0].get_links()[0][1] == version_util.version_range( ">=1.0.0") vuln.add_dependency([("app2", ">=1.0.0"), ("app3", ">=1.0.0")]) dep_list = vuln.get_dependencies() #~ print(dep_list[1].get_links()) assert dep_list[1].get_links()[0].provides_string == "app2" assert dep_list[1].get_links( )[0].version_range == version_util.version_range(">=1.0.0") assert dep_list[1].get_links()[1].provides_string == "app3" assert dep_list[1].get_links( )[1].version_range == version_util.version_range(">=1.0.0")
def test_vulnerability_difficulty(): vuln = vulnerability(name, desc) assert vuln.get_difficulty() == None vuln.set_difficulty(1) assert vuln.get_difficulty() == 1 vuln.set_difficulty(3) assert vuln.get_difficulty() == 3 vuln.set_difficulty('easy') assert vuln.get_difficulty() == 1 vuln.set_difficulty('medium') assert vuln.get_difficulty() == 2 vuln.set_difficulty('hard') assert vuln.get_difficulty() == 3 try: vuln.set_difficulty({}) assert False except ValueError: assert True try: vuln.set_difficulty(4) assert False except ValueError: assert True try: vuln.set_difficulty('nope') assert False except ValueError: assert True
def test_vulnerability_dependency_add(): provides = 'test' version = '3.0.1' vuln = vulnerability(name, desc, provides, version) vuln.add_dependency(("app1", ">=1.0.0")) dep_list = vuln.get_dependencies() assert dep_list[0].get_links()[0][0] == "app1" assert dep_list[0].get_links()[0][1] == version_util.version_range(">=1.0.0") vuln.add_dependency( [("app2", ">=1.0.0"), ("app3", ">=1.0.0")] ) dep_list = vuln.get_dependencies() #~ print(dep_list[1].get_links()) assert dep_list[1].get_links()[0].provides_string == "app2" assert dep_list[1].get_links()[0].version_range == version_util.version_range(">=1.0.0") assert dep_list[1].get_links()[1].provides_string == "app3" assert dep_list[1].get_links()[1].version_range == version_util.version_range(">=1.0.0")
def test_vulnerability_create_invalid(): provides = ['t'] version = '1.0.0' try: vuln = vulnerability(name, desc, provides, version) assert False except ValueError: assert True provides = ['t'] version = '1.0.0' try: vuln = vulnerability({"g": "g"}, desc, provides, version) assert False except ValueError: assert True
def test_vulnerability_supported_os(): provides = 'test' version = '1.0.0' vuln = vulnerability(name, desc, provides, version) vuln2 = vulnerability(name, desc, provides, version) vuln3 = vulnerability(name, desc, provides, version) if platform.system() == 'Linux': vuln.add_supported_os('linux') assert vuln.check_os_support() == True plat_data = platform.linux_distribution() if 'ubuntu' in plat_data[0].lower(): vuln2.add_supported_os('linux', 'ubuntu') assert vuln2.check_os_support() == True vuln2.add_supported_os('linux', 'centos') assert vuln2.check_os_support() == True vuln3.add_supported_os('linux', 'debian') assert vuln3.check_os_support() == False elif 'centos' in plat_data[0].lower(): vuln2 = vulnerability(name, desc, provides, version) vuln2.add_supported_os('linux', 'centos') assert vuln2.check_os_support() == True vuln2.add_supported_os('linux', 'debian') assert vuln2.check_os_support() == True vuln3.add_supported_os('linux', 'ubuntu') assert vuln3.check_os_support() == False
def test_vulnerability_create_basic(): vuln = vulnerability(name, desc) assert vuln.name() == name assert vuln.description() == desc assert vuln.provides() == None assert vuln.version() == None
def test_vulnerability_link_valid_https(): vuln = vulnerability(name, desc) link = "https://google.com/?q=test" vuln.set_link(link) assert vuln.get_link() == link
def test_vulnerability_create_invalid(): provides = ['t'] version = '1.0.0' try: vuln = vulnerability(name, desc, provides, version) assert False except ValueError: assert True provides = ['t'] version = '1.0.0' try: vuln = vulnerability({"g":"g"}, desc, provides, version) assert False except ValueError: assert True
def test_vulnerability_link_invalid(): vuln = vulnerability(name, desc) link = "test" try: vuln.set_link(link) assert False except ValueError: assert True
def test_vulnerability_create(): provides = 'test' version = '1.0.0' vuln = vulnerability(name, desc, provides, version) assert vuln.name() == name assert vuln.description() == desc assert vuln.provides() == provides assert vuln.version() == version_util.version(version)
def test_vulnerability_version_compare_invalid(): provides = 'test' version = '1.0.0' vuln = vulnerability(name, desc, provides, version) try: vuln.version() > 'asd' assert False except ValueError: assert True
def test_vulnerability_version_compare1(): provides = 'test' version = '1.0.0' vuln = vulnerability(name, desc, provides, version) vuln_ver = vuln.version() assert (vuln_ver == "1.0.1") == False assert (vuln_ver == "1.0.0") == True assert (vuln_ver < "2.0.0") == True version = '2.0k' vuln = vulnerability(name, desc, provides, version) vuln_ver = vuln.version() assert (vuln_ver == "1.0.1") == False assert (vuln_ver == "1.0.0") == False assert (vuln_ver > "2.0.0") == True
def test_vulnerability_cmd_modifies(): provides = 'test' version = '3.0.1' cmd = "cat" vuln = vulnerability(name, desc, provides, version) vuln.add_cmd_modifies(cmd) cmd_list = vuln.get_cmd_modifies() assert cmd_list[0] == cmd
def test_vulnerability_version_range1(): provides = 'test' version = '1.0.0' vuln = vulnerability(name, desc, provides, version) assert vuln.is_in_range(">1.0.1") == False assert vuln.is_in_range("<1.0.1") == True assert vuln.is_in_range(">1.0.0") == False assert vuln.is_in_range(">=1.0.0") == True assert vuln.is_in_range("<=1.0.0") == True assert vuln.is_in_range("<=2.0.0") == True assert vuln.is_in_range(">=2.0.0") == False assert vuln.is_in_range(">=2.0.0c") == False assert vuln.is_in_range("=2.0.0v") == False
def test_vulnerability_dependency_invalid(): provides = 'test' version = '1.0.0' vuln = vulnerability(name, desc, provides, version) try: vuln.add_dependency('a') assert False except ValueError: assert True try: vuln.add_dependency((None, 'blaa')) assert False except ValueError: assert True try: vuln.add_dependency(None) assert False except ValueError: assert True
def test_vulnerability_cmd_modifies_invalid(): provides = 'test' version = '1.0.0' vuln = vulnerability(name, desc, provides, version) try: vuln.add_cmd_modifies({}) assert False except ValueError: assert True try: vuln.add_cmd_modifies(None) assert False except ValueError: assert True try: vuln.add_cmd_modifies(True) assert False except ValueError: assert True