Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validation of custom local schemas #235

Merged
merged 3 commits into from
Apr 4, 2024
Merged

Conversation

ostefano
Copy link
Contributor

@ostefano ostefano commented Apr 3, 2024

Fix issue #234 (as mentioned by @clenk here #228)

CC @adulau @clenk @ejratl @rpiazza

@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.36%. Comparing base (2330398) to head (3ee4784).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #235      +/-   ##
==========================================
- Coverage   94.47%   94.36%   -0.12%     
==========================================
  Files          66       66              
  Lines        6174     6211      +37     
==========================================
+ Hits         5833     5861      +28     
- Misses        341      350       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ostefano
Copy link
Contributor Author

ostefano commented Apr 3, 2024

Added a new test exercising this use case

@ostefano ostefano mentioned this pull request Apr 3, 2024
@clenk
Copy link
Contributor

clenk commented Apr 4, 2024

Thanks, this is great! I realized there is another use case the previous jsonschema version supported. Consider the following:

test_schemas/tool.json:

{
  "allOf": [
    {
        "properties": {
            "foo_value": {
                "type": "string"
            }
        },
        "required": ["foo_value"]
    },
    {
      "$ref": "bar.json"
    }
  ]
}

test_schemas/bar.json:

{
    "properties": {
        "bar_value": {
            "type": "string"
        }
}

test/test_tool.json:

{
  "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"
}

stix2_validator -s ~/Downloads/test_schemas ~/Downloads/test/test_tool.json won't be able to resolve bar.json from tool.json's $ref property. What would you think of catching if there's no scheme in the URI, assuming it should be file, and appending the file:// scheme to it?

@ostefano
Copy link
Contributor Author

ostefano commented Apr 4, 2024

@clenk not sure this is supported by jsonschema.
The tool.json scheme is not processed by either the callback or the load_validator method.

Looking into this (but this should have been yet another test).
Note: there is no way to catch that error, because the schema is not picked up by the callback. The only approach is to rethink the whole logic, so not an easy fix.

@ostefano ostefano force-pushed the custom branch 2 times, most recently from 7cebb1e to 5a3be9a Compare April 4, 2024 18:58
@ostefano
Copy link
Contributor Author

ostefano commented Apr 4, 2024

Found a workaround but Windows test fail now.

@ostefano
Copy link
Contributor Author

ostefano commented Apr 4, 2024

@clenk alright, the last use case you posted has been added as additional test, and all tests are now passing, even on Windows.

Can we merge this and also cut a new release as per #232?

@ostefano
Copy link
Contributor Author

ostefano commented Apr 4, 2024

Uh, weird.
Here it succeeds as follows:

[-] Results for: ./stix2validator/test/v21/test_examples/tool.json
[+] STIX JSON: Valid
    [!] Warning: tool--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f: {401} Custom property 'foo_value' should be implemented using an extension with an 'extension_type' of 'property-extension' or 'toplevel-property-extension'.
    [!] Warning: tool--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f: {401} Custom property 'bar_value' should be implemented using an extension with an 'extension_type' of 'property-extension' or 'toplevel-property-extension'.

@clenk
Copy link
Contributor

clenk commented Apr 4, 2024

Looks good to me! (user error on my part confused me into thinking it didn't work) Thank you very much!!

@rpiazza rpiazza merged commit 555391c into oasis-open:master Apr 4, 2024
9 checks passed
@ostefano
Copy link
Contributor Author

ostefano commented Apr 4, 2024

Cool :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants