Skip to content

Commit 6c3a689

Browse files
fixed indentation
1 parent 03f9af4 commit 6c3a689

File tree

1 file changed

+120
-125
lines changed

1 file changed

+120
-125
lines changed

stix2/test/test_data_sources.py

Lines changed: 120 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -7,138 +7,133 @@
77
#Data Source (common API)
88

99

10-
11-
12-
1310
#TAXII
1411
def test_ds_taxii():
15-
ds = taxii.TAXIIDataSource()
16-
assert ds.name == 'TAXII'
12+
ds = taxii.TAXIIDataSource()
13+
assert ds.name == 'TAXII'
1714

1815
def test_ds_taxii_name():
19-
ds = taxii.TAXIIDataSource(name='My Data Source Name')
20-
assert ds.name == "My Data Source Name"
16+
ds = taxii.TAXIIDataSource(name='My Data Source Name')
17+
assert ds.name == "My Data Source Name"
2118

2219
def test_ds_params():
23-
url = "http://taxii_url.com:5000"
24-
creds = {"username":"Wade", "password":"Wilson"}
25-
ds = taxii.TAXIIDataSource(api_root=url,
26-
auth= creds)
27-
assert ds.taxii_info['api_root']['url'] == url
28-
assert ds.taxii_info['auth'] == creds
20+
url = "http://taxii_url.com:5000"
21+
creds = {"username":"Wade", "password":"Wilson"}
22+
ds = taxii.TAXIIDataSource(api_root=url,
23+
auth= creds)
24+
assert ds.taxii_info['api_root']['url'] == url
25+
assert ds.taxii_info['auth'] == creds
2926

3027
def test_parse_taxii_filters():
31-
query = [
32-
{
33-
"field":"added_after",
34-
"op":"=",
35-
"value":"2016-02-01T00:00:01.000Z"
36-
},
37-
{
38-
"field":"id",
39-
"op":"=",
40-
"value":"taxii stix object ID"
41-
},
42-
{
43-
"field":"type",
44-
"op":"=",
45-
"value":"taxii stix object ID"
46-
},
47-
{
48-
"field":"version",
49-
"op":"=",
50-
"value":"first"
51-
},
52-
{
53-
"field":"created_by_ref",
54-
"op":"=",
55-
"value":"Bane"
56-
}
57-
]
58-
59-
expected_params = {
60-
"added_after":"2016-02-01T00:00:01.000Z",
61-
"match[id]":"taxii stix object ID",
62-
"match[type]":"taxii stix object ID",
63-
"match[version]":"first"
64-
}
65-
66-
ds = taxii.TAXIIDataSource()
67-
68-
taxii_filters = ds._parse_taxii_filters(query)
69-
70-
assert taxii_filters == expected_params
71-
72-
73-
def test_add_get_filter():
74-
class dummy(object):
75-
x = 4
76-
77-
obj_1 = dummy()
78-
79-
#First 3 filters are valid, remaining fields are erroneous in some way
80-
filters = [
81-
{
82-
"field": "type",
83-
"op": '=',
84-
"value":"malware"
85-
},
86-
{
87-
"field":"id",
88-
"op":"!=",
89-
"value":"stix object id"
90-
},
91-
{
92-
"field":"labels",
93-
"op":"in",
94-
"value":["heartbleed","malicious-activity"]
95-
},
96-
{
97-
"field":"revoked",
98-
"value":"filter missing \'op\' field"
99-
},
100-
{
101-
"field":"granular_markings",
102-
"op":"=",
103-
"value":"not supported field - just place holder"
104-
},
105-
{
106-
"field":"modified",
107-
"op":"*",
108-
"value":"not supported operator - just place holder"
109-
},
110-
{
111-
"field":"created",
112-
"op":"=",
113-
"value":obj_1
114-
}
115-
]
116-
117-
expected_errors =[
118-
"Filter was missing a required field(key). Each filter requires 'field', 'op', 'value' keys.",
119-
"Filter 'field' is not a STIX 2.0 common property. Currently only STIX object common properties supported",
120-
"Filter operation(from 'op' field) not supported",
121-
"Filter 'value' type is not supported. The type(value) must be python immutable type or dictionary"
122-
]
123-
124-
ds = taxii.TAXIIDataSource()
125-
ids, statuses = ds.add_filter(filters)
126-
127-
#7 filters should have been successfully added
128-
assert len(ids) == 7
129-
130-
#all filters added to data source
131-
for idx, status in enumerate(statuses):
132-
assert status['filter'] == filters[idx]
133-
134-
#proper status warnings were triggered
135-
assert statuses[3]['errors'][0]== expected_errors[0]
136-
assert statuses[4]['errors'][0]== expected_errors[1]
137-
assert statuses[5]['errors'][0]== expected_errors[2]
138-
assert statuses[6]['errors'][0]== expected_errors[3]
139-
140-
141-
28+
query = [
29+
{
30+
"field":"added_after",
31+
"op":"=",
32+
"value":"2016-02-01T00:00:01.000Z"
33+
},
34+
{
35+
"field":"id",
36+
"op":"=",
37+
"value":"taxii stix object ID"
38+
},
39+
{
40+
"field":"type",
41+
"op":"=",
42+
"value":"taxii stix object ID"
43+
},
44+
{
45+
"field":"version",
46+
"op":"=",
47+
"value":"first"
48+
},
49+
{
50+
"field":"created_by_ref",
51+
"op":"=",
52+
"value":"Bane"
53+
}
54+
]
55+
56+
expected_params = {
57+
"added_after":"2016-02-01T00:00:01.000Z",
58+
"match[id]":"taxii stix object ID",
59+
"match[type]":"taxii stix object ID",
60+
"match[version]":"first"
61+
}
62+
63+
ds = taxii.TAXIIDataSource()
64+
65+
taxii_filters = ds._parse_taxii_filters(query)
66+
67+
assert taxii_filters == expected_params
68+
69+
70+
def test_add_get_remove_filter():
71+
class dummy(object):
72+
x = 4
73+
74+
obj_1 = dummy()
75+
76+
#First 3 filters are valid, remaining fields are erroneous in some way
77+
filters = [
78+
{
79+
"field": "type",
80+
"op": '=',
81+
"value":"malware"
82+
},
83+
{
84+
"field":"id",
85+
"op":"!=",
86+
"value":"stix object id"
87+
},
88+
{
89+
"field":"labels",
90+
"op":"in",
91+
"value":["heartbleed","malicious-activity"]
92+
},
93+
{
94+
"field":"revoked",
95+
"value":"filter missing \'op\' field"
96+
},
97+
{
98+
"field":"granular_markings",
99+
"op":"=",
100+
"value":"not supported field - just place holder"
101+
},
102+
{
103+
"field":"modified",
104+
"op":"*",
105+
"value":"not supported operator - just place holder"
106+
},
107+
{
108+
"field":"created",
109+
"op":"=",
110+
"value":obj_1
111+
}
112+
]
113+
114+
expected_errors =[
115+
"Filter was missing a required field(key). Each filter requires 'field', 'op', 'value' keys.",
116+
"Filter 'field' is not a STIX 2.0 common property. Currently only STIX object common properties supported",
117+
"Filter operation(from 'op' field) not supported",
118+
"Filter 'value' type is not supported. The type(value) must be python immutable type or dictionary"
119+
]
120+
121+
ds = taxii.TAXIIDataSource()
122+
#add
123+
ids, statuses = ds.add_filter(filters)
124+
125+
#7 filters should have been successfully added
126+
assert len(ids) == 7
127+
128+
#all filters added to data source
129+
for idx, status in enumerate(statuses):
130+
assert status['filter'] == filters[idx]
131+
132+
#proper status warnings were triggered
133+
assert statuses[3]['errors'][0] == expected_errors[0]
134+
assert statuses[4]['errors'][0] == expected_errors[1]
135+
assert statuses[5]['errors'][0] == expected_errors[2]
136+
assert statuses[6]['errors'][0] == expected_errors[3]
142137

143138

144139

@@ -166,7 +161,7 @@ def test_data_source_get():
166161
167162
#filter testing
168163
def test_add_filter():
169-
ds = file.FileDataSource()
164+
ds = file.FileDataSource()
170165
171166
172167
'''

0 commit comments

Comments
 (0)