Exemplo n.º 1
0
def test_cve_dh_create():
    """ 
     Test creation of the data-access-handler for CVE database 
    """
    init_args = db_args
    cve_dh = cda.create_cve_dh(storage_type, init_args)
    assert isinstance(cve_dh, cda.CveDH) == True
Exemplo n.º 2
0
def test_query_cve_data():
    """ 
     Test query for CVE record from CSV file
    """
    cve_dh = cda.create_cve_dh(storage_type, init_args) 
    result = cve_dh.get_cve_data_for_package(sample_query_package) 
    assert isinstance(result, list) == True 
    assert result == sample_query_result
Exemplo n.º 3
0
def test_data_timestamp():
    """
     Test retrieval of the data timestamp 
    """
    cve_dh = cda.create_cve_dh(storage_type, db_args)
    result = cve_dh.data_timestamp()
    format = cda.TIMESTAMP_FORMAT
    dt_obj = datetime.datetime.strptime(result, format)
    assert isinstance(dt_obj, datetime.datetime) == True
Exemplo n.º 4
0
def _init_data_storage(app):
    """
   Initialize CVE data-storage handler using CveDal() data-abstraction layer class.
  """

    print("Initializing CVE data Storage ...")

    storage_type = app.config['STORAGE_TYPE']
    storage_args = app.config['STORAGE_ARGS']

    app.logger.info("Initializing storage for type (%s)" % (storage_type))

    d_args = storage_args[storage_type]
    d_args['logger'] = app.logger

    cve_dh = cve_data_abstraction.create_cve_dh(storage_type, d_args)

    app.cve_dh = cve_dh
Exemplo n.º 5
0
            "host": "74d2d85b57664f819ccea15b57fed5c0.example.org"
        }],
    ]

    ## Test CSV by default
    storage_type = 'csv'
    file_path = 'csv_data/bad_cve_data.3.csv'
    file_path = 'csv_data/cve.csv'
    d_args = {'file_path': file_path}

    ## Test database
    if len(sys.argv) > 1:
        if sys.argv[1] == 'database':
            from config import BaseConfig
            storage_type = 'database'
            d_args = BaseConfig.STORAGE_ARGS[storage_type]

    ## Create our CVE data-handler
    print("Creating CVE data-handler for storage-type: [%s]" % (storage_type))
    cve_dh = cve_data_abstraction.create_cve_dh(storage_type, d_args)

    for input_payload in l_payloads:
        print("%s: INPUT: %s" % (myname, str(input_payload)))
        try:
            d_result = analyze_vulnerable_package_list(input_payload, cve_dh)
            print("%s: RESULT: %s\n" % (myname, str(d_result)))
        except Exception as e:
            print(
                "%s: ERROR - analyze_vulnerable_package_list() failed with exception: %s"
                % (myname, e))
Exemplo n.º 6
0
def test_cve_dh_create_exc():
    """
     Verify that cda.create_cve_dh() raise an CveStorageError() exception as expected with invalid storage-type 
    """
    with pytest.raises(CveStorageError):
        cve_dh = cda.create_cve_dh(invalid_storage_type, {})