formatting

stix2.0
= 2018-05-18 11:45:40 -04:00
parent 6004ec597c
commit e484b7c25f
2 changed files with 10 additions and 5 deletions

View File

@ -268,7 +268,7 @@ class TAXIICollectionSource(DataSource):
# deduplicate data (before filtering as reduces wasted filtering) # deduplicate data (before filtering as reduces wasted filtering)
all_data = deduplicate(all_data) all_data = deduplicate(all_data)
# a pply local (CompositeDataSource, TAXIICollectionSource and query) filters # apply local (CompositeDataSource, TAXIICollectionSource and query) filters
query.remove(taxii_filters) query.remove(taxii_filters)
all_data = list(apply_common_filters(all_data, query)) all_data = list(apply_common_filters(all_data, query))

View File

@ -326,6 +326,7 @@ def test_get_all_versions(collection):
def test_can_read_error(collection_no_rw_access): def test_can_read_error(collection_no_rw_access):
"""create a TAXIICOllectionSource with a taxii2client.Collection """create a TAXIICOllectionSource with a taxii2client.Collection
instance that does not have read access, check ValueError exception is raised""" instance that does not have read access, check ValueError exception is raised"""
with pytest.raises(DataSourceError) as excinfo: with pytest.raises(DataSourceError) as excinfo:
TAXIICollectionSource(collection_no_rw_access) TAXIICollectionSource(collection_no_rw_access)
assert "Collection object provided does not have read access" in str(excinfo.value) assert "Collection object provided does not have read access" in str(excinfo.value)
@ -334,6 +335,7 @@ def test_can_read_error(collection_no_rw_access):
def test_can_write_error(collection_no_rw_access): def test_can_write_error(collection_no_rw_access):
"""create a TAXIICOllectionSink with a taxii2client.Collection """create a TAXIICOllectionSink with a taxii2client.Collection
instance that does not have write access, check ValueError exception is raised""" instance that does not have write access, check ValueError exception is raised"""
with pytest.raises(DataSourceError) as excinfo: with pytest.raises(DataSourceError) as excinfo:
TAXIICollectionSink(collection_no_rw_access) TAXIICollectionSink(collection_no_rw_access)
assert "Collection object provided does not have write access" in str(excinfo.value) assert "Collection object provided does not have write access" in str(excinfo.value)
@ -343,9 +345,9 @@ def test_get_404():
"""a TAXIICollectionSource.get() call that receives an HTTP 404 response """a TAXIICollectionSource.get() call that receives an HTTP 404 response
code from the taxii2client should be be returned as None. code from the taxii2client should be be returned as None.
TAXII spec states that a TAXII server can return a 404 for TAXII spec states that a TAXII server can return a 404 for nonexistent
nonexistent resources or lack of access. Decided that None is acceptable resources or lack of access. Decided that None is acceptable reponse
reponse to imply that state of the TAXII endpoint. to imply that state of the TAXII endpoint.
""" """
class TAXIICollection404(): class TAXIICollection404():
@ -360,14 +362,16 @@ def test_get_404():
# this will raise 404 from mock TAXII Client but TAXIICollectionStore # this will raise 404 from mock TAXII Client but TAXIICollectionStore
# should handle gracefully and return None # should handle gracefully and return None
stix_obj = ds.get("indicator--1") # this will raise 404 from stix_obj = ds.get("indicator--1")
assert stix_obj is None assert stix_obj is None
def test_all_versions_404(collection): def test_all_versions_404(collection):
""" a TAXIICollectionSource.all_version() call that recieves an HTTP 404 """ a TAXIICollectionSource.all_version() call that recieves an HTTP 404
response code from the taxii2client should be returned as an exception""" response code from the taxii2client should be returned as an exception"""
ds = TAXIICollectionStore(collection) ds = TAXIICollectionStore(collection)
with pytest.raises(DataSourceError) as excinfo: with pytest.raises(DataSourceError) as excinfo:
ds.all_versions("indicator--1") ds.all_versions("indicator--1")
assert "are either not found or access is denied" in str(excinfo.value) assert "are either not found or access is denied" in str(excinfo.value)
@ -377,6 +381,7 @@ def test_all_versions_404(collection):
def test_query_404(collection): def test_query_404(collection):
""" a TAXIICollectionSource.query() call that recieves an HTTP 404 """ a TAXIICollectionSource.query() call that recieves an HTTP 404
response code from the taxii2client should be returned as an exception""" response code from the taxii2client should be returned as an exception"""
ds = TAXIICollectionStore(collection) ds = TAXIICollectionStore(collection)
query = [Filter("type", "=", "malware")] query = [Filter("type", "=", "malware")]