Skip to content

Commit

Permalink
Fix breaking change on SCIM proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
xjunior committed Dec 30, 2024
1 parent bdb141c commit 85221d3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion audiences-react/src/scim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function useScim(): UseScimResources {
const { get } = useFetch(uri)

const filter = async (resourceId: string, displayName: string) => {
return await get(`${resourceId}?filter=${displayName}`)
return await get(`${resourceId}?query=${displayName}`)
}

return { filter }
Expand Down
12 changes: 11 additions & 1 deletion audiences/app/controllers/audiences/scim_proxy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ class ScimProxyController < ApplicationController
def get
resources = Audiences::Scim.resource(params[:scim_path].to_sym)
.query(
filter: "displayName co \"#{params[:filter]}\"",
filter: filter_param,
startIndex: params[:startIndex], count: params[:count],
attributes: Audiences.exposed_user_attributes.join(",")
)

render json: resources, except: %w[schemas meta]
end

private

def filter_param
if params[:query]
"displayName co \"#{params[:query]}\""
else
params[:filter]
end
end
end
end
36 changes: 30 additions & 6 deletions audiences/spec/controllers/scim_proxy_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,43 @@
it "returns the Resources key from the response" do
allow(resource_query).to receive(:query).and_return({ "response" => "body" })

get :get, params: { scim_path: "MyResources", filter: "name eq John" }
get :get, params: { scim_path: "MyResources", query: "John" }

expect(response.parsed_body).to eq({ "response" => "body" })
end

it "proxies queries with arguments" do
it "proxies pagination arguments over to the SCIM backend" do
expect(resource_query).to(
receive(:query)
.with(hash_including(filter: 'displayName co "John"', startIndex: "12", count: "21"))
.with(hash_including(startIndex: "12", count: "21"))
.and_return({ "response" => "body" })
)

get :get, params: { scim_path: "MyResources", count: 21, startIndex: 12, filter: "John" }
get :get, params: { scim_path: "MyResources", count: 21, startIndex: 12 }

expect(response.parsed_body).to eq({ "response" => "body" })
end

it "proxies queries with displayName filter from query" do
expect(resource_query).to(
receive(:query)
.with(hash_including(filter: 'displayName co "John"'))
.and_return({ "response" => "body" })
)

get :get, params: { scim_path: "MyResources", query: "John" }

expect(response.parsed_body).to eq({ "response" => "body" })
end

it "proxies queries with raw filter for backward compatibility with clients" do
expect(resource_query).to(
receive(:query)
.with(hash_including(filter: 'displayName eq "John"'))
.and_return({ "response" => "body" })
)

get :get, params: { scim_path: "MyResources", filter: 'displayName eq "John"' }

expect(response.parsed_body).to eq({ "response" => "body" })
end
Expand All @@ -47,7 +71,7 @@
"meta" => "meta",
})

get :get, params: { scim_path: "MyResources", filter: "name eq John" }
get :get, params: { scim_path: "MyResources" }

expect(response.parsed_body).to eq({ "response" => "body" })
end
Expand All @@ -59,7 +83,7 @@
.and_return({ "response" => "body" })
)

get :get, params: { scim_path: "MyResources", count: 21, startIndex: 12, filter: "name eq John" }
get :get, params: { scim_path: "MyResources" }

expect(response.parsed_body).to eq({ "response" => "body" })
end
Expand Down

0 comments on commit 85221d3

Please sign in to comment.