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 exception raised when patch endpoint receives invalid request #30

Merged
merged 1 commit into from
Jun 17, 2020

Conversation

rreinhardt9
Copy link
Contributor

@rreinhardt9 rreinhardt9 commented Jun 16, 2020

Fixes #29

Testing Notes

Is any special setup required to test this change? Non-obvious things that should be checked?

A list of things to test:

  • Here is testing an invalid request curl -X PATCH 'http://dev:api_key@localhost:3000/scim/v2/Users/819216' -d '{"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], "Operations": [{"op":"Add","path":"displayName","value":"Norris, Chuck"}]}' -H 'Content-Type: application/scim+json'
  • A valid request should still work as expected curl -X PATCH 'http://dev:api_key@localhost:3000/scim/v2/Users/819216' -d '{"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], "Operations": [{"op":"replace,"value":{"active":true}]}' -H 'Content-Type: application/scim+json'

To test this, I pointed a locally running lessonly app at the gem (locally) using the bundler path directive. Let me know and we can pair on testing because that requires some set up that I'd be glad to help with!

Merge Instructions

Please rebase my commits when merging

raise ScimRails::ExceptionHandler::UnsupportedPatchRequest
end

valid_operation = params["Operations"].find(handle_invalid) do |operation|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The argument supplied to "find" is called when no match is found. So if no valid operation is found, it calls the lambda raising the exception.

{
op: "replace",
path: "displayName",
value: "Francis"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the format of the bad operations we were seeing in production. They had paths with string values.

@rreinhardt9 rreinhardt9 force-pushed the fix-malformed-patch-exception branch from 99c72ca to 058fe75 Compare June 16, 2020 16:52
fixes lessonly#29

The patch endpoint isn't fully scim compliant yet and only allows for
specific operations. When we received a specific format of request that
wasn't valid, it was raising an exception instead of returning the
expected 422 response.

Add extra validation to prevent this situation when receiving an
unexpected body for a patch request.
@rreinhardt9 rreinhardt9 force-pushed the fix-malformed-patch-exception branch from 058fe75 to a6aa2a0 Compare June 16, 2020 17:20

operations = params["Operations"] || {}

valid_operation = operations.find(handle_invalid) do |operation|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lambda passed to find is called when nothing is found... so in this case if a valid operation is not found it calls the handler that will raise the UnsupportedPatchRequest exception

Copy link
Member

@wernull wernull left a comment

Choose a reason for hiding this comment

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

Looks good! I was having issues with the dummy app but we can look into that some other time. I got everything testing good in a different app pointing to the local gem.

@wernull wernull merged commit 0b5c207 into lessonly:master Jun 17, 2020
@rreinhardt9 rreinhardt9 deleted the fix-malformed-patch-exception branch August 6, 2020 21:03
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.

Exception when patch endpoint receives unexpected request format.
2 participants