scimitar 1.7.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/scimitar/active_record_backed_resources_controller.rb +10 -49
- data/app/controllers/scimitar/application_controller.rb +11 -35
- data/app/controllers/scimitar/schemas_controller.rb +0 -5
- data/app/models/scimitar/engine_configuration.rb +5 -13
- data/app/models/scimitar/error_response.rb +0 -12
- data/app/models/scimitar/lists/query_parser.rb +10 -25
- data/app/models/scimitar/resources/base.rb +4 -14
- data/app/models/scimitar/resources/mixin.rb +13 -137
- data/app/models/scimitar/schema/address.rb +0 -1
- data/app/models/scimitar/schema/attribute.rb +5 -14
- data/app/models/scimitar/schema/base.rb +1 -1
- data/app/models/scimitar/schema/vdtp.rb +1 -1
- data/app/models/scimitar/service_provider_configuration.rb +3 -14
- data/config/initializers/scimitar.rb +3 -28
- data/lib/scimitar/version.rb +2 -2
- data/lib/scimitar.rb +2 -6
- 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 -36
- 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 +10 -61
- data/spec/apps/dummy/config/routes.rb +6 -15
- data/spec/apps/dummy/db/migrate/20210304014602_create_mock_users.rb +1 -10
- 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 -11
- data/spec/controllers/scimitar/application_controller_spec.rb +3 -72
- data/spec/controllers/scimitar/resource_types_controller_spec.rb +2 -2
- data/spec/controllers/scimitar/schemas_controller_spec.rb +2 -10
- data/spec/models/scimitar/complex_types/email_spec.rb +2 -0
- data/spec/models/scimitar/lists/query_parser_spec.rb +9 -76
- data/spec/models/scimitar/resources/base_spec.rb +70 -208
- data/spec/models/scimitar/resources/base_validation_spec.rb +2 -27
- data/spec/models/scimitar/resources/mixin_spec.rb +43 -768
- data/spec/models/scimitar/schema/attribute_spec.rb +3 -22
- 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 +64 -423
- data/spec/requests/application_controller_spec.rb +3 -16
- metadata +7 -11
- data/LICENSE.txt +0 -21
- data/README.md +0 -671
- data/spec/apps/dummy/app/controllers/custom_save_mock_users_controller.rb +0 -24
@@ -9,22 +9,11 @@ module Scimitar
|
|
9
9
|
class ServiceProviderConfiguration
|
10
10
|
include ActiveModel::Model
|
11
11
|
|
12
|
-
attr_accessor
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:bulk,
|
16
|
-
:filter,
|
17
|
-
:changePassword,
|
18
|
-
:sort,
|
19
|
-
:etag,
|
20
|
-
:authenticationSchemes,
|
21
|
-
:schemas,
|
22
|
-
:meta,
|
23
|
-
)
|
12
|
+
attr_accessor :patch, :bulk, :filter, :changePassword,
|
13
|
+
:sort, :etag, :authenticationSchemes,
|
14
|
+
:schemas, :meta
|
24
15
|
|
25
16
|
def initialize(attributes = {})
|
26
|
-
@uses_defaults = attributes.empty?
|
27
|
-
|
28
17
|
defaults = {
|
29
18
|
bulk: Supportable.unsupported,
|
30
19
|
changePassword: Supportable.unsupported,
|
@@ -38,10 +38,9 @@ Rails.application.config.to_prepare do # (required for >= Rails 7 / Zeitwerk)
|
|
38
38
|
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({
|
39
39
|
|
40
40
|
# If you have filters you want to run for any Scimitar action/route, you
|
41
|
-
# can define them here.
|
42
|
-
#
|
43
|
-
#
|
44
|
-
# customise how Scimitar generates URLs:
|
41
|
+
# can define them here. For example, you might use a before-action to set
|
42
|
+
# up some multi-tenancy related state, or skip Rails CSRF token
|
43
|
+
# verification. For example:
|
45
44
|
#
|
46
45
|
# application_controller_mixin: Module.new do
|
47
46
|
# def self.included(base)
|
@@ -55,10 +54,6 @@ Rails.application.config.to_prepare do # (required for >= Rails 7 / Zeitwerk)
|
|
55
54
|
# prepend_before_action :setup_some_kind_of_multi_tenancy_data
|
56
55
|
# end
|
57
56
|
# end
|
58
|
-
#
|
59
|
-
# def scim_schemas_url(options)
|
60
|
-
# super(custom_param: 'value', **options)
|
61
|
-
# end
|
62
57
|
# end, # ...other configuration entries might follow...
|
63
58
|
|
64
59
|
# If you want to support username/password authentication:
|
@@ -86,26 +81,6 @@ Rails.application.config.to_prepare do # (required for >= Rails 7 / Zeitwerk)
|
|
86
81
|
# Note that both basic and token authentication can be declared, with the
|
87
82
|
# parameters in the inbound HTTP request determining which is invoked.
|
88
83
|
|
89
|
-
# Scimitar rescues certain error cases and exceptions, in order to return a
|
90
|
-
# JSON response to the API caller. If you want exceptions to also be
|
91
|
-
# reported to a third party system such as sentry.io or raygun.com, you can
|
92
|
-
# configure a Proc to do so. It is passed a Ruby exception subclass object.
|
93
|
-
# For example, a minimal sentry.io reporter might do this:
|
94
|
-
#
|
95
|
-
# exception_reporter: Proc.new do | exception |
|
96
|
-
# Sentry.capture_exception(exception)
|
97
|
-
# end
|
98
|
-
#
|
99
|
-
# You will still need to configure your reporting system according to its
|
100
|
-
# documentation (e.g. via a Rails "config/initializers/<foo>.rb" file).
|
101
|
-
|
102
|
-
# Scimilar treats "VDTP" (Value, Display, Type, Primary) attribute values,
|
103
|
-
# used for e.g. e-mail addresses or phone numbers, as required by default.
|
104
|
-
# If you encounter a service which calls these with e.g. "null" value data,
|
105
|
-
# you can configure all values to be optional. You'll need to deal with
|
106
|
-
# whatever that means for you receiving system in your model code.
|
107
|
-
#
|
108
|
-
# optional_value_fields_required: false
|
109
84
|
})
|
110
85
|
|
111
86
|
end
|
data/lib/scimitar/version.rb
CHANGED
@@ -3,11 +3,11 @@ module Scimitar
|
|
3
3
|
# Gem version. If this changes, be sure to re-run "bundle install" or
|
4
4
|
# "bundle update".
|
5
5
|
#
|
6
|
-
VERSION = '
|
6
|
+
VERSION = '2.0.0'
|
7
7
|
|
8
8
|
# Date for VERSION. If this changes, be sure to re-run "bundle install"
|
9
9
|
# or "bundle update".
|
10
10
|
#
|
11
|
-
DATE = '
|
11
|
+
DATE = '2022-03-04'
|
12
12
|
|
13
13
|
end
|
data/lib/scimitar.rb
CHANGED
@@ -4,9 +4,7 @@ require 'scimitar/engine'
|
|
4
4
|
|
5
5
|
module Scimitar
|
6
6
|
def self.service_provider_configuration=(custom_configuration)
|
7
|
-
|
8
|
-
@service_provider_configuration = custom_configuration
|
9
|
-
end
|
7
|
+
@service_provider_configuration = custom_configuration
|
10
8
|
end
|
11
9
|
|
12
10
|
def self.service_provider_configuration(location:)
|
@@ -16,9 +14,7 @@ module Scimitar
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def self.engine_configuration=(custom_configuration)
|
19
|
-
|
20
|
-
@engine_configuration = custom_configuration
|
21
|
-
end
|
17
|
+
@engine_configuration = custom_configuration
|
22
18
|
end
|
23
19
|
|
24
20
|
def self.engine_configuration
|
@@ -1,24 +1,18 @@
|
|
1
1
|
class MockUser < ActiveRecord::Base
|
2
2
|
|
3
|
-
self.primary_key = :primary_key
|
4
|
-
|
5
3
|
# ===========================================================================
|
6
4
|
# TEST ATTRIBUTES - see db/migrate/20210304014602_create_mock_users.rb etc.
|
7
5
|
# ===========================================================================
|
8
6
|
|
9
7
|
READWRITE_ATTRS = %w{
|
10
|
-
|
8
|
+
id
|
11
9
|
scim_uid
|
12
10
|
username
|
13
|
-
password
|
14
11
|
first_name
|
15
12
|
last_name
|
16
13
|
work_email_address
|
17
14
|
home_email_address
|
18
15
|
work_phone_number
|
19
|
-
organization
|
20
|
-
department
|
21
|
-
mock_groups
|
22
16
|
}
|
23
17
|
|
24
18
|
has_and_belongs_to_many :mock_groups
|
@@ -44,10 +38,9 @@ class MockUser < ActiveRecord::Base
|
|
44
38
|
|
45
39
|
def self.scim_attributes_map
|
46
40
|
return {
|
47
|
-
id: :
|
41
|
+
id: :id,
|
48
42
|
externalId: :scim_uid,
|
49
43
|
userName: :username,
|
50
|
-
password: :password,
|
51
44
|
name: {
|
52
45
|
givenName: :first_name,
|
53
46
|
familyName: :last_name
|
@@ -89,23 +82,7 @@ class MockUser < ActiveRecord::Base
|
|
89
82
|
}
|
90
83
|
}
|
91
84
|
],
|
92
|
-
active: :is_active
|
93
|
-
|
94
|
-
# Custom extension schema - see configuration in
|
95
|
-
# "spec/apps/dummy/config/initializers/scimitar.rb".
|
96
|
-
#
|
97
|
-
organization: :organization,
|
98
|
-
department: :department,
|
99
|
-
userGroups: [
|
100
|
-
{
|
101
|
-
list: :mock_groups,
|
102
|
-
find_with: ->(value) { MockGroup.find(value["value"]) },
|
103
|
-
using: {
|
104
|
-
value: :id,
|
105
|
-
display: :display_name
|
106
|
-
}
|
107
|
-
}
|
108
|
-
]
|
85
|
+
active: :is_active
|
109
86
|
}
|
110
87
|
end
|
111
88
|
|
@@ -115,16 +92,11 @@ class MockUser < ActiveRecord::Base
|
|
115
92
|
|
116
93
|
def self.scim_queryable_attributes
|
117
94
|
return {
|
118
|
-
'
|
119
|
-
'
|
120
|
-
'
|
121
|
-
'
|
122
|
-
'
|
123
|
-
'groups' => { column: MockGroup.arel_table[:id] },
|
124
|
-
'groups.value' => { column: MockGroup.arel_table[:id] },
|
125
|
-
'emails' => { columns: [ :work_email_address, :home_email_address ] },
|
126
|
-
'emails.value' => { columns: [ :work_email_address, :home_email_address ] },
|
127
|
-
'emails.type' => { ignore: true } # We can't filter on that; it'll just search all e-mails
|
95
|
+
'name.givenName' => { column: :first_name },
|
96
|
+
'name.familyName' => { column: :last_name },
|
97
|
+
'emails' => { columns: [ :work_email_address, :home_email_address ] },
|
98
|
+
'emails.value' => { columns: [ :work_email_address, :home_email_address ] },
|
99
|
+
'emails.type' => { ignore: true } # We can't filter on that; it'll just search all e-mails
|
128
100
|
}
|
129
101
|
end
|
130
102
|
|
@@ -1,15 +1,38 @@
|
|
1
|
+
require 'active_support/core_ext/integer/time'
|
2
|
+
|
1
3
|
Rails.application.configure do
|
2
4
|
config.cache_classes = true
|
3
5
|
config.eager_load = false
|
4
|
-
config.serve_static_files = true
|
5
|
-
config.static_cache_control = 'public, max-age=3600'
|
6
|
-
config.consider_all_requests_local = true
|
7
6
|
|
8
|
-
|
7
|
+
# Configure public file server for tests with Cache-Control for performance.
|
8
|
+
config.public_file_server.enabled = true
|
9
|
+
config.public_file_server.headers = {
|
10
|
+
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
|
11
|
+
}
|
9
12
|
|
13
|
+
# Show full error reports and disable caching.
|
14
|
+
config.consider_all_requests_local = true
|
10
15
|
config.action_controller.perform_caching = false
|
16
|
+
config.cache_store = :null_store
|
17
|
+
|
18
|
+
# Raise exceptions instead of rendering exception templates.
|
19
|
+
config.action_dispatch.show_exceptions = false
|
20
|
+
|
21
|
+
# Disable request forgery protection in test environment.
|
11
22
|
config.action_controller.allow_forgery_protection = false
|
12
23
|
|
13
|
-
|
24
|
+
# Print deprecation notices to the stderr.
|
14
25
|
config.active_support.deprecation = :stderr
|
26
|
+
|
27
|
+
# Raise exceptions for disallowed deprecations.
|
28
|
+
config.active_support.disallowed_deprecation = :raise
|
29
|
+
|
30
|
+
# Tell Active Support which deprecation messages to disallow.
|
31
|
+
config.active_support.disallowed_deprecation_warnings = []
|
32
|
+
|
33
|
+
# Raises error for missing translations.
|
34
|
+
config.i18n.raise_on_missing_translations = true
|
35
|
+
|
36
|
+
# Annotate rendered view with file names.
|
37
|
+
# config.action_view.annotate_rendered_view_with_filenames = true
|
15
38
|
end
|
@@ -1,67 +1,16 @@
|
|
1
1
|
# Test app configuration.
|
2
2
|
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# Further, https://github.com/RIPAGlobal/scimitar/pull/54 fixed warning
|
13
|
-
# messages in a way that worked on Rails 6+ but, for V1 Scimitar, it would
|
14
|
-
# break existing working setups that didn't use the +to_prepare+ wrapper. Their
|
15
|
-
# application configuration would be written *first* but then *overwritten* by
|
16
|
-
# the default +to_prepare+ block in Scimitar itself, since that runs later. The
|
17
|
-
# file below does *not* use +to_prepare+ in order to test the workaround that
|
18
|
-
# was produced; it should work on all Ruby versions as-is.
|
19
|
-
#
|
20
|
-
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({
|
21
|
-
|
22
|
-
application_controller_mixin: Module.new do
|
23
|
-
def self.included(base)
|
24
|
-
base.class_eval do
|
25
|
-
def test_hook; end
|
26
|
-
before_action :test_hook
|
3
|
+
Rails.application.config.to_prepare do
|
4
|
+
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new({
|
5
|
+
|
6
|
+
application_controller_mixin: Module.new do
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
def test_hook; end
|
10
|
+
before_action :test_hook
|
11
|
+
end
|
27
12
|
end
|
28
13
|
end
|
29
14
|
|
30
|
-
|
31
|
-
super(test: 1, **options)
|
32
|
-
end
|
33
|
-
|
34
|
-
def scim_resource_type_url(options)
|
35
|
-
super(test: 1, **options)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
})
|
40
|
-
|
41
|
-
module ScimSchemaExtensions
|
42
|
-
module User
|
43
|
-
class Enterprise < Scimitar::Schema::Base
|
44
|
-
def initialize(options = {})
|
45
|
-
super(
|
46
|
-
name: 'ExtendedUser',
|
47
|
-
description: 'Enterprise extension for a User',
|
48
|
-
id: self.class.id,
|
49
|
-
scim_attributes: self.class.scim_attributes
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.id
|
54
|
-
'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.scim_attributes
|
58
|
-
[
|
59
|
-
Scimitar::Schema::Attribute.new(name: 'organization', type: 'string'),
|
60
|
-
Scimitar::Schema::Attribute.new(name: 'department', type: 'string')
|
61
|
-
]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
15
|
+
})
|
65
16
|
end
|
66
|
-
|
67
|
-
Scimitar::Resources::User.extend_schema ScimSchemaExtensions::User::Enterprise
|
@@ -6,26 +6,17 @@
|
|
6
6
|
Rails.application.routes.draw do
|
7
7
|
mount Scimitar::Engine, at: '/'
|
8
8
|
|
9
|
-
get 'Users',
|
10
|
-
get 'Users/:id',
|
11
|
-
post 'Users',
|
12
|
-
put 'Users/:id',
|
13
|
-
patch 'Users/:id',
|
14
|
-
delete 'Users/:id',
|
15
|
-
|
16
|
-
get 'Groups', to: 'mock_groups#index'
|
17
|
-
get 'Groups/:id', to: 'mock_groups#show'
|
18
|
-
patch 'Groups/:id', to: 'mock_groups#update'
|
9
|
+
get 'Users', to: 'mock_users#index'
|
10
|
+
get 'Users/:id', to: 'mock_users#show'
|
11
|
+
post 'Users', to: 'mock_users#create'
|
12
|
+
put 'Users/:id', to: 'mock_users#replace'
|
13
|
+
patch 'Users/:id', to: 'mock_users#update'
|
14
|
+
delete 'Users/:id', to: 'mock_users#destroy'
|
19
15
|
|
20
16
|
# For testing blocks passed to ActiveRecordBackedResourcesController#destroy
|
21
17
|
#
|
22
18
|
delete 'CustomDestroyUsers/:id', to: 'custom_destroy_mock_users#destroy'
|
23
19
|
|
24
|
-
# For testing blocks passed to ActiveRecordBackedResourcesController#save!
|
25
|
-
#
|
26
|
-
post 'CustomSaveUsers', to: 'custom_save_mock_users#create'
|
27
|
-
get 'CustomSaveUsers/:id', to: 'custom_save_mock_users#show'
|
28
|
-
|
29
20
|
# For testing environment inside Scimitar::ApplicationController subclasses.
|
30
21
|
#
|
31
22
|
get 'CustomRequestVerifiers', to: 'custom_request_verifiers#index'
|
@@ -1,24 +1,15 @@
|
|
1
1
|
class CreateMockUsers < ActiveRecord::Migration[6.1]
|
2
2
|
def change
|
3
|
-
create_table :mock_users
|
4
|
-
t.timestamps
|
3
|
+
create_table :mock_users do |t|
|
5
4
|
|
6
|
-
# Support part of the core schema
|
7
|
-
#
|
8
5
|
t.text :scim_uid
|
9
6
|
t.text :username
|
10
|
-
t.text :password
|
11
7
|
t.text :first_name
|
12
8
|
t.text :last_name
|
13
9
|
t.text :work_email_address
|
14
10
|
t.text :home_email_address
|
15
11
|
t.text :work_phone_number
|
16
12
|
|
17
|
-
# Support the custom extension schema - see configuration in
|
18
|
-
# "spec/apps/dummy/config/initializers/scimitar.rb".
|
19
|
-
#
|
20
|
-
t.text :organization
|
21
|
-
t.text :department
|
22
13
|
end
|
23
14
|
end
|
24
15
|
end
|
@@ -1,13 +1,8 @@
|
|
1
1
|
class CreateJoinTableMockGroupsMockUsers < ActiveRecord::Migration[6.1]
|
2
2
|
def change
|
3
|
-
|
4
|
-
t.
|
5
|
-
t.
|
6
|
-
|
7
|
-
# The 'foreign_key:' option (used above) only works for 'id' column names
|
8
|
-
# but the test data has a column named 'primary_key' for 'mock_users'.
|
9
|
-
#
|
10
|
-
t.foreign_key :mock_users, primary_key: :primary_key
|
3
|
+
create_join_table :mock_groups, :mock_users do |t|
|
4
|
+
t.index [:mock_group_id, :mock_user_id]
|
5
|
+
t.index [:mock_user_id, :mock_group_id]
|
11
6
|
end
|
12
7
|
end
|
13
8
|
end
|
@@ -24,26 +24,19 @@ ActiveRecord::Schema.define(version: 2021_03_08_044214) do
|
|
24
24
|
|
25
25
|
create_table "mock_groups_users", id: false, force: :cascade do |t|
|
26
26
|
t.bigint "mock_group_id", null: false
|
27
|
-
t.
|
28
|
-
t.index ["mock_group_id"], name: "
|
29
|
-
t.index ["mock_user_id"], name: "
|
27
|
+
t.bigint "mock_user_id", null: false
|
28
|
+
t.index ["mock_group_id", "mock_user_id"], name: "index_mock_groups_users_on_mock_group_id_and_mock_user_id"
|
29
|
+
t.index ["mock_user_id", "mock_group_id"], name: "index_mock_groups_users_on_mock_user_id_and_mock_group_id"
|
30
30
|
end
|
31
31
|
|
32
|
-
create_table "mock_users",
|
33
|
-
t.datetime "created_at", null: false
|
34
|
-
t.datetime "updated_at", null: false
|
32
|
+
create_table "mock_users", force: :cascade do |t|
|
35
33
|
t.text "scim_uid"
|
36
34
|
t.text "username"
|
37
|
-
t.text "password"
|
38
35
|
t.text "first_name"
|
39
36
|
t.text "last_name"
|
40
37
|
t.text "work_email_address"
|
41
38
|
t.text "home_email_address"
|
42
39
|
t.text "work_phone_number"
|
43
|
-
t.text "organization"
|
44
|
-
t.text "department"
|
45
40
|
end
|
46
41
|
|
47
|
-
add_foreign_key "mock_groups_users", "mock_groups"
|
48
|
-
add_foreign_key "mock_groups_users", "mock_users", primary_key: "primary_key"
|
49
42
|
end
|
@@ -24,7 +24,7 @@ RSpec.describe Scimitar::ApplicationController do
|
|
24
24
|
get :index, params: { format: :scim }
|
25
25
|
expect(response).to be_ok
|
26
26
|
expect(JSON.parse(response.body)).to eql({ 'message' => 'cool, cool!' })
|
27
|
-
expect(response.headers['
|
27
|
+
expect(response.headers['WWW_AUTHENTICATE']).to eql('Basic')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'renders failure with bad password' do
|
@@ -84,7 +84,7 @@ RSpec.describe Scimitar::ApplicationController do
|
|
84
84
|
get :index, params: { format: :scim }
|
85
85
|
expect(response).to be_ok
|
86
86
|
expect(JSON.parse(response.body)).to eql({ 'message' => 'cool, cool!' })
|
87
|
-
expect(response.headers['
|
87
|
+
expect(response.headers['WWW_AUTHENTICATE']).to eql('Bearer')
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'renders failure with bad token' do
|
@@ -169,74 +169,5 @@ RSpec.describe Scimitar::ApplicationController do
|
|
169
169
|
expect(parsed_body).to include('status' => '500')
|
170
170
|
expect(parsed_body).to include('detail' => 'Bang')
|
171
171
|
end
|
172
|
-
|
173
|
-
context 'with an exception reporter' do
|
174
|
-
around :each do | example |
|
175
|
-
original_configuration = Scimitar.engine_configuration.exception_reporter
|
176
|
-
Scimitar.engine_configuration.exception_reporter = Proc.new do | exception |
|
177
|
-
@exception = exception
|
178
|
-
end
|
179
|
-
example.run()
|
180
|
-
ensure
|
181
|
-
Scimitar.engine_configuration.exception_reporter = original_configuration
|
182
|
-
end
|
183
|
-
|
184
|
-
context 'and "internal server error"' do
|
185
|
-
it 'is invoked' do
|
186
|
-
get :index, params: { format: :scim }
|
187
|
-
|
188
|
-
expect(@exception).to be_a(RuntimeError)
|
189
|
-
expect(@exception.message).to eql('Bang')
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'and "not found"' do
|
194
|
-
controller do
|
195
|
-
def index
|
196
|
-
handle_resource_not_found(ActiveRecord::RecordNotFound.new(42))
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'is invoked' do
|
201
|
-
get :index, params: { format: :scim }
|
202
|
-
|
203
|
-
expect(@exception).to be_a(ActiveRecord::RecordNotFound)
|
204
|
-
expect(@exception.message).to eql('42')
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context 'and bad JSON' do
|
209
|
-
controller do
|
210
|
-
def index
|
211
|
-
begin
|
212
|
-
raise 'Hello'
|
213
|
-
rescue
|
214
|
-
raise ActionDispatch::Http::Parameters::ParseError
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'is invoked' do
|
220
|
-
get :index, params: { format: :scim }
|
221
|
-
|
222
|
-
expect(@exception).to be_a(ActionDispatch::Http::Parameters::ParseError)
|
223
|
-
expect(@exception.message).to eql('Hello')
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
context 'and a bad content type' do
|
228
|
-
controller do
|
229
|
-
def index; end
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'is invoked' do
|
233
|
-
request.headers['Content-Type'] = 'text/plain'
|
234
|
-
get :index
|
235
|
-
|
236
|
-
expect(@exception).to be_a(Scimitar::ErrorResponse)
|
237
|
-
expect(@exception.message).to eql('Only application/scim+json type is accepted.')
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end # "context 'exception reporter' do"
|
241
|
-
end # "context 'error handling' do"
|
172
|
+
end
|
242
173
|
end
|
@@ -9,8 +9,8 @@ RSpec.describe Scimitar::ResourceTypesController do
|
|
9
9
|
it 'renders the resource type for user' do
|
10
10
|
get :index, format: :scim
|
11
11
|
response_hash = JSON.parse(response.body)
|
12
|
-
expected_response = [ Scimitar::Resources::User.resource_type(scim_resource_type_url(name: 'User'
|
13
|
-
Scimitar::Resources::Group.resource_type(scim_resource_type_url(name: 'Group'
|
12
|
+
expected_response = [ Scimitar::Resources::User.resource_type(scim_resource_type_url(name: 'User')),
|
13
|
+
Scimitar::Resources::Group.resource_type(scim_resource_type_url(name: 'Group'))
|
14
14
|
].to_json
|
15
15
|
|
16
16
|
response_hash = JSON.parse(response.body)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Scimitar::SchemasController do
|
4
|
-
routes { Scimitar::Engine.routes }
|
5
4
|
|
6
5
|
before(:each) { allow(controller).to receive(:authenticated?).and_return(true) }
|
7
6
|
|
@@ -15,9 +14,9 @@ RSpec.describe Scimitar::SchemasController do
|
|
15
14
|
get :index, params: { format: :scim }
|
16
15
|
expect(response).to be_ok
|
17
16
|
parsed_body = JSON.parse(response.body)
|
18
|
-
expect(parsed_body.length).to eql(
|
17
|
+
expect(parsed_body.length).to eql(2)
|
19
18
|
schema_names = parsed_body.map {|schema| schema['name']}
|
20
|
-
expect(schema_names).to match_array(['User', '
|
19
|
+
expect(schema_names).to match_array(['User', 'Group'])
|
21
20
|
end
|
22
21
|
|
23
22
|
it 'returns only the User schema when its id is provided' do
|
@@ -27,13 +26,6 @@ RSpec.describe Scimitar::SchemasController do
|
|
27
26
|
expect(parsed_body['name']).to eql('User')
|
28
27
|
end
|
29
28
|
|
30
|
-
it 'includes the controller customised schema location' do
|
31
|
-
get :index, params: { name: Scimitar::Schema::User.id, format: :scim }
|
32
|
-
expect(response).to be_ok
|
33
|
-
parsed_body = JSON.parse(response.body)
|
34
|
-
expect(parsed_body.dig('meta', 'location')).to eq scim_schemas_url(name: Scimitar::Schema::User.id, test: 1)
|
35
|
-
end
|
36
|
-
|
37
29
|
it 'returns only the Group schema when its id is provided' do
|
38
30
|
get :index, params: { name: Scimitar::Schema::Group.id, format: :scim }
|
39
31
|
expect(response).to be_ok
|