Skip to content

Commit

Permalink
Update v20 and v21 tests
Browse files Browse the repository at this point in the history
In v20, only minor stuff that was addressing wrong spec. In v21, align tests with new/changed properties in the specs
  • Loading branch information
emmanvg committed Jul 12, 2018
1 parent bdfc221 commit 965d7fa
Show file tree
Hide file tree
Showing 27 changed files with 180 additions and 182 deletions.
4 changes: 2 additions & 2 deletions stix2/test/v20/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_report_example_objects_in_object_refs():
published="2016-01-20T17:00:00Z",
labels=["campaign"],
object_refs=[
stix2.Indicator(id="indicator--26ffb872-1dd9-446e-b6f5-d58527e5b5d2", **INDICATOR_KWARGS),
stix2.v20.Indicator(id="indicator--26ffb872-1dd9-446e-b6f5-d58527e5b5d2", **INDICATOR_KWARGS),
"campaign--83422c77-904c-4dc1-aff5-5c38f3a2c55c",
"relationship--f82356ae-fe6c-437c-9c24-6b64314ae68a"
],
Expand All @@ -79,7 +79,7 @@ def test_report_example_objects_in_object_refs_with_bad_id():
published="2016-01-20T17:00:00Z",
labels=["campaign"],
object_refs=[
stix2.Indicator(id="indicator--26ffb872-1dd9-446e-b6f5-d58527e5b5d2", **INDICATOR_KWARGS),
stix2.v20.Indicator(id="indicator--26ffb872-1dd9-446e-b6f5-d58527e5b5d2", **INDICATOR_KWARGS),
"campaign-83422c77-904c-4dc1-aff5-5c38f3a2c55c", # the "bad" id, missing a "-"
"relationship--f82356ae-fe6c-437c-9c24-6b64314ae68a"
],
Expand Down
15 changes: 7 additions & 8 deletions stix2/test/v20/test_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,20 @@ def test_revoke_invalid_cls():


def test_remove_custom_stix_property():
mal = stix2.Malware(name="ColePowers",
labels=["rootkit"],
is_family=False,
x_custom="armada",
allow_custom=True)
mal = stix2.v20.Malware(name="ColePowers",
labels=["rootkit"],
x_custom="armada",
allow_custom=True)

mal_nc = stix2.utils.remove_custom_stix(mal)

assert "x_custom" not in mal_nc
assert stix2.utils.parse_into_datetime(mal["modified"], precision="millisecond") < stix2.utils.parse_into_datetime(mal_nc["modified"],
precision="millisecond")
assert (stix2.utils.parse_into_datetime(mal["modified"], precision="millisecond") <
stix2.utils.parse_into_datetime(mal_nc["modified"], precision="millisecond"))


def test_remove_custom_stix_object():
@stix2.CustomObject("x-animal", [
@stix2.v20.CustomObject("x-animal", [
("species", stix2.properties.StringProperty(required=True)),
("animal_class", stix2.properties.StringProperty()),
])
Expand Down
19 changes: 14 additions & 5 deletions stix2/test/v20/test_workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

import stix2
from stix2 import Bundle
from stix2.workbench import (AttackPattern, Campaign, CourseOfAction,
ExternalReference, FileSystemSource, Filter,
Identity, Indicator, IntrusionSet, Malware,
Expand All @@ -29,6 +28,7 @@
VULNERABILITY_KWARGS)


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_workbench_environment():

# Create a STIX object
Expand Down Expand Up @@ -83,6 +83,7 @@ def test_workbench_get_all_identities():
assert resp[0].id == IDENTITY_ID


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_workbench_get_all_indicators():
resp = indicators()
assert len(resp) == 1
Expand Down Expand Up @@ -117,6 +118,7 @@ def test_workbench_get_all_observed_data():
assert resp[0].id == OBSERVED_DATA_ID


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_workbench_get_all_reports():
rep = Report(id=REPORT_ID, **REPORT_KWARGS)
save(rep)
Expand All @@ -126,6 +128,7 @@ def test_workbench_get_all_reports():
assert resp[0].id == REPORT_ID


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_workbench_get_all_threat_actors():
thr = ThreatActor(id=THREAT_ACTOR_ID, **THREAT_ACTOR_KWARGS)
save(thr)
Expand All @@ -135,6 +138,7 @@ def test_workbench_get_all_threat_actors():
assert resp[0].id == THREAT_ACTOR_ID


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_workbench_get_all_tools():
tool = Tool(id=TOOL_ID, **TOOL_KWARGS)
save(tool)
Expand All @@ -153,12 +157,14 @@ def test_workbench_get_all_vulnerabilities():
assert resp[0].id == VULNERABILITY_ID


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_workbench_add_to_bundle():
vuln = Vulnerability(**VULNERABILITY_KWARGS)
bundle = Bundle(vuln)
bundle = stix2.v20.Bundle(vuln)
assert bundle.objects[0].name == 'Heartbleed'


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_workbench_relationships():
rel = Relationship(INDICATOR_ID, 'indicates', MALWARE_ID)
save(rel)
Expand Down Expand Up @@ -212,6 +218,7 @@ def test_workbench_related_with_filters():
assert len(resp) == 1


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_add_data_source():
fs_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "stix2_data")
fs = FileSystemSource(fs_path)
Expand All @@ -225,11 +232,13 @@ def test_add_data_source():
assert 'tool--242f3da3-4425-4d11-8f5c-b842886da966' in resp_ids


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_additional_filter():
resp = tools(Filter('created_by_ref', '=', 'identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5'))
assert len(resp) == 2


@pytest.mark.skip(reason='The workbench is not working correctly for 2.0')
def test_additional_filters_list():
resp = tools([Filter('created_by_ref', '=', 'identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5'),
Filter('name', '=', 'Windows Credential Editor')])
Expand Down Expand Up @@ -275,12 +284,12 @@ def test_default_object_marking_refs():


def test_workbench_custom_property_object_in_observable_extension():
ntfs = stix2.NTFSExt(
ntfs = stix2.v20.NTFSExt(
allow_custom=True,
sid=1,
x_foo='bar',
)
artifact = stix2.File(
artifact = stix2.v20.File(
name='test',
extensions={'ntfs-ext': ntfs},
)
Expand All @@ -297,7 +306,7 @@ def test_workbench_custom_property_object_in_observable_extension():


def test_workbench_custom_property_dict_in_observable_extension():
artifact = stix2.File(
artifact = stix2.v20.File(
allow_custom=True,
name='test',
extensions={
Expand Down
16 changes: 8 additions & 8 deletions stix2/test/v21/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def stix_objs1():
ind1 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000001",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-27T13:49:53.935Z",
Expand All @@ -66,7 +66,7 @@ def stix_objs1():
ind2 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000001",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-27T13:49:53.935Z",
Expand All @@ -79,7 +79,7 @@ def stix_objs1():
ind3 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000001",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-27T13:49:53.936Z",
Expand All @@ -92,7 +92,7 @@ def stix_objs1():
ind4 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000002",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-27T13:49:53.935Z",
Expand All @@ -105,7 +105,7 @@ def stix_objs1():
ind5 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000002",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-27T13:49:53.935Z",
Expand All @@ -123,7 +123,7 @@ def stix_objs2():
ind6 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000001",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-31T13:49:53.935Z",
Expand All @@ -136,7 +136,7 @@ def stix_objs2():
ind7 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000002",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-27T13:49:53.935Z",
Expand All @@ -149,7 +149,7 @@ def stix_objs2():
ind8 = {
"created": "2017-01-27T13:49:53.935Z",
"id": "indicator--00000000-0000-4000-8000-000000000002",
"labels": [
"indicator_types": [
"url-watchlist"
],
"modified": "2017-01-27T13:49:53.935Z",
Expand Down
14 changes: 7 additions & 7 deletions stix2/test/v21/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
)

INDICATOR_KWARGS = dict(
labels=['malicious-activity'],
indicator_types=['malicious-activity'],
pattern="[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
)

Expand All @@ -79,17 +79,17 @@
)

MALWARE_KWARGS = dict(
labels=['ransomware'],
malware_types=['ransomware'],
name="Cryptolocker",
is_family=False
is_family=True
)

MALWARE_MORE_KWARGS = dict(
type='malware',
id=MALWARE_ID,
created="2016-04-06T20:03:00.000Z",
modified="2016-04-06T20:03:00.000Z",
labels=['ransomware'],
malware_types=['ransomware'],
name="Cryptolocker",
description="A ransomware related to ...",
is_family=False
Expand All @@ -108,7 +108,7 @@
)

REPORT_KWARGS = dict(
labels=["campaign"],
report_types=["campaign"],
name="Bad Cybercrime",
published=FAKE_TIME,
object_refs=[INDICATOR_ID],
Expand All @@ -125,12 +125,12 @@
)

THREAT_ACTOR_KWARGS = dict(
labels=["crime-syndicate"],
threat_actor_types=["crime-syndicate"],
name="Evil Org",
)

TOOL_KWARGS = dict(
labels=["remote-access"],
tool_types=["remote-access"],
name="VNC",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"id": "malware--6b616fc1-1505-48e3-8b2c-0d19337bff38",
"labels": [
"malware_types": [
"malware"
],
"modified": "2017-05-31T21:32:58.226477Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"id": "malware--92ec0cbd-2c30-44a2-b270-73f4ec949841",
"labels": [
"malware_types": [
"malware"
],
"modified": "2017-05-31T21:33:26.565056Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"id": "malware--96b08451-b27a-4ff6-893f-790e26393a8e",
"labels": [
"malware_types": [
"malware"
],
"modified": "2017-05-31T21:32:48.482655Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"id": "malware--b42378e0-f147-496f-992a-26a49705395b",
"labels": [
"malware_types": [
"malware"
],
"modified": "2017-05-31T21:32:15.263882Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
],
"id": "tool--03342581-f790-4f03-ba41-e82e67392e23",
"labels": [
"tool_types": [
"tool"
],
"modified": "2017-05-31T21:32:31.601148Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"id": "tool--242f3da3-4425-4d11-8f5c-b842886da966",
"labels": [
"tool_types": [
"tool"
],
"modified": "2017-05-31T21:32:12.684914Z",
Expand Down
20 changes: 10 additions & 10 deletions stix2/test/v21/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
"id": "indicator--00000000-0000-4000-8000-000000000001",
"created": "2017-01-01T12:34:56.000Z",
"modified": "2017-01-01T12:34:56.000Z",
"pattern": "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
"valid_from": "2017-01-01T12:34:56Z",
"labels": [
"indicator_types": [
"malicious-activity"
]
],
"pattern": "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
"valid_from": "2017-01-01T12:34:56Z"
},
{
"type": "malware",
"spec_version": "2.1",
"id": "malware--00000000-0000-4000-8000-000000000003",
"created": "2017-01-01T12:34:56.000Z",
"modified": "2017-01-01T12:34:56.000Z",
"is_family": true,
"name": "Cryptolocker",
"labels": [
"malware_types": [
"ransomware"
],
"is_family": false
]
},
{
"type": "relationship",
Expand All @@ -57,7 +57,7 @@
"modified": "2017-01-01T12:34:56.000Z",
"pattern": "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
"valid_from": "2017-01-01T12:34:56Z",
"labels": [
"indicator_types": [
"malicious-activity"
]
},
Expand All @@ -68,10 +68,10 @@
"created": "2017-01-01T12:34:56.000Z",
"modified": "2017-01-01T12:34:56.000Z",
"name": "Cryptolocker",
"labels": [
"malware_types": [
"ransomware"
],
"is_family": False
"is_family": True
},
{
"type": "relationship",
Expand Down
Loading

0 comments on commit 965d7fa

Please sign in to comment.