@icure/api 7.1.34 → 7.1.35
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.
- package/icc-api/api/IccAuthApi.d.ts +1 -0
- package/icc-api/api/IccAuthApi.js +1 -0
- package/icc-api/api/IccAuthApi.js.map +1 -1
- package/icc-x-api/index.d.ts +22 -29
- package/icc-x-api/index.js +60 -38
- package/icc-x-api/index.js.map +1 -1
- package/package.json +1 -1
- package/test/icc-api/api/IccDocumentApi.d.ts +1 -0
- package/test/icc-api/api/IccDocumentApi.js +200 -0
- package/test/icc-api/api/IccDocumentApi.js.map +1 -0
- package/test/icc-api/api/IccGroupApi.d.ts +1 -0
- package/test/icc-api/api/IccGroupApi.js +50 -0
- package/test/icc-api/api/IccGroupApi.js.map +1 -0
- package/test/icc-api/api/IccRoleApi.d.ts +1 -0
- package/test/icc-api/api/IccRoleApi.js +34 -0
- package/test/icc-api/api/IccRoleApi.js.map +1 -0
- package/test/icc-api/api/IccUserApi.d.ts +1 -0
- package/test/icc-api/api/IccUserApi.js +80 -0
- package/test/icc-api/api/IccUserApi.js.map +1 -0
- package/test/icc-api/e2e/IccCalendarItemApi.d.ts +1 -0
- package/test/icc-api/e2e/IccCalendarItemApi.js +45 -0
- package/test/icc-api/e2e/IccCalendarItemApi.js.map +1 -0
- package/test/icc-api/model/modelHelpersTest.d.ts +1 -0
- package/test/icc-api/model/modelHelpersTest.js +45 -0
- package/test/icc-api/model/modelHelpersTest.js.map +1 -0
- package/test/icc-x-api/auth/group-switch-test.d.ts +1 -0
- package/test/icc-x-api/auth/group-switch-test.js +81 -0
- package/test/icc-x-api/auth/group-switch-test.js.map +1 -0
- package/test/icc-x-api/auth/jwt-concurrency-test.d.ts +2 -0
- package/test/icc-x-api/auth/jwt-concurrency-test.js +113 -0
- package/test/icc-x-api/auth/jwt-concurrency-test.js.map +1 -0
- package/test/icc-x-api/auth/smart-auth-provider-test.d.ts +1 -0
- package/test/icc-x-api/auth/smart-auth-provider-test.js +222 -0
- package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -0
- package/test/icc-x-api/crypto/KeyManager-test.d.ts +1 -0
- package/test/icc-x-api/crypto/KeyManager-test.js +225 -0
- package/test/icc-x-api/crypto/KeyManager-test.js.map +1 -0
- package/test/icc-x-api/crypto/concurrency.d.ts +1 -0
- package/test/icc-x-api/crypto/concurrency.js +35 -0
- package/test/icc-x-api/crypto/concurrency.js.map +1 -0
- package/test/icc-x-api/crypto/crypto-utils.d.ts +1 -0
- package/test/icc-x-api/crypto/crypto-utils.js +80 -0
- package/test/icc-x-api/crypto/crypto-utils.js.map +1 -0
- package/test/icc-x-api/crypto/cryptoTest.d.ts +2 -0
- package/test/icc-x-api/crypto/cryptoTest.js +275 -0
- package/test/icc-x-api/crypto/cryptoTest.js.map +1 -0
- package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.d.ts +1 -0
- package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js +132 -0
- package/test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.js.map +1 -0
- package/test/icc-x-api/crypto/full-crypto-test.d.ts +1 -0
- package/test/icc-x-api/crypto/full-crypto-test.js +458 -0
- package/test/icc-x-api/crypto/full-crypto-test.js.map +1 -0
- package/test/icc-x-api/crypto/shamir.d.ts +2 -0
- package/test/icc-x-api/crypto/shamir.js +156 -0
- package/test/icc-x-api/crypto/shamir.js.map +1 -0
- package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.d.ts +1 -0
- package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js +75 -0
- package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +1 -0
- package/test/icc-x-api/data-compatibility-test-7to6.d.ts +1 -0
- package/test/icc-x-api/data-compatibility-test-7to6.js +343 -0
- package/test/icc-x-api/data-compatibility-test-7to6.js.map +1 -0
- package/test/icc-x-api/entity-with-attachments-api-test.d.ts +1 -0
- package/test/icc-x-api/entity-with-attachments-api-test.js +142 -0
- package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -0
- package/test/icc-x-api/filters/filters.d.ts +1 -0
- package/test/icc-x-api/filters/filters.js +49 -0
- package/test/icc-x-api/filters/filters.js.map +1 -0
- package/test/icc-x-api/icc-accesslog-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-accesslog-x-api.js +121 -0
- package/test/icc-x-api/icc-accesslog-x-api.js.map +1 -0
- package/test/icc-x-api/icc-auth-api.d.ts +1 -0
- package/test/icc-x-api/icc-auth-api.js +46 -0
- package/test/icc-x-api/icc-auth-api.js.map +1 -0
- package/test/icc-x-api/icc-calendar-item-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-calendar-item-x-api.js +146 -0
- package/test/icc-x-api/icc-calendar-item-x-api.js.map +1 -0
- package/test/icc-x-api/icc-contact-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-contact-x-api.js +311 -0
- package/test/icc-x-api/icc-contact-x-api.js.map +1 -0
- package/test/icc-x-api/icc-form-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-form-x-api.js +331 -0
- package/test/icc-x-api/icc-form-x-api.js.map +1 -0
- package/test/icc-x-api/icc-helement-x-api-test.d.ts +1 -0
- package/test/icc-x-api/icc-helement-x-api-test.js +158 -0
- package/test/icc-x-api/icc-helement-x-api-test.js.map +1 -0
- package/test/icc-x-api/icc-invoice-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-invoice-x-api.js +115 -0
- package/test/icc-x-api/icc-invoice-x-api.js.map +1 -0
- package/test/icc-x-api/icc-maintenance-task-x-api-test.d.ts +1 -0
- package/test/icc-x-api/icc-maintenance-task-x-api-test.js +230 -0
- package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +1 -0
- package/test/icc-x-api/icc-patient-x-api-test.d.ts +1 -0
- package/test/icc-x-api/icc-patient-x-api-test.js +169 -0
- package/test/icc-x-api/icc-patient-x-api-test.js.map +1 -0
- package/test/icc-x-api/icc-time-table-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-time-table-x-api.js +110 -0
- package/test/icc-x-api/icc-time-table-x-api.js.map +1 -0
- package/test/icc-x-api/icc-user-x-api-test.d.ts +1 -0
- package/test/icc-x-api/icc-user-x-api-test.js +108 -0
- package/test/icc-x-api/icc-user-x-api-test.js.map +1 -0
- package/test/icc-x-api/icureapi-group-test.d.ts +1 -0
- package/test/icc-x-api/icureapi-group-test.js +130 -0
- package/test/icc-x-api/icureapi-group-test.js.map +1 -0
- package/test/icc-x-api/patient-user.d.ts +2 -0
- package/test/icc-x-api/patient-user.js +117 -0
- package/test/icc-x-api/patient-user.js.map +1 -0
- package/test/icc-x-api/storage/storage.d.ts +1 -0
- package/test/icc-x-api/storage/storage.js +50 -0
- package/test/icc-x-api/storage/storage.js.map +1 -0
- package/test/icc-x-api/subscription-apis.d.ts +2 -0
- package/test/icc-x-api/subscription-apis.js +498 -0
- package/test/icc-x-api/subscription-apis.js.map +1 -0
- package/test/icc-x-api/test-api-no-parent.d.ts +1 -0
- package/test/icc-x-api/test-api-no-parent.js +79 -0
- package/test/icc-x-api/test-api-no-parent.js.map +1 -0
- package/test/icc-x-api/test-legacy-data-support.d.ts +1 -0
- package/test/icc-x-api/test-legacy-data-support.js +231 -0
- package/test/icc-x-api/test-legacy-data-support.js.map +1 -0
- package/test/icc-x-api/utils/crypto-utils-test.d.ts +1 -0
- package/test/icc-x-api/utils/crypto-utils-test.js +586 -0
- package/test/icc-x-api/utils/crypto-utils-test.js.map +1 -0
- package/test/icc-x-api/utils/graph-test.d.ts +1 -0
- package/test/icc-x-api/utils/graph-test.js +54 -0
- package/test/icc-x-api/utils/graph-test.js.map +1 -0
- package/test/support/CSM-185.d.ts +1 -0
- package/test/support/CSM-185.js +120 -0
- package/test/support/CSM-185.js.map +1 -0
- package/test/support/CSM-87.d.ts +0 -0
- package/test/support/CSM-87.js +21 -0
- package/test/support/CSM-87.js.map +1 -0
- package/test/support/CSM-93.d.ts +1 -0
- package/test/support/CSM-93.js +111 -0
- package/test/support/CSM-93.js.map +1 -0
- package/test/utils/TestApi.d.ts +3 -0
- package/test/utils/TestApi.js +27 -0
- package/test/utils/TestApi.js.map +1 -0
- package/test/utils/TestCollectionUtils.d.ts +1 -0
- package/test/utils/TestCollectionUtils.js +109 -0
- package/test/utils/TestCollectionUtils.js.map +1 -0
- package/test/utils/TestCryptoStrategies.d.ts +37 -0
- package/test/utils/TestCryptoStrategies.js +72 -0
- package/test/utils/TestCryptoStrategies.js.map +1 -0
- package/test/utils/TestStorage.d.ts +31 -0
- package/test/utils/TestStorage.js +88 -0
- package/test/utils/TestStorage.js.map +1 -0
- package/test/utils/test_utils.d.ts +60 -0
- package/test/utils/test_utils.js +313 -0
- package/test/utils/test_utils.js.map +1 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TestCryptoStrategies = void 0;
|
|
13
|
+
const RSA_1 = require("../../icc-x-api/crypto/RSA");
|
|
14
|
+
const utils_1 = require("../../icc-x-api/crypto/utils");
|
|
15
|
+
const crypto_1 = require("crypto");
|
|
16
|
+
const icc_x_api_1 = require("../../icc-x-api");
|
|
17
|
+
class TestCryptoStrategies {
|
|
18
|
+
constructor(keyPair, verifiedSelfKeys = {}, recoveredParentKeys = {}) {
|
|
19
|
+
this.recoveredParentKeys = recoveredParentKeys;
|
|
20
|
+
this.RSA = new RSA_1.RSAUtils(crypto_1.webcrypto);
|
|
21
|
+
this.recoverAndVerifyCallsParams = [];
|
|
22
|
+
this.keyPair = keyPair;
|
|
23
|
+
this.verifiedSelfKeys = verifiedSelfKeys;
|
|
24
|
+
}
|
|
25
|
+
generateNewKeyForDataOwner(self) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
if (!this.keyPair)
|
|
28
|
+
return false;
|
|
29
|
+
const knownKeys = (0, utils_1.hexPublicKeysOf)(self.dataOwner);
|
|
30
|
+
const publicKey = (0, icc_x_api_1.ua2hex)(yield this.RSA.exportKey(this.keyPair.publicKey, 'spki'));
|
|
31
|
+
return knownKeys.has(publicKey) ? false : this.keyPair;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
recoverAndVerifySelfHierarchyKeys(keysData, cryptoPrimitives) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
this.recoverAndVerifyCallsParams.push(keysData);
|
|
37
|
+
const self = keysData[keysData.length - 1].dataOwner;
|
|
38
|
+
const knownKeys = (0, utils_1.hexPublicKeysOf)(self.dataOwner);
|
|
39
|
+
const publicKey = this.keyPair ? (0, icc_x_api_1.ua2hex)(yield this.RSA.exportKey(this.keyPair.publicKey, 'spki')) : undefined;
|
|
40
|
+
return Object.fromEntries(yield Promise.all(keysData.map((currData) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (currData.dataOwner.dataOwner.id !== self.dataOwner.id) {
|
|
42
|
+
const recoveredKey = this.recoveredParentKeys[currData.dataOwner.dataOwner.id];
|
|
43
|
+
return [
|
|
44
|
+
currData.dataOwner.dataOwner.id,
|
|
45
|
+
{
|
|
46
|
+
recoveredKeys: recoveredKey
|
|
47
|
+
? {
|
|
48
|
+
[recoveredKey.publicKey.slice(-32)]: yield cryptoPrimitives.RSA.importKeyPair('pkcs8', (0, icc_x_api_1.hex2ua)(recoveredKey.privateKey), 'spki', (0, icc_x_api_1.hex2ua)(recoveredKey.publicKey)),
|
|
49
|
+
}
|
|
50
|
+
: {},
|
|
51
|
+
keyAuthenticity: {},
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
else if (publicKey === undefined || !knownKeys.has(publicKey)) {
|
|
56
|
+
return [currData.dataOwner.dataOwner.id, { recoveredKeys: {}, keyAuthenticity: this.verifiedSelfKeys }];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return [
|
|
60
|
+
currData.dataOwner.dataOwner.id,
|
|
61
|
+
{ recoveredKeys: { [publicKey.slice(-32)]: this.keyPair }, keyAuthenticity: this.verifiedSelfKeys },
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
}))));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
verifyDelegatePublicKeys(delegate, publicKeys) {
|
|
68
|
+
return Promise.resolve(publicKeys);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.TestCryptoStrategies = TestCryptoStrategies;
|
|
72
|
+
//# sourceMappingURL=TestCryptoStrategies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestCryptoStrategies.js","sourceRoot":"","sources":["../../../test/utils/TestCryptoStrategies.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAA8D;AAE9D,wDAA8D;AAC9D,mCAAkC;AAClC,+CAAkE;AAIlE,MAAa,oBAAoB;IAM/B,YACE,OAA4B,EAC5B,mBAA6C,EAAE,EAC9B,sBAA+D,EAAE;QAAjE,wBAAmB,GAAnB,mBAAmB,CAA8C;QANnE,QAAG,GAAG,IAAI,cAAQ,CAAC,kBAAgB,CAAC,CAAA;QACrD,gCAA2B,GAAgG,EAAE,CAAA;QAO3H,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,C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api/crypto/RSA'\nimport { DataOwner } from '../../icc-x-api/icc-data-owner-x-api'\nimport { hexPublicKeysOf } from '../../icc-x-api/crypto/utils'\nimport { webcrypto } from 'crypto'\nimport { CryptoPrimitives, hex2ua, ua2hex } from '../../icc-x-api'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\n\nexport class TestCryptoStrategies implements CryptoStrategies {\n private readonly keyPair: KeyPair<CryptoKey> | undefined\n private readonly verifiedSelfKeys: { [p: string]: boolean }\n private readonly RSA = new RSAUtils(webcrypto as any)\n recoverAndVerifyCallsParams: Array<{ dataOwner: DataOwnerWithType; unknownKeys: string[]; unavailableKeys: string[] }[]> = []\n\n constructor(\n keyPair?: KeyPair<CryptoKey>,\n verifiedSelfKeys: { [p: string]: boolean } = {},\n private readonly recoveredParentKeys: { [parentId: string]: KeyPair<string> } = {}\n ) {\n this.keyPair = keyPair\n this.verifiedSelfKeys = verifiedSelfKeys\n }\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType): Promise<KeyPair<CryptoKey> | boolean> {\n if (!this.keyPair) return false\n const knownKeys = hexPublicKeysOf(self.dataOwner)\n const publicKey = ua2hex(await this.RSA.exportKey(this.keyPair.publicKey, 'spki'))\n return knownKeys.has(publicKey) ? false : this.keyPair\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: { dataOwner: DataOwnerWithType; unknownKeys: string[]; unavailableKeys: string[] }[],\n cryptoPrimitives: CryptoPrimitives\n ): Promise<{ [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } } }> {\n this.recoverAndVerifyCallsParams.push(keysData)\n const self = keysData[keysData.length - 1].dataOwner\n const knownKeys = hexPublicKeysOf(self.dataOwner)\n const publicKey = this.keyPair ? ua2hex(await this.RSA.exportKey(this.keyPair.publicKey, 'spki')) : undefined\n return Object.fromEntries(\n await Promise.all(\n keysData.map(async (currData) => {\n if (currData.dataOwner.dataOwner.id! !== self.dataOwner.id!) {\n const recoveredKey = this.recoveredParentKeys[currData.dataOwner.dataOwner.id!]\n return [\n currData.dataOwner.dataOwner.id!,\n {\n recoveredKeys: recoveredKey\n ? {\n [recoveredKey.publicKey.slice(-32)]: await cryptoPrimitives.RSA.importKeyPair(\n 'pkcs8',\n hex2ua(recoveredKey.privateKey),\n 'spki',\n hex2ua(recoveredKey.publicKey)\n ),\n }\n : {},\n keyAuthenticity: {},\n },\n ]\n } else if (publicKey === undefined || !knownKeys.has(publicKey)) {\n return [currData.dataOwner.dataOwner.id!, { recoveredKeys: {}, keyAuthenticity: this.verifiedSelfKeys }]\n } else {\n return [\n currData.dataOwner.dataOwner.id!,\n { recoveredKeys: { [publicKey.slice(-32)]: this.keyPair }, keyAuthenticity: this.verifiedSelfKeys },\n ]\n }\n })\n )\n )\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[]): Promise<string[]> {\n return Promise.resolve(publicKeys)\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { KeyStorageFacade, StorageFacade } from '../../icc-x-api';
|
|
2
|
+
import { KeyPair } from '../../icc-x-api/crypto/RSA';
|
|
3
|
+
import { StorageEntryKeysFactory } from '../../icc-x-api/storage/StorageEntryKeysFactory';
|
|
4
|
+
export declare class TestStorage implements StorageFacade<string> {
|
|
5
|
+
private readonly data;
|
|
6
|
+
getItem(key: string): Promise<string | undefined>;
|
|
7
|
+
removeItem(key: string): Promise<void>;
|
|
8
|
+
setItem(key: string, valueToStore: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare class TestKeyStorage implements KeyStorageFacade {
|
|
11
|
+
private readonly data;
|
|
12
|
+
deleteKeypair(key: string): Promise<void>;
|
|
13
|
+
getKeypair(key: string): Promise<{
|
|
14
|
+
publicKey: JsonWebKey;
|
|
15
|
+
privateKey: JsonWebKey;
|
|
16
|
+
} | undefined>;
|
|
17
|
+
getPrivateKey(key: string): Promise<JsonWebKey | undefined>;
|
|
18
|
+
getPublicKey(key: string): Promise<JsonWebKey | undefined>;
|
|
19
|
+
storeKeyPair(key: string, keyPair: {
|
|
20
|
+
publicKey: JsonWebKey;
|
|
21
|
+
privateKey: JsonWebKey;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function testStorageWithKeys(data: {
|
|
25
|
+
dataOwnerId: string;
|
|
26
|
+
pairs: KeyPair<string>[];
|
|
27
|
+
}[]): Promise<{
|
|
28
|
+
keyStorage: KeyStorageFacade;
|
|
29
|
+
storage: StorageFacade<string>;
|
|
30
|
+
keyFactory: StorageEntryKeysFactory;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.testStorageWithKeys = exports.TestKeyStorage = exports.TestStorage = void 0;
|
|
13
|
+
const icc_x_api_1 = require("../../icc-x-api");
|
|
14
|
+
const DefaultStorageEntryKeysFactory_1 = require("../../icc-x-api/storage/DefaultStorageEntryKeysFactory");
|
|
15
|
+
const IcureStorageFacade_1 = require("../../icc-x-api/storage/IcureStorageFacade");
|
|
16
|
+
class TestStorage {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.data = new Map();
|
|
19
|
+
}
|
|
20
|
+
getItem(key) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return this.data.get(key);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
removeItem(key) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
this.data.delete(key);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
setItem(key, valueToStore) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
this.data.set(key, valueToStore);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.TestStorage = TestStorage;
|
|
37
|
+
class TestKeyStorage {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.data = new Map();
|
|
40
|
+
}
|
|
41
|
+
deleteKeypair(key) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
this.data.delete(key);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
getKeypair(key) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
return this.data.get(key);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getPrivateKey(key) {
|
|
52
|
+
var _a;
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
return (_a = (yield this.getKeypair(key))) === null || _a === void 0 ? void 0 : _a.privateKey;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getPublicKey(key) {
|
|
58
|
+
var _a;
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return (_a = (yield this.getKeypair(key))) === null || _a === void 0 ? void 0 : _a.publicKey;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
storeKeyPair(key, keyPair) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
this.data.set(key, keyPair);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.TestKeyStorage = TestKeyStorage;
|
|
70
|
+
function testStorageWithKeys(data) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const keyStorage = new TestKeyStorage();
|
|
73
|
+
const keyFactory = new DefaultStorageEntryKeysFactory_1.DefaultStorageEntryKeysFactory();
|
|
74
|
+
const storage = new TestStorage();
|
|
75
|
+
const icureStorage = new IcureStorageFacade_1.IcureStorageFacade(keyStorage, storage, keyFactory);
|
|
76
|
+
for (const { dataOwnerId, pairs } of data) {
|
|
77
|
+
for (const pair of pairs) {
|
|
78
|
+
yield icureStorage.saveKey(dataOwnerId, pair.publicKey.slice(-32), {
|
|
79
|
+
privateKey: (0, icc_x_api_1.pkcs8ToJwk)((0, icc_x_api_1.hex2ua)(pair.privateKey)),
|
|
80
|
+
publicKey: (0, icc_x_api_1.spkiToJwk)((0, icc_x_api_1.hex2ua)(pair.publicKey)),
|
|
81
|
+
}, true);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { keyFactory, keyStorage, storage };
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.testStorageWithKeys = testStorageWithKeys;
|
|
88
|
+
//# sourceMappingURL=TestStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestStorage.js","sourceRoot":"","sources":["../../../test/utils/TestStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAgG;AAGhG,2GAAuG;AACvG,mFAA+E;AAE/E,MAAa,WAAW;IAAxB;QACmB,SAAI,GAAG,IAAI,GAAG,EAAkB,CAAA;IAanD,CAAC;IAXO,OAAO,CAAC,GAAW;;YACvB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC;KAAA;IAEK,UAAU,CAAC,GAAW;;YAC1B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACvB,CAAC;KAAA;IAEK,OAA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M,YAAY,CAAC,OAAO,CACxB,WAAW,EACX,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EACzB;oBACE,UAAU,EAAE,IAAA,sBAAU,EAAC,IAAA,kBAAM,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAC/C,SAAS,EAAE,IAAA,qBAAS,EAAC,IAAA,kBAAM,EAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBAC7C,EACD,IAAI,CACL,CAAA;aACF;SACF;QACD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA;IAC5C,CAAC;CAAA;AArBD,kDAqBC","sourcesContent":["import { hex2ua, KeyStorageFacade, pkcs8ToJwk, spkiToJwk, StorageFacade } from '../../icc-x-api'\nimport { KeyPair } from '../../icc-x-api/crypto/RSA'\nimport { StorageEntryKeysFactory } from '../../icc-x-api/storage/StorageEntryKeysFactory'\nimport { DefaultStorageEntryKeysFactory } from '../../icc-x-api/storage/DefaultStorageEntryKeysFactory'\nimport { IcureStorageFacade } from '../../icc-x-api/storage/IcureStorageFacade'\n\nexport class TestStorage implements StorageFacade<string> {\n private readonly data = new Map<string, string>()\n\n async getItem(key: string): Promise<string | undefined> {\n return this.data.get(key)\n }\n\n async removeItem(key: string): Promise<void> {\n this.data.delete(key)\n }\n\n async setItem(key: string, valueToStore: string): Promise<void> {\n this.data.set(key, valueToStore)\n }\n}\n\nexport class TestKeyStorage implements KeyStorageFacade {\n private readonly data = new Map<string, KeyPair<JsonWebKey>>()\n\n async deleteKeypair(key: string): Promise<void> {\n this.data.delete(key)\n }\n\n async getKeypair(key: string): Promise<{ publicKey: JsonWebKey; privateKey: JsonWebKey } | undefined> {\n return this.data.get(key)\n }\n\n async getPrivateKey(key: string): Promise<JsonWebKey | undefined> {\n return (await this.getKeypair(key))?.privateKey\n }\n\n async getPublicKey(key: string): Promise<JsonWebKey | undefined> {\n return (await this.getKeypair(key))?.publicKey\n }\n\n async storeKeyPair(key: string, keyPair: { publicKey: JsonWebKey; privateKey: JsonWebKey }): Promise<void> {\n this.data.set(key, keyPair)\n }\n}\n\nexport async function testStorageWithKeys(\n data: { dataOwnerId: string; pairs: KeyPair<string>[] }[]\n): Promise<{ keyStorage: KeyStorageFacade; storage: StorageFacade<string>; keyFactory: StorageEntryKeysFactory }> {\n const keyStorage = new TestKeyStorage()\n const keyFactory = new DefaultStorageEntryKeysFactory()\n const storage = new TestStorage()\n const icureStorage = new IcureStorageFacade(keyStorage, storage, keyFactory)\n for (const { dataOwnerId, pairs } of data) {\n for (const pair of pairs) {\n await icureStorage.saveKey(\n dataOwnerId,\n pair.publicKey.slice(-32),\n {\n privateKey: pkcs8ToJwk(hex2ua(pair.privateKey)),\n publicKey: spkiToJwk(hex2ua(pair.publicKey)),\n },\n true\n )\n }\n }\n return { keyFactory, keyStorage, storage }\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IcureApi, Apis } from '../../icc-x-api';
|
|
2
|
+
import { User } from '../../icc-api/model/User';
|
|
3
|
+
import { TestVars, UserDetails } from '@icure/test-setup/types';
|
|
4
|
+
import { EnvInitializer } from '@icure/test-setup/decorators';
|
|
5
|
+
import 'isomorphic-fetch';
|
|
6
|
+
import { Group } from '../../icc-api/model/Group';
|
|
7
|
+
export declare function getTempEmail(): string;
|
|
8
|
+
export declare function setLocalStorage(fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>): void;
|
|
9
|
+
export declare const hcp1Username: string;
|
|
10
|
+
export declare const hcp2Username: string;
|
|
11
|
+
export declare const hcp3Username: string;
|
|
12
|
+
export declare const patUsername: string;
|
|
13
|
+
export declare function getEnvironmentInitializer(): Promise<EnvInitializer>;
|
|
14
|
+
export declare namespace TestUtils {
|
|
15
|
+
function initApi(envVars: TestVars, userName?: string): Promise<IcureApi>;
|
|
16
|
+
function initMasterApi(envVars: TestVars): Promise<IcureApi>;
|
|
17
|
+
}
|
|
18
|
+
export declare function getApiAndAddPrivateKeysForUser(iCureUrl: string, details: UserDetails): Promise<IcureApi>;
|
|
19
|
+
export declare function createNewHcpApi(env: TestVars): Promise<{
|
|
20
|
+
api: Apis;
|
|
21
|
+
credentials: UserDetails;
|
|
22
|
+
user: User;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function createHcpHierarchyApis(env: TestVars): Promise<{
|
|
25
|
+
grandApi: Apis;
|
|
26
|
+
grandUser: User;
|
|
27
|
+
grandCredentials: UserDetails;
|
|
28
|
+
parentApi: Apis;
|
|
29
|
+
parentUser: User;
|
|
30
|
+
parentCredentials: UserDetails;
|
|
31
|
+
childApi: Apis;
|
|
32
|
+
childUser: User;
|
|
33
|
+
childCredentials: UserDetails;
|
|
34
|
+
child2Api: Apis;
|
|
35
|
+
child2User: User;
|
|
36
|
+
child2Credentials: UserDetails;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a parent HCP with a key and a child HCP without any initialised key
|
|
40
|
+
*/
|
|
41
|
+
export declare function createNewHcpWithoutKeyAndParentWithKey(env: TestVars, props?: {
|
|
42
|
+
initialiseEmptyKeyForChild?: boolean;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
parentCredentials: UserDetails;
|
|
45
|
+
childUser: string;
|
|
46
|
+
childDataOwnerId: string;
|
|
47
|
+
childPassword: string;
|
|
48
|
+
}>;
|
|
49
|
+
export type UserInManyGroupsDetails = {
|
|
50
|
+
user1: User;
|
|
51
|
+
user2: User;
|
|
52
|
+
group3: Group;
|
|
53
|
+
userPw3: string;
|
|
54
|
+
user3: User;
|
|
55
|
+
group2: Group;
|
|
56
|
+
group1: Group;
|
|
57
|
+
userPw12: string;
|
|
58
|
+
userLogin: string;
|
|
59
|
+
};
|
|
60
|
+
export declare function createUserInMultipleGroups(env: TestVars): Promise<UserInManyGroupsDetails>;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var _a, _b, _c, _d;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createUserInMultipleGroups = exports.createNewHcpWithoutKeyAndParentWithKey = exports.createHcpHierarchyApis = exports.createNewHcpApi = exports.getApiAndAddPrivateKeysForUser = exports.TestUtils = exports.getEnvironmentInitializer = exports.patUsername = exports.hcp3Username = exports.hcp2Username = exports.hcp1Username = exports.setLocalStorage = exports.getTempEmail = void 0;
|
|
14
|
+
const icc_x_api_1 = require("../../icc-x-api");
|
|
15
|
+
const os_1 = require("os");
|
|
16
|
+
const util_1 = require("util");
|
|
17
|
+
const uuid_1 = require("uuid");
|
|
18
|
+
const crypto_1 = require("crypto");
|
|
19
|
+
const TestApi_1 = require("./TestApi");
|
|
20
|
+
const apiV6_1 = require("@icure/apiV6");
|
|
21
|
+
const TestStorage_1 = require("./TestStorage");
|
|
22
|
+
const TestCryptoStrategies_1 = require("./TestCryptoStrategies");
|
|
23
|
+
const User_1 = require("../../icc-api/model/User");
|
|
24
|
+
const builder_1 = require("@icure/test-setup/builder");
|
|
25
|
+
const types_1 = require("@icure/test-setup/types");
|
|
26
|
+
require("isomorphic-fetch");
|
|
27
|
+
const icc_api_1 = require("../../icc-api");
|
|
28
|
+
function getTempEmail() {
|
|
29
|
+
return `${(0, uuid_1.v4)().substring(0, 8)}@icure.com`;
|
|
30
|
+
}
|
|
31
|
+
exports.getTempEmail = getTempEmail;
|
|
32
|
+
function setLocalStorage(fetch) {
|
|
33
|
+
;
|
|
34
|
+
global.localStorage = new (require('node-localstorage').LocalStorage)((0, os_1.tmpdir)(), 5 * Math.pow(1024, 3));
|
|
35
|
+
global.fetch = fetch;
|
|
36
|
+
global.Storage = '';
|
|
37
|
+
global.TextDecoder = util_1.TextDecoder;
|
|
38
|
+
global.TextEncoder = util_1.TextEncoder;
|
|
39
|
+
global.headers = Headers;
|
|
40
|
+
}
|
|
41
|
+
exports.setLocalStorage = setLocalStorage;
|
|
42
|
+
exports.hcp1Username = (_a = process.env.ICURE_TS_TEST_HCP_USER) !== null && _a !== void 0 ? _a : getTempEmail();
|
|
43
|
+
exports.hcp2Username = (_b = process.env.ICURE_TS_TEST_HCP_2_USER) !== null && _b !== void 0 ? _b : getTempEmail();
|
|
44
|
+
exports.hcp3Username = (_c = process.env.ICURE_TS_TEST_HCP_3_USER) !== null && _c !== void 0 ? _c : getTempEmail();
|
|
45
|
+
exports.patUsername = (_d = process.env.ICURE_TS_TEST_PAT_USER) !== null && _d !== void 0 ? _d : getTempEmail();
|
|
46
|
+
let cachedInitializer;
|
|
47
|
+
function getEnvironmentInitializer() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!cachedInitializer) {
|
|
50
|
+
const env = (0, types_1.getEnvVariables)();
|
|
51
|
+
const scratchDir = 'test/scratch';
|
|
52
|
+
const baseEnvironment = env.testEnvironment === 'docker' ? new builder_1.TestEnvironmentBuilder().setUpDockerEnvironment(scratchDir, ['mock']) : new builder_1.TestEnvironmentBuilder();
|
|
53
|
+
cachedInitializer = yield baseEnvironment
|
|
54
|
+
.withGroup(fetch, {
|
|
55
|
+
patient: ['BASIC_USER', 'BASIC_DATA_OWNER'],
|
|
56
|
+
hcp: [
|
|
57
|
+
'BASIC_USER',
|
|
58
|
+
'BASIC_DATA_OWNER',
|
|
59
|
+
'PATIENT_USER_MANAGER',
|
|
60
|
+
'HIERARCHICAL_DATA_OWNER',
|
|
61
|
+
'TOPIC_MANAGER',
|
|
62
|
+
'TOPIC_PARTICIPANT',
|
|
63
|
+
'LEGACY_MESSAGE_MANAGER',
|
|
64
|
+
],
|
|
65
|
+
device: ['BASIC_USER', 'BASIC_DATA_OWNER'],
|
|
66
|
+
user: ['BASIC_USER'],
|
|
67
|
+
})
|
|
68
|
+
.withMasterUser(fetch)
|
|
69
|
+
.addHcp({ login: exports.hcp1Username })
|
|
70
|
+
.addHcp({ login: exports.hcp2Username })
|
|
71
|
+
.addHcp({ login: exports.hcp3Username })
|
|
72
|
+
.addPatient({ login: exports.patUsername })
|
|
73
|
+
.withSafeguard()
|
|
74
|
+
.withEnvironmentSummary()
|
|
75
|
+
.build();
|
|
76
|
+
}
|
|
77
|
+
return cachedInitializer;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.getEnvironmentInitializer = getEnvironmentInitializer;
|
|
81
|
+
var TestUtils;
|
|
82
|
+
(function (TestUtils) {
|
|
83
|
+
function initApi(envVars, userName = exports.hcp1Username) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
return yield getApiAndAddPrivateKeysForUser(envVars.iCureUrl, envVars.dataOwnerDetails[userName]);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
TestUtils.initApi = initApi;
|
|
89
|
+
function initMasterApi(envVars) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
return yield getApiAndAddPrivateKeysForUser(envVars.iCureUrl, envVars.masterHcp);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
TestUtils.initMasterApi = initMasterApi;
|
|
95
|
+
})(TestUtils = exports.TestUtils || (exports.TestUtils = {}));
|
|
96
|
+
function getApiAndAddPrivateKeysForUser(iCureUrl, details) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const RSA = new icc_x_api_1.RSAUtils(crypto_1.webcrypto);
|
|
99
|
+
const keys = {
|
|
100
|
+
publicKey: yield RSA.importKey('spki', (0, icc_x_api_1.hex2ua)(details.publicKey), ['encrypt']),
|
|
101
|
+
privateKey: yield RSA.importKey('pkcs8', (0, icc_x_api_1.hex2ua)(details.privateKey), ['decrypt']),
|
|
102
|
+
};
|
|
103
|
+
return yield (0, TestApi_1.TestApi)(iCureUrl, details.user, details.password, crypto_1.webcrypto, keys);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
exports.getApiAndAddPrivateKeysForUser = getApiAndAddPrivateKeysForUser;
|
|
107
|
+
function createHealthcarePartyUser(api, userLogin, userToken, publicKey, privateKey) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const { publicKey: newPublicKey, privateKey: newPrivateKey } = yield api.cryptoApi.RSA.generateKeyPair();
|
|
110
|
+
const publicKeyHex = !!publicKey && !!privateKey ? publicKey : (0, icc_x_api_1.ua2hex)(yield api.cryptoApi.RSA.exportKey(newPublicKey, 'spki'));
|
|
111
|
+
const privateKeyHex = !!publicKey && !!privateKey ? privateKey : (0, icc_x_api_1.ua2hex)(yield api.cryptoApi.RSA.exportKey(newPrivateKey, 'pkcs8'));
|
|
112
|
+
const hcp = yield api.healthcarePartyApi.createHealthcareParty(new apiV6_1.HealthcareParty({
|
|
113
|
+
id: (0, uuid_1.v4)(),
|
|
114
|
+
firstName: (0, uuid_1.v4)().substring(0, 6),
|
|
115
|
+
lastName: (0, uuid_1.v4)().substring(0, 6),
|
|
116
|
+
publicKey: publicKeyHex,
|
|
117
|
+
}));
|
|
118
|
+
const hcpUser = yield api.userApi.createUser(new User_1.User({
|
|
119
|
+
id: (0, uuid_1.v4)(),
|
|
120
|
+
name: userLogin,
|
|
121
|
+
login: userLogin,
|
|
122
|
+
email: userLogin,
|
|
123
|
+
healthcarePartyId: hcp.id,
|
|
124
|
+
}));
|
|
125
|
+
const token = yield api.userApi.getToken(hcpUser.id, (0, uuid_1.v4)(), 24 * 60 * 60, userToken);
|
|
126
|
+
return {
|
|
127
|
+
user: hcpUser.login,
|
|
128
|
+
dataOwnerId: hcp.id,
|
|
129
|
+
password: token,
|
|
130
|
+
publicKey: publicKeyHex,
|
|
131
|
+
privateKey: privateKeyHex,
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function createNewHcpApi(env) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const initialisationApi = yield (0, apiV6_1.Api)(env.iCureUrl + '/rest/v1', env.masterHcp.user, env.masterHcp.password, crypto_1.webcrypto, fetch, true, false);
|
|
138
|
+
const primitives = new icc_x_api_1.CryptoPrimitives(crypto_1.webcrypto);
|
|
139
|
+
const credentials = yield createHealthcarePartyUser(initialisationApi, `user-${primitives.randomUuid()}`, primitives.randomUuid());
|
|
140
|
+
const storage = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
141
|
+
{ dataOwnerId: credentials.dataOwnerId, pairs: [{ privateKey: credentials.privateKey, publicKey: credentials.publicKey }] },
|
|
142
|
+
]);
|
|
143
|
+
const api = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: credentials.user, password: credentials.password }, new TestCryptoStrategies_1.TestCryptoStrategies(), crypto_1.webcrypto, fetch, {
|
|
144
|
+
storage: storage.storage,
|
|
145
|
+
keyStorage: storage.keyStorage,
|
|
146
|
+
entryKeysFactory: storage.keyFactory,
|
|
147
|
+
});
|
|
148
|
+
return { api, credentials, user: yield api.userApi.getCurrentUser() };
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
exports.createNewHcpApi = createNewHcpApi;
|
|
152
|
+
function createHcpHierarchyApis(env) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const initialisationApi = yield (0, apiV6_1.Api)(env.iCureUrl + '/rest/v1', env.masterHcp.user, env.masterHcp.password, crypto_1.webcrypto, fetch, true, false);
|
|
155
|
+
const primitives = new icc_x_api_1.CryptoPrimitives(crypto_1.webcrypto);
|
|
156
|
+
const grandCredentials = yield createHealthcarePartyUser(initialisationApi, `grand-${primitives.randomUuid()}`, primitives.randomUuid());
|
|
157
|
+
const parentCredentials = yield createHealthcarePartyUser(initialisationApi, `parent-${primitives.randomUuid()}`, primitives.randomUuid());
|
|
158
|
+
const childCredentials = yield createHealthcarePartyUser(initialisationApi, `child-${primitives.randomUuid()}`, primitives.randomUuid());
|
|
159
|
+
const child2Credentials = yield createHealthcarePartyUser(initialisationApi, `child2-${primitives.randomUuid()}`, primitives.randomUuid());
|
|
160
|
+
yield initialisationApi.healthcarePartyApi.modifyHealthcareParty(Object.assign(Object.assign({}, (yield initialisationApi.healthcarePartyApi.getHealthcareParty(parentCredentials.dataOwnerId))), { parentId: grandCredentials.dataOwnerId }));
|
|
161
|
+
yield initialisationApi.healthcarePartyApi.modifyHealthcareParty(Object.assign(Object.assign({}, (yield initialisationApi.healthcarePartyApi.getHealthcareParty(childCredentials.dataOwnerId))), { parentId: parentCredentials.dataOwnerId }));
|
|
162
|
+
yield initialisationApi.healthcarePartyApi.modifyHealthcareParty(Object.assign(Object.assign({}, (yield initialisationApi.healthcarePartyApi.getHealthcareParty(child2Credentials.dataOwnerId))), { parentId: grandCredentials.dataOwnerId }));
|
|
163
|
+
const grandStorage = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
164
|
+
{ dataOwnerId: grandCredentials.dataOwnerId, pairs: [{ privateKey: grandCredentials.privateKey, publicKey: grandCredentials.publicKey }] },
|
|
165
|
+
]);
|
|
166
|
+
const grandApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: grandCredentials.user, password: grandCredentials.password }, new TestCryptoStrategies_1.TestCryptoStrategies(), crypto_1.webcrypto, fetch, {
|
|
167
|
+
storage: grandStorage.storage,
|
|
168
|
+
keyStorage: grandStorage.keyStorage,
|
|
169
|
+
entryKeysFactory: grandStorage.keyFactory,
|
|
170
|
+
});
|
|
171
|
+
const parentStorage = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
172
|
+
{ dataOwnerId: grandCredentials.dataOwnerId, pairs: [{ privateKey: grandCredentials.privateKey, publicKey: grandCredentials.publicKey }] },
|
|
173
|
+
{ dataOwnerId: parentCredentials.dataOwnerId, pairs: [{ privateKey: parentCredentials.privateKey, publicKey: parentCredentials.publicKey }] },
|
|
174
|
+
]);
|
|
175
|
+
const parentApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: parentCredentials.user, password: parentCredentials.password }, new TestCryptoStrategies_1.TestCryptoStrategies(), crypto_1.webcrypto, fetch, {
|
|
176
|
+
storage: parentStorage.storage,
|
|
177
|
+
keyStorage: parentStorage.keyStorage,
|
|
178
|
+
entryKeysFactory: parentStorage.keyFactory,
|
|
179
|
+
});
|
|
180
|
+
const parentUser = yield parentApi.userApi.modifyUser(Object.assign(Object.assign({}, (yield parentApi.userApi.getCurrentUser())), { autoDelegations: { all: [grandCredentials.dataOwnerId] } }));
|
|
181
|
+
const childStorage = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
182
|
+
{ dataOwnerId: grandCredentials.dataOwnerId, pairs: [{ privateKey: grandCredentials.privateKey, publicKey: grandCredentials.publicKey }] },
|
|
183
|
+
{ dataOwnerId: parentCredentials.dataOwnerId, pairs: [{ privateKey: parentCredentials.privateKey, publicKey: parentCredentials.publicKey }] },
|
|
184
|
+
{ dataOwnerId: childCredentials.dataOwnerId, pairs: [{ privateKey: childCredentials.privateKey, publicKey: childCredentials.publicKey }] },
|
|
185
|
+
]);
|
|
186
|
+
const childApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: childCredentials.user, password: childCredentials.password }, new TestCryptoStrategies_1.TestCryptoStrategies(), crypto_1.webcrypto, fetch, {
|
|
187
|
+
storage: childStorage.storage,
|
|
188
|
+
keyStorage: childStorage.keyStorage,
|
|
189
|
+
entryKeysFactory: childStorage.keyFactory,
|
|
190
|
+
});
|
|
191
|
+
const childUser = yield childApi.userApi.modifyUser(Object.assign(Object.assign({}, (yield childApi.userApi.getCurrentUser())), { autoDelegations: { all: [grandCredentials.dataOwnerId, parentCredentials.dataOwnerId] } }));
|
|
192
|
+
const child2Storage = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
193
|
+
{ dataOwnerId: grandCredentials.dataOwnerId, pairs: [{ privateKey: grandCredentials.privateKey, publicKey: grandCredentials.publicKey }] },
|
|
194
|
+
{ dataOwnerId: child2Credentials.dataOwnerId, pairs: [{ privateKey: child2Credentials.privateKey, publicKey: child2Credentials.publicKey }] },
|
|
195
|
+
]);
|
|
196
|
+
const child2Api = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: child2Credentials.user, password: child2Credentials.password }, new TestCryptoStrategies_1.TestCryptoStrategies(), crypto_1.webcrypto, fetch, {
|
|
197
|
+
storage: child2Storage.storage,
|
|
198
|
+
keyStorage: child2Storage.keyStorage,
|
|
199
|
+
entryKeysFactory: child2Storage.keyFactory,
|
|
200
|
+
});
|
|
201
|
+
const child2User = yield child2Api.userApi.modifyUser(Object.assign(Object.assign({}, (yield child2Api.userApi.getCurrentUser())), { autoDelegations: { all: [grandCredentials.dataOwnerId] } }));
|
|
202
|
+
return {
|
|
203
|
+
grandApi,
|
|
204
|
+
grandUser: yield grandApi.userApi.getCurrentUser(),
|
|
205
|
+
grandCredentials,
|
|
206
|
+
parentApi,
|
|
207
|
+
parentUser,
|
|
208
|
+
parentCredentials,
|
|
209
|
+
childApi,
|
|
210
|
+
childUser,
|
|
211
|
+
childCredentials,
|
|
212
|
+
child2Api,
|
|
213
|
+
child2User,
|
|
214
|
+
child2Credentials,
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
exports.createHcpHierarchyApis = createHcpHierarchyApis;
|
|
219
|
+
/**
|
|
220
|
+
* Create a parent HCP with a key and a child HCP without any initialised key
|
|
221
|
+
*/
|
|
222
|
+
function createNewHcpWithoutKeyAndParentWithKey(env, props = {}) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const initialisationApi = yield (0, apiV6_1.Api)(env.iCureUrl + '/rest/v1', env.masterHcp.user, env.masterHcp.password, crypto_1.webcrypto, fetch, true, false);
|
|
225
|
+
const primitives = new icc_x_api_1.CryptoPrimitives(crypto_1.webcrypto);
|
|
226
|
+
const parentCredentials = yield createHealthcarePartyUser(initialisationApi, `parent-${primitives.randomUuid()}`, primitives.randomUuid());
|
|
227
|
+
const childUser = (0, uuid_1.v4)() + '@email.com';
|
|
228
|
+
const childPassword = (0, uuid_1.v4)();
|
|
229
|
+
const childHcp = new apiV6_1.HealthcareParty({
|
|
230
|
+
id: (0, uuid_1.v4)(),
|
|
231
|
+
firstName: (0, uuid_1.v4)().substring(0, 6),
|
|
232
|
+
lastName: (0, uuid_1.v4)().substring(0, 6),
|
|
233
|
+
parentId: parentCredentials.dataOwnerId,
|
|
234
|
+
});
|
|
235
|
+
if (props.initialiseEmptyKeyForChild) {
|
|
236
|
+
childHcp.publicKey = '';
|
|
237
|
+
}
|
|
238
|
+
yield initialisationApi.healthcarePartyApi.createHealthcareParty(childHcp);
|
|
239
|
+
yield initialisationApi.userApi.createUser(new User_1.User({
|
|
240
|
+
id: (0, uuid_1.v4)(),
|
|
241
|
+
name: childUser,
|
|
242
|
+
login: childUser,
|
|
243
|
+
email: childUser,
|
|
244
|
+
passwordHash: childPassword,
|
|
245
|
+
healthcarePartyId: childHcp.id,
|
|
246
|
+
}));
|
|
247
|
+
return {
|
|
248
|
+
parentCredentials,
|
|
249
|
+
childUser,
|
|
250
|
+
childPassword,
|
|
251
|
+
childDataOwnerId: childHcp.id,
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
exports.createNewHcpWithoutKeyAndParentWithKey = createNewHcpWithoutKeyAndParentWithKey;
|
|
256
|
+
function createUserInMultipleGroups(env) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
const primitives = new icc_x_api_1.CryptoPrimitives(crypto_1.webcrypto);
|
|
259
|
+
const userGroup1Id = primitives.randomUuid(); // Same username-pw as group 2
|
|
260
|
+
const userGroup2Id = primitives.randomUuid(); // Same username-pw as group 1
|
|
261
|
+
const userGroup3Id = primitives.randomUuid(); // Same username as group 1/2, different pw
|
|
262
|
+
const userLogin = `maria-${primitives.randomUuid()}@pompei.it`;
|
|
263
|
+
const userPw12 = `geppetto-${primitives.randomUuid()}`;
|
|
264
|
+
const userPw3 = `pinocchio-${primitives.randomUuid()}`;
|
|
265
|
+
const user1Id = primitives.randomUuid();
|
|
266
|
+
const user2Id = primitives.randomUuid();
|
|
267
|
+
const user3Id = primitives.randomUuid();
|
|
268
|
+
const api = yield icc_x_api_1.IcureBasicApi.initialise(env.iCureUrl, { username: 'john', password: 'LetMeIn' }, fetch); // pragma: allowlist secret
|
|
269
|
+
const group1 = yield api.groupApi.createGroup(userGroup1Id, `test-group-1-${primitives.randomUuid()}`, primitives.randomUuid(), undefined, undefined, undefined, undefined, undefined, {});
|
|
270
|
+
const group2 = yield api.groupApi.createGroup(userGroup2Id, `test-group-2-${primitives.randomUuid()}`, primitives.randomUuid(), undefined, undefined, undefined, undefined, undefined, {});
|
|
271
|
+
const group3 = yield api.groupApi.createGroup(userGroup3Id, `test-group-3-${primitives.randomUuid()}`, primitives.randomUuid(), undefined, undefined, undefined, undefined, undefined, {});
|
|
272
|
+
const user1 = yield api.userApi.createUserInGroup(userGroup1Id, {
|
|
273
|
+
id: user1Id,
|
|
274
|
+
name: userLogin,
|
|
275
|
+
login: userLogin,
|
|
276
|
+
email: userLogin,
|
|
277
|
+
passwordHash: userPw12,
|
|
278
|
+
});
|
|
279
|
+
const user2 = yield api.userApi.createUserInGroup(userGroup2Id, {
|
|
280
|
+
id: user2Id,
|
|
281
|
+
name: userLogin,
|
|
282
|
+
login: userLogin,
|
|
283
|
+
email: userLogin,
|
|
284
|
+
passwordHash: userPw12,
|
|
285
|
+
});
|
|
286
|
+
const user3 = yield api.userApi.createUserInGroup(userGroup3Id, {
|
|
287
|
+
id: user3Id,
|
|
288
|
+
name: userLogin,
|
|
289
|
+
login: userLogin,
|
|
290
|
+
email: userLogin,
|
|
291
|
+
passwordHash: userPw3,
|
|
292
|
+
});
|
|
293
|
+
console.log(`Waiting for user to be created - ${userLogin}`);
|
|
294
|
+
yield (0, icc_x_api_1.retry)(() => __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
yield new icc_api_1.IccUserApi(env.iCureUrl, {}, new icc_x_api_1.BasicAuthenticationProvider(`${userGroup1Id}/${user1Id}`, userPw12), fetch).getCurrentUser();
|
|
296
|
+
yield new icc_api_1.IccUserApi(env.iCureUrl, {}, new icc_x_api_1.BasicAuthenticationProvider(`${userGroup2Id}/${user2Id}`, userPw12), fetch).getCurrentUser();
|
|
297
|
+
yield new icc_api_1.IccUserApi(env.iCureUrl, {}, new icc_x_api_1.BasicAuthenticationProvider(`${userGroup3Id}/${user3Id}`, userPw3), fetch).getCurrentUser();
|
|
298
|
+
}), 10, 5000, 1);
|
|
299
|
+
return {
|
|
300
|
+
user1,
|
|
301
|
+
user2,
|
|
302
|
+
group3,
|
|
303
|
+
userPw3,
|
|
304
|
+
user3,
|
|
305
|
+
group2,
|
|
306
|
+
group1,
|
|
307
|
+
userPw12,
|
|
308
|
+
userLogin,
|
|
309
|
+
};
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
exports.createUserInMultipleGroups = createUserInMultipleGroups;
|
|
313
|
+
//# sourceMappingURL=test_utils.js.map
|