Skip to content

Commit 5d1d0ff

Browse files
author
Andrew Burns
committed
Add proper spec for SCIM user schema
- Fix missing fields. - It is a pain to duplicate the schema fields in the spec; however: - It makes sure that we don't miss any
1 parent eee88f9 commit 5d1d0ff

File tree

2 files changed

+142
-21
lines changed

2 files changed

+142
-21
lines changed

app/services/parameter_service.rb

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,27 @@ module ParameterService
1313
# https://datatracker.ietf.org/doc/html/rfc7643#section-4
1414
SCIM_CORE_USER_SCHEMA = {
1515
"id" => :value,
16-
"department" => :value,
1716
"userName" => :value,
17+
"externalId" => :value,
18+
"active" => :value,
19+
"addresses" => [],
20+
"costCenter" => :value,
21+
"department" => :value,
1822
"displayName" => :value,
19-
"nickName" => :value,
23+
"division" => :value,
24+
"emails" => [],
25+
"employeeNumber" => :value,
26+
"entitlements" => [],
27+
"groups" => [],
28+
"ims" => [],
29+
"locale" => :value,
30+
"meta" => {
31+
"resourceType" => :value,
32+
"created" => :value,
33+
"lastModified" => :value,
34+
"location" => :value,
35+
"version" => :value,
36+
},
2037
"name" => {
2138
"formatted" => :value,
2239
"familyName" => :value,
@@ -25,28 +42,17 @@ module ParameterService
2542
"honorificPrefix" => :value,
2643
"honorificSuffix" => :value,
2744
},
28-
"profileUrl" => :value,
29-
"title" => :value,
30-
"userType" => :value,
31-
"preferredLanguage" => :value,
32-
"locale" => :value,
33-
"timezone" => :value,
34-
"active" => :value,
45+
"nickName" => :value,
46+
"organization" => :value,
3547
"password" => :value,
36-
"emails" => [],
3748
"phoneNumbers" => [],
38-
"ims" => :value,
39-
"photos" => :value,
40-
"addresses" => {
41-
"formatted" => :value,
42-
"streetAddress" => :value,
43-
"locality" => :value,
44-
"region" => :value,
45-
"postalCode" => :value,
46-
"country" => :value,
47-
},
48-
"entitlements" => [],
49+
"photos" => [],
50+
"preferredLanguage" => :value,
51+
"profileUrl" => :value,
4952
"roles" => [],
53+
"timezone" => :value,
54+
"title" => :value,
55+
"userType" => :value,
5056
"x509Certificates" => [],
5157
}
5258

spec/services/parameter_service_spec.rb

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,86 @@
11
require "spec_helper"
22

33
RSpec.describe ParameterService, type: :service do
4+
describe "SCIM_CORE_USER_SCHEMA.contains?" do
5+
let(:schema) { ParameterService::SCIM_CORE_USER_SCHEMA }
6+
7+
# Singular Simple Value Attributes
8+
%w(
9+
id
10+
externalId
11+
userName
12+
displayName
13+
nickName
14+
profileUrl
15+
title
16+
userType
17+
preferredLanguage
18+
locale
19+
timezone
20+
active
21+
password
22+
employeeNumber
23+
costCenter
24+
organization
25+
division
26+
department
27+
).each do |attr|
28+
it attr do
29+
expect(schema).to have_key(attr), "Expected schema to have simple attribute #{attr}"
30+
expect(schema[attr]).to be_kind_of(Symbol), "Expected schema attribute #{attr} to be a simple value!"
31+
end
32+
end
33+
34+
# Complex Types
35+
{
36+
meta: %w(
37+
resourceType
38+
created
39+
lastModified
40+
location
41+
version
42+
),
43+
name: %w(
44+
formatted
45+
familyName
46+
givenName
47+
middleName
48+
honorificPrefix
49+
honorificSuffix
50+
),
51+
}.stringify_keys.each do |attr, sub_attrs|
52+
it "#{attr} (and #{sub_attrs.length} sub-fields)" do
53+
sub_schema = schema[attr]
54+
55+
expect(schema).to have_key(attr), "Expected schema to have root key #{attr}"
56+
expect(schema[attr]).to be_kind_of(Hash), "Expected schema attribute #{attr} to be a Hash!"
57+
58+
sub_attrs.each do |sub_attr|
59+
expect(sub_schema).to have_key(sub_attr), "Expected schema.#{attr} to have key #{sub_attr}"
60+
end
61+
end
62+
end
63+
64+
# Muti-Valued Array Attributes
65+
%w(
66+
addresses
67+
emails
68+
phoneNumbers
69+
ims
70+
photos
71+
groups
72+
entitlements
73+
roles
74+
x509Certificates
75+
).each do |attr|
76+
it "#{attr} (array)" do
77+
expect(schema).to have_key(attr), "Expected schema to have root key #{attr}"
78+
expect(schema[attr]).to be_kind_of(Array), "Expected schema attribute #{attr} to be an array!"
79+
end
80+
end
81+
82+
end
83+
484
describe ".invalid_parameters" do
585
let(:schema) { ParameterService::SCIM_CORE_USER_SCHEMA }
686
let(:good_params) do
@@ -61,6 +141,41 @@
61141
end
62142
end
63143

144+
context "valid" do
145+
context "core schema - " do
146+
ParameterService::SCIM_CORE_USER_SCHEMA.each do |key, schema_metadata|
147+
data =
148+
case schema_metadata.class.name
149+
when Hash.name
150+
d = schema_metadata.dup
151+
d.keys.each do |k|
152+
d[k] = Faker::Lorem.sentence
153+
end
154+
d
155+
when Array.name
156+
[Faker::Lorem.sentence]
157+
when Symbol.name
158+
Faker::Lorem.sentence
159+
else
160+
:fail
161+
end
162+
163+
if data == :fail
164+
it key.to_s do
165+
fail "Unknown data type in schema :#{key} => #{schema_metadata.class}"
166+
end
167+
else
168+
it key.to_s do
169+
params = good_params.merge(key => data)
170+
171+
result = subject.invalid_parameters(schema, params)
172+
expect(result).to be_empty
173+
end
174+
end
175+
end
176+
end
177+
end
178+
64179
context "invalid" do
65180
context "data type" do
66181
it "schema=Hash, param=String" do

0 commit comments

Comments
 (0)