-
Notifications
You must be signed in to change notification settings - Fork 78
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
Fix exception raised when patch endpoint receives invalid request #30
Conversation
raise ScimRails::ExceptionHandler::UnsupportedPatchRequest | ||
end | ||
|
||
valid_operation = params["Operations"].find(handle_invalid) do |operation| |
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 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" |
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.
This is the format of the bad operations we were seeing in production. They had paths with string values.
99c72ca
to
058fe75
Compare
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.
058fe75
to
a6aa2a0
Compare
|
||
operations = params["Operations"] || {} | ||
|
||
valid_operation = operations.find(handle_invalid) do |operation| |
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 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
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.
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.
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:
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'
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