Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions app/controllers/scim_rails/scim_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,23 @@ def put_active_param
end

def patch_active_param
active = params.dig("Operations", 0, "value", "active")
raise ScimRails::ExceptionHandler::UnsupportedPatchRequest if active.nil?
active
handle_invalid = lambda do
raise ScimRails::ExceptionHandler::UnsupportedPatchRequest
end

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

valid_patch_operation?(operation)
end

valid_operation.dig("value", "active")
end

def valid_patch_operation?(operation)
operation["op"] == "replace" &&
operation["value"] &&
operation["value"]["active"]
end
end
end
47 changes: 47 additions & 0 deletions spec/controllers/scim_rails/scim_users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,53 @@
response_body = JSON.parse(response.body)
expect(response_body.dig("schemas", 0)).to eq "urn:ietf:params:scim:api:messages:2.0:Error"
end

it "returns 422 when value is " do
patch :patch_update, params: {
id: 1,
Operations: [
{
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.

}
]
}

expect(response.status).to eq 422
response_body = JSON.parse(response.body)
expect(response_body.dig("schemas", 0)).to eq "urn:ietf:params:scim:api:messages:2.0:Error"
end

it "returns 422 when value is missing" do
patch :patch_update, params: {
id: 1,
Operations: [
{
op: "replace"
}
]
}

expect(response.status).to eq 422
response_body = JSON.parse(response.body)
expect(response_body.dig("schemas", 0)).to eq "urn:ietf:params:scim:api:messages:2.0:Error"
end

it "returns 422 operations key is missing" do
patch :patch_update, params: {
id: 1,
Foobars: [
{
op: "replace"
}
]
}

expect(response.status).to eq 422
response_body = JSON.parse(response.body)
expect(response_body.dig("schemas", 0)).to eq "urn:ietf:params:scim:api:messages:2.0:Error"
end
end
end

Expand Down