Example #1
0
def get_latest_version_non_cve(eco, pkg, ver=""):
    """To check if the latest version (input) has cve."""
    result_data = []
    logger.info("Fetching latest non cve version {e} {p}".format(e=eco, p=pkg))
    if ver and ver != "-1":
        # Check if the passed latest version has cve or not
        query_str = "g.V().has('pecosystem', eco).has('pname', pkg).has('version', ver)" \
                    ".not(outE('has_snyk_cve')).valueMap()"
        payload = {
            'gremlin': query_str,
            'bindings': {
                'eco': eco,
                'pkg': pkg,
                'ver': ver
            }
        }
        gremlin_response = execute_gremlin_dsl(payload)
        result_data = get_response_data(gremlin_response, [])
    if len(result_data) == 0:
        # result_data will be 0 if cve is found. Fetch all versions
        logger.info("Latest version node not found in graph")
        all_ver = get_all_versions(eco, pkg, True)
        # Use util function to select the latest of all the versions fetched
        return select_latest_version(all_ver)
    else:
        logger.info("Latest version node found in graph")
        return ver
def test_select_vesion_empty():
    """Test empty version list use-case."""
    assert "" == select_latest_version()

    assert "" == select_latest_version([])