Commit 8945154

mo <mo.khan@gmail.com>
2019-06-15 19:56:13
add mapping for missing scim attributes
1 parent e5af5ad
Changed files (4)
app
models
config
initializers
spec
app/models/scim/user.rb
@@ -2,11 +2,14 @@
 
 module SCIM
   class User
+    include ActiveModel::Model
     ATTRIBUTES = {
+      'emails.value': :email,
+      'meta.created' => :created_at,
+      'meta.lastModified' => :updated_at,
       userName: :email,
-      'meta.lastModified' => :updated_at
+      user_name: :email,
     }.with_indifferent_access
-    include ActiveModel::Model
     attr_accessor :id, :schemas, :userName, :name, :locale, :timezone, :password
 
     validate :must_be_user_schema
config/initializers/scim_kit.rb
@@ -1,4 +1,3 @@
-
 ActiveSupport::Notifications.subscribe 'proof.routes_loaded' do
   url_helpers = Rails.application.routes.url_helpers
 
@@ -18,49 +17,49 @@ ActiveSupport::Notifications.subscribe 'proof.routes_loaded' do
       x.endpoint = url_helpers.scim_v2_groups_url
     end
     config.schema(id: Scim::Kit::V2::Schemas::USER, name: "User", location: url_helpers.scim_v2_schema_url(id: Scim::Kit::V2::Schemas::USER)) do |schema|
-      schema.add_attribute(name: 'userName') do |x|
+      schema.add_attribute(name: :user_name) do |x|
         x.required = true
         x.uniqueness = :server
       end
-      schema.add_attribute(name: 'password') do |x|
+      schema.add_attribute(name: :password) do |x|
         x.mutability = :write_only
         x.required = false
         x.returned = :never
       end
-      schema.add_attribute(name: 'emails') do |x|
+      schema.add_attribute(name: :emails) do |x|
         x.multi_valued = true
-        x.add_attribute(name: 'value')
-        x.add_attribute(name: 'primary', type: :boolean)
+        x.add_attribute(name: :value)
+        x.add_attribute(name: :primary, type: :boolean)
       end
-      schema.add_attribute(name: 'groups') do |x|
+      schema.add_attribute(name: :groups) do |x|
         x.multi_valued = true
         x.mutability = :read_only
-        x.add_attribute(name: 'value') do |y|
+        x.add_attribute(name: :value) do |y|
           y.mutability = :read_only
         end
         x.add_attribute(name: '$ref', type: :reference) do |y|
           y.reference_types = %w[User Group]
           y.mutability = :read_only
         end
-        x.add_attribute(name: 'display') do |y|
+        x.add_attribute(name: :display) do |y|
           y.mutability = :read_only
         end
       end
-      schema.add_attribute(name: 'timezone')
-      schema.add_attribute(name: 'locale')
+      schema.add_attribute(name: :timezone)
+      schema.add_attribute(name: :locale)
     end
     config.schema(id: Scim::Kit::V2::Schemas::GROUP, name: "Group", location: url_helpers.scim_v2_schema_url(id: Scim::Kit::V2::Schemas::GROUP)) do |schema|
-      schema.add_attribute(name: 'displayName')
-      schema.add_attribute(name: 'members') do |x|
+      schema.add_attribute(name: :display_name)
+      schema.add_attribute(name: :members) do |x|
         x.multi_valued = true
-        x.add_attribute(name: 'value') do |y|
+        x.add_attribute(name: :value) do |y|
           y.mutability = :immutable
         end
         x.add_attribute(name: '$ref') do |y|
           y.reference_types = %w[User Group]
           y.mutability = :immutable
         end
-        x.add_attribute(name: 'type') do |y|
+        x.add_attribute(name: :type) do |y|
           y.canonical_values = %w[User Group]
           y.mutability = :immutable
         end
spec/models/user_spec.rb
@@ -23,6 +23,11 @@ RSpec.describe User do
       expect(results).to match_array(users)
     end
 
+    specify do
+      results = subject.scim_search("emails.value eq \"#{random_user.email}\"")
+      expect(results).to match_array([random_user])
+    end
+
     specify do
       results = subject.scim_search("userName eq \"#{random_user.email}\"")
       expect(results).to match_array([random_user])
@@ -102,4 +107,14 @@ RSpec.describe User do
       specify { expect(results).to match_array([first_user, second_user]) }
     end
   end
+
+  describe ".scim_mapper" do
+    subject { described_class }
+
+    specify { expect(subject.scim_mapper['emails.value']).to be(:email) }
+    specify { expect(subject.scim_mapper['meta.created']).to be(:created_at) }
+    specify { expect(subject.scim_mapper['meta.lastModified']).to be(:updated_at) }
+    specify { expect(subject.scim_mapper[:userName]).to be(:email) }
+    specify { expect(subject.scim_mapper[:user_name]).to be(:email) }
+  end
 end
.rubocop.yml
@@ -3,7 +3,7 @@ require: rubocop-rspec
 # https://github.com/bbatsov/rubocop/blob/master/config/default.yml
 AllCops:
   TargetRubyVersion:
-    2.5
+    2.6
   Exclude:
     - 'bin/**/*'
     - 'config/initializers/*.rb'