Skip to content

Commit

Permalink
Deploying to gh-pages from @ 7aecd3a 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
passbolt-github committed Nov 7, 2024
1 parent c9adf18 commit 3c7bba2
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 7 deletions.
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"generatedAt":1730882338834,"builder":{"name":"webpack5"},"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":true,"hasStorybookEslint":false,"refCount":0,"packageManager":{"type":"npm","version":"10.7.0"},"language":"javascript","storybookPackages":{},"framework":{},"addons":{"@storybook/addon-links":{"version":"6.5.16"},"@storybook/addon-essentials":{"options":{"backgrounds":false},"version":"6.5.16"}}}
{"generatedAt":1730989298350,"builder":{"name":"webpack5"},"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":true,"hasStorybookEslint":false,"refCount":0,"packageManager":{"type":"npm","version":"10.7.0"},"language":"javascript","storybookPackages":{},"framework":{},"addons":{"@storybook/addon-links":{"version":"6.5.16"},"@storybook/addon-essentials":{"options":{"backgrounds":false},"version":"6.5.16"}}}
12 changes: 10 additions & 2 deletions shared/models/entity/sessionKey/sessionKeysBundleEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,18 @@ class SessionKeysBundleEntity extends EntityV2 {

/**
* Get user id
* @returns {string}
* @returns {string | null}
*/
get userId() {
return this._props.user_id;
return this._props.user_id || null;
}

/**
* Get modified
* @returns {string | null}
*/
get modified() {
return this._props.modified || null;
}

/*
Expand Down
16 changes: 16 additions & 0 deletions shared/models/entity/sessionKey/sessionKeysBundleEntity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ describe("SessionKeysBundleEntity", () => {
expect(entity.data).toBeInstanceOf(SessionKeysBundleDataEntity);
expect(entity.data.toDto()).toStrictEqual(dto.data);
});

it("`userId` should return the right value: with string", () => {
expect.assertions(1);
const dto = defaultSessionKeysBundleDto();
const entity = new SessionKeysBundleEntity(dto);

expect(entity.userId).toStrictEqual(dto.user_id);
});

it("`modified` should return the right value: with string", () => {
expect.assertions(1);
const dto = defaultSessionKeysBundleDto();
const entity = new SessionKeysBundleEntity(dto);

expect(entity.modified).toStrictEqual(dto.modified);
});
});

describe("::setters", () => {
Expand Down
19 changes: 19 additions & 0 deletions shared/models/entity/sessionKey/sessionKeysBundlesCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ class SessionKeysBundlesCollection extends EntityV2Collection {
hasSomeEncryptedSessionKeysBundles() {
return this.items.some(sessionKeysBundleEntity => !sessionKeysBundleEntity.isDecrypted);
}

/**
* Order by the most recently modified session key in the collection if any.
* The key with a non null modified date and having the most recent date will be the first.
* If keys do not have modified date, the last one will be the first.
* If no session key bundle is found in the collection, do nothing.
*
*/
sortByModified() {
this._items.sort((sessionKeysBundleEntityA, sessionKeysBundleEntityB) => {
if (!sessionKeysBundleEntityA.modified) {
return 1;
} else if (!sessionKeysBundleEntityB.modified) {
return -1;
} else {
return sessionKeysBundleEntityB.modified > sessionKeysBundleEntityA.modified ? 1 : -1;
}
});
}
}

export default SessionKeysBundlesCollection;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import EntitySchema from "../abstract/entitySchema";
import SessionKeysBundlesCollection from "./sessionKeysBundlesCollection";
import {defaultSessionKeysBundlesDtos} from "./sessionKeysBundlesCollection.test.data";
import {v4 as uuidv4} from "uuid";
import {decryptedSessionKeysBundleDto} from "./sessionKeysBundleEntity.test.data";
import {decryptedSessionKeysBundleDto, defaultSessionKeysBundleDto} from "./sessionKeysBundleEntity.test.data";

describe("SessionKeysBundlesCollection", () => {
describe("::getSchema", () => {
Expand Down Expand Up @@ -129,6 +129,38 @@ describe("SessionKeysBundlesCollection", () => {
});
});

describe("::sortByMostRecent", () => {
it("should sort by most recent by modified if property is defined", async() => {
const user_id = uuidv4();
const recentSessionKeysBundleRecent = defaultSessionKeysBundleDto({user_id: user_id, modified: "2024-10-11T08:09:00+00:00"});
const oldSessionKeysBundle = defaultSessionKeysBundleDto({user_id});
const dtos = [oldSessionKeysBundle, recentSessionKeysBundleRecent];
const collection = new SessionKeysBundlesCollection(dtos);
collection.sortByModified();
expect(collection.toDto()).toEqual([recentSessionKeysBundleRecent, oldSessionKeysBundle]);
});

it("should sort by most recent by modified and let at the last position if property is not defined", async() => {
const user_id = uuidv4();
const noModifiedSessionKeysBundleRecent = defaultSessionKeysBundleDto({user_id: user_id, modified: undefined});
const sessionKeysBundle = defaultSessionKeysBundleDto({user_id});
const dtos = [sessionKeysBundle, noModifiedSessionKeysBundleRecent];
const collection = new SessionKeysBundlesCollection(dtos);
collection.sortByModified();
expect(collection.toDto()).toEqual([sessionKeysBundle, noModifiedSessionKeysBundleRecent]);
});

it("should sort by most recent by modified and put the first one at the last position cause modified property is not defined", async() => {
const user_id = uuidv4();
const recentSessionKeysBundleRecent = defaultSessionKeysBundleDto({user_id: user_id});
const oldSessionKeysBundle = defaultSessionKeysBundleDto({user_id: user_id, modified: undefined});
const dtos = [oldSessionKeysBundle, recentSessionKeysBundleRecent];
const collection = new SessionKeysBundlesCollection(dtos);
collection.sortByModified();
expect(collection.toDto()).toEqual([recentSessionKeysBundleRecent, oldSessionKeysBundle]);
});
});

describe("::pushMany", () => {
it("[performance] should ensure performance adding large dataset remains effective.", async() => {
const count = 10_000;
Expand Down
13 changes: 13 additions & 0 deletions shared/models/entity/sessionKey/sessionKeysCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ class SessionKeysCollection extends EntityV2Collection {

super.pushMany(data, entityOptions, options);
}

/*
* ==================================================
* Filters
* ==================================================
*/

/**
* Filter out the session keys not matching the given foreign model and foreignIds.
*/
filterOutSessionKeysNotMatchingForeignModelAndForeignIds(foreignModel, foreignIds) {
this.filterByCallback(sessionKey => sessionKey.foreignModel === foreignModel && foreignIds.includes(sessionKey.foreignId));
}
}

export default SessionKeysCollection;
20 changes: 20 additions & 0 deletions shared/models/entity/sessionKey/sessionKeysCollection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import EntitySchema from "../abstract/entitySchema";
import SessionKeysCollection from "./sessionKeysCollection";
import {defaultSessionKeysDtos} from "./sessionKeysCollection.test.data";
import {defaultSessionKeyDto} from "./sessionKeyEntity.test.data";
import {v4 as uuidv4} from "uuid";

describe("SessionKeysCollection", () => {
describe("::getSchema", () => {
Expand Down Expand Up @@ -94,6 +96,24 @@ describe("SessionKeysCollection", () => {
});
});

describe("::filterOutMetadataEncrypted", () => {
it("should filter out the resource which have metadata key type different than user_key.", async() => {
expect.assertions(3);

const foreignId1 = uuidv4();
const foreignId2 = uuidv4();
const foreignId3 = uuidv4();
const dtos = [defaultSessionKeyDto({foreign_id: foreignId1}), defaultSessionKeyDto({foreign_id: foreignId2}), defaultSessionKeyDto({foreign_id: foreignId3})];
const collection = new SessionKeysCollection(dtos);

collection.filterOutSessionKeysNotMatchingForeignModelAndForeignIds("Resource", [foreignId1, foreignId3]);

expect(collection).toHaveLength(2);
expect(collection.items[0].toDto()).toEqual(dtos[0]);
expect(collection.items[1].toDto()).toEqual(dtos[2]);
});
});

describe("::pushMany", () => {
it("[performance] should ensure performance adding large dataset remains effective.", async() => {
const count = 10_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,18 @@ class SessionKeysBundleEntity extends EntityV2 {

/**
* Get user id
* @returns {string}
* @returns {string | null}
*/
get userId() {
return this._props.user_id;
return this._props.user_id || null;
}

/**
* Get modified
* @returns {string | null}
*/
get modified() {
return this._props.modified || null;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ describe("SessionKeysBundleEntity", () => {
expect(entity.data).toBeInstanceOf(SessionKeysBundleDataEntity);
expect(entity.data.toDto()).toStrictEqual(dto.data);
});

it("`userId` should return the right value: with string", () => {
expect.assertions(1);
const dto = defaultSessionKeysBundleDto();
const entity = new SessionKeysBundleEntity(dto);

expect(entity.userId).toStrictEqual(dto.user_id);
});

it("`modified` should return the right value: with string", () => {
expect.assertions(1);
const dto = defaultSessionKeysBundleDto();
const entity = new SessionKeysBundleEntity(dto);

expect(entity.modified).toStrictEqual(dto.modified);
});
});

describe("::setters", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ class SessionKeysBundlesCollection extends EntityV2Collection {
hasSomeEncryptedSessionKeysBundles() {
return this.items.some(sessionKeysBundleEntity => !sessionKeysBundleEntity.isDecrypted);
}

/**
* Order by the most recently modified session key in the collection if any.
* The key with a non null modified date and having the most recent date will be the first.
* If keys do not have modified date, the last one will be the first.
* If no session key bundle is found in the collection, do nothing.
*
*/
sortByModified() {
this._items.sort((sessionKeysBundleEntityA, sessionKeysBundleEntityB) => {
if (!sessionKeysBundleEntityA.modified) {
return 1;
} else if (!sessionKeysBundleEntityB.modified) {
return -1;
} else {
return sessionKeysBundleEntityB.modified > sessionKeysBundleEntityA.modified ? 1 : -1;
}
});
}
}

export default SessionKeysBundlesCollection;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import EntitySchema from "../abstract/entitySchema";
import SessionKeysBundlesCollection from "./sessionKeysBundlesCollection";
import {defaultSessionKeysBundlesDtos} from "./sessionKeysBundlesCollection.test.data";
import {v4 as uuidv4} from "uuid";
import {decryptedSessionKeysBundleDto} from "./sessionKeysBundleEntity.test.data";
import {decryptedSessionKeysBundleDto, defaultSessionKeysBundleDto} from "./sessionKeysBundleEntity.test.data";

describe("SessionKeysBundlesCollection", () => {
describe("::getSchema", () => {
Expand Down Expand Up @@ -129,6 +129,38 @@ describe("SessionKeysBundlesCollection", () => {
});
});

describe("::sortByMostRecent", () => {
it("should sort by most recent by modified if property is defined", async() => {
const user_id = uuidv4();
const recentSessionKeysBundleRecent = defaultSessionKeysBundleDto({user_id: user_id, modified: "2024-10-11T08:09:00+00:00"});
const oldSessionKeysBundle = defaultSessionKeysBundleDto({user_id});
const dtos = [oldSessionKeysBundle, recentSessionKeysBundleRecent];
const collection = new SessionKeysBundlesCollection(dtos);
collection.sortByModified();
expect(collection.toDto()).toEqual([recentSessionKeysBundleRecent, oldSessionKeysBundle]);
});

it("should sort by most recent by modified and let at the last position if property is not defined", async() => {
const user_id = uuidv4();
const noModifiedSessionKeysBundleRecent = defaultSessionKeysBundleDto({user_id: user_id, modified: undefined});
const sessionKeysBundle = defaultSessionKeysBundleDto({user_id});
const dtos = [sessionKeysBundle, noModifiedSessionKeysBundleRecent];
const collection = new SessionKeysBundlesCollection(dtos);
collection.sortByModified();
expect(collection.toDto()).toEqual([sessionKeysBundle, noModifiedSessionKeysBundleRecent]);
});

it("should sort by most recent by modified and put the first one at the last position cause modified property is not defined", async() => {
const user_id = uuidv4();
const recentSessionKeysBundleRecent = defaultSessionKeysBundleDto({user_id: user_id});
const oldSessionKeysBundle = defaultSessionKeysBundleDto({user_id: user_id, modified: undefined});
const dtos = [oldSessionKeysBundle, recentSessionKeysBundleRecent];
const collection = new SessionKeysBundlesCollection(dtos);
collection.sortByModified();
expect(collection.toDto()).toEqual([recentSessionKeysBundleRecent, oldSessionKeysBundle]);
});
});

describe("::pushMany", () => {
it("[performance] should ensure performance adding large dataset remains effective.", async() => {
const count = 10_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ class SessionKeysCollection extends EntityV2Collection {

super.pushMany(data, entityOptions, options);
}

/*
* ==================================================
* Filters
* ==================================================
*/

/**
* Filter out the session keys not matching the given foreign model and foreignIds.
*/
filterOutSessionKeysNotMatchingForeignModelAndForeignIds(foreignModel, foreignIds) {
this.filterByCallback(sessionKey => sessionKey.foreignModel === foreignModel && foreignIds.includes(sessionKey.foreignId));
}
}

export default SessionKeysCollection;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import EntitySchema from "../abstract/entitySchema";
import SessionKeysCollection from "./sessionKeysCollection";
import {defaultSessionKeysDtos} from "./sessionKeysCollection.test.data";
import {defaultSessionKeyDto} from "./sessionKeyEntity.test.data";
import {v4 as uuidv4} from "uuid";

describe("SessionKeysCollection", () => {
describe("::getSchema", () => {
Expand Down Expand Up @@ -94,6 +96,24 @@ describe("SessionKeysCollection", () => {
});
});

describe("::filterOutMetadataEncrypted", () => {
it("should filter out the resource which have metadata key type different than user_key.", async() => {
expect.assertions(3);

const foreignId1 = uuidv4();
const foreignId2 = uuidv4();
const foreignId3 = uuidv4();
const dtos = [defaultSessionKeyDto({foreign_id: foreignId1}), defaultSessionKeyDto({foreign_id: foreignId2}), defaultSessionKeyDto({foreign_id: foreignId3})];
const collection = new SessionKeysCollection(dtos);

collection.filterOutSessionKeysNotMatchingForeignModelAndForeignIds("Resource", [foreignId1, foreignId3]);

expect(collection).toHaveLength(2);
expect(collection.items[0].toDto()).toEqual(dtos[0]);
expect(collection.items[1].toDto()).toEqual(dtos[2]);
});
});

describe("::pushMany", () => {
it("[performance] should ensure performance adding large dataset remains effective.", async() => {
const count = 10_000;
Expand Down

0 comments on commit 3c7bba2

Please sign in to comment.