From 85221d3d489e1893ecbb6374afa29baffd2aa57d Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Mon, 30 Dec 2024 11:25:53 -0300 Subject: [PATCH] Fix breaking change on SCIM proxy --- audiences-react/src/scim.ts | 2 +- .../audiences/scim_proxy_controller.rb | 12 ++++++- .../controllers/scim_proxy_controller_spec.rb | 36 +++++++++++++++---- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/audiences-react/src/scim.ts b/audiences-react/src/scim.ts index dada8e0b..0bce3314 100644 --- a/audiences-react/src/scim.ts +++ b/audiences-react/src/scim.ts @@ -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 } diff --git a/audiences/app/controllers/audiences/scim_proxy_controller.rb b/audiences/app/controllers/audiences/scim_proxy_controller.rb index 4eaeb0f2..3385c5c5 100644 --- a/audiences/app/controllers/audiences/scim_proxy_controller.rb +++ b/audiences/app/controllers/audiences/scim_proxy_controller.rb @@ -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 diff --git a/audiences/spec/controllers/scim_proxy_controller_spec.rb b/audiences/spec/controllers/scim_proxy_controller_spec.rb index f61e2bd8..2b875bd0 100644 --- a/audiences/spec/controllers/scim_proxy_controller_spec.rb +++ b/audiences/spec/controllers/scim_proxy_controller_spec.rb @@ -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 @@ -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 @@ -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