2018-07-03 13:00:18 +02:00
|
|
|
import json
|
|
|
|
|
|
|
|
from medallion.filters.basic_filter import BasicFilter
|
|
|
|
import pytest
|
|
|
|
from requests.models import Response
|
2020-04-03 21:58:56 +02:00
|
|
|
from taxii2client.common import _filter_kwargs_to_query_params
|
2020-04-03 23:19:36 +02:00
|
|
|
from taxii2client.v21 import Collection
|
2018-07-03 13:00:18 +02:00
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
import stix2
|
2018-07-03 13:00:18 +02:00
|
|
|
from stix2.datastore import DataSourceError
|
|
|
|
from stix2.datastore.filters import Filter
|
2020-04-03 23:19:36 +02:00
|
|
|
from stix2.utils import get_timestamp
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/'
|
|
|
|
|
|
|
|
|
|
|
|
class MockTAXIICollectionEndpoint(Collection):
|
|
|
|
"""Mock for taxii2_client.TAXIIClient"""
|
|
|
|
|
2018-11-01 13:17:34 +01:00
|
|
|
def __init__(self, url, collection_info):
|
|
|
|
super(MockTAXIICollectionEndpoint, self).__init__(
|
|
|
|
url, collection_info=collection_info,
|
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
self.objects = []
|
2020-04-03 23:19:36 +02:00
|
|
|
self.manifests = []
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
def add_objects(self, bundle):
|
|
|
|
self._verify_can_write()
|
2021-03-12 22:46:34 +01:00
|
|
|
if isinstance(bundle, str):
|
2020-06-18 17:36:18 +02:00
|
|
|
bundle = json.loads(bundle)
|
2021-03-02 02:47:30 +01:00
|
|
|
for obj in bundle.get("objects", []):
|
|
|
|
self.objects.append(obj)
|
2020-04-03 23:19:36 +02:00
|
|
|
self.manifests.append(
|
|
|
|
{
|
|
|
|
"date_added": get_timestamp(),
|
2021-03-02 02:47:30 +01:00
|
|
|
"id": obj["id"],
|
2020-04-03 23:19:36 +02:00
|
|
|
"media_type": "application/stix+json;version=2.1",
|
2021-03-02 02:47:30 +01:00
|
|
|
"version": obj.get("modified", obj.get("created", get_timestamp())),
|
2020-04-03 23:19:36 +02:00
|
|
|
},
|
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
def get_objects(self, **filter_kwargs):
|
|
|
|
self._verify_can_read()
|
|
|
|
query_params = _filter_kwargs_to_query_params(filter_kwargs)
|
2018-11-30 00:36:37 +01:00
|
|
|
assert isinstance(query_params, dict)
|
|
|
|
full_filter = BasicFilter(query_params)
|
2018-07-03 13:00:18 +02:00
|
|
|
objs = full_filter.process_filter(
|
|
|
|
self.objects,
|
|
|
|
("id", "type", "version"),
|
2020-04-03 23:19:36 +02:00
|
|
|
self.manifests,
|
|
|
|
100,
|
2020-04-03 21:58:56 +02:00
|
|
|
)[0]
|
2018-07-03 13:00:18 +02:00
|
|
|
if objs:
|
2021-03-02 02:47:30 +01:00
|
|
|
return {
|
|
|
|
"objects": objs,
|
|
|
|
"more": False,
|
|
|
|
}
|
2018-07-03 13:00:18 +02:00
|
|
|
else:
|
|
|
|
resp = Response()
|
|
|
|
resp.status_code = 404
|
|
|
|
resp.raise_for_status()
|
|
|
|
|
2018-11-30 00:36:37 +01:00
|
|
|
def get_object(self, id, **filter_kwargs):
|
2018-07-03 13:00:18 +02:00
|
|
|
self._verify_can_read()
|
2018-11-30 00:36:37 +01:00
|
|
|
query_params = _filter_kwargs_to_query_params(filter_kwargs)
|
|
|
|
assert isinstance(query_params, dict)
|
|
|
|
full_filter = BasicFilter(query_params)
|
|
|
|
|
|
|
|
# In this endpoint we must first filter objects by id beforehand.
|
|
|
|
objects = [x for x in self.objects if x["id"] == id]
|
|
|
|
if objects:
|
|
|
|
filtered_objects = full_filter.process_filter(
|
|
|
|
objects,
|
|
|
|
("version",),
|
2020-04-03 23:19:36 +02:00
|
|
|
self.manifests,
|
|
|
|
100,
|
2020-04-03 21:58:56 +02:00
|
|
|
)[0]
|
2018-11-30 00:36:37 +01:00
|
|
|
else:
|
|
|
|
filtered_objects = []
|
|
|
|
if filtered_objects:
|
2021-03-02 02:47:30 +01:00
|
|
|
return {
|
|
|
|
"objects": filtered_objects,
|
|
|
|
"more": False,
|
|
|
|
}
|
2018-07-03 13:00:18 +02:00
|
|
|
else:
|
|
|
|
resp = Response()
|
|
|
|
resp.status_code = 404
|
|
|
|
resp.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2020-04-03 23:19:36 +02:00
|
|
|
def collection(stix_objs1, stix_objs1_manifests):
|
2018-07-13 17:10:05 +02:00
|
|
|
mock = MockTAXIICollectionEndpoint(
|
2018-11-01 13:17:34 +01:00
|
|
|
COLLECTION_URL, {
|
2018-07-13 17:10:05 +02:00
|
|
|
"id": "91a7b528-80eb-42ed-a74d-c6fbd5a26116",
|
|
|
|
"title": "Writable Collection",
|
|
|
|
"description": "This collection is a dropbox for submitting indicators",
|
|
|
|
"can_read": True,
|
|
|
|
"can_write": True,
|
|
|
|
"media_types": [
|
|
|
|
"application/vnd.oasis.stix+json; version=2.0",
|
|
|
|
],
|
2018-11-01 13:17:34 +01:00
|
|
|
},
|
2018-07-13 17:10:05 +02:00
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
mock.objects.extend(stix_objs1)
|
2020-04-03 23:19:36 +02:00
|
|
|
mock.manifests.extend(stix_objs1_manifests)
|
2018-07-03 13:00:18 +02:00
|
|
|
return mock
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2020-04-03 23:19:36 +02:00
|
|
|
def collection_no_rw_access(stix_objs1, stix_objs1_manifests):
|
2018-07-13 17:10:05 +02:00
|
|
|
mock = MockTAXIICollectionEndpoint(
|
2018-11-01 13:17:34 +01:00
|
|
|
COLLECTION_URL, {
|
2018-07-13 17:10:05 +02:00
|
|
|
"id": "91a7b528-80eb-42ed-a74d-c6fbd5a26116",
|
|
|
|
"title": "Not writeable or readable Collection",
|
|
|
|
"description": "This collection is a dropbox for submitting indicators",
|
|
|
|
"can_read": False,
|
|
|
|
"can_write": False,
|
|
|
|
"media_types": [
|
|
|
|
"application/vnd.oasis.stix+json; version=2.0",
|
|
|
|
],
|
2018-11-01 13:17:34 +01:00
|
|
|
},
|
2018-07-13 17:10:05 +02:00
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
mock.objects.extend(stix_objs1)
|
2020-04-03 23:19:36 +02:00
|
|
|
mock.manifests.extend(stix_objs1_manifests)
|
2018-07-03 13:00:18 +02:00
|
|
|
return mock
|
|
|
|
|
|
|
|
|
|
|
|
def test_ds_taxii(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
ds = stix2.TAXIICollectionSource(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
assert ds.collection is not None
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_stix2_object(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionSink(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
# create new STIX threat-actor
|
2018-07-13 17:10:05 +02:00
|
|
|
ta = stix2.v21.ThreatActor(
|
|
|
|
name="Teddy Bear",
|
|
|
|
threat_actor_types=["nation-state"],
|
|
|
|
sophistication="innovator",
|
|
|
|
resource_level="government",
|
|
|
|
goals=[
|
|
|
|
"compromising environment NGOs",
|
|
|
|
"water-hole attacks geared towards energy sector",
|
|
|
|
],
|
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
tc_sink.add(ta)
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_stix2_with_custom_object(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionStore(collection, allow_custom=True)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
# create new STIX threat-actor
|
2018-07-13 17:10:05 +02:00
|
|
|
ta = stix2.v21.ThreatActor(
|
|
|
|
name="Teddy Bear",
|
|
|
|
threat_actor_types=["nation-state"],
|
|
|
|
sophistication="innovator",
|
|
|
|
resource_level="government",
|
|
|
|
goals=[
|
|
|
|
"compromising environment NGOs",
|
|
|
|
"water-hole attacks geared towards energy sector",
|
|
|
|
],
|
|
|
|
foo="bar",
|
|
|
|
allow_custom=True,
|
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
tc_sink.add(ta)
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_list_object(collection, indicator):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionSink(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
# create new STIX threat-actor
|
2018-07-13 17:10:05 +02:00
|
|
|
ta = stix2.v21.ThreatActor(
|
|
|
|
name="Teddy Bear",
|
|
|
|
threat_actor_types=["nation-state"],
|
|
|
|
sophistication="innovator",
|
|
|
|
resource_level="government",
|
|
|
|
goals=[
|
|
|
|
"compromising environment NGOs",
|
|
|
|
"water-hole attacks geared towards energy sector",
|
|
|
|
],
|
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
tc_sink.add([ta, indicator])
|
|
|
|
|
|
|
|
|
2018-11-30 00:36:37 +01:00
|
|
|
def test_get_object_found(collection):
|
|
|
|
tc_source = stix2.TAXIICollectionSource(collection)
|
|
|
|
result = tc_source.query([
|
|
|
|
stix2.Filter("id", "=", "indicator--00000000-0000-4000-8000-000000000001"),
|
|
|
|
])
|
|
|
|
assert result
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_object_not_found(collection):
|
|
|
|
tc_source = stix2.TAXIICollectionSource(collection)
|
|
|
|
result = tc_source.get("indicator--00000000-0000-4000-8000-000000000012")
|
|
|
|
assert result is None
|
|
|
|
|
|
|
|
|
2018-07-03 13:00:18 +02:00
|
|
|
def test_add_stix2_bundle_object(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionSink(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
# create new STIX threat-actor
|
2018-07-13 17:10:05 +02:00
|
|
|
ta = stix2.v21.ThreatActor(
|
|
|
|
name="Teddy Bear",
|
|
|
|
threat_actor_types=["nation-state"],
|
|
|
|
sophistication="innovator",
|
|
|
|
resource_level="government",
|
|
|
|
goals=[
|
|
|
|
"compromising environment NGOs",
|
|
|
|
"water-hole attacks geared towards energy sector",
|
|
|
|
],
|
|
|
|
)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink.add(stix2.v21.Bundle(objects=[ta]))
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_add_str_object(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionSink(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
# create new STIX threat-actor
|
|
|
|
ta = """{
|
|
|
|
"type": "threat-actor",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"id": "threat-actor--eddff64f-feb1-4469-b07c-499a73c96415",
|
|
|
|
"created": "2018-04-23T16:40:50.847Z",
|
|
|
|
"modified": "2018-04-23T16:40:50.847Z",
|
|
|
|
"name": "Teddy Bear",
|
2018-07-12 20:33:00 +02:00
|
|
|
"threat_actor_types": [
|
|
|
|
"nation-state"
|
|
|
|
],
|
2018-07-03 13:00:18 +02:00
|
|
|
"goals": [
|
|
|
|
"compromising environment NGOs",
|
|
|
|
"water-hole attacks geared towards energy sector"
|
|
|
|
],
|
|
|
|
"sophistication": "innovator",
|
2018-07-12 20:33:00 +02:00
|
|
|
"resource_level": "government"
|
2018-07-03 13:00:18 +02:00
|
|
|
}"""
|
|
|
|
|
|
|
|
tc_sink.add(ta)
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_dict_object(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionSink(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
ta = {
|
|
|
|
"type": "threat-actor",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"id": "threat-actor--eddff64f-feb1-4469-b07c-499a73c96415",
|
|
|
|
"created": "2018-04-23T16:40:50.847Z",
|
|
|
|
"modified": "2018-04-23T16:40:50.847Z",
|
|
|
|
"name": "Teddy Bear",
|
|
|
|
"goals": [
|
|
|
|
"compromising environment NGOs",
|
2018-07-13 17:10:05 +02:00
|
|
|
"water-hole attacks geared towards energy sector",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"sophistication": "innovator",
|
|
|
|
"resource_level": "government",
|
2018-07-12 20:33:00 +02:00
|
|
|
"threat_actor_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"nation-state",
|
|
|
|
],
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tc_sink.add(ta)
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_dict_bundle_object(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionSink(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
ta = {
|
|
|
|
"type": "bundle",
|
|
|
|
"id": "bundle--860ccc8d-56c9-4fda-9384-84276fb52fb1",
|
|
|
|
"objects": [
|
|
|
|
{
|
|
|
|
"type": "threat-actor",
|
2018-07-03 15:40:51 +02:00
|
|
|
"spec_version": "2.1",
|
2018-07-03 13:00:18 +02:00
|
|
|
"id": "threat-actor--dc5a2f41-f76e-425a-81fe-33afc7aabd75",
|
|
|
|
"created": "2018-04-23T18:45:11.390Z",
|
|
|
|
"modified": "2018-04-23T18:45:11.390Z",
|
|
|
|
"name": "Teddy Bear",
|
|
|
|
"goals": [
|
|
|
|
"compromising environment NGOs",
|
2018-07-13 17:10:05 +02:00
|
|
|
"water-hole attacks geared towards energy sector",
|
2018-07-03 13:00:18 +02:00
|
|
|
],
|
|
|
|
"sophistication": "innovator",
|
|
|
|
"resource_level": "government",
|
2018-07-12 20:33:00 +02:00
|
|
|
"threat_actor_types": [
|
2018-07-13 17:10:05 +02:00
|
|
|
"nation-state",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2018-07-03 13:00:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tc_sink.add(ta)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_stix2_object(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
tc_sink = stix2.TAXIICollectionSource(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
2018-07-11 15:43:37 +02:00
|
|
|
objects = tc_sink.get("indicator--00000000-0000-4000-8000-000000000001")
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
assert objects
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_taxii_filters(collection):
|
|
|
|
query = [
|
|
|
|
Filter("added_after", "=", "2016-02-01T00:00:01.000Z"),
|
|
|
|
Filter("id", "=", "taxii stix object ID"),
|
|
|
|
Filter("type", "=", "taxii stix object ID"),
|
|
|
|
Filter("version", "=", "first"),
|
|
|
|
Filter("created_by_ref", "=", "Bane"),
|
|
|
|
]
|
|
|
|
|
|
|
|
taxii_filters_expected = [
|
|
|
|
Filter("added_after", "=", "2016-02-01T00:00:01.000Z"),
|
|
|
|
Filter("id", "=", "taxii stix object ID"),
|
|
|
|
Filter("type", "=", "taxii stix object ID"),
|
2018-07-13 17:10:05 +02:00
|
|
|
Filter("version", "=", "first"),
|
2018-07-03 13:00:18 +02:00
|
|
|
]
|
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
ds = stix2.TAXIICollectionSource(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
taxii_filters = ds._parse_taxii_filters(query)
|
|
|
|
|
|
|
|
assert taxii_filters == taxii_filters_expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_get_remove_filter(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
ds = stix2.TAXIICollectionSource(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
# First 3 filters are valid, remaining properties are erroneous in some way
|
|
|
|
valid_filters = [
|
|
|
|
Filter('type', '=', 'malware'),
|
|
|
|
Filter('id', '!=', 'stix object id'),
|
2018-07-12 20:33:00 +02:00
|
|
|
Filter('threat_actor_types', 'in', ["heartbleed", "malicious-activity"]),
|
2018-07-03 13:00:18 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
assert len(ds.filters) == 0
|
|
|
|
|
|
|
|
ds.filters.add(valid_filters[0])
|
|
|
|
assert len(ds.filters) == 1
|
|
|
|
|
|
|
|
# Addin the same filter again will have no effect since `filters` acts
|
|
|
|
# like a set
|
|
|
|
ds.filters.add(valid_filters[0])
|
|
|
|
assert len(ds.filters) == 1
|
|
|
|
|
|
|
|
ds.filters.add(valid_filters[1])
|
|
|
|
assert len(ds.filters) == 2
|
|
|
|
|
|
|
|
ds.filters.add(valid_filters[2])
|
|
|
|
assert len(ds.filters) == 3
|
|
|
|
|
|
|
|
assert valid_filters == [f for f in ds.filters]
|
|
|
|
|
|
|
|
# remove
|
|
|
|
ds.filters.remove(valid_filters[0])
|
|
|
|
|
|
|
|
assert len(ds.filters) == 2
|
|
|
|
|
|
|
|
ds.filters.add(valid_filters)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_all_versions(collection):
|
2018-07-03 15:40:51 +02:00
|
|
|
ds = stix2.TAXIICollectionStore(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
2018-07-11 15:43:37 +02:00
|
|
|
indicators = ds.all_versions('indicator--00000000-0000-4000-8000-000000000001')
|
2018-07-03 13:00:18 +02:00
|
|
|
# There are 3 indicators but 2 share the same 'modified' timestamp
|
|
|
|
assert len(indicators) == 2
|
|
|
|
|
|
|
|
|
|
|
|
def test_can_read_error(collection_no_rw_access):
|
|
|
|
"""create a TAXIICOllectionSource with a taxii2client.Collection
|
|
|
|
instance that does not have read access, check ValueError exception is raised"""
|
|
|
|
|
|
|
|
with pytest.raises(DataSourceError) as excinfo:
|
2018-07-03 15:40:51 +02:00
|
|
|
stix2.TAXIICollectionSource(collection_no_rw_access)
|
2018-07-03 13:00:18 +02:00
|
|
|
assert "Collection object provided does not have read access" in str(excinfo.value)
|
|
|
|
|
|
|
|
|
|
|
|
def test_can_write_error(collection_no_rw_access):
|
|
|
|
"""create a TAXIICOllectionSink with a taxii2client.Collection
|
|
|
|
instance that does not have write access, check ValueError exception is raised"""
|
|
|
|
|
|
|
|
with pytest.raises(DataSourceError) as excinfo:
|
2018-07-03 15:40:51 +02:00
|
|
|
stix2.TAXIICollectionSink(collection_no_rw_access)
|
2018-07-03 13:00:18 +02:00
|
|
|
assert "Collection object provided does not have write access" in str(excinfo.value)
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_404():
|
|
|
|
"""a TAXIICollectionSource.get() call that receives an HTTP 404 response
|
|
|
|
code from the taxii2client should be be returned as None.
|
|
|
|
|
|
|
|
TAXII spec states that a TAXII server can return a 404 for nonexistent
|
|
|
|
resources or lack of access. Decided that None is acceptable reponse
|
|
|
|
to imply that state of the TAXII endpoint.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class TAXIICollection404():
|
|
|
|
can_read = True
|
|
|
|
|
|
|
|
def get_object(self, id, version=None):
|
|
|
|
resp = Response()
|
|
|
|
resp.status_code = 404
|
|
|
|
resp.raise_for_status()
|
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
ds = stix2.TAXIICollectionSource(TAXIICollection404())
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
# this will raise 404 from mock TAXII Client but TAXIICollectionStore
|
|
|
|
# should handle gracefully and return None
|
|
|
|
stix_obj = ds.get("indicator--1")
|
|
|
|
assert stix_obj is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_all_versions_404(collection):
|
|
|
|
""" a TAXIICollectionSource.all_version() call that recieves an HTTP 404
|
|
|
|
response code from the taxii2client should be returned as an exception"""
|
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
ds = stix2.TAXIICollectionStore(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
|
|
|
|
with pytest.raises(DataSourceError) as excinfo:
|
|
|
|
ds.all_versions("indicator--1")
|
|
|
|
assert "are either not found or access is denied" in str(excinfo.value)
|
|
|
|
assert "404" in str(excinfo.value)
|
|
|
|
|
|
|
|
|
|
|
|
def test_query_404(collection):
|
|
|
|
""" a TAXIICollectionSource.query() call that recieves an HTTP 404
|
|
|
|
response code from the taxii2client should be returned as an exception"""
|
|
|
|
|
2018-07-03 15:40:51 +02:00
|
|
|
ds = stix2.TAXIICollectionStore(collection)
|
2018-07-03 13:00:18 +02:00
|
|
|
query = [Filter("type", "=", "malware")]
|
|
|
|
|
|
|
|
with pytest.raises(DataSourceError) as excinfo:
|
|
|
|
ds.query(query=query)
|
|
|
|
assert "are either not found or access is denied" in str(excinfo.value)
|
|
|
|
assert "404" in str(excinfo.value)
|