Commit f92596f

mokha <mokha@cisco.com>
2018-09-19 22:41:22
render 404 when user cannot be found.
1 parent 42ccaef
Changed files (3)
app
spec
requests
app/controllers/scim/v2/users_controller.rb
@@ -3,6 +3,11 @@
 module Scim
   module V2
     class UsersController < ::Scim::Controller
+      rescue_from ActiveRecord::RecordNotFound do |_error|
+        @resource_id = params[:id] if params[:id].present?
+        render "record_not_found", status: :not_found
+      end
+
       def index
         render json: {
           schemas: [Scim::Shady::Messages::LIST_RESPONSE],
app/views/scim/record_not_found.scim.jbuilder
@@ -0,0 +1,5 @@
+# frozen_string_literal: true
+
+json.schemas ["urn:ietf:params:scim:api:messages:2.0:Error"]
+json.detail "Resource #{@resource_id} not found"
+json.status "404"
spec/requests/scim/v2/users_spec.rb
@@ -78,6 +78,16 @@ describe '/scim/v2/users' do
       specify { expect(json[:name][:familyName]).to eql(user.email) }
       specify { expect(json[:name][:givenName]).to eql(user.email) }
     end
+
+    context "when the resource does not exist" do
+      before { get "/scim/v2/users/#{SecureRandom.uuid}", headers: headers }
+
+      specify { expect(response).to have_http_status(:not_found) }
+      let(:json) { JSON.parse(response.body, symbolize_names: true) }
+      specify { expect(json[:schemas]).to match_array(['urn:ietf:params:scim:api:messages:2.0:Error']) }
+      specify { expect(json[:detail]).to be_present }
+      specify { expect(json[:status]).to eql('404') }
+    end
   end
 
   describe "GET /scim/v2/users" do