diff --git a/app/controllers/scimitar/application_controller.rb b/app/controllers/scimitar/application_controller.rb index e9e4c71..d679914 100644 --- a/app/controllers/scimitar/application_controller.rb +++ b/app/controllers/scimitar/application_controller.rb @@ -101,6 +101,9 @@ def require_scim request.format = :scim elsif request.format == :scim request.headers['CONTENT_TYPE'] = scim_mime_type + elsif request.media_type.downcase == 'application/json' && request.user_agent.start_with?('Google') # https://github.com/pond/scimitar/issues/142 + request.format = :scim + request.headers["CONTENT_TYPE"] = scim_mime_type else handle_scim_error(ErrorResponse.new(status: 406, detail: "Only #{scim_mime_type} type is accepted.")) end diff --git a/spec/controllers/scimitar/application_controller_spec.rb b/spec/controllers/scimitar/application_controller_spec.rb index d1665cf..f56265d 100644 --- a/spec/controllers/scimitar/application_controller_spec.rb +++ b/spec/controllers/scimitar/application_controller_spec.rb @@ -291,6 +291,25 @@ def index; end expect(@exception.message).to eql('Only application/scim+json type is accepted.') end end + + context 'and with Google SCIM calls' do + it 'reaches the controller action if the expected agent is making the request' do + request.headers['Content-Type'] = 'application/json' + request.headers['User-Agent' ] = 'Google-Auto-Provisioning' + get :index + + expect(@exception).to be_a(RuntimeError) + expect(@exception.message).to eql('Bang') + end + + it 'is invoked early for unrecognised agents' do + request.headers['Content-Type'] = 'application/json' + get :index + + expect(@exception).to be_a(Scimitar::ErrorResponse) + expect(@exception.message).to eql('Only application/scim+json type is accepted.') + end + end # "context 'and with Google SCIM calls' do" end # "context 'exception reporter' do" end # "context 'error handling' do" end