Skip to content

Commit

Permalink
Fix(SCIMMY.Resources.*): make basepath mutable for multi-tenant envir…
Browse files Browse the repository at this point in the history
…onments
  • Loading branch information
sleelin committed Nov 15, 2023
1 parent 431ce49 commit 7cd3145
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/lib/resources/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export class Group extends Types.Resource {
/** @implements {SCIMMY.Types.Resource.basepath} */
static basepath(path) {
if (path === undefined) return Group.#basepath;
else if (Group.#basepath === undefined)
Group.#basepath = (path.endsWith(Group.endpoint) ? path : `${path}${Group.endpoint}`);
else Group.#basepath = (path.endsWith(Group.endpoint) ? path : `${path}${Group.endpoint}`);

return Group;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/resources/resourcetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export class ResourceType extends Types.Resource {
/** @implements {SCIMMY.Types.Resource.basepath} */
static basepath(path) {
if (path === undefined) return ResourceType.#basepath;
else if (ResourceType.#basepath === undefined)
ResourceType.#basepath = (path.endsWith(ResourceType.endpoint) ? path : `${path}${ResourceType.endpoint}`);
else ResourceType.#basepath = (path.endsWith(ResourceType.endpoint) ? path : `${path}${ResourceType.endpoint}`);

return ResourceType;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/resources/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export class Schema extends Types.Resource {
/** @implements {SCIMMY.Types.Resource.basepath} */
static basepath(path) {
if (path === undefined) return Schema.#basepath;
else if (Schema.#basepath === undefined)
Schema.#basepath = (path.endsWith(Schema.endpoint) ? path : `${path}${Schema.endpoint}`);
else Schema.#basepath = (path.endsWith(Schema.endpoint) ? path : `${path}${Schema.endpoint}`);

return Schema;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/resources/spconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export class ServiceProviderConfig extends Types.Resource {
/** @implements {SCIMMY.Types.Resource.basepath} */
static basepath(path) {
if (path === undefined) return ServiceProviderConfig.#basepath;
else if (ServiceProviderConfig.#basepath === undefined)
ServiceProviderConfig.#basepath = (path.endsWith(ServiceProviderConfig.endpoint) ? path : `${path}${ServiceProviderConfig.endpoint}`);
else ServiceProviderConfig.#basepath = (path.endsWith(ServiceProviderConfig.endpoint) ? path : `${path}${ServiceProviderConfig.endpoint}`);

return ServiceProviderConfig;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/resources/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export class User extends Types.Resource {
/** @implements {SCIMMY.Types.Resource.basepath} */
static basepath(path) {
if (path === undefined) return User.#basepath;
else if (User.#basepath === undefined)
User.#basepath = (path.endsWith(User.endpoint) ? path : `${path}${User.endpoint}`);
else User.#basepath = (path.endsWith(User.endpoint) ? path : `${path}${User.endpoint}`);

return User;
}
Expand Down
12 changes: 5 additions & 7 deletions test/hooks/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,14 @@ export default {
"Static method 'basepath' was not a function");
});

it("should only set basepath once, then do nothing", () => {
const expected = `/scim${TargetResource.endpoint}`;

it("should be mutable", () => {
TargetResource.basepath("/scim");
assert.ok(TargetResource.basepath() === (expected),
"Static method 'basepath' did not set or ignore resource basepath");
assert.ok(TargetResource.basepath() === (`/scim${TargetResource.endpoint}`),
`Static method 'basepath' did not set resource basepath to '/scim${TargetResource.endpoint}'`);

TargetResource.basepath("/test");
assert.ok(TargetResource.basepath() === (expected),
"Static method 'basepath' did not do nothing when basepath was already set");
assert.ok(TargetResource.basepath() === (`/test${TargetResource.endpoint}`),
`Static method 'basepath' did not set resource basepath to '/test${TargetResource.endpoint}'`);
});
}),
construct: (TargetResource, filterable = true) => (() => {
Expand Down

0 comments on commit 7cd3145

Please sign in to comment.