44import pytest
55from requests .models import Response
66import six
7- from taxii2client import Collection
87from taxii2client .common import _filter_kwargs_to_query_params
8+ from taxii2client .v21 import Collection
99
1010import stix2
1111from stix2 .datastore import DataSourceError
1212from stix2 .datastore .filters import Filter
13+ from stix2 .utils import get_timestamp
1314
1415COLLECTION_URL = 'https://example.com/api1/collections/91a7b528-80eb-42ed-a74d-c6fbd5a26116/'
1516
@@ -22,13 +23,22 @@ def __init__(self, url, collection_info):
2223 url , collection_info = collection_info ,
2324 )
2425 self .objects = []
26+ self .manifests = []
2527
2628 def add_objects (self , bundle ):
2729 self ._verify_can_write ()
2830 if isinstance (bundle , six .string_types ):
2931 bundle = json .loads (bundle , encoding = 'utf-8' )
3032 for object in bundle .get ("objects" , []):
3133 self .objects .append (object )
34+ self .manifests .append (
35+ {
36+ "date_added" : get_timestamp (),
37+ "id" : object ["id" ],
38+ "media_type" : "application/stix+json;version=2.1" ,
39+ "version" : object .get ("modified" , object .get ("created" , get_timestamp ())),
40+ },
41+ )
3242
3343 def get_objects (self , ** filter_kwargs ):
3444 self ._verify_can_read ()
@@ -38,11 +48,10 @@ def get_objects(self, **filter_kwargs):
3848 objs = full_filter .process_filter (
3949 self .objects ,
4050 ("id" , "type" , "version" ),
41- [] ,
42- None ,
51+ self . manifests ,
52+ 100 ,
4353 )[0 ]
4454 if objs :
45- print (objs )
4655 return stix2 .v21 .Bundle (objects = objs )
4756 else :
4857 resp = Response ()
@@ -61,8 +70,8 @@ def get_object(self, id, **filter_kwargs):
6170 filtered_objects = full_filter .process_filter (
6271 objects ,
6372 ("version" ,),
64- [] ,
65- None ,
73+ self . manifests ,
74+ 100 ,
6675 )[0 ]
6776 else :
6877 filtered_objects = []
@@ -75,7 +84,7 @@ def get_object(self, id, **filter_kwargs):
7584
7685
7786@pytest .fixture
78- def collection (stix_objs1 ):
87+ def collection (stix_objs1 , stix_objs1_manifests ):
7988 mock = MockTAXIICollectionEndpoint (
8089 COLLECTION_URL , {
8190 "id" : "91a7b528-80eb-42ed-a74d-c6fbd5a26116" ,
@@ -90,11 +99,12 @@ def collection(stix_objs1):
9099 )
91100
92101 mock .objects .extend (stix_objs1 )
102+ mock .manifests .extend (stix_objs1_manifests )
93103 return mock
94104
95105
96106@pytest .fixture
97- def collection_no_rw_access (stix_objs1 ):
107+ def collection_no_rw_access (stix_objs1 , stix_objs1_manifests ):
98108 mock = MockTAXIICollectionEndpoint (
99109 COLLECTION_URL , {
100110 "id" : "91a7b528-80eb-42ed-a74d-c6fbd5a26116" ,
@@ -109,6 +119,7 @@ def collection_no_rw_access(stix_objs1):
109119 )
110120
111121 mock .objects .extend (stix_objs1 )
122+ mock .manifests .extend (stix_objs1_manifests )
112123 return mock
113124
114125
0 commit comments