예제 #1
0
def get_version_map():
    """ Read changelog and get SQLITE_SOURCE_ID to use for versions """
    version_map = []

    changeurl = "https://www.sqlite.org/changes.html"
    version_pattern = re.compile(
        r"<h3>\d{4}-\d{2}-\d{2} \((\d+\.\d+[.\d]*)\)</h3>")
    id_patterns = [
        re.compile(r'SQLITE_SOURCE_ID: "([^"]+)"'),
        re.compile(r'"*(\d{4}-\d{2}-\d{2} \d+:\d+:\d+ [\w]+)"*'),
    ]
    try:
        response = request.urlopen(changeurl)
        lines = response.readlines()

        last_version = "UNKNOWN"
        for line_encoded in lines:
            line = line_encoded.decode("UTF-8")

            ver_match = version_pattern.search(line)
            if ver_match:
                last_version = ver_match.group(1)
            for id_pattern in id_patterns:
                id_match = id_pattern.search(line)
                if id_match:
                    version_map.append([last_version, id_match.group(1)])
                    break

    except error.URLError as err:
        LOGGER.error("Could not fetch " + changeurl + ", " + str(err))

    return version_map
예제 #2
0
    def test_json_validation(self, year):
        """ Validate latest nvd json file against their published schema """
        # Open the latest nvd file on disk
        with gzip.open(
                os.path.join(DISK_LOCATION_DEFAULT,
                             f"nvdcve-1.1-{year}.json.gz"),
                "rb",
        ) as json_file:
            nvd_json = json.loads(json_file.read())
            LOGGER.info(
                f"Loaded json for year {year}: nvdcve-1.1-{year}.json.gz")

            # Validate -- will raise a ValidationError if not valid
            try:
                validate(nvd_json, self.SCHEMA)
                LOGGER.info("Validation complete")
            except ValidationError as ve:
                LOGGER.error(ve)
                pytest.fail("Validation error occurred")