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-2318 Allow for form data at session create endpoint #429

Merged
merged 17 commits into from
Jan 19, 2024

Conversation

360dgries
Copy link
Contributor

Summary

Added a guard in the test_session create endpoint so it only parses as a json when the request does not contain form-data.

Testing Guidance

Added a spec test in spec/requests/test_sessions_spec.rb as well as a helper function to setup the form data request. Requesting a closer look at these to make sure I set them up correctly, as I'm still picking up the ins-outs of spec testing the more web-facing parts of the project.

Copy link

codecov bot commented Jan 10, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (fef1e5d) 77.02% compared to head (8a55eeb) 77.08%.
Report is 6 commits behind head on main.

Files Patch % Lines
dev_suites/dev_infrastructure_test/empty_group.rb 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #429      +/-   ##
==========================================
+ Coverage   77.02%   77.08%   +0.05%     
==========================================
  Files         218      220       +2     
  Lines       10914    10946      +32     
  Branches     1026     1029       +3     
==========================================
+ Hits         8407     8438      +31     
- Misses       1928     1929       +1     
  Partials      579      579              
Flag Coverage Δ
backend 93.91% <96.96%> (+0.02%) ⬆️

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.

* Add Data Rights Legend

* Remove copyright from README
@@ -10,7 +10,9 @@ class Create < Controller

def handle(req, res)
params = req.params.to_h
params.merge!(JSON.parse(req.body.string).symbolize_keys) unless req.body.string.blank?
unless req.body.string.blank? || req.env['CONTENT_TYPE'].include?('multipart/form-data')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Compound conditions with unless are really confusing, so you should change this to use if.

@@ -10,7 +10,9 @@ class Create < Controller

def handle(req, res)
params = req.params.to_h
params.merge!(JSON.parse(req.body.string).symbolize_keys) unless req.body.string.blank?
if !req.body.string.blank? && !req.env['CONTENT_TYPE'].include?('multipart/form-data')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use present? instead of !blank?.

Why check that the content type isn't form data instead of checking whether the content type is json? Also, that isn't the only content type used by forms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I've changed it to just check for json instead before attempting to parse as a json. I'm still learning in's and out's of request handling -- is there any form data that is non json that could need additional handling? My understanding is that Hanabi will handle most forms automatically.

Shaumik-Ashraf and others added 3 commits January 17, 2024 15:53
- add Inferno::Utils::NamedThorActions
- add dry-inflector dependency
- add Inferno::CLI::New thor generator
- add lib/inferno/apps/cli/templates/ folder with ERB templates for new Inferno test kit

---------

Co-authored-by: Alyssa Wang <awang@mitre.org>
Co-authored-by: Stephen MacVicar <Jammjammjamm@users.noreply.github.com>
@@ -10,7 +10,9 @@ class Create < Controller

def handle(req, res)
params = req.params.to_h
params.merge!(JSON.parse(req.body.string).symbolize_keys) unless req.body.string.blank?
if req.body.string.present? && req.env['CONTENT_TYPE'].include?('application/json')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if req.body.string.present? && req.env['CONTENT_TYPE'].include?('application/json')
if req.body.string.present? && req.env['CONTENT_TYPE']&.include?('application/json')

@360dgries 360dgries merged commit 5c35cf6 into main Jan 19, 2024
10 checks passed
Jammjammjamm added a commit that referenced this pull request Feb 12, 2024
Jammjammjamm added a commit that referenced this pull request Feb 12, 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.

5 participants