2017-03-22 13:46:39 +01:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import stix2
|
|
|
|
|
2017-05-09 21:10:53 +02:00
|
|
|
from .constants import (FAKE_TIME, INDICATOR_KWARGS, MALWARE_KWARGS,
|
|
|
|
RELATIONSHIP_KWARGS)
|
2017-03-22 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Inspired by: http://stackoverflow.com/a/24006251
|
|
|
|
@pytest.fixture
|
|
|
|
def clock(monkeypatch):
|
|
|
|
|
2017-06-23 00:47:35 +02:00
|
|
|
class mydatetime(stix2.utils.STIXdatetime):
|
2017-03-22 13:46:39 +01:00
|
|
|
@classmethod
|
|
|
|
def now(cls, tz=None):
|
|
|
|
return FAKE_TIME
|
|
|
|
|
2017-06-23 00:47:35 +02:00
|
|
|
monkeypatch.setattr(stix2.utils, 'STIXdatetime', mydatetime)
|
2017-03-22 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def uuid4(monkeypatch):
|
|
|
|
def wrapper():
|
|
|
|
data = [0]
|
|
|
|
|
|
|
|
def wrapped():
|
|
|
|
data[0] += 1
|
2018-06-27 18:34:49 +02:00
|
|
|
return "00000000-0000-4000-8000-00000000%04x" % data[0]
|
2017-03-22 13:46:39 +01:00
|
|
|
|
|
|
|
return wrapped
|
|
|
|
monkeypatch.setattr(uuid, "uuid4", wrapper())
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def indicator(uuid4, clock):
|
|
|
|
return stix2.Indicator(**INDICATOR_KWARGS)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def malware(uuid4, clock):
|
|
|
|
return stix2.Malware(**MALWARE_KWARGS)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def relationship(uuid4, clock):
|
|
|
|
return stix2.Relationship(**RELATIONSHIP_KWARGS)
|
2018-04-06 20:19:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2018-04-23 15:08:29 +02:00
|
|
|
def stix_objs1():
|
2018-04-06 20:19:51 +02:00
|
|
|
ind1 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
ind2 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
ind3 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.936Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
ind4 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
ind5 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
return [ind1, ind2, ind3, ind4, ind5]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2018-04-23 15:08:29 +02:00
|
|
|
def stix_objs2():
|
2018-04-06 20:19:51 +02:00
|
|
|
ind6 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000001",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-31T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
ind7 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
ind8 = {
|
|
|
|
"created": "2017-01-27T13:49:53.935Z",
|
2018-06-27 18:34:49 +02:00
|
|
|
"id": "indicator--00000000-0000-4000-8000-000000000002",
|
2018-04-06 20:19:51 +02:00
|
|
|
"labels": [
|
|
|
|
"url-watchlist"
|
|
|
|
],
|
|
|
|
"modified": "2017-01-27T13:49:53.935Z",
|
|
|
|
"name": "Malicious site hosting downloader",
|
|
|
|
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
|
|
|
"type": "indicator",
|
|
|
|
"valid_from": "2017-01-27T13:49:53.935382Z"
|
|
|
|
}
|
|
|
|
return [ind6, ind7, ind8]
|
2018-04-23 20:12:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def real_stix_objs2(stix_objs2):
|
|
|
|
return [stix2.parse(x) for x in stix_objs2]
|