From b89149e4fb47c79c8e0b05c6de3ce6e788e6b545 Mon Sep 17 00:00:00 2001 From: Igor Artemenko Date: Wed, 9 Oct 2024 14:57:05 +0100 Subject: [PATCH] [JEDI-382] Forward pagination parameters to SCIM (#397) https://runway.powerhrg.com/backlog_items/JEDI-382 Before, both ``` curl -X GET 'http://localhost:3000/audiences/scim/Titles?count=1' | json_pp ``` and ``` curl -X GET 'http://localhost:3000/audiences/scim/Titles?startIndex=101' | json_pp ``` returned the same response as a simple `GET /audiences/scim/Titles`. The `count` and `startIndex` parameters are valid for paginating SCIM and work when querying `https://id.powerhrg.com/api/scim` directly. This change forwards both parameters (if present) so that the SCIM request includes them. --- .../audiences/scim_proxy_controller.rb | 2 +- audiences/spec/requests/scim_proxy_spec.rb | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/audiences/app/controllers/audiences/scim_proxy_controller.rb b/audiences/app/controllers/audiences/scim_proxy_controller.rb index f6780644..e17b7046 100644 --- a/audiences/app/controllers/audiences/scim_proxy_controller.rb +++ b/audiences/app/controllers/audiences/scim_proxy_controller.rb @@ -4,7 +4,7 @@ module Audiences class ScimProxyController < ApplicationController def get resources = Audiences::Scim.resource(params[:scim_path].to_sym) - .query(filter: params[:filter]) + .query(filter: params[:filter], startIndex: params[:startIndex], count: params[:count]) render json: resources, except: %w[schemas meta] end diff --git a/audiences/spec/requests/scim_proxy_spec.rb b/audiences/spec/requests/scim_proxy_spec.rb index 1ab4fb08..43160c70 100644 --- a/audiences/spec/requests/scim_proxy_spec.rb +++ b/audiences/spec/requests/scim_proxy_spec.rb @@ -29,7 +29,8 @@ context "GET /audiences/scim" do it "returns the Resources key from the response" do attrs = "id,externalId,displayName" - stub_request(:get, "http://example.com/scim/v2/MyResources?attributes=#{attrs}&filter=name eq John") + query = "attributes=#{attrs}&count&filter=name eq John&startIndex" + stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}") .to_return(status: 200, body: response_body, headers: {}) get audience_scim_proxy_path(scim_path: "MyResources", filter: "name eq John") @@ -42,9 +43,32 @@ ]) end + it "returns 'count' resources" do + attrs = "id,externalId,displayName" + query = "attributes=#{attrs}&count=1&filter&startIndex" + stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}") + .to_return(status: 200, body: { Resources: resources.slice(0, 1) }.to_json, headers: {}) + + get audience_scim_proxy_path(scim_path: "MyResources", count: 1) + + expect(response.parsed_body).to match([{ "displayName" => "A Name", "externalId" => "1", "photos" => "photo 1" }]) + end + + it "returns resources starting from 'startIndex'" do + attrs = "id,externalId,displayName" + query = "attributes=#{attrs}&count&filter&startIndex=3" + stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}") + .to_return(status: 200, body: { Resources: resources.slice(2, 1) }.to_json, headers: {}) + + get audience_scim_proxy_path(scim_path: "MyResources", startIndex: 3) + + expect(response.parsed_body).to match([{ "displayName" => "YAN", "externalId" => "3", "photos" => "photo 3" }]) + end + it "removes the schemas and meta from the resources" do attrs = "id,externalId,displayName" - stub_request(:get, "http://example.com/scim/v2/MyResources?attributes=#{attrs}&filter=name eq John") + query = "attributes=#{attrs}&count&filter=name eq John&startIndex" + stub_request(:get, "http://example.com/scim/v2/MyResources?#{query}") .to_return(status: 200, body: response_body, headers: {}) get audience_scim_proxy_path(scim_path: "MyResources", filter: "name eq John")