Update to get tests passing
parent
b82606ba38
commit
b8c96e37a2
|
@ -292,7 +292,7 @@ class DataSource(object):
|
||||||
"status": "added as a common filter",
|
"status": "added as a common filter",
|
||||||
"filter": filter_,
|
"filter": filter_,
|
||||||
"data_source_name": self.name,
|
"data_source_name": self.name,
|
||||||
"data_source_id": self.id_
|
"data_source_id": self.id,
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
self.filter_allowed[id_] = False
|
self.filter_allowed[id_] = False
|
||||||
|
@ -301,7 +301,7 @@ class DataSource(object):
|
||||||
"filter": filter_,
|
"filter": filter_,
|
||||||
"errors": copy.deepcopy(errors),
|
"errors": copy.deepcopy(errors),
|
||||||
"data_source_name": self.name,
|
"data_source_name": self.name,
|
||||||
"data_source_id": self.id_
|
"data_source_id": self.id,
|
||||||
})
|
})
|
||||||
del errors[:]
|
del errors[:]
|
||||||
|
|
||||||
|
@ -661,7 +661,7 @@ class CompositeDataSource(object):
|
||||||
"status": "added as a common filter",
|
"status": "added as a common filter",
|
||||||
"filter": filter_,
|
"filter": filter_,
|
||||||
"data_source_name": self.name,
|
"data_source_name": self.name,
|
||||||
"data_source_id": self.id_
|
"data_source_id": self.id
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
self.filter_allowed[id_] = False
|
self.filter_allowed[id_] = False
|
||||||
|
@ -670,7 +670,7 @@ class CompositeDataSource(object):
|
||||||
"filter": filter_,
|
"filter": filter_,
|
||||||
"errors": errors,
|
"errors": errors,
|
||||||
"data_source_name": self.name,
|
"data_source_name": self.name,
|
||||||
"data_source_id": self.id_
|
"data_source_id": self.id
|
||||||
})
|
})
|
||||||
del errors[:]
|
del errors[:]
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
from taxii2_client import Collection
|
from taxii2_client import Collection
|
||||||
|
|
||||||
from stix2.sources import taxii
|
from stix2.sources import DataSource, taxii
|
||||||
|
|
||||||
COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/'
|
COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/'
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ def test_ds_taxii_name(collection):
|
||||||
assert ds.name == "My Data Source Name"
|
assert ds.name == "My Data Source Name"
|
||||||
|
|
||||||
|
|
||||||
def test_parse_taxii_filters(collection):
|
def test_parse_taxii_filters():
|
||||||
query = [
|
query = [
|
||||||
{
|
{
|
||||||
"field": "added_after",
|
"field": "added_after",
|
||||||
|
@ -74,12 +74,7 @@ def test_parse_taxii_filters(collection):
|
||||||
assert taxii_filters == expected_params
|
assert taxii_filters == expected_params
|
||||||
|
|
||||||
|
|
||||||
def test_add_get_remove_filter(collection):
|
def test_add_get_remove_filter():
|
||||||
|
|
||||||
class dummy(object):
|
|
||||||
x = 4
|
|
||||||
|
|
||||||
obj_1 = dummy()
|
|
||||||
|
|
||||||
# First 3 filters are valid, remaining fields are erroneous in some way
|
# First 3 filters are valid, remaining fields are erroneous in some way
|
||||||
filters = [
|
filters = [
|
||||||
|
@ -103,7 +98,7 @@ def test_add_get_remove_filter(collection):
|
||||||
"value": "filter missing \'op\' field"
|
"value": "filter missing \'op\' field"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "granular_markings",
|
"field": "description",
|
||||||
"op": "=",
|
"op": "=",
|
||||||
"value": "not supported field - just place holder"
|
"value": "not supported field - just place holder"
|
||||||
},
|
},
|
||||||
|
@ -115,7 +110,7 @@ def test_add_get_remove_filter(collection):
|
||||||
{
|
{
|
||||||
"field": "created",
|
"field": "created",
|
||||||
"op": "=",
|
"op": "=",
|
||||||
"value": obj_1
|
"value": set(),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -126,7 +121,7 @@ def test_add_get_remove_filter(collection):
|
||||||
"Filter 'value' type is not supported. The type(value) must be python immutable type or dictionary"
|
"Filter 'value' type is not supported. The type(value) must be python immutable type or dictionary"
|
||||||
]
|
]
|
||||||
|
|
||||||
ds = taxii.TAXIICollectionSource(collection)
|
ds = DataSource()
|
||||||
# add
|
# add
|
||||||
ids, statuses = ds.add_filter(filters)
|
ids, statuses = ds.add_filter(filters)
|
||||||
|
|
||||||
|
@ -168,7 +163,7 @@ def test_add_get_remove_filter(collection):
|
||||||
assert id_ in ids[:3]
|
assert id_ in ids[:3]
|
||||||
|
|
||||||
|
|
||||||
def test_apply_common_filters(collection):
|
def test_apply_common_filters():
|
||||||
stix_objs = [
|
stix_objs = [
|
||||||
{
|
{
|
||||||
"created": "2017-01-27T13:49:53.997Z",
|
"created": "2017-01-27T13:49:53.997Z",
|
||||||
|
@ -218,11 +213,11 @@ def test_apply_common_filters(collection):
|
||||||
{
|
{
|
||||||
"field": "labels",
|
"field": "labels",
|
||||||
"op": "in",
|
"op": "in",
|
||||||
"value": "trojan"
|
"value": "remote-access-trojan"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
ds = taxii.TAXIICollectionSource(collection)
|
ds = DataSource()
|
||||||
|
|
||||||
resp = ds.apply_common_filters(stix_objs, [filters[0]])
|
resp = ds.apply_common_filters(stix_objs, [filters[0]])
|
||||||
ids = [r['id'] for r in resp]
|
ids = [r['id'] for r in resp]
|
||||||
|
@ -236,7 +231,7 @@ def test_apply_common_filters(collection):
|
||||||
assert resp[0]['id'] == stix_objs[0]['id']
|
assert resp[0]['id'] == stix_objs[0]['id']
|
||||||
|
|
||||||
|
|
||||||
def test_deduplicate(collection):
|
def test_deduplicate():
|
||||||
stix_objs = [
|
stix_objs = [
|
||||||
{
|
{
|
||||||
"created": "2017-01-27T13:49:53.935Z",
|
"created": "2017-01-27T13:49:53.935Z",
|
||||||
|
@ -300,7 +295,7 @@ def test_deduplicate(collection):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
ds = taxii.TAXIICollectionSource(collection)
|
ds = DataSource()
|
||||||
unique = ds.deduplicate(stix_objs)
|
unique = ds.deduplicate(stix_objs)
|
||||||
|
|
||||||
# Only 3 objects are unique
|
# Only 3 objects are unique
|
||||||
|
|
Loading…
Reference in New Issue