scimitar 1.5.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/scimitar/active_record_backed_resources_controller.rb +6 -27
- data/app/controllers/scimitar/application_controller.rb +9 -29
- data/app/models/scimitar/engine_configuration.rb +3 -7
- data/app/models/scimitar/error_response.rb +0 -12
- data/app/models/scimitar/errors.rb +1 -1
- data/app/models/scimitar/lists/query_parser.rb +4 -14
- data/app/models/scimitar/resources/base.rb +1 -1
- data/app/models/scimitar/resources/mixin.rb +4 -113
- data/app/models/scimitar/schema/address.rb +0 -1
- data/app/models/scimitar/schema/attribute.rb +1 -1
- data/app/models/scimitar/schema/base.rb +3 -1
- data/app/models/scimitar/schema/vdtp.rb +1 -1
- data/config/initializers/scimitar.rb +70 -86
- data/lib/scimitar/version.rb +2 -2
- data/spec/apps/dummy/app/controllers/mock_groups_controller.rb +1 -1
- data/spec/apps/dummy/app/models/mock_group.rb +1 -1
- data/spec/apps/dummy/app/models/mock_user.rb +8 -19
- data/spec/apps/dummy/config/application.rb +1 -0
- data/spec/apps/dummy/config/environments/test.rb +28 -5
- data/spec/apps/dummy/config/initializers/scimitar.rb +9 -44
- data/spec/apps/dummy/config/routes.rb +0 -4
- data/spec/apps/dummy/db/migrate/20210304014602_create_mock_users.rb +1 -9
- data/spec/apps/dummy/db/migrate/20210308044214_create_join_table_mock_groups_mock_users.rb +3 -8
- data/spec/apps/dummy/db/schema.rb +4 -10
- data/spec/controllers/scimitar/application_controller_spec.rb +1 -70
- data/spec/controllers/scimitar/schemas_controller_spec.rb +2 -2
- data/spec/models/scimitar/complex_types/email_spec.rb +2 -0
- data/spec/models/scimitar/lists/query_parser_spec.rb +9 -9
- data/spec/models/scimitar/resources/base_spec.rb +66 -161
- data/spec/models/scimitar/resources/base_validation_spec.rb +2 -27
- data/spec/models/scimitar/resources/mixin_spec.rb +43 -757
- data/spec/models/scimitar/resources/user_spec.rb +4 -4
- data/spec/models/scimitar/schema/attribute_spec.rb +3 -0
- data/spec/models/scimitar/schema/base_spec.rb +1 -1
- data/spec/models/scimitar/schema/user_spec.rb +0 -10
- data/spec/requests/active_record_backed_resources_controller_spec.rb +40 -309
- data/spec/requests/application_controller_spec.rb +3 -17
- metadata +7 -7
@@ -250,185 +250,90 @@ RSpec.describe Scimitar::Resources::Base do
|
|
250
250
|
end # "context 'dynamic setters based on schema' do"
|
251
251
|
|
252
252
|
context 'schema extension' do
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
'custom-id'
|
257
|
-
end
|
258
|
-
|
259
|
-
def self.scim_attributes
|
260
|
-
[ Scimitar::Schema::Attribute.new(name: 'name', type: 'string') ]
|
261
|
-
end
|
253
|
+
ThirdCustomSchema = Class.new(Scimitar::Schema::Base) do
|
254
|
+
def self.id
|
255
|
+
'custom-id'
|
262
256
|
end
|
263
257
|
|
264
|
-
|
265
|
-
|
266
|
-
'extension-id'
|
267
|
-
end
|
268
|
-
|
269
|
-
def self.scim_attributes
|
270
|
-
[ Scimitar::Schema::Attribute.new(name: 'relationship', type: 'string', required: true) ]
|
271
|
-
end
|
258
|
+
def self.scim_attributes
|
259
|
+
[ Scimitar::Schema::Attribute.new(name: 'name', type: 'string') ]
|
272
260
|
end
|
261
|
+
end
|
273
262
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
def self.endpoint
|
280
|
-
'/gaga'
|
281
|
-
end
|
282
|
-
|
283
|
-
def self.resource_type_id
|
284
|
-
'CustomResource'
|
285
|
-
end
|
286
|
-
end
|
287
|
-
}
|
288
|
-
|
289
|
-
context '#initialize' do
|
290
|
-
it 'allows setting extension attributes' do
|
291
|
-
resource = resource_class.new('extension-id' => {relationship: 'GAGA'})
|
292
|
-
expect(resource.relationship).to eql('GAGA')
|
293
|
-
end
|
294
|
-
end # "context '#initialize' do"
|
295
|
-
|
296
|
-
context '#as_json' do
|
297
|
-
it 'namespaces the extension attributes' do
|
298
|
-
resource = resource_class.new(relationship: 'GAGA')
|
299
|
-
hash = resource.as_json
|
300
|
-
expect(hash["schemas"]).to eql(['custom-id', 'extension-id'])
|
301
|
-
expect(hash["extension-id"]).to eql("relationship" => 'GAGA')
|
302
|
-
end
|
303
|
-
end # "context '#as_json' do"
|
304
|
-
|
305
|
-
context '.resource_type' do
|
306
|
-
it 'appends the extension schemas' do
|
307
|
-
resource_type = resource_class.resource_type('http://gaga')
|
308
|
-
expect(resource_type.meta.location).to eql('http://gaga')
|
309
|
-
expect(resource_type.schemaExtensions.count).to eql(1)
|
310
|
-
end
|
311
|
-
|
312
|
-
context 'validation' do
|
313
|
-
it 'validates into custom schema' do
|
314
|
-
resource = resource_class.new('extension-id' => {})
|
315
|
-
expect(resource.valid?).to eql(false)
|
263
|
+
ExtensionSchema = Class.new(Scimitar::Schema::Base) do
|
264
|
+
def self.id
|
265
|
+
'extension-id'
|
266
|
+
end
|
316
267
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
end # context 'validation'
|
322
|
-
end # "context '.resource_type' do"
|
268
|
+
def self.scim_attributes
|
269
|
+
[ Scimitar::Schema::Attribute.new(name: 'relationship', type: 'string', required: true) ]
|
270
|
+
end
|
271
|
+
end
|
323
272
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
expect(found.name).to eql('name')
|
329
|
-
expect(found.type).to eql('string')
|
330
|
-
end
|
273
|
+
let(:resource_class) {
|
274
|
+
Class.new(Scimitar::Resources::Base) do
|
275
|
+
set_schema ThirdCustomSchema
|
276
|
+
extend_schema ExtensionSchema
|
331
277
|
|
332
|
-
|
333
|
-
|
334
|
-
expect(found).to be_present
|
335
|
-
expect(found.name).to eql('relationship')
|
336
|
-
expect(found.type).to eql('string')
|
278
|
+
def self.endpoint
|
279
|
+
'/gaga'
|
337
280
|
end
|
338
|
-
end # "context '.find_attribute' do"
|
339
|
-
end # "context 'of custom schema' do"
|
340
281
|
|
341
|
-
|
342
|
-
|
343
|
-
def self.id
|
344
|
-
'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'
|
345
|
-
end
|
346
|
-
|
347
|
-
def self.scim_attributes
|
348
|
-
[
|
349
|
-
Scimitar::Schema::Attribute.new(name: 'organization', type: 'string'),
|
350
|
-
Scimitar::Schema::Attribute.new(name: 'department', type: 'string')
|
351
|
-
]
|
282
|
+
def self.resource_type_id
|
283
|
+
'CustomResource'
|
352
284
|
end
|
353
285
|
end
|
286
|
+
}
|
354
287
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
'/Users'
|
362
|
-
end
|
363
|
-
|
364
|
-
def self.resource_type_id
|
365
|
-
'User'
|
366
|
-
end
|
367
|
-
end
|
368
|
-
}
|
369
|
-
|
370
|
-
context '#initialize' do
|
371
|
-
it 'allows setting extension attributes' do
|
372
|
-
resource = resource_class.new('urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => {organization: 'SOMEORG', department: 'SOMEDPT'})
|
288
|
+
context '#initialize' do
|
289
|
+
it 'allows setting extension attributes' do
|
290
|
+
resource = resource_class.new('extension-id' => {relationship: 'GAGA'})
|
291
|
+
expect(resource.relationship).to eql('GAGA')
|
292
|
+
end
|
293
|
+
end # "context '#initialize' do"
|
373
294
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
295
|
+
context '#as_json' do
|
296
|
+
it 'namespaces the extension attributes' do
|
297
|
+
resource = resource_class.new(relationship: 'GAGA')
|
298
|
+
hash = resource.as_json
|
299
|
+
expect(hash["schemas"]).to eql(['custom-id', 'extension-id'])
|
300
|
+
expect(hash["extension-id"]).to eql("relationship" => 'GAGA')
|
301
|
+
end
|
302
|
+
end # "context '#as_json' do"
|
378
303
|
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
304
|
+
context '.resource_type' do
|
305
|
+
it 'appends the extension schemas' do
|
306
|
+
resource_type = resource_class.resource_type('http://gaga')
|
307
|
+
expect(resource_type.meta.location).to eql('http://gaga')
|
308
|
+
expect(resource_type.schemaExtensions.count).to eql(1)
|
309
|
+
end
|
383
310
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
311
|
+
context 'validation' do
|
312
|
+
it 'validates into custom schema' do
|
313
|
+
resource = resource_class.new('extension-id' => {})
|
314
|
+
expect(resource.valid?).to eql(false)
|
388
315
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
expect(resource_type.meta.location).to eql('http://example.com')
|
393
|
-
expect(resource_type.schemaExtensions.count).to eql(1)
|
316
|
+
resource = resource_class.new('extension-id' => {relationship: 'GAGA'})
|
317
|
+
expect(resource.relationship).to eql('GAGA')
|
318
|
+
expect(resource.valid?).to eql(true)
|
394
319
|
end
|
320
|
+
end # context 'validation'
|
321
|
+
end # "context '.resource_type' do"
|
395
322
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
userName: 'SOMEUSR',
|
404
|
-
organization: 'SOMEORG',
|
405
|
-
department: 'SOMEDPT'
|
406
|
-
}
|
407
|
-
)
|
408
|
-
|
409
|
-
expect(resource.organization).to eql('SOMEORG')
|
410
|
-
expect(resource.department ).to eql('SOMEDPT')
|
411
|
-
expect(resource.valid? ).to eql(true)
|
412
|
-
end
|
413
|
-
end # context 'validation'
|
414
|
-
end # "context '.resource_type' do"
|
415
|
-
|
416
|
-
context '.find_attribute' do
|
417
|
-
it 'finds in first schema' do
|
418
|
-
found = resource_class().find_attribute('userName') # Defined in Scimitar::Schema::User
|
419
|
-
|
420
|
-
expect(found).to be_present
|
421
|
-
expect(found.name).to eql('userName')
|
422
|
-
expect(found.type).to eql('string')
|
423
|
-
end
|
323
|
+
context '.find_attribute' do
|
324
|
+
it 'finds in first schema' do
|
325
|
+
found = resource_class().find_attribute('name') # Defined in ThirdCustomSchema
|
326
|
+
expect(found).to be_present
|
327
|
+
expect(found.name).to eql('name')
|
328
|
+
expect(found.type).to eql('string')
|
329
|
+
end
|
424
330
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
end # "context 'of core schema' do"
|
331
|
+
it 'finds across schemas' do
|
332
|
+
found = resource_class().find_attribute('relationship') # Defined in ExtensionSchema
|
333
|
+
expect(found).to be_present
|
334
|
+
expect(found.name).to eql('relationship')
|
335
|
+
expect(found.type).to eql('string')
|
336
|
+
end
|
337
|
+
end # "context '.find_attribute' do"
|
433
338
|
end # "context 'schema extension' do"
|
434
339
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Scimitar::Resources::Base do
|
4
|
+
|
4
5
|
context '#valid?' do
|
5
6
|
MyCustomSchema = Class.new(Scimitar::Schema::Base) do
|
6
7
|
def self.id
|
@@ -20,9 +21,6 @@ RSpec.describe Scimitar::Resources::Base do
|
|
20
21
|
),
|
21
22
|
Scimitar::Schema::Attribute.new(
|
22
23
|
name: 'complexNames', complexType: Scimitar::ComplexTypes::Name, multiValued:true, required: false
|
23
|
-
),
|
24
|
-
Scimitar::Schema::Attribute.new(
|
25
|
-
name: 'vdtpTestByEmail', complexType: Scimitar::ComplexTypes::Email, required: false
|
26
24
|
)
|
27
25
|
]
|
28
26
|
end
|
@@ -59,28 +57,5 @@ RSpec.describe Scimitar::Resources::Base do
|
|
59
57
|
expect(resource.valid?).to be(false)
|
60
58
|
expect(resource.errors.full_messages).to match_array(["Complexnames has to follow the complexType format.", "Complexnames familyname has the wrong type. It has to be a(n) string."])
|
61
59
|
end
|
62
|
-
|
63
|
-
context 'configuration of required values in VDTP schema' do
|
64
|
-
around :each do | example |
|
65
|
-
original_configuration = Scimitar.engine_configuration.optional_value_fields_required
|
66
|
-
Scimitar::Schema::Email.instance_variable_set('@scim_attributes', nil)
|
67
|
-
example.run()
|
68
|
-
ensure
|
69
|
-
Scimitar.engine_configuration.optional_value_fields_required = original_configuration
|
70
|
-
Scimitar::Schema::Email.instance_variable_set('@scim_attributes', nil)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'requires a value by default' do
|
74
|
-
resource = MyCustomResource.new(vdtpTestByEmail: { value: nil }, enforce: false)
|
75
|
-
expect(resource.valid?).to be(false)
|
76
|
-
expect(resource.errors.full_messages).to match_array(['Vdtptestbyemail value is required'])
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'can be configured for optional values' do
|
80
|
-
Scimitar.engine_configuration.optional_value_fields_required = false
|
81
|
-
resource = MyCustomResource.new(vdtpTestByEmail: { value: nil }, enforce: false)
|
82
|
-
expect(resource.valid?).to be(true)
|
83
|
-
end
|
84
|
-
end # "context 'configuration of required values in VDTP schema' do"
|
85
|
-
end # "context '#valid?' do"
|
60
|
+
end
|
86
61
|
end
|