Skip to content

Commit

Permalink
Merge pull request #49 from scimmyjs/issue/41-unknown-sub-attribute-r…
Browse files Browse the repository at this point in the history
…esponse

Ignore unknown sub-attributes when coercing complex values in `SCIMMY.Types.Attribute`
  • Loading branch information
sleelin authored Sep 11, 2024
2 parents f87028a + b789de1 commit 9d132c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ export default class Config {
// No shorthand, make sure value is an object
else if (value === Object(value)) {
try {
// Make sure all object keys correspond to valid config attributes
for (let name of Object.keys(value)) Schemas.ServiceProviderConfig.definition.attribute(`${key}.${name}`);

// Coerce the value and assign it to the config property
Object.assign(target, Schemas.ServiceProviderConfig.definition.attribute(key)
.coerce({...target, supported: true, ...value}));
Expand Down
11 changes: 2 additions & 9 deletions src/lib/types/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,8 @@ export class Attribute {
for (let [key, value] of Object.entries(source)) try {
target[key.toLowerCase()] = value;
} catch (ex) {
// Attempted to add an undeclared attribute to the value
if (ex instanceof TypeError && ex.message.endsWith("not extensible")) {
ex.message = `Complex attribute '${this.name}' `
+ (typeof source !== "object" || Array.isArray(source)
? `expected complex value but found type '${typeof source}'`
: `does not declare subAttribute '${key}'`);
}

throw ex;
// Ignore attempts to add an undeclared attribute to the value, raise all other errors
if (!(ex instanceof TypeError && ex.message.endsWith("not extensible"))) throw ex;
}

// Reassign values to catch missing required sub-attributes
Expand Down
2 changes: 1 addition & 1 deletion test/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("SCIMMY.Config", () => {
{name: "TypeError", message: "SCIM configuration: schema does not define attribute 'test'"},
"Static method 'set' accepted unknown attribute object key");
assert.throws(() => SCIMMY.Config.set("patch", {test: true}),
{name: "TypeError", message: "SCIM configuration: complex attribute 'patch' does not declare subAttribute 'test'"},
{name: "TypeError", message: "SCIM configuration: attribute 'patch' of schema 'urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig' does not declare subAttribute 'test'"},
"Static method 'set' accepted unknown sub-attribute object key");
});

Expand Down

0 comments on commit 9d132c8

Please sign in to comment.