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

FI-2728: Prevent Test Runner from Crashing When Validator Response Contains Bad Characters #518

Merged
merged 9 commits into from
Aug 27, 2024

Conversation

vanessuniq
Copy link
Contributor

@vanessuniq vanessuniq commented Aug 16, 2024

Summary

Ticket Description: We saw an issue where a validator response contained a null character and it crashed the test runner, so it kept spinning forever. Since we don't control the validator and especially the tx server, make sure an unexpected response doesn't crash anything.

I was able to reproduce the issue by mocking the validator service with various unexpected response formats, including non-printable/control characters, which led to crashes when the test runner attempted to persist the response. By using Mockoon to simulate these edge cases, I confirmed that the issue was specifically related to non-printable characters in the response body, which caused SQLite exceptions during persistence.

Changes Made:

  • Sanitized the response body: The response body is now sanitized to remove non-printable/control characters before parsing or persisting, preventing crashes and database exceptions.
  • Improved JSON Parsing Error Handling: The JSON parsing process has been refined, ensuring that malformed responses are caught, and users are provided with clear, actionable error messages.
  • Prevent storing null validator session: Added a null check to prevent storing null validator session IDs (This should fix ticket FI-2914)
  • Update unit tests accordingly

Copy link

codecov bot commented Aug 16, 2024

Codecov Report

Attention: Patch coverage is 70.83333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 79.66%. Comparing base (e1b8fb6) to head (a894c0c).
Report is 1 commits behind head on main.

Files Patch % Lines
lib/inferno/jobs/invoke_validator_session.rb 0.00% 6 Missing ⚠️
lib/inferno/dsl/fhir_resource_validation.rb 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #518      +/-   ##
==========================================
+ Coverage   79.65%   79.66%   +0.01%     
==========================================
  Files         249      249              
  Lines       13177    13179       +2     
  Branches     1289     1283       -6     
==========================================
+ Hits        10496    10499       +3     
+ Misses       1932     1931       -1     
  Partials      749      749              
Flag Coverage Δ
backend 91.69% <70.83%> (+0.02%) ⬆️
frontend 74.54% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

@dehall dehall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I was able to reproduce the issue while testing this. The ticket says "bad characters" but I think the only real culprit is the null character. Using mockoon I wasn't able to get a realistic response containing the null character, but I was able to get *a* response containing the null character, and that produced the same problem as Steve originally reported on the bulk data test kit PR a while back: the test runner hits an exception in SQLite and then the UI spins forever. Can you try again with a response specifically containing a null character? I was able to get a null character to paste with the (mac) terminal command echo "\u0000" | pbcopy .

lib/inferno/dsl/fhir_resource_validation.rb Outdated Show resolved Hide resolved
end
operation_outcome_from_hl7_wrapped_response(JSON.parse(response.body))
rescue JSON::ParserError
runnable.add_message('error', "Validator Response: HTTP #{response.status}\n#{response.body}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this runnable gets persisted to the DB, I think this might be where the change to handle null characters will need to be.

@vanessuniq
Copy link
Contributor Author

Ok I was able to reproduce the issue while testing this. The ticket says "bad characters" but I think the only real culprit is the null character. Using mockoon I wasn't able to get a realistic response containing the null character, but I was able to get a response containing the null character, and that produced the same problem as Steve originally reported on the bulk data test kit PR a while back: the test runner hits an exception in SQLite and then the UI spins forever. Can you try again with a response specifically containing a null character? I was able to get a null character to paste with the (mac) terminal command echo "\u0000" | pbcopy .

Thanks! that helped.

@vanessuniq vanessuniq changed the title FI-2728: Improve JSON Parsing Error Handling for Validator Responses FI-2728: Prevent Test Runner from Crashing When Validator Response Contains Bad Characters Aug 26, 2024
Signed-off-by: Vanessa Fotso <[email protected]>
Signed-off-by: Vanessa Fotso <[email protected]>
'Validator response was an unexpected format. ' \
'Review Messages tab or validator service logs for more information.'
end
# Sanitize the response body by removing non-printable/control characters
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of the comment and make a method called remove_invalid_characters or something like that.

@vanessuniq vanessuniq merged commit 9fab4c0 into main Aug 27, 2024
9 of 10 checks passed
@rpassas rpassas mentioned this pull request Sep 11, 2024
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.

3 participants