Commit 447ea16
Changed files (7)
app
controllers
concerns
scim
models
spec
models
requests
scim
app/controllers/concerns/pageable.rb
@@ -12,6 +12,7 @@ module Pageable
actual = params.fetch(key, default).to_i
return bottom if actual < bottom
return top if actual > top
+
actual
end
end
app/controllers/scim/v2/users_controller.rb
@@ -59,7 +59,7 @@ module Scim
page_param(:count, default: 25, bottom: 0, top: 25)
end
- def apply_filter_to(scope, raw_filter)
+ def apply_filter_to(scope, _raw_filter)
parser = Scim::Kit::V2::Filter.new
parse_tree = parser.parse(params[:filter])
scope.scim_filter_for(parse_tree)
app/models/scim/visitor.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Scim
class Visitor
def self.result_for(tree)
app/models/paginate.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Paginate < SimpleDelegator
attr_reader :page, :page_size
app/models/user.rb
@@ -13,7 +13,7 @@ class User < ApplicationRecord
validates :timezone, inclusion: VALID_TIMEZONES
validates :locale, inclusion: VALID_LOCALES
- scope :scim_filter_for, -> (tree) { Scim::Visitor.result_for(tree) }
+ scope :scim_filter_for, ->(tree) { Scim::Visitor.result_for(tree) }
def name_id_for(name_id_format)
Saml::Kit::Namespaces::PERSISTENT == name_id_format ? id : email
spec/models/user_spec.rb
@@ -21,27 +21,27 @@ RSpec.describe User do
end
specify do
- results = User.scim_filter_for(tree_for("userName eq \"#{random_user.email}\""))
+ results = described_class.scim_filter_for(tree_for("userName eq \"#{random_user.email}\""))
expect(results).to match_array([random_user])
end
specify do
- results = User.scim_filter_for(tree_for("userName ne \"#{random_user.email}\""))
+ results = described_class.scim_filter_for(tree_for("userName ne \"#{random_user.email}\""))
expect(results.pluck(:email)).not_to include(random_user.email)
end
specify do
- results = User.scim_filter_for(tree_for("userName co \"#{random_user.email[1..-2]}\""))
+ results = described_class.scim_filter_for(tree_for("userName co \"#{random_user.email[1..-2]}\""))
expect(results).to match_array([random_user])
end
specify do
- results = User.scim_filter_for(tree_for("userName sw \"#{random_user.email[0..3]}\""))
+ results = described_class.scim_filter_for(tree_for("userName sw \"#{random_user.email[0..3]}\""))
expect(results).to match_array([random_user])
end
specify do
- results = User.scim_filter_for(tree_for("userName ew \"#{random_user.email[-8..-1]}\""))
+ results = described_class.scim_filter_for(tree_for("userName ew \"#{random_user.email[-8..-1]}\""))
expect(results).to match_array([random_user])
end
@@ -49,7 +49,7 @@ RSpec.describe User do
freeze_time
random_user.update!(updated_at: 10.minutes.from_now)
- results = User.scim_filter_for(tree_for("meta.lastModified gt \"#{Time.now.iso8601}\""))
+ results = described_class.scim_filter_for(tree_for("meta.lastModified gt \"#{Time.now.iso8601}\""))
expect(results).to match_array([random_user])
end
@@ -57,7 +57,7 @@ RSpec.describe User do
freeze_time
random_user.update!(updated_at: 10.minutes.from_now)
- results = User.scim_filter_for(tree_for("meta.lastModified ge \"#{random_user.updated_at.iso8601}\""))
+ results = described_class.scim_filter_for(tree_for("meta.lastModified ge \"#{random_user.updated_at.iso8601}\""))
expect(results).to match_array([random_user])
end
@@ -65,7 +65,7 @@ RSpec.describe User do
freeze_time
random_user.update!(updated_at: 10.minutes.from_now)
- results = User.scim_filter_for(tree_for("meta.lastModified lt \"#{Time.now.iso8601}\""))
+ results = described_class.scim_filter_for(tree_for("meta.lastModified lt \"#{Time.now.iso8601}\""))
expect(results).to match_array(users - [random_user])
end
@@ -73,14 +73,14 @@ RSpec.describe User do
freeze_time
random_user.update!(updated_at: 10.minutes.ago)
- results = User.scim_filter_for(tree_for("meta.lastModified le \"#{random_user.updated_at.iso8601}\""))
+ results = described_class.scim_filter_for(tree_for("meta.lastModified le \"#{random_user.updated_at.iso8601}\""))
expect(results).to match_array([random_user])
end
specify do
first_user = users.sample
second_user = users.sample
- results = User.scim_filter_for(
+ results = described_class.scim_filter_for(
tree_for(%(userName eq "#{first_user.email}" or userName eq "#{second_user.email}"))
)
expect(results.pluck(:email)).to match_array([first_user.email, second_user.email])
@@ -95,7 +95,7 @@ RSpec.describe User do
first_user.update!(updated_at: 11.minutes.from_now)
second_user.update!(updated_at: 12.minutes.from_now)
- results = User.scim_filter_for(
+ results = described_class.scim_filter_for(
tree_for(%(meta.lastModified gt "#{10.minutes.from_now.iso8601}" and meta.lastModified lt "#{15.minutes.from_now.iso8601}"))
)
expect(results).to match_array([first_user, second_user])
spec/requests/scim/v2/users_spec.rb
@@ -144,8 +144,8 @@ describe '/scim/v2/users' do
specify { expect(response.body).to be_present }
specify { expect(json[:schemas]).to match_array([Scim::Kit::V2::Messages::LIST_RESPONSE]) }
specify { expect(json[:totalResults]).to be(users.count + 1) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(1) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(1) }
specify { expect(json[:Resources][0][:id]).to eql(User.order(:created_at).offset(0).limit(1).pluck(:id).first) }
end
@@ -154,8 +154,8 @@ describe '/scim/v2/users' do
specify { expect(response).to have_http_status(:ok) }
specify { expect(json[:totalResults]).to be(users.count + 1) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(25) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(25) }
specify { expect(json[:Resources]).to be_present }
end
@@ -164,8 +164,8 @@ describe '/scim/v2/users' do
specify { expect(response).to have_http_status(:ok) }
specify { expect(json[:totalResults]).to be(users.count + 1) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(25) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(25) }
specify { expect(json[:Resources]).to be_present }
end
@@ -174,8 +174,8 @@ describe '/scim/v2/users' do
specify { expect(response).to have_http_status(:ok) }
specify { expect(json[:totalResults]).to be(users.count + 1) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(25) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(25) }
specify { expect(json[:Resources]).to be_present }
end
@@ -185,8 +185,8 @@ describe '/scim/v2/users' do
specify { expect(response).to have_http_status(:ok) }
specify { expect(json[:schemas]).to match_array([Scim::Kit::V2::Messages::LIST_RESPONSE]) }
specify { expect(json[:totalResults]).to be(users.count + 1) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(0) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(0) }
specify { expect(json[:Resources]).to be_empty }
end
@@ -195,8 +195,8 @@ describe '/scim/v2/users' do
specify { expect(response).to have_http_status(:ok) }
specify { expect(json[:totalResults]).to be(users.count + 1) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(0) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(0) }
specify { expect(json[:Resources]).to be_empty }
end
end
@@ -211,8 +211,8 @@ describe '/scim/v2/users' do
specify { expect(response).to have_http_status(:ok) }
specify { expect(json[:totalResults]).to be(1) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(25) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(25) }
specify { expect(json[:Resources]).to be_present }
specify { expect(json[:Resources][0][:id]).to eql(matching_user.to_param) }
end
@@ -224,12 +224,12 @@ describe '/scim/v2/users' do
%(userName eq "#{first_matching_user.email}" or userName eq "#{second_matching_user.email}")
end
- before { get "/scim/v2/users", params: { filter: filter }, headers: headers }
+ before { get "/scim/v2/users", params: { filter: filter }, headers: headers }
specify { expect(response).to have_http_status(:ok) }
specify { expect(json[:totalResults]).to be(2) }
- specify { expect(json[:startIndex]).to eql(1) }
- specify { expect(json[:itemsPerPage]).to eql(25) }
+ specify { expect(json[:startIndex]).to be(1) }
+ specify { expect(json[:itemsPerPage]).to be(25) }
specify { expect(json[:Resources]).to be_present }
specify { expect(json[:Resources].map { |x| x[:id] }).to match_array([first_matching_user.to_param, second_matching_user.to_param]) }
end
@@ -247,7 +247,7 @@ describe '/scim/v2/users' do
specify { expect(json[:schemas]).to match_array([Scim::Kit::V2::Messages::LIST_RESPONSE]) }
specify { expect(json[:totalResults]).to be(1) }
specify { expect(json[:Resources]).not_to be_empty }
- specify { expect(json[:Resources][0]).to eql({ id: user.to_param, displayName: user.email }) }
+ specify { expect(json[:Resources][0]).to eql(id: user.to_param, displayName: user.email) }
end
end