Commit 3dd64ffe authored by James Edwards-Jones's avatar James Edwards-Jones

SCIM Users Entity

parent 68818f67
......@@ -105,11 +105,8 @@ module API
status 200
present :totalResults, results.count
present :startIndex, params[:startIndex].presence || 1
present :itemsPerPage, per_page(params[:count])
present :schemas, ['urn:ietf:params:scim:api:messages:2.0:ListResponse']
present :Resources, response_page, with: ::EE::Gitlab::Scim::User
result_set = { resources: response_page, total_results: results.count, items_per_page: per_page(params[:count]), start_index: params[:startIndex] }
present result_set, with: ::EE::Gitlab::Scim::Users
end
desc 'Get a SAML user' do
......
# frozen_string_literal: true
module EE
module Gitlab
module Scim
class Users < Grape::Entity
expose :schemas
expose :total_results, as: :totalResults
expose :items_per_page, as: :itemsPerPage
expose :start_index, as: :startIndex
expose :resources, as: :Resources, using: ::EE::Gitlab::Scim::User
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:ListResponse'
def schemas
[DEFAULT_SCHEMA]
end
def total_results
object[:total_results] || resources.count
end
def items_per_page
object[:items_per_page] || Kaminari.config.default_per_page
end
def start_index
object[:start_index].presence || 1
end
def resources
object[:resources] || []
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe ::EE::Gitlab::Scim::Users do
let(:user) { build(:user) }
let(:identity) { build(:group_saml_identity, user: user) }
let(:entity) do
described_class.new(resources: [identity])
end
subject { entity.as_json }
it 'contains the schemas' do
expect(subject[:schemas]).to eq(['urn:ietf:params:scim:api:messages:2.0:ListResponse'])
end
it 'calculates the totalResults' do
expect(subject[:totalResults]).to eq(1)
end
it 'contains the default itemsPerPage' do
expect(subject[:itemsPerPage]).to eq(20)
end
it 'contains the default startIndex' do
expect(subject[:startIndex]).to eq(1)
end
it 'contains the user' do
expect(subject[:Resources]).not_to be_empty
end
it 'contains the user ID' do
expect(subject[:Resources].first[:id]).to eq(identity.extern_uid)
end
context 'with configured values' do
let(:entity) do
described_class.new(resources: [identity], total_results: 31, items_per_page: 10, start_index: 30)
end
it 'contains the configured totalResults' do
expect(subject[:totalResults]).to eq(31)
end
it 'contains the configured itemsPerPage' do
expect(subject[:itemsPerPage]).to eq(10)
end
it 'contains the configured startIndex' do
expect(subject[:startIndex]).to eq(30)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment