Skip to content

Commit

Permalink
flaky 3
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiazza committed Apr 16, 2024
1 parent 3c92d7c commit b8782e3
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 126 deletions.
8 changes: 4 additions & 4 deletions stix2/test/v21/test_artifact.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand Down Expand Up @@ -35,6 +33,7 @@
True,
)


def test_basic_artifact():
store.sink.generate_stix_schema()
artifact_stix_object = stix2.parse(basic_artifact_dict)
Expand All @@ -44,13 +43,14 @@ def test_basic_artifact():
for attrib in basic_artifact_dict.keys():
assert basic_artifact_dict[attrib] == read_obj[attrib]


def test_encrypted_artifact():
store.sink.generate_stix_schema()
artifact_stix_object = stix2.parse(encrypted_artifact_dict)
store.add(artifact_stix_object)
read_obj = json.loads(store.get(artifact_stix_object['id']).serialize())

for attrib in encrypted_artifact_dict.keys():
if attrib == 'hashes': # TODO hashes are saved to separate table, functionality to retrieve is WIP
if attrib == 'hashes': # TODO hashes are saved to separate table, functionality to retrieve is WIP
continue
assert encrypted_artifact_dict[attrib] == read_obj[attrib]
assert encrypted_artifact_dict[attrib] == read_obj[attrib]
5 changes: 2 additions & 3 deletions stix2/test/v21/test_autonomous_system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore

Expand All @@ -21,11 +19,12 @@
True,
)


def test_autonomous_system():
store.sink.generate_stix_schema()
as_obj = stix2.parse(as_dict)
store.add(as_obj)
read_obj = json.loads(store.get(as_obj['id']).serialize())

for attrib in as_dict.keys():
assert as_dict[attrib] == read_obj[attrib]
assert as_dict[attrib] == read_obj[attrib]
8 changes: 3 additions & 5 deletions stix2/test/v21/test_directory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore

Expand All @@ -26,17 +24,17 @@
True,
)


def test_directory():
store.sink.generate_stix_schema()
directory_obj = stix2.parse(directory_dict)
store.add(directory_obj)
read_obj = json.loads(store.get(directory_obj['id']).serialize())

for attrib in directory_dict.keys():
if attrib == "contains_refs": # TODO remove skip once we can pull from table join
if attrib == "contains_refs": # TODO remove skip once we can pull from table join
continue
if attrib == "ctime" or attrib == "mtime": # convert both into stix2 date format for consistency
if attrib == "ctime" or attrib == "mtime": # convert both into stix2 date format for consistency
assert stix2.utils.parse_into_datetime(directory_dict[attrib]) == stix2.utils.parse_into_datetime(read_obj[attrib])
continue
assert directory_dict[attrib] == read_obj[attrib]

5 changes: 2 additions & 3 deletions stix2/test/v21/test_domain_name.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore

Expand All @@ -19,11 +17,12 @@
True,
)


def test_autonomous_system():
store.sink.generate_stix_schema()
domain_name_obj = stix2.parse(domain_name_dict)
store.add(domain_name_obj)
read_obj = json.loads(store.get(domain_name_obj['id']).serialize())

for attrib in domain_name_dict.keys():
assert domain_name_dict[attrib] == read_obj[attrib]
assert domain_name_dict[attrib] == read_obj[attrib]
3 changes: 1 addition & 2 deletions stix2/test/v21/test_email_address.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand All @@ -22,6 +20,7 @@
True,
)


def test_email_addr():
store.sink.generate_stix_schema()
email_addr_stix_object = stix2.parse(email_addr_dict)
Expand Down
35 changes: 19 additions & 16 deletions stix2/test/v21/test_email_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand Down Expand Up @@ -63,19 +61,19 @@
},
"body_multipart": [
{
"content_type": "text/plain; charset=utf-8",
"content_disposition": "inline",
"body": "Cats are funny!",
"content_type": "text/plain; charset=utf-8",
"content_disposition": "inline",
"body": "Cats are funny!",
},
{
"content_type": "image/png",
"content_disposition": "attachment; filename=\"tabby.png\"",
"body_raw_ref": "artifact--4cce66f8-6eaa-53cb-85d5-3a85fca3a6c5",
"content_type": "image/png",
"content_disposition": "attachment; filename=\"tabby.png\"",
"body_raw_ref": "artifact--4cce66f8-6eaa-53cb-85d5-3a85fca3a6c5",
},
{
"content_type": "application/zip",
"content_disposition": "attachment; filename=\"tabby_pics.zip\"",
"body_raw_ref": "file--6ce09d9c-0ad3-5ebf-900c-e3cb288955b5",
"content_type": "application/zip",
"content_disposition": "attachment; filename=\"tabby_pics.zip\"",
"body_raw_ref": "file--6ce09d9c-0ad3-5ebf-900c-e3cb288955b5",
},
],
}
Expand All @@ -87,6 +85,7 @@
True,
)


def test_email_msg():
store.sink.generate_stix_schema()
email_msg_stix_object = stix2.parse(email_msg_dict)
Expand All @@ -95,13 +94,16 @@ def test_email_msg():

for attrib in email_msg_dict.keys():
if attrib == "to_refs" or attrib == "cc_refs" or attrib == "bcc_refs" \
or attrib == "additional_header_fields": # join multiple tables not implemented yet
or attrib == "additional_header_fields": # join multiple tables not implemented yet
continue
if attrib == "date":
assert stix2.utils.parse_into_datetime(email_msg_dict[attrib]) == stix2.utils.parse_into_datetime(read_obj[attrib])
assert stix2.utils.parse_into_datetime(email_msg_dict[attrib]) == stix2.utils.parse_into_datetime(
read_obj[attrib],
)
continue
assert email_msg_dict[attrib] == read_obj[attrib]


def test_multipart_email_msg():
store.sink.generate_stix_schema()
multipart_email_msg_stix_object = stix2.parse(multipart_email_msg_dict)
Expand All @@ -110,10 +112,11 @@ def test_multipart_email_msg():

for attrib in multipart_email_msg_dict.keys():
if attrib == "to_refs" or attrib == "cc_refs" or attrib == "bcc_refs" \
or attrib == "additional_header_fields" or attrib == "body_multipart": # join multiple tables not implemented yet
or attrib == "additional_header_fields" or attrib == "body_multipart": # join multiple tables not implemented yet
continue
if attrib == "date":
assert stix2.utils.parse_into_datetime(multipart_email_msg_dict[attrib]) == stix2.utils.parse_into_datetime(read_obj[attrib])
assert stix2.utils.parse_into_datetime(multipart_email_msg_dict[attrib]) == stix2.utils.parse_into_datetime(
read_obj[attrib],
)
continue
assert multipart_email_msg_dict[attrib] == read_obj[attrib]

6 changes: 2 additions & 4 deletions stix2/test/v21/test_file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand Down Expand Up @@ -36,6 +34,7 @@
True,
)


def test_file():
store.sink.generate_stix_schema()
file_stix_object = stix2.parse(file_dict)
Expand All @@ -44,10 +43,9 @@ def test_file():
read_obj = json.loads(store.get(file_stix_object['id']).serialize())

for attrib in file_dict.keys():
if attrib == "contains_refs" or attrib == "hashes": # join multiple tables not implemented yet
if attrib == "contains_refs" or attrib == "hashes": # join multiple tables not implemented yet
continue
if attrib == "ctime" or attrib == "mtime" or attrib == "atime":
assert stix2.utils.parse_into_datetime(file_dict[attrib]) == stix2.utils.parse_into_datetime(read_obj[attrib])
continue
assert file_dict[attrib] == read_obj[attrib]

6 changes: 1 addition & 5 deletions stix2/test/v21/test_ipv4_ipv6.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand All @@ -27,6 +23,7 @@
True,
)


def test_ipv4():
store.sink.generate_stix_schema()
ipv4_stix_object = stix2.parse(ipv4_dict)
Expand All @@ -45,4 +42,3 @@ def test_ipv6():

for attrib in ipv6_dict.keys():
assert ipv6_dict[attrib] == read_obj[attrib]

6 changes: 1 addition & 5 deletions stix2/test/v21/test_mutex.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand All @@ -20,6 +16,7 @@
True,
)


def test_mutex():
store.sink.generate_stix_schema()
mutex_stix_object = stix2.parse(mutex_dict)
Expand All @@ -28,4 +25,3 @@ def test_mutex():

for attrib in mutex_dict.keys():
assert mutex_dict[attrib] == read_obj[attrib]

12 changes: 3 additions & 9 deletions stix2/test/v21/test_network_traffic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand Down Expand Up @@ -29,7 +25,7 @@
"dst_packets": 100,
"src_payload_ref": "artifact--3857f78d-7d16-5092-99fe-ecff58408b02",
"dst_payload_ref": "artifact--3857f78d-7d16-5092-99fe-ecff58408b03",
"encapsulates_refs" : [
"encapsulates_refs": [
"network-traffic--53e0bf48-2eee-5c03-8bde-ed7049d2c0a3",
"network-traffic--53e0bf48-2eee-5c03-8bde-ed7049d2c0a4",
],
Expand All @@ -43,19 +39,17 @@
True,
)


def test_network_traffic():
store.sink.generate_stix_schema()
network_traffic_stix_object = stix2.parse(network_traffic_dict)
store.add(network_traffic_stix_object)
read_obj = store.get(network_traffic_stix_object['id'])

for attrib in network_traffic_dict.keys():
if attrib == "encapsulates_refs": # multiple table join not implemented
if attrib == "encapsulates_refs": # multiple table join not implemented
continue
if attrib == "start" or attrib == "end":
assert stix2.utils.parse_into_datetime(network_traffic_dict[attrib]) == stix2.utils.parse_into_datetime(read_obj[attrib])
continue
assert network_traffic_dict[attrib] == read_obj[attrib]



7 changes: 3 additions & 4 deletions stix2/test/v21/test_process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand Down Expand Up @@ -37,6 +35,7 @@
True,
)


def test_process():
store.sink.generate_stix_schema()
process_stix_object = stix2.parse(process_dict)
Expand All @@ -45,10 +44,10 @@ def test_process():
read_obj = json.loads(store.get(process_stix_object['id']).serialize())

for attrib in process_dict.keys():
if attrib == "child_refs" or attrib == "opened_connection_refs" or attrib == "environment_variables": # join multiple tables not implemented yet
if attrib == "child_refs" or attrib == "opened_connection_refs" or attrib == "environment_variables":
# join multiple tables not implemented yet
continue
if attrib == "created_time":
assert stix2.utils.parse_into_datetime(process_dict[attrib]) == stix2.utils.parse_into_datetime(read_obj[attrib])
continue
assert process_dict[attrib] == read_obj[attrib]

4 changes: 1 addition & 3 deletions stix2/test/v21/test_software.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties
Expand All @@ -23,6 +21,7 @@
True,
)


def test_software():
store.sink.generate_stix_schema()
software_stix_object = stix2.parse(software_dict)
Expand All @@ -32,4 +31,3 @@ def test_software():

for attrib in software_dict.keys():
assert software_dict[attrib] == read_obj[attrib]

8 changes: 3 additions & 5 deletions stix2/test/v21/test_url.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import datetime as dt
import json

import pytest

import stix2
from stix2.datastore.relational_db.relational_db import RelationalDBStore
import stix2.properties

url_dict = {
"type": "url",
"id": "url--a5477287-23ac-5971-a010-5c287877fa60",
"value" : "https://example.com/research/index.html",
"value": "https://example.com/research/index.html",
}

store = RelationalDBStore(
Expand All @@ -20,11 +17,12 @@
True,
)


def test_url():
store.sink.generate_stix_schema()
url_stix_object = stix2.parse(url_dict)
store.add(url_stix_object)
read_obj = json.loads(store.get(url_stix_object['id']).serialize())

for attrib in url_dict.keys():
assert url_dict[attrib] == read_obj[attrib]
assert url_dict[attrib] == read_obj[attrib]
Loading

0 comments on commit b8782e3

Please sign in to comment.