Example #1
0
def test_record_set(python_record_path):
    """Test hash code."""
    record1 = Record.from_file(python_record_path, 'python')
    record2 = Record.from_file(python_record_path, 'python')

    s = set()
    s.add(record1)
    s.add(record2)
    assert len(s) == 1
Example #2
0
def test_equality(java_record_path, python_record_path):
    """Test the __eq__ operatator implementation."""
    record1 = Record.from_file(python_record_path, 'python')
    record2 = Record.from_file(python_record_path, 'python')
    record3 = Record.from_file(java_record_path, 'java')

    assert record1 == record2
    assert record1 != record3

    assert record1 != "foobar"
Example #3
0
def test_record_python(python_record_path):
    """Test Record(), for Python."""
    record = Record.from_file(python_record_path, 'python')

    assert record.affects('werkzeug')
    assert record.affects('werkzeug', version='0.11.10')
    assert record.affects('werkzeug', version='0')
    assert not record.affects('werkzeug', version='1')
Example #4
0
def test_str(python_record_path):
    """Test str()."""
    version_range = VersionRange('==1.2.0')
    assert str(version_range) == '==1.2.0'

    affected = Affected.from_dict(
        {
            'name': 'my-package',
            'version': [],
            'fixedin': []
        },
        ecosystem='python')
    assert str(affected) == 'my-package'

    record = Record.from_file(python_record_path, 'python')
    assert str(record) == 'CVE-2016-10516'
Example #5
0
    def from_dir(cls, db_dir):
        """Build database from directory."""
        records = {'java': set(), 'javascript': set(), 'python': set()}

        for ecosystem in records.keys():
            db_dir_lang = os.path.join(db_dir, ecosystem)
            for dirpath, dirnames, filenames in os.walk(db_dir_lang):
                for filename in filenames:
                    if not filename.endswith(('.yaml', '.yml')):
                        continue
                    try:
                        fullpath = os.path.join(dirpath, filename)
                        record = Record.from_file(fullpath, ecosystem)
                        records[ecosystem].add(record)
                    except ParseError as e:
                        _logger.warning(str(e))
        return cls(records=records)
Example #6
0
def test_record_java(java_record_path):
    """Test Record(), for Java."""
    record = Record.from_file(java_record_path, 'java')

    assert record.affects('com.google.guava:guava')
    assert not record.affects('com.google.guava:guava-nonexistent')

    assert record.affects('com.google.guava:guava', version='24.1')
    assert record.affects('com.google.guava:guava', version='15.0')
    assert record.affects('com.google.guava:guava', version='11.0')
    assert not record.affects('com.google.guava:guava', version='10.0')

    assert record.affects('com.google.guava:guava-gwt')
    assert record.affects('com.google.guava:guava-gwt', version='24.1')
    assert record.affects('com.google.guava:guava-gwt', version='15.0')
    assert record.affects('com.google.guava:guava-gwt', version='11.0')
    assert not record.affects('com.google.guava:guava-gwt', version='10.0')
Example #7
0
def test_record_unparseable(unparseable_record_path):
    """Test Record(), for unparseable YAML."""
    with pytest.raises(ParseError) as e:
        assert e is not None
        record = Record.from_file(unparseable_record_path, 'java')
        assert record is not None
Example #8
0
def test_record_repr(python_record_path):
    """Test repr() for the Record class."""
    record = Record.from_file(python_record_path, 'python')
    assert record is not None
    assert repr(record) == '<Record(cve_id=CVE-2016-10516)>'
Example #9
0
def test_invalid_yaml(invalid_record_path):
    """Test ParseError on invalid record."""
    with pytest.raises(ParseError):
        Record.from_file(invalid_record_path, 'python')
Example #10
0
def iter_records():
    for yaml_path, ecosystem in iter_yaml_paths():
        print(yaml_path)
        record = Record.from_file(yaml_path, ecosystem=ecosystem)
        yield yaml_path, record, ecosystem