spec/models/scimitar/resources/mixin_spec.rb in scimitar-2.4.0 vs spec/models/scimitar/resources/mixin_spec.rb in scimitar-2.4.1
- old
+ new
@@ -170,10 +170,11 @@
instance.first_name = 'Foo'
instance.last_name = 'Bar'
instance.work_email_address = 'foo.bar@test.com'
instance.home_email_address = nil
instance.work_phone_number = '+642201234567'
+ instance.organization = 'SOMEORG'
g1 = MockGroup.create!(display_name: 'Group 1')
g2 = MockGroup.create!(display_name: 'Group 2')
g3 = MockGroup.create!(display_name: 'Group 3')
@@ -192,11 +193,16 @@
'phoneNumbers'=> [{'type'=>'work', 'primary'=>false, 'value'=>'+642201234567'}],
'id' => uuid,
'externalId' => 'AA02984',
'groups' => [{'display'=>g1.display_name, 'value'=>g1.id.to_s}, {'display'=>g3.display_name, 'value'=>g3.id.to_s}],
'meta' => {'location'=>"https://test.com/mock_users/#{uuid}", 'resourceType'=>'User'},
- 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User']
+ 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User', 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'],
+
+ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => {
+ 'organization' => 'SOMEORG',
+ 'department' => nil
+ }
})
end
end # "context 'with a UUID, renamed primary key column' do"
context 'with an integer, conventionally named primary key column' do
@@ -316,11 +322,13 @@
{'type'=>'work', 'primary'=>false, 'value'=>'work@test.com'},
{'type'=>'home', 'value'=>'home@test.com'},
],
'meta' => {'location'=>'https://test.com/static_map_test', 'resourceType'=>'User'},
- 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User']
+ 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User', 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'],
+
+ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => {}
})
end
end # "context 'using static mappings' do"
context 'using dynamic lists' do
@@ -343,11 +351,13 @@
{'display'=>'Group 2', 'value'=>'2'},
{'display'=>'Group 3', 'value'=>'3'},
],
'meta' => {'location'=>'https://test.com/dynamic_map_test', 'resourceType'=>'User'},
- 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User']
+ 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User', 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'],
+
+ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => {}
})
end
end # "context 'using dynamic lists' do"
end # "context 'with arrays' do"
@@ -400,11 +410,16 @@
'phoneNumbers' => [{'type' => 'work', 'primary' => false, 'value' => '+642201234567' }],
'groups' => [{'type' => 'Group', 'value' => '1'}, {'type' => 'Group', 'value' => '2'}],
'id' => '42', # Note, String
'externalId' => 'AA02984',
'meta' => {'location' => 'https://test.com/mock_users/42', 'resourceType' => 'User'},
- 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User']
+ 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User', 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'],
+
+ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => {
+ 'organization' => 'SOMEORG',
+ 'DEPARTMENT' => 'SOMEDPT'
+ }
}
hash = spec_helper_hupcase(hash) if force_upper_case
instance = MockUser.new
@@ -416,10 +431,12 @@
expect(instance.first_name ).to eql('Foo')
expect(instance.last_name ).to eql('Bar')
expect(instance.work_email_address).to eql('foo.bar@test.com')
expect(instance.home_email_address).to be_nil
expect(instance.work_phone_number ).to eql('+642201234567')
+ expect(instance.organization ).to eql('SOMEORG')
+ expect(instance.department ).to eql('SOMEDPT')
end
it 'honouring read-write lists' do
g1 = MockGroup.create!(display_name: 'Nested group')
@@ -702,10 +719,25 @@
expect(scim_hash['name']['givenName' ]).to eql('Baz')
expect(scim_hash['name']['familyName']).to eql('Bar')
end
+ it 'with schema extensions: overwrites' do
+ path = [ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User', 'organization' ]
+ scim_hash = { 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => { 'organization' => 'SOMEORG' } }.with_indifferent_case_insensitive_access()
+
+ @instance.send(
+ :from_patch_backend!,
+ nature: 'add',
+ path: path,
+ value: 'OTHERORG',
+ altering_hash: scim_hash
+ )
+
+ expect(scim_hash['urn:ietf:params:scim:schemas:extension:enterprise:2.0:User']['organization' ]).to eql('OTHERORG')
+ end
+
# For 'add', filter at end-of-path is nonsensical and not
# supported by spec or Scimitar; we only test mid-path filters.
#
context 'with filter mid-path' do
it 'by string match: overwrites' do
@@ -890,10 +922,25 @@
)
expect(scim_hash['name']['givenName']).to eql('Baz')
end
+ it 'with schema extensions: adds' do
+ path = [ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User', 'organization' ]
+ scim_hash = {}.with_indifferent_case_insensitive_access()
+
+ @instance.send(
+ :from_patch_backend!,
+ nature: 'add',
+ path: path,
+ value: 'SOMEORG',
+ altering_hash: scim_hash
+ )
+
+ expect(scim_hash['urn:ietf:params:scim:schemas:extension:enterprise:2.0:User']['organization' ]).to eql('SOMEORG')
+ end
+
context 'with filter mid-path: adds' do
it 'by string match' do
path = [ 'emails[type eq "work"]', 'value' ]
scim_hash = {
'emails' => [
@@ -1231,11 +1278,11 @@
expect(scim_hash).to_not have_key('emails')
end
# What we expect:
#
- # https://www.rfc-editor.org/rfc/rfc7644#section-3.5.2.2
+ # https://tools.ietf.org/html/rfc7644#section-3.5.2.2
# https://docs.snowflake.com/en/user-guide/scim-intro.html#patch-scim-v2-groups-id
#
# ...vs accounting for the unusual payloads we sometimes get,
# tested here.
#
@@ -2676,9 +2723,41 @@
]
}
@instance.from_scim_patch!(patch_hash: patch)
expect(@instance.first_name).to eql('Baz')
+ end
+
+ # Note odd ":" separating schema ID from first attribute, although
+ # the nature of JSON rendering / other payloads might lead you to
+ # expect a "." as with any other path component.
+ #
+ # Note the ":" separating the schema ID (URN) from the attribute.
+ # The nature of JSON rendering / other payloads might lead you to
+ # expect a "." as with any complex types, but that's not the case;
+ # see https://tools.ietf.org/html/rfc7644#section-3.10, or
+ # https://tools.ietf.org/html/rfc7644#section-3.5.2 of which in
+ # particular, https://tools.ietf.org/html/rfc7644#page-35.
+ #
+ it 'which updates attributes defined by extension schema' do
+ @instance.update!(department: 'SOMEDPT')
+
+ path = 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:department'
+ path = path.upcase if force_upper_case
+
+ patch = {
+ 'schemas' => ['urn:ietf:params:scim:api:messages:2.0:PatchOp'],
+ 'Operations' => [
+ {
+ 'op' => 'replace',
+ 'path' => path,
+ 'value' => 'OTHERDPT'
+ }
+ ]
+ }
+
+ @instance.from_scim_patch!(patch_hash: patch)
+ expect(@instance.department).to eql('OTHERDPT')
end
it 'which updates with filter match' do
@instance.update!(work_email_address: 'work@test.com', home_email_address: 'home@test.com')