putting test files in stix type folder that exists on git (bc there are files in it)

stix2.0
= 2018-03-14 19:34:07 -04:00
parent f4558c0958
commit 2fbde05e6c
1 changed files with 11 additions and 11 deletions

View File

@ -50,16 +50,16 @@ def fs_sink():
def bad_json_files():
# create erroneous JSON files for tests to make sure handled gracefully
with open(os.path.join(FS_PATH, "indicator", "indicator--test-non-json.txt"), "w+") as f:
with open(os.path.join(FS_PATH, "intrusion-set", "intrusion-set--test-non-json.txt"), "w+") as f:
f.write("Im not a JSON file")
with open(os.path.join(FS_PATH, "indicator", "indicator--test-bad-json.json"), "w+") as f:
with open(os.path.join(FS_PATH, "intrusion-set", "intrusion-set--test-bad-json.json"), "w+") as f:
f.write("Im not a JSON formatted file")
yield True # dummy yield so can have teardown
os.remove(os.path.join(FS_PATH, "indicator", "indicator--test-non-json.txt"))
os.remove(os.path.join(FS_PATH, "indicator", "indicator--test-bad-json.json"))
os.remove(os.path.join(FS_PATH, "intrusion-set", "intrusion-set--test-non-json.txt"))
os.remove(os.path.join(FS_PATH, "intrusion-set", "intrusion-set--test-bad-json.json"))
@pytest.fixture
@ -68,17 +68,17 @@ def bad_stix_files():
# bad STIX object
stix_obj = {
"id": "indicator--test-bad-stix",
"id": "intrusion-set--test-bad-stix",
"spec_version": "2.0"
# no "type" field
}
with open(os.path.join(FS_PATH, "indicator", "indicator--test-non-stix.json"), "w+") as f:
with open(os.path.join(FS_PATH, "intrusion-set", "intrusion-set--test-non-stix.json"), "w+") as f:
f.write(json.dumps(stix_obj))
yield True # dummy yield so can have teardown
os.remove(os.path.join(FS_PATH, "indicator", "indicator--test-non-stix.json"))
os.remove(os.path.join(FS_PATH, "intrusion-set", "intrusion-set--test-non-stix.json"))
@pytest.fixture(scope='module')
@ -117,18 +117,18 @@ def test_filesystem_source_bad_json_file(fs_source, bad_json_files):
# - one file should just be skipped (silently) as its a ".txt" extension
# - one file should be parsed and raise Exception bc its not JSON
try:
fs_source.get("indicator--test-bad-json")
fs_source.get("intrusion-set--test-bad-json")
except TypeError as e:
assert "indicator--test-bad-json" in str(e)
assert "intrusion-set--test-bad-json" in str(e)
assert "could either not be parsed to JSON or was not valid STIX JSON" in str(e)
def test_filesystem_source_bad_stix_file(fs_source, bad_stix_files):
# this tests handling of bad STIX json object
try:
fs_source.get("indicator--test-non-stix")
fs_source.get("intrusion-set--test-non-stix")
except TypeError as e:
assert "indicator--test-non-stix" in str(e)
assert "intrusion-set--test-non-stix" in str(e)
assert "could either not be parsed to JSON or was not valid STIX JSON" in str(e)