def test_workbench_related():
    rel1 = Relationship(constants.MALWARE_ID, 'targets', constants.IDENTITY_ID)
    rel2 = Relationship(constants.CAMPAIGN_ID, 'uses', constants.MALWARE_ID)
    save([rel1, rel2])

    resp = get(constants.MALWARE_ID).related()
    assert len(resp) == 3
    assert any(x['id'] == constants.CAMPAIGN_ID for x in resp)
    assert any(x['id'] == constants.INDICATOR_ID for x in resp)
    assert any(x['id'] == constants.IDENTITY_ID for x in resp)

    resp = get(constants.MALWARE_ID).related(relationship_type='indicates')
    assert len(resp) == 1
Exemple #2
0
def test_workbench_relationships():
    rel = Relationship(INDICATOR_ID, 'indicates', MALWARE_ID)
    save(rel)

    ind = get(INDICATOR_ID)
    resp = ind.relationships()
    assert len(resp) == 1
    assert resp[0].relationship_type == 'indicates'
    assert resp[0].source_ref == INDICATOR_ID
    assert resp[0].target_ref == MALWARE_ID
Exemple #3
0
def test_workbench_related_with_filters():
    malware = Malware(labels=["ransomware"],
                      name="CryptorBit",
                      created_by_ref=IDENTITY_ID)
    rel = Relationship(malware.id, 'variant-of', MALWARE_ID)
    save([malware, rel])

    filters = [Filter('created_by_ref', '=', IDENTITY_ID)]
    resp = get(MALWARE_ID).related(filters=filters)

    assert len(resp) == 1
    assert resp[0].name == malware.name
    assert resp[0].created_by_ref == IDENTITY_ID

    # filters arg can also be single filter
    resp = get(MALWARE_ID).related(filters=filters[0])
    assert len(resp) == 1