def test_add_update_unique_node_with_diff_properties_status_opened():
    """Test add/update security node with opended status (closed_at should not come in query)."""
    pcve = IngestionData(_get_sample_payload_status_opened())
    se = pcve.security_event
    g = Traversel()
    g.add_update_unique_node_with_diff_properties(pcve.security_event, pcve.updated_security_event).next()

    assert ("g.V().has('url', '{san_url}')"
            ".fold()"
            ".coalesce(unfold()"
            ".property('vertex_label', '{vertex_label}')"
            ".property('status', '{e_status}')"
            ".property('title', '{san_title}')"
            ".property('body', '{san_body}')"
            ".property('updated_at', {updated_at})"
            ".property('ecosystem', '{e_ecosystem}')"
            ".property('probable_cve', '{probable_cve}')"
            ".property('cves', '{cve1}')"
            ".property('updated_date', {updated_date})"
            ".property('updated_yearmonth', {updated_yearmonth})"
            ".property('updated_year', {updated_year})"
            ", "
            "addV('security_event')"
            ".property('vertex_label', '{vertex_label}')"
            ".property('event_type', '{e_event_type}')"
            ".property('url', '{san_url}')"
            ".property('api_url', '{san_api_url}')"
            ".property('status', '{e_status}')"
            ".property('title', '{san_title}')"
            ".property('body', '{san_body}')"
            ".property('event_id', '{event_id}')"
            ".property('created_at', {created_at})"
            ".property('updated_at', {updated_at})"
            ".property('repo_name', '{repo_name}')"
            ".property('repo_path', '{san_repo_path}')"
            ".property('ecosystem', '{e_ecosystem}')"
            ".property('creator_name', '{creator_name}')"
            ".property('creator_url', '{san_creator_url}')"
            ".property('probable_cve', '{probable_cve}')"
            ".property('cves', '{cve1}')"
            ".property('updated_date', {updated_date})"
            ".property('updated_yearmonth', {updated_yearmonth})"
            ".property('updated_year', {updated_year})"
            ".property('feedback_count', {feedback_count})"
            ".property('overall_feedback', '{e_overall_feedback}')"
            ").next()".format(e_status=se.status.value, e_event_type=se.event_type.value,
                              e_ecosystem=se.ecosystem.value, e_overall_feedback=se.overall_feedback.value,
                              san_url=sanitize(se.url), san_api_url=sanitize(se.api_url),
                              san_creator_url=sanitize(se.creator_url), san_repo_path=sanitize(se.repo_path),
                              san_title=sanitize(se.title), san_body=sanitize(se.body), cve1=se.cves.pop(),
                              **pcve.security_event.__dict__) == str(g))
def test_get_cves_from_text():
    """Test the retriving CVE logic."""
    pcve = IngestionData(_get_sample_payload_with_cve_text())
    g = Traversel()
    g.add_update_unique_node_with_diff_properties(pcve.security_event, pcve.updated_security_event).next()
    query = str(g)

    # Total 24 cves in poperty adding string : 12 in insert query and 12 in update query
    assert len(re.findall(".property\\('cves'", query)) == 24

    # As 'CVE-2014-0999' is present in title and description but we should get unique data
    # Getting one for insert and one for update query
    assert len(re.findall(".property\\('cves', 'CVE-2014-0999'\\)", query)) == 2

    # Invalid cve, should not get in string
    assert ".property\\('cves', 'CVE-123-1234'\\)" not in query
示例#3
0
def ingest_data_into_graph(data):
    """Ingests given json object to graph."""
    pcve = IngestionData(data)
    g = Traversel()  # pylint: disable=invalid-name
    query = (g.add_update_unique_node_with_diff_properties(
        pcve.security_event, pcve.updated_security_event).next())

    execute_query(query)
    return {'status': 'success'}