Skip to content

Commit

Permalink
Merge pull request #235 from ostefano/custom
Browse files Browse the repository at this point in the history
Fix validation of custom local schemas
  • Loading branch information
rpiazza authored Apr 4, 2024
2 parents 5ebca8c + 3ee4784 commit 555391c
Show file tree
Hide file tree
Showing 9 changed files with 436 additions and 12 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_version():
'cpe',
'jsonschema[format-nongpl]>=4.20.0',
'python-dateutil',
'requests',
'simplejson',
'stix2-patterns>=0.4.1',
]
Expand Down
2 changes: 1 addition & 1 deletion stix2validator/test/v20/misc_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_run_validation(caplog):


def test_run_validation_nonexistent_file():
options = ValidationOptions(files='asdf.json', version="2.0")
options = ValidationOptions(files=['asdf.json'], version="2.0")
with pytest.raises(NoJSONFileFoundError):
run_validation(options)

Expand Down
26 changes: 26 additions & 0 deletions stix2validator/test/v21/misc_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
EXAMPLE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'..', '..', 'schemas-2.1', 'examples',
'indicator-to-campaign-relationship.json')
CUSTOM = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_examples', 'tlp-amber.json')
CUSTOM_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_schemas')
RELATIVE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_examples', 'tool.json')
RELATIVE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_schemas')
IDENTITY = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'test_examples', 'identity.json')
IDENTITY_CUSTOM = os.path.join(os.path.dirname(os.path.realpath(__file__)),
Expand Down Expand Up @@ -65,6 +73,24 @@ def test_validate_file(caplog):
assert 'STIX JSON: Valid' in caplog.text


def test_validate_file_custom(caplog):
caplog.set_level('INFO')
results = validate_file(CUSTOM, options=ValidationOptions(schema_dir=CUSTOM_DIR))
assert results.is_valid

print_results(results)
assert 'STIX JSON: Valid' in caplog.text


def test_validate_file_custom_relative(caplog):
caplog.set_level('INFO')
results = validate_file(RELATIVE, options=ValidationOptions(schema_dir=RELATIVE_DIR))
assert results.is_valid

print_results(results)
assert 'STIX JSON: Valid' in caplog.text


def test_validate_file_warning(caplog):
results = validate_file(IDENTITY_CUSTOM)
assert results.is_valid
Expand Down
19 changes: 19 additions & 0 deletions stix2validator/test/v21/test_examples/tlp-amber.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "bundle",
"id": "bundle--63ab8e67-acac-4817-845a-d09f0e86954c",
"objects": [
{
"type": "marking-definition",
"spec_version": "2.1",
"id": "marking-definition--55d920b0-5e8b-4f79-9ee9-91f868d9b421",
"created": "2022-10-01T00:00:00.000Z",
"name": "TLP:AMBER",
"extensions": {
"extension-definition--60a3c5c5-0d10-413e-aab3-9e08dde9e88d": {
"extension_type": "property-extension",
"tlp_2_0" : "amber"
}
}
}
]
}
12 changes: 12 additions & 0 deletions stix2validator/test/v21/test_examples/tool.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "tool",
"spec_version": "2.1",
"id": "tool--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f",
"created_by_ref": "identity--f431f809-377b-45e0-aa1c-6a4751cae5ff",
"created": "2016-04-06T20:03:48.000Z",
"modified": "2016-04-06T20:03:48.000Z",
"tool_types": [ "remote-access"],
"name": "VNC",
"foo_value": "bizz",
"bar_value": "buzz"
}
7 changes: 7 additions & 0 deletions stix2validator/test/v21/test_schemas/bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"properties": {
"bar_value": {
"type": "string"
}
}
}
Loading

0 comments on commit 555391c

Please sign in to comment.