-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add SARIF schema test #105
base: main
Are you sure you want to change the base?
Add SARIF schema test #105
Conversation
@@ -289,6 +289,7 @@ def navigate_trace_frames( | |||
callee_port=trace_frame.callee_port, | |||
caller="", | |||
caller_port="", | |||
filename="", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to conform with the schema definition
@@ -48,7 +48,7 @@ | |||
|
|||
class SARIF: | |||
version: str = "2.1.0" | |||
schema: str = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json" # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the old schema is actually had a broken regex and it was fixed in the codeQL schema see this commit github/codeql-action@9824588
if len(trace_tuples) == 0: | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to conform with the schema definition
I think the failing test is just a flaky test. I don't think the failure is from this PR |
/cc @arthaud not sure if you guys missed this PR :D |
import jsonschema | ||
import requests | ||
|
||
from sapp.sarif import SARIF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Below we use relative imports and here we use an absolute import, is this intentional? If not then let's try to be consisent.
output = sarif.to_json() | ||
output = json.loads(output) | ||
try: | ||
response = requests.get(SARIF.schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of tests pulling random stuff from the internet. Maybe we could just push that file in the repository?
output = sarif.to_json() | ||
output = json.loads(output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sarif.to_json()
does a json.dumps
internally, so this is doing a back-and-forth between the python representation and a string. It would be nice to avoid this, but I guess that's not a big deal for a test..
sarif = SARIF("mariana-trench", session, set(issues)) | ||
output = sarif.to_json() | ||
output = json.loads(output) | ||
try: | ||
response = requests.get(SARIF.schema) | ||
response.raise_for_status() | ||
schema = response.json() | ||
jsonschema.Draft202012Validator(schema).validate(output) | ||
except Exception as e: | ||
print(f"Error downloading schema: {e}") | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move that in a function, since it's used twice.
input_return_map = { | ||
(session, issues[0].issue_instance_id, TraceKind.POSTCONDITION): [ | ||
source_frames_query_results[0], | ||
source_frames_query_results[1], | ||
], | ||
(session, issues[0].issue_instance_id, TraceKind.PRECONDITION): [ | ||
sink_frames_query_results[0], | ||
sink_frames_query_results[1], | ||
], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? From my understanding, since we use self.fakes.precondition
/postcondition
, those should be in the database and initial_frames
should find those?
Pre-submission checklist
black .
usort format .
flake8
pip install -r requirements-dev.txt
and completed the following:./scripts/run-tests.sh
and made sure all tests are passingSummary
This PR adds initial tests to SARIF output from SAPP. Currently the SARIF output has no test coverage at all. This API add a schema test that the output SARIF passes the defined schema.
Test Plan
and running the specific new tests