Commit 0521359
Changed files (4)
app
controllers
scim
models
config
spec
requests
scim
app/controllers/scim/v2/users_controller.rb
@@ -27,6 +27,15 @@ module Scim
render json: user.to_scim(self).to_json, status: :created
end
+ def update
+ user = User.find_by(uuid: params[:id])
+ user.update!(email: user_params[:userName])
+
+ response.headers['Content-Type'] = 'application/scim+json'
+ response.headers['Location'] = scim_v2_users_url(user)
+ render json: user.to_scim(self).to_json, status: :ok
+ end
+
private
def user_params
app/models/user.rb
@@ -31,6 +31,9 @@ class User < ApplicationRecord
x.updated_at = updated_at
x.location = url_helpers.scim_v2_users_url(self)
x.version = lock_version
+ x.emails do |y|
+ y.add(email, primary: true)
+ end
end
end
config/routes.rb
@@ -8,7 +8,7 @@ Rails.application.routes.draw do
resources :registrations, only: [:new, :create]
namespace :scim do
- namespace :v2, defaults: { format: 'json' } do
+ namespace :v2, defaults: { format: :scim } do
post ".search", to: "search#index"
resources :users, only: [:index, :show, :create, :update, :destroy]
get :ServiceProviderConfig, to: "service_providers#index"
spec/requests/scim/v2/users_spec.rb
@@ -39,7 +39,7 @@ describe '/scim/v2/users' do
let(:user) { create(:user) }
it 'returns the requested resource' do
- get "/scim/v2/users/#{user.uuid}"
+ get "/scim/v2/users/#{user.uuid}", headers: headers
expect(response).to have_http_status(:ok)
expect(response.headers['Content-Type']).to eql('application/scim+json')
@@ -60,7 +60,7 @@ describe '/scim/v2/users' do
describe "GET /scim/v2/users" do
it 'returns an empty set of results' do
- get "/scim/v2/users?attributes=userName"
+ get "/scim/v2/users?attributes=userName", headers: headers
expect(response).to have_http_status(:ok)
expect(response.headers['Content-Type']).to eql('application/scim+json')
@@ -72,4 +72,30 @@ describe '/scim/v2/users' do
expect(json[:Resources]).to be_empty
end
end
+
+ describe "PUT /scim/v1/users" do
+ let(:user) { create(:user) }
+ let(:new_email) { FFaker::Internet.email }
+
+ it 'updates the user' do
+ body = { schemas: [Scim::Shady::Schemas::USER], userName: new_email }
+ put "/scim/v2/users/#{user.uuid}", headers: headers, params: body.to_json
+
+ expect(response).to have_http_status(:ok)
+ expect(response.headers['Content-Type']).to eql('application/scim+json')
+ expect(response.headers['Location']).to eql(scim_v2_users_url(user))
+ expect(response.body).to be_present
+
+ json = JSON.parse(response.body, symbolize_names: true)
+ expect(json[:schemas]).to match_array([Scim::Shady::Schemas::USER])
+ expect(json[:id]).to be_present
+ expect(json[:userName]).to eql(new_email)
+ expect(json[:meta][:resourceType]).to eql('User')
+ expect(json[:meta][:created]).to be_present
+ expect(json[:meta][:lastModified]).to be_present
+ expect(json[:meta][:version]).to be_present
+ expect(json[:meta][:location]).to be_present
+ expect(json[:emails]).to match_array([value: new_email, type: 'work', primary: true])
+ end
+ end
end