@icure/api 7.1.33 → 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-api/api/IccInsuranceApi.js +4 -3
- package/icc-api/api/IccInsuranceApi.js.map +1 -1
- package/icc-api/api/IccUserApi.d.ts +8 -10
- package/icc-api/api/IccUserApi.js +14 -18
- package/icc-api/api/IccUserApi.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,275 @@
|
|
|
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
|
+
/* make node behave */
|
|
13
|
+
require("isomorphic-fetch");
|
|
14
|
+
const icc_api_1 = require("../../../icc-api");
|
|
15
|
+
const chai_1 = require("chai");
|
|
16
|
+
require("mocha");
|
|
17
|
+
const Patient_1 = require("../../../icc-api/model/Patient");
|
|
18
|
+
const test_utils_1 = require("../../utils/test_utils");
|
|
19
|
+
const AuthenticationProvider_1 = require("../../../icc-x-api/auth/AuthenticationProvider");
|
|
20
|
+
var initApi = test_utils_1.TestUtils.initApi;
|
|
21
|
+
const types_1 = require("@icure/test-setup/types");
|
|
22
|
+
let env;
|
|
23
|
+
(0, test_utils_1.setLocalStorage)(fetch);
|
|
24
|
+
describe('Create a patient from scratch', () => {
|
|
25
|
+
before(function () {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
this.timeout(600000);
|
|
28
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
29
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
it('should create a patient in the database', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const api = yield initApi(env, test_utils_1.hcp1Username);
|
|
34
|
+
const user = yield api.userApi.getCurrentUser();
|
|
35
|
+
const note = 'A secured note that is encrypted';
|
|
36
|
+
const patient = yield api.patientApi.createPatientWithUser(user, yield api.patientApi.newInstance(user, new Patient_1.Patient({
|
|
37
|
+
lastName: 'Biden',
|
|
38
|
+
firstName: 'Joe',
|
|
39
|
+
note,
|
|
40
|
+
})));
|
|
41
|
+
(0, chai_1.expect)(patient.note).to.equal(note);
|
|
42
|
+
console.log(`Created patient (decrypted): ${patient.id}: ${patient.firstName} ${patient.lastName} [note:${patient.note}, encryptedSelf:${patient.encryptedSelf}]`);
|
|
43
|
+
const fetched = yield api.patientApi.getPatientWithUser(user, patient.id);
|
|
44
|
+
console.log(`Fetched patient (decrypted): ${fetched.id}: ${fetched.firstName} ${fetched.lastName} [note:${fetched.note}, encryptedSelf:${fetched.encryptedSelf}]`);
|
|
45
|
+
(0, chai_1.expect)(fetched.id).to.equal(patient.id);
|
|
46
|
+
(0, chai_1.expect)(fetched.note).to.equal(note);
|
|
47
|
+
const fetchedWithoutDecryption = yield new icc_api_1.IccPatientApi(env.iCureUrl, {}, new AuthenticationProvider_1.BasicAuthenticationProvider(env.dataOwnerDetails[test_utils_1.hcp1Username].user, env.dataOwnerDetails[test_utils_1.hcp1Username].password), fetch).getPatient(patient.id);
|
|
48
|
+
console.log(`Fetched patient (encrypted):${fetchedWithoutDecryption.id}: ${fetchedWithoutDecryption.firstName} ${fetchedWithoutDecryption.lastName} [note: ${fetchedWithoutDecryption.note}]`);
|
|
49
|
+
(0, chai_1.expect)(fetchedWithoutDecryption.id).to.equal(patient.id);
|
|
50
|
+
(0, chai_1.expect)(fetchedWithoutDecryption.note).to.be.undefined;
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
53
|
+
describe('Init confidential delegation in patient', () => {
|
|
54
|
+
before(function () {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
this.timeout(600000);
|
|
57
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
58
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it('should return a patient with a confidential delegation', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = yield (0, test_utils_1.createHcpHierarchyApis)(env);
|
|
63
|
+
const others = [
|
|
64
|
+
{ api: child2Api, user: child2User },
|
|
65
|
+
{ api: parentApi, user: parentUser },
|
|
66
|
+
{ api: grandApi, user: grandUser },
|
|
67
|
+
];
|
|
68
|
+
const note = 'Some note';
|
|
69
|
+
const pat = yield childApi.patientApi.createPatientWithUser(childUser, yield childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe', note }));
|
|
70
|
+
// All parents and siblings should have access to the decrypted data and to the initial secret id
|
|
71
|
+
(0, chai_1.expect)(yield childApi.cryptoApi.entities.secretIdsOf(pat)).to.have.length(1);
|
|
72
|
+
(0, chai_1.expect)((yield childApi.patientApi.getPatientWithUser(childUser, pat.id)).note).to.equal(note);
|
|
73
|
+
const originalSecretId = (yield childApi.cryptoApi.entities.secretIdsOf(pat))[0];
|
|
74
|
+
for (const { api, user } of others) {
|
|
75
|
+
(0, chai_1.expect)(yield api.cryptoApi.entities.secretIdsOf(pat)).to.have.length(1);
|
|
76
|
+
(0, chai_1.expect)((yield api.cryptoApi.entities.secretIdsOf(pat))[0]).to.equal(originalSecretId);
|
|
77
|
+
(0, chai_1.expect)((yield api.patientApi.getPatientWithUser(user, pat.id)).note).to.equal(note);
|
|
78
|
+
}
|
|
79
|
+
// Initially there shouldn't be any secret confidential secret id
|
|
80
|
+
(0, chai_1.expect)(yield childApi.cryptoApi.confidential.getConfidentialSecretId(pat)).to.be.undefined;
|
|
81
|
+
// Now create a confidential delegation
|
|
82
|
+
const patWithConfidential = yield childApi.patientApi.initConfidentialSecretId(pat, childUser);
|
|
83
|
+
// Confidential secret id should be different from the original secret id
|
|
84
|
+
const confidentialDelegationKey = yield childApi.cryptoApi.confidential.getConfidentialSecretId(patWithConfidential);
|
|
85
|
+
const nonConfidentialDelegationKey = yield childApi.cryptoApi.confidential.getAnySecretIdSharedWithParents(patWithConfidential);
|
|
86
|
+
(0, chai_1.expect)(confidentialDelegationKey).to.not.equal(nonConfidentialDelegationKey);
|
|
87
|
+
(0, chai_1.expect)(nonConfidentialDelegationKey).to.equal(originalSecretId);
|
|
88
|
+
// Child has access to confidential and not confidential secret ids.
|
|
89
|
+
const childSecretIds = yield childApi.cryptoApi.entities.secretIdsOf(patWithConfidential);
|
|
90
|
+
(0, chai_1.expect)(childSecretIds).to.have.length(2);
|
|
91
|
+
(0, chai_1.expect)(childSecretIds).to.have.contain(nonConfidentialDelegationKey);
|
|
92
|
+
(0, chai_1.expect)(childSecretIds).to.have.contain(confidentialDelegationKey);
|
|
93
|
+
// All parents and siblings should have access to the decrypted data even after initialising confidential delegations...
|
|
94
|
+
(0, chai_1.expect)((yield childApi.patientApi.getPatientWithUser(childUser, pat.id)).note).to.equal(note);
|
|
95
|
+
for (const { api, user } of others) {
|
|
96
|
+
(0, chai_1.expect)((yield api.patientApi.getPatientWithUser(user, pat.id)).note).to.equal(note);
|
|
97
|
+
}
|
|
98
|
+
// ...but not to the confidential secret id
|
|
99
|
+
for (const { api } of others) {
|
|
100
|
+
const secretIds = yield api.cryptoApi.entities.secretIdsOf(patWithConfidential);
|
|
101
|
+
(0, chai_1.expect)(secretIds).to.have.length(1);
|
|
102
|
+
(0, chai_1.expect)(secretIds).to.contain(nonConfidentialDelegationKey);
|
|
103
|
+
}
|
|
104
|
+
// If a secret delegation is already available there is no need to create a new one
|
|
105
|
+
const patWithConfidentialAgain = yield childApi.patientApi.initConfidentialSecretId(patWithConfidential, childUser);
|
|
106
|
+
(0, chai_1.expect)(patWithConfidentialAgain.rev).to.equal(patWithConfidentialAgain.rev);
|
|
107
|
+
(0, chai_1.expect)(yield childApi.cryptoApi.entities.secretIdsOf(patWithConfidentialAgain)).to.have.length(2);
|
|
108
|
+
// Different users will have different confidential secret ids...
|
|
109
|
+
(0, chai_1.expect)(yield child2Api.cryptoApi.confidential.getConfidentialSecretId(patWithConfidential)).to.be.undefined;
|
|
110
|
+
const patWithMoreConfidentialIds = yield child2Api.patientApi.initConfidentialSecretId(patWithConfidential, child2User);
|
|
111
|
+
// ...child continues to know the same secret ids...
|
|
112
|
+
const childSecretIdsRepeat = yield childApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds);
|
|
113
|
+
(0, chai_1.expect)(childSecretIdsRepeat).to.have.length(2);
|
|
114
|
+
(0, chai_1.expect)(childSecretIdsRepeat).to.have.contain(nonConfidentialDelegationKey);
|
|
115
|
+
(0, chai_1.expect)(childSecretIdsRepeat).to.have.contain(confidentialDelegationKey);
|
|
116
|
+
// ...but child2 now also knows a different secret id...
|
|
117
|
+
const child2secretIds = yield child2Api.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds);
|
|
118
|
+
const child2confidential = yield child2Api.cryptoApi.confidential.getConfidentialSecretId(patWithMoreConfidentialIds);
|
|
119
|
+
(0, chai_1.expect)(child2confidential).to.not.equal(confidentialDelegationKey);
|
|
120
|
+
(0, chai_1.expect)(child2confidential).to.not.equal(nonConfidentialDelegationKey);
|
|
121
|
+
(0, chai_1.expect)(child2secretIds).to.have.length(2);
|
|
122
|
+
(0, chai_1.expect)(child2secretIds).to.contain(nonConfidentialDelegationKey);
|
|
123
|
+
(0, chai_1.expect)(child2secretIds).to.contain(child2confidential);
|
|
124
|
+
// ...and their parents still don't know them
|
|
125
|
+
(0, chai_1.expect)(yield grandApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.length(1);
|
|
126
|
+
(0, chai_1.expect)(yield grandApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.contain(nonConfidentialDelegationKey);
|
|
127
|
+
(0, chai_1.expect)(yield parentApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.length(1);
|
|
128
|
+
(0, chai_1.expect)(yield parentApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.contain(nonConfidentialDelegationKey);
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
describe('Test that contact information can be decrypted', () => {
|
|
132
|
+
before(function () {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
this.timeout(600000);
|
|
135
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
136
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it('should return a contact with decrypted information', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = yield (0, test_utils_1.createHcpHierarchyApis)(env);
|
|
141
|
+
const allApis = [
|
|
142
|
+
{ api: childApi, user: childUser },
|
|
143
|
+
{ api: child2Api, user: child2User },
|
|
144
|
+
{ api: parentApi, user: parentUser },
|
|
145
|
+
{ api: grandApi, user: grandUser },
|
|
146
|
+
];
|
|
147
|
+
const pat = yield childApi.patientApi.createPatientWithUser(childUser, yield childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe' }));
|
|
148
|
+
const idFlat = childApi.cryptoApi.primitives.randomUuid();
|
|
149
|
+
const idCompound = childApi.cryptoApi.primitives.randomUuid();
|
|
150
|
+
const idSalut = childApi.cryptoApi.primitives.randomUuid();
|
|
151
|
+
const idAtoi = childApi.cryptoApi.primitives.randomUuid();
|
|
152
|
+
const instance = yield childApi.contactApi.newInstance(childUser, pat, {
|
|
153
|
+
services: [
|
|
154
|
+
{
|
|
155
|
+
id: idFlat,
|
|
156
|
+
content: { fr: { stringValue: 'Salut' }, nl: { stringValue: 'Halo' } },
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: idCompound,
|
|
160
|
+
content: {
|
|
161
|
+
fr: {
|
|
162
|
+
compoundValue: [
|
|
163
|
+
{ id: idSalut, content: { fr: { stringValue: 'Salut' } } },
|
|
164
|
+
{ id: idAtoi, content: { fr: { stringValue: 'à toi' } } },
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
const created = yield childApi.contactApi.createContactWithUser(childUser, instance);
|
|
172
|
+
const createdFlat = created.services.find((x) => x.id === idFlat);
|
|
173
|
+
const createdCompound = created.services.find((x) => x.id === idCompound);
|
|
174
|
+
const createdSalut = createdCompound.content.fr.compoundValue.find((x) => x.id === idSalut);
|
|
175
|
+
const createdAtoi = createdCompound.content.fr.compoundValue.find((x) => x.id === idAtoi);
|
|
176
|
+
for (const { api, user } of allApis) {
|
|
177
|
+
console.log('Trying with user: ' + user.login);
|
|
178
|
+
const check = yield api.contactApi.getContactWithUser(user, created.id);
|
|
179
|
+
const checkFlat = check.services.find((x) => x.id == idFlat);
|
|
180
|
+
const checkCompound = check.services.find((x) => x.id == idCompound);
|
|
181
|
+
const checkSalut = checkCompound.content.fr.compoundValue.find((x) => x.id === idSalut);
|
|
182
|
+
const checkAtoi = checkCompound.content.fr.compoundValue.find((x) => x.id === idAtoi);
|
|
183
|
+
(0, chai_1.expect)(checkFlat).to.not.be.undefined;
|
|
184
|
+
(0, chai_1.expect)(checkFlat).to.not.be.null;
|
|
185
|
+
(0, chai_1.expect)(checkSalut).to.not.be.undefined;
|
|
186
|
+
(0, chai_1.expect)(checkSalut).to.not.be.null;
|
|
187
|
+
(0, chai_1.expect)(checkAtoi).to.not.be.undefined;
|
|
188
|
+
(0, chai_1.expect)(checkAtoi).to.not.be.null;
|
|
189
|
+
(0, chai_1.expect)(checkFlat.content.fr.stringValue).to.equal(createdFlat.content.fr.stringValue);
|
|
190
|
+
(0, chai_1.expect)(checkFlat.content.nl.stringValue).to.equal(createdFlat.content.nl.stringValue);
|
|
191
|
+
(0, chai_1.expect)(checkFlat.content.encryptedSelf).to.not.be.null;
|
|
192
|
+
(0, chai_1.expect)(checkSalut.content.fr.stringValue).to.equal(createdSalut.content.fr.stringValue);
|
|
193
|
+
(0, chai_1.expect)(checkSalut.encryptedSelf).to.not.be.null;
|
|
194
|
+
(0, chai_1.expect)(checkAtoi.content.fr.stringValue).to.equal(createdAtoi.content.fr.stringValue);
|
|
195
|
+
(0, chai_1.expect)(checkAtoi.encryptedSelf).to.not.be.null;
|
|
196
|
+
}
|
|
197
|
+
}));
|
|
198
|
+
});
|
|
199
|
+
describe('test that confidential helement information cannot be retrieved at MH level', () => {
|
|
200
|
+
before(function () {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
this.timeout(600000);
|
|
203
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
204
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
it('should find the confidential data only when logged as the user', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
+
const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = yield (0, test_utils_1.createHcpHierarchyApis)(env);
|
|
209
|
+
const others = [
|
|
210
|
+
{ api: child2Api, user: child2User },
|
|
211
|
+
{ api: parentApi, user: parentUser },
|
|
212
|
+
{ api: grandApi, user: grandUser },
|
|
213
|
+
];
|
|
214
|
+
const pat = yield childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe' });
|
|
215
|
+
const modifiedPatient = (yield childApi.patientApi.initConfidentialSecretId(pat, childUser));
|
|
216
|
+
const confidentialHe = yield childApi.healthcareElementApi.createHealthElementWithUser(childUser, yield childApi.healthcareElementApi.newInstance(childUser, modifiedPatient, { descr: 'Confidential info' }, { confidential: true }));
|
|
217
|
+
const retrievedHesAsUser = yield childApi.healthcareElementApi.findBy(childUser.healthcarePartyId, modifiedPatient);
|
|
218
|
+
(0, chai_1.expect)(retrievedHesAsUser.length).to.equal(1, 'User should see its confidential data');
|
|
219
|
+
for (const { api, user } of others) {
|
|
220
|
+
const retrievedHesAsMh = yield api.healthcareElementApi.findBy(user.healthcarePartyId, modifiedPatient);
|
|
221
|
+
(0, chai_1.expect)(retrievedHesAsMh.length).to.equal(0, 'MH should not see confidential data');
|
|
222
|
+
let failedToRetrieve = false;
|
|
223
|
+
try {
|
|
224
|
+
yield api.healthcareElementApi.getHealthElementWithUser(user, confidentialHe.id);
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
console.log(e);
|
|
228
|
+
failedToRetrieve = true;
|
|
229
|
+
}
|
|
230
|
+
(0, chai_1.expect)(failedToRetrieve).to.equal(true, 'MH should fail to retrieve confidential data');
|
|
231
|
+
// Even if in some way I could get the contact I should not be able to decrypt it
|
|
232
|
+
(0, chai_1.expect)(yield api.cryptoApi.entities.encryptionKeysOf(confidentialHe)).to.have.length(0);
|
|
233
|
+
}
|
|
234
|
+
}));
|
|
235
|
+
});
|
|
236
|
+
describe('test that confidential contact information cannot be retrieved at MH level', () => {
|
|
237
|
+
before(function () {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
this.timeout(600000);
|
|
240
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
241
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
it('should find the confidential data only when logged as the user', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
+
const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = yield (0, test_utils_1.createHcpHierarchyApis)(env);
|
|
246
|
+
const others = [
|
|
247
|
+
{ api: child2Api, user: child2User },
|
|
248
|
+
{ api: parentApi, user: parentUser },
|
|
249
|
+
{ api: grandApi, user: grandUser },
|
|
250
|
+
];
|
|
251
|
+
const pat = yield childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe' });
|
|
252
|
+
const modifiedPatient = (yield childApi.patientApi.initConfidentialSecretId(pat, childUser));
|
|
253
|
+
const confidentialCtc = yield childApi.contactApi.createContactWithUser(childUser, yield childApi.healthcareElementApi.newInstance(childUser, modifiedPatient, { descr: 'Confidential info', services: [], subContacts: [] }, { confidential: true }));
|
|
254
|
+
yield childApi.contactApi.createContactWithUser(childUser, yield childApi.healthcareElementApi.newInstance(childUser, modifiedPatient, { descr: 'Non confidential info', services: [], subContacts: [] }, { confidential: false }));
|
|
255
|
+
const retrievedCtcsAsUser = yield childApi.contactApi.findBy(childUser.healthcarePartyId, modifiedPatient);
|
|
256
|
+
(0, chai_1.expect)(retrievedCtcsAsUser.length).to.equal(2, 'User should see its confidential data');
|
|
257
|
+
for (const { api, user } of others) {
|
|
258
|
+
const retrievedCtcsAsMh = yield api.contactApi.findBy(user.healthcarePartyId, modifiedPatient);
|
|
259
|
+
(0, chai_1.expect)(retrievedCtcsAsMh.length).to.equal(1, 'MH should not see confidential data');
|
|
260
|
+
// Even if in some way I could get the contact id I should not be able to get it
|
|
261
|
+
let failedToRetrieve = false;
|
|
262
|
+
try {
|
|
263
|
+
yield api.contactApi.getContactWithUser(user, confidentialCtc.id);
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
console.log(e);
|
|
267
|
+
failedToRetrieve = true;
|
|
268
|
+
}
|
|
269
|
+
(0, chai_1.expect)(failedToRetrieve).to.equal(true, 'MH should fail to retrieve confidential data');
|
|
270
|
+
// Even if in some way I could get the contact I should not be able to decrypt it
|
|
271
|
+
(0, chai_1.expect)(yield api.cryptoApi.entities.encryptionKeysOf(confidentialCtc)).to.have.length(0);
|
|
272
|
+
}
|
|
273
|
+
}));
|
|
274
|
+
});
|
|
275
|
+
//# sourceMappingURL=cryptoTest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cryptoTest.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/cryptoTest.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sBAAsB;AACtB,4BAAyB;AACzB,8CAAgD;AAChD,+BAA6B;AAC7B,iBAAc;AAEd,4DAAwD;AACxD,uDAAkJ;AAClJ,2FAA4F;AAC5F,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,mDAAmE;AAEnE,IAAI,GAAyB,CAAA;AAE7B,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AAEtB,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,MAAM,CAAC;;YACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;YACrD,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAA,uBAAe,GAAE,CAAC,CAAA;QACpD,CAAC;KAAA,CAAC,CAAA;IAEF,EAAE,CAAC,yCAAyC,EAAE,GAAS,EAAE;QACvD,MAAM,GAAG,GAAG,MAAM,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AAE,eAAe,CAAC,CAAA;QAC3G,IAAA,aAAM,EAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,uCAAuC,CAAC,CAAA;QAEvF,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,MAAM,EAAE;YAClC,MAAM,iBAAiB,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAkB,EAAE,eAAe,CAAC,CAAA;YAC/F,IAAA,aAAM,EAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,qCAAqC,CAAC,CAAA;YACnF,gFAAgF;YAChF,IAAI,gBAAgB,GAAG,KAAK,CAAA;YAC5B,IAAI;gBACF,MAAM,GAAG,CAAC,UAAU,CAAC,kBAAkB,CAAC,IAAI,EAAE,eAAgB,CAAC,EAAG,CAAC,CAAA;aACpE;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;gBACd,gBAAgB,GAAG,IAAI,CAAA;aACxB;YACD,IAAA,aAAM,EAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,8CAA8C,CAAC,CAAA;YACvF,iFAAiF;YACjF,IAAA,aAAM,EAAC,MAAM,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,eAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;SAC1F;IACH,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["/* make node behave */\nimport 'isomorphic-fetch'\nimport { IccPatientApi } from '../../../icc-api'\nimport { expect } from 'chai'\nimport 'mocha'\n\nimport { Patient } from '../../../icc-api/model/Patient'\nimport { createHcpHierarchyApis, getEnvironmentInitializer, hcp1Username, hcp2Username, setLocalStorage, TestUtils } from '../../utils/test_utils'\nimport { BasicAuthenticationProvider } from '../../../icc-x-api/auth/AuthenticationProvider'\nimport initApi = TestUtils.initApi\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nlet env: TestVars | undefined\n\nsetLocalStorage(fetch)\n\ndescribe('Create a patient from scratch', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('should create a patient in the database', async () => {\n const api = await initApi(env!, hcp1Username)\n const user = await api.userApi.getCurrentUser()\n\n const note = 'A secured note that is encrypted'\n const patient = await api.patientApi.createPatientWithUser(\n user,\n await api.patientApi.newInstance(\n user,\n new Patient({\n lastName: 'Biden',\n firstName: 'Joe',\n note,\n })\n )\n )\n expect(patient.note).to.equal(note)\n\n console.log(\n `Created patient (decrypted): ${patient.id}: ${patient.firstName} ${patient.lastName} [note:${patient.note}, encryptedSelf:${patient.encryptedSelf}]`\n )\n\n const fetched = await api.patientApi.getPatientWithUser(user, patient.id)\n console.log(\n `Fetched patient (decrypted): ${fetched.id}: ${fetched.firstName} ${fetched.lastName} [note:${fetched.note}, encryptedSelf:${fetched.encryptedSelf}]`\n )\n expect(fetched.id).to.equal(patient.id)\n expect(fetched.note).to.equal(note)\n\n const fetchedWithoutDecryption = await new IccPatientApi(\n env!.iCureUrl,\n {},\n new BasicAuthenticationProvider(env!.dataOwnerDetails[hcp1Username].user, env!.dataOwnerDetails[hcp1Username].password),\n fetch as any\n ).getPatient(patient.id)\n\n console.log(\n `Fetched patient (encrypted):${fetchedWithoutDecryption.id}: ${fetchedWithoutDecryption.firstName} ${fetchedWithoutDecryption.lastName} [note: ${fetchedWithoutDecryption.note}]`\n )\n expect(fetchedWithoutDecryption.id).to.equal(patient.id)\n expect(fetchedWithoutDecryption.note).to.be.undefined\n })\n})\n\ndescribe('Init confidential delegation in patient', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('should return a patient with a confidential delegation', async () => {\n const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = await createHcpHierarchyApis(env!)\n const others = [\n { api: child2Api, user: child2User },\n { api: parentApi, user: parentUser },\n { api: grandApi, user: grandUser },\n ]\n\n const note = 'Some note'\n const pat = await childApi.patientApi.createPatientWithUser(\n childUser,\n await childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe', note })\n )\n\n // All parents and siblings should have access to the decrypted data and to the initial secret id\n expect(await childApi.cryptoApi.entities.secretIdsOf(pat)).to.have.length(1)\n expect((await childApi.patientApi.getPatientWithUser(childUser, pat.id)).note).to.equal(note)\n const originalSecretId = (await childApi.cryptoApi.entities.secretIdsOf(pat))[0]\n for (const { api, user } of others) {\n expect(await api.cryptoApi.entities.secretIdsOf(pat)).to.have.length(1)\n expect((await api.cryptoApi.entities.secretIdsOf(pat))[0]).to.equal(originalSecretId)\n expect((await api.patientApi.getPatientWithUser(user, pat.id)).note).to.equal(note)\n }\n\n // Initially there shouldn't be any secret confidential secret id\n expect(await childApi.cryptoApi.confidential.getConfidentialSecretId(pat)).to.be.undefined\n\n // Now create a confidential delegation\n const patWithConfidential = await childApi.patientApi.initConfidentialSecretId(pat, childUser)\n\n // Confidential secret id should be different from the original secret id\n const confidentialDelegationKey = await childApi.cryptoApi.confidential.getConfidentialSecretId(patWithConfidential)\n const nonConfidentialDelegationKey = await childApi.cryptoApi.confidential.getAnySecretIdSharedWithParents(patWithConfidential)\n expect(confidentialDelegationKey).to.not.equal(nonConfidentialDelegationKey)\n expect(nonConfidentialDelegationKey).to.equal(originalSecretId)\n\n // Child has access to confidential and not confidential secret ids.\n const childSecretIds = await childApi.cryptoApi.entities.secretIdsOf(patWithConfidential)\n expect(childSecretIds).to.have.length(2)\n expect(childSecretIds).to.have.contain(nonConfidentialDelegationKey)\n expect(childSecretIds).to.have.contain(confidentialDelegationKey)\n\n // All parents and siblings should have access to the decrypted data even after initialising confidential delegations...\n expect((await childApi.patientApi.getPatientWithUser(childUser, pat.id)).note).to.equal(note)\n for (const { api, user } of others) {\n expect((await api.patientApi.getPatientWithUser(user, pat.id)).note).to.equal(note)\n }\n\n // ...but not to the confidential secret id\n for (const { api } of others) {\n const secretIds = await api.cryptoApi.entities.secretIdsOf(patWithConfidential)\n expect(secretIds).to.have.length(1)\n expect(secretIds).to.contain(nonConfidentialDelegationKey)\n }\n\n // If a secret delegation is already available there is no need to create a new one\n const patWithConfidentialAgain = await childApi.patientApi.initConfidentialSecretId(patWithConfidential, childUser)\n expect(patWithConfidentialAgain.rev).to.equal(patWithConfidentialAgain.rev)\n expect(await childApi.cryptoApi.entities.secretIdsOf(patWithConfidentialAgain)).to.have.length(2)\n\n // Different users will have different confidential secret ids...\n expect(await child2Api.cryptoApi.confidential.getConfidentialSecretId(patWithConfidential)).to.be.undefined\n const patWithMoreConfidentialIds = await child2Api.patientApi.initConfidentialSecretId(patWithConfidential, child2User)\n\n // ...child continues to know the same secret ids...\n const childSecretIdsRepeat = await childApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)\n expect(childSecretIdsRepeat).to.have.length(2)\n expect(childSecretIdsRepeat).to.have.contain(nonConfidentialDelegationKey)\n expect(childSecretIdsRepeat).to.have.contain(confidentialDelegationKey)\n\n // ...but child2 now also knows a different secret id...\n const child2secretIds = await child2Api.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)\n const child2confidential = await child2Api.cryptoApi.confidential.getConfidentialSecretId(patWithMoreConfidentialIds)\n expect(child2confidential).to.not.equal(confidentialDelegationKey)\n expect(child2confidential).to.not.equal(nonConfidentialDelegationKey)\n expect(child2secretIds).to.have.length(2)\n expect(child2secretIds).to.contain(nonConfidentialDelegationKey)\n expect(child2secretIds).to.contain(child2confidential)\n\n // ...and their parents still don't know them\n expect(await grandApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.length(1)\n expect(await grandApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.contain(nonConfidentialDelegationKey)\n expect(await parentApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.length(1)\n expect(await parentApi.cryptoApi.entities.secretIdsOf(patWithMoreConfidentialIds)).to.have.contain(nonConfidentialDelegationKey)\n })\n})\n\ndescribe('Test that contact information can be decrypted', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('should return a contact with decrypted information', async () => {\n const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = await createHcpHierarchyApis(env!)\n const allApis = [\n { api: childApi, user: childUser },\n { api: child2Api, user: child2User },\n { api: parentApi, user: parentUser },\n { api: grandApi, user: grandUser },\n ]\n\n const pat = await childApi.patientApi.createPatientWithUser(\n childUser,\n await childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe' })\n )\n const idFlat = childApi.cryptoApi.primitives.randomUuid()\n const idCompound = childApi.cryptoApi.primitives.randomUuid()\n const idSalut = childApi.cryptoApi.primitives.randomUuid()\n const idAtoi = childApi.cryptoApi.primitives.randomUuid()\n const instance = await childApi.contactApi.newInstance(childUser, pat, {\n services: [\n {\n id: idFlat,\n content: { fr: { stringValue: 'Salut' }, nl: { stringValue: 'Halo' } },\n },\n {\n id: idCompound,\n content: {\n fr: {\n compoundValue: [\n { id: idSalut, content: { fr: { stringValue: 'Salut' } } },\n { id: idAtoi, content: { fr: { stringValue: 'à toi' } } },\n ],\n },\n },\n },\n ],\n })\n const created = await childApi.contactApi.createContactWithUser(childUser, instance)\n const createdFlat = created!.services!.find((x) => x.id === idFlat)!\n const createdCompound = created!.services!.find((x) => x.id === idCompound)!\n const createdSalut = createdCompound.content!.fr.compoundValue!.find((x) => x.id === idSalut)!\n const createdAtoi = createdCompound.content!.fr.compoundValue!.find((x) => x.id === idAtoi)!\n\n for (const { api, user } of allApis) {\n console.log('Trying with user: ' + user.login)\n const check = await api.contactApi.getContactWithUser(user, created!.id!)\n const checkFlat = check!.services!.find((x) => x.id == idFlat)!\n const checkCompound = check!.services!.find((x) => x.id == idCompound)!\n const checkSalut = checkCompound.content!.fr.compoundValue!.find((x) => x.id === idSalut)!\n const checkAtoi = checkCompound.content!.fr.compoundValue!.find((x) => x.id === idAtoi)!\n\n expect(checkFlat).to.not.be.undefined\n expect(checkFlat).to.not.be.null\n expect(checkSalut).to.not.be.undefined\n expect(checkSalut).to.not.be.null\n expect(checkAtoi).to.not.be.undefined\n expect(checkAtoi).to.not.be.null\n\n expect(checkFlat.content!.fr.stringValue).to.equal(createdFlat!.content!.fr.stringValue)\n expect(checkFlat.content!.nl.stringValue).to.equal(createdFlat!.content!.nl.stringValue)\n expect(checkFlat.content!.encryptedSelf).to.not.be.null\n\n expect(checkSalut.content!.fr.stringValue).to.equal(createdSalut.content!.fr.stringValue)\n expect(checkSalut.encryptedSelf).to.not.be.null\n\n expect(checkAtoi.content!.fr.stringValue).to.equal(createdAtoi.content!.fr.stringValue)\n expect(checkAtoi.encryptedSelf).to.not.be.null\n }\n })\n})\n\ndescribe('test that confidential helement information cannot be retrieved at MH level', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('should find the confidential data only when logged as the user', async () => {\n const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = await createHcpHierarchyApis(env!)\n const others = [\n { api: child2Api, user: child2User },\n { api: parentApi, user: parentUser },\n { api: grandApi, user: grandUser },\n ]\n\n const pat = await childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe' })\n const modifiedPatient = (await childApi.patientApi.initConfidentialSecretId(pat, childUser))!\n\n const confidentialHe = await childApi.healthcareElementApi.createHealthElementWithUser(\n childUser,\n await childApi.healthcareElementApi.newInstance(childUser, modifiedPatient, { descr: 'Confidential info' }, { confidential: true })\n )\n\n const retrievedHesAsUser = await childApi.healthcareElementApi.findBy(childUser.healthcarePartyId!, modifiedPatient)\n expect(retrievedHesAsUser.length).to.equal(1, 'User should see its confidential data')\n\n for (const { api, user } of others) {\n const retrievedHesAsMh = await api.healthcareElementApi.findBy(user.healthcarePartyId!, modifiedPatient)\n expect(retrievedHesAsMh.length).to.equal(0, 'MH should not see confidential data')\n let failedToRetrieve = false\n try {\n await api.healthcareElementApi.getHealthElementWithUser(user, confidentialHe.id!)\n } catch (e) {\n console.log(e)\n failedToRetrieve = true\n }\n expect(failedToRetrieve).to.equal(true, 'MH should fail to retrieve confidential data')\n // Even if in some way I could get the contact I should not be able to decrypt it\n expect(await api.cryptoApi.entities.encryptionKeysOf(confidentialHe!)).to.have.length(0)\n }\n })\n})\n\ndescribe('test that confidential contact information cannot be retrieved at MH level', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('should find the confidential data only when logged as the user', async () => {\n const { grandApi, grandUser, childApi, childUser, parentApi, parentUser, child2Api, child2User } = await createHcpHierarchyApis(env!)\n const others = [\n { api: child2Api, user: child2User },\n { api: parentApi, user: parentUser },\n { api: grandApi, user: grandUser },\n ]\n\n const pat = await childApi.patientApi.newInstance(childUser, { firstName: 'John', lastName: 'Doe' })\n const modifiedPatient = (await childApi.patientApi.initConfidentialSecretId(pat, childUser))!\n\n const confidentialCtc = await childApi.contactApi.createContactWithUser(\n childUser,\n await childApi.healthcareElementApi.newInstance(\n childUser,\n modifiedPatient,\n\n { descr: 'Confidential info', services: [], subContacts: [] },\n { confidential: true }\n )\n )\n\n await childApi.contactApi.createContactWithUser(\n childUser,\n await childApi.healthcareElementApi.newInstance(\n childUser,\n modifiedPatient,\n { descr: 'Non confidential info', services: [], subContacts: [] },\n { confidential: false }\n )\n )\n\n const retrievedCtcsAsUser = await childApi.contactApi.findBy(childUser.healthcarePartyId!, modifiedPatient)\n expect(retrievedCtcsAsUser.length).to.equal(2, 'User should see its confidential data')\n\n for (const { api, user } of others) {\n const retrievedCtcsAsMh = await api.contactApi.findBy(user.healthcarePartyId!, modifiedPatient)\n expect(retrievedCtcsAsMh.length).to.equal(1, 'MH should not see confidential data')\n // Even if in some way I could get the contact id I should not be able to get it\n let failedToRetrieve = false\n try {\n await api.contactApi.getContactWithUser(user, confidentialCtc!.id!)\n } catch (e) {\n console.log(e)\n failedToRetrieve = true\n }\n expect(failedToRetrieve).to.equal(true, 'MH should fail to retrieve confidential data')\n // Even if in some way I could get the contact I should not be able to decrypt it\n expect(await api.cryptoApi.entities.encryptionKeysOf(confidentialCtc!)).to.have.length(0)\n }\n })\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
const icc_x_api_1 = require("../../../icc-x-api");
|
|
13
|
+
const CalendarItem_1 = require("../../../icc-api/model/CalendarItem");
|
|
14
|
+
const models_1 = require("../../../icc-api/model/models");
|
|
15
|
+
const mocha_1 = require("mocha");
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
17
|
+
require("isomorphic-fetch");
|
|
18
|
+
const chai_1 = require("chai");
|
|
19
|
+
const MaintenanceTaskAfterDateFilter_1 = require("../../../icc-x-api/filters/MaintenanceTaskAfterDateFilter");
|
|
20
|
+
const test_utils_1 = require("../../utils/test_utils");
|
|
21
|
+
const TestStorage_1 = require("../../utils/TestStorage");
|
|
22
|
+
const TestCryptoStrategies_1 = require("../../utils/TestCryptoStrategies");
|
|
23
|
+
const KeyPairUpdateRequest_1 = require("../../../icc-x-api/maintenance/KeyPairUpdateRequest");
|
|
24
|
+
const types_1 = require("@icure/test-setup/types");
|
|
25
|
+
function _getHcpKeyUpdateMaintenanceTask(delegateApi) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const delegateUser = yield delegateApi.userApi.getCurrentUser();
|
|
28
|
+
const notifications = yield delegateApi.maintenanceTaskApi.filterMaintenanceTasksByWithUser(delegateUser, undefined, undefined, new models_1.FilterChainMaintenanceTask({
|
|
29
|
+
filter: new MaintenanceTaskAfterDateFilter_1.MaintenanceTaskAfterDateFilter({
|
|
30
|
+
date: new Date().getTime() - 100000,
|
|
31
|
+
}),
|
|
32
|
+
}));
|
|
33
|
+
return notifications.rows.sort((a, b) => a.created - b.created)[notifications.rows.length - 1];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
(0, test_utils_1.setLocalStorage)(fetch);
|
|
37
|
+
let env;
|
|
38
|
+
(0, mocha_1.describe)('Full battery of tests on crypto and keys', function () {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
(0, mocha_1.before)(function () {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
this.timeout(600000);
|
|
43
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
44
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
(0, mocha_1.it)(`Create calendar item as a patient`, () => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const previousPubKey = env.dataOwnerDetails[test_utils_1.patUsername].publicKey;
|
|
49
|
+
const api = yield (0, test_utils_1.getApiAndAddPrivateKeysForUser)(env.iCureUrl, env.dataOwnerDetails[test_utils_1.patUsername]);
|
|
50
|
+
const u = yield api.userApi.getCurrentUser();
|
|
51
|
+
const delegateApi = yield (0, test_utils_1.getApiAndAddPrivateKeysForUser)(env.iCureUrl, env.dataOwnerDetails[test_utils_1.hcp1Username]);
|
|
52
|
+
const delegateUser = yield delegateApi.userApi.getCurrentUser();
|
|
53
|
+
const delegateHcp = yield delegateApi.healthcarePartyApi.getHealthcareParty(delegateUser.healthcarePartyId);
|
|
54
|
+
const patient = yield api.patientApi.getPatientWithUser(u, u.patientId);
|
|
55
|
+
// Create a Record to share with delegateHcp: this will trigger the creation of a new aes exchange key as well
|
|
56
|
+
const initialRecord = yield api.calendarItemApi.newInstance(u, new CalendarItem_1.CalendarItem({ id: `${u.id}-ci-initial`, title: 'CI-INITIAL' }), {
|
|
57
|
+
additionalDelegates: { [delegateHcp.id]: 'WRITE' },
|
|
58
|
+
});
|
|
59
|
+
const savedInitialRecord = yield api.calendarItemApi.createCalendarItemWithHcParty(u, initialRecord);
|
|
60
|
+
// Decrypting this AES Key to compare it with AES key decrypted with new key in the next steps
|
|
61
|
+
yield api.cryptoApi.forceReload();
|
|
62
|
+
const decryptedAesWithPreviousKey = yield api.cryptoApi.exchangeKeys.getDecryptionExchangeKeysFor(patient.id, delegateHcp.id);
|
|
63
|
+
(0, chai_1.expect)(decryptedAesWithPreviousKey).to.have.length(1);
|
|
64
|
+
const oldExchangeKeyRaw = (0, icc_x_api_1.ua2hex)(yield api.cryptoApi.primitives.AES.exportKey(decryptedAesWithPreviousKey[0], 'raw'));
|
|
65
|
+
// And creates a new one
|
|
66
|
+
const newKey = yield api.cryptoApi.primitives.RSA.generateKeyPair();
|
|
67
|
+
const publicKey = (0, icc_x_api_1.ua2hex)(yield api.cryptoApi.primitives.RSA.exportKey(newKey.publicKey, 'spki'));
|
|
68
|
+
const apiAfterNewKey = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: env.dataOwnerDetails[test_utils_1.patUsername].user, password: env.dataOwnerDetails[test_utils_1.patUsername].password }, new TestCryptoStrategies_1.TestCryptoStrategies(newKey), crypto_1.webcrypto, fetch, {
|
|
69
|
+
storage: new TestStorage_1.TestStorage(),
|
|
70
|
+
keyStorage: new TestStorage_1.TestKeyStorage(),
|
|
71
|
+
});
|
|
72
|
+
const user = yield apiAfterNewKey.userApi.getCurrentUser();
|
|
73
|
+
yield apiAfterNewKey.icureMaintenanceTaskApi.createMaintenanceTasksForNewKeypair(user, newKey);
|
|
74
|
+
// Api with new key should not be able to decrypt past exchange key with delegateHcp
|
|
75
|
+
yield apiAfterNewKey.cryptoApi.forceReload();
|
|
76
|
+
const decryptedAesAfterShareBackRequest = yield apiAfterNewKey.cryptoApi.exchangeKeys.getDecryptionExchangeKeysFor(patient.id, delegateHcp.id);
|
|
77
|
+
(0, chai_1.expect)(decryptedAesAfterShareBackRequest).to.have.length(1);
|
|
78
|
+
const newExchangeKeyRaw = (0, icc_x_api_1.ua2hex)(yield api.cryptoApi.primitives.AES.exportKey(decryptedAesAfterShareBackRequest[0], 'raw'));
|
|
79
|
+
// User can get not encrypted information from iCure (HCP, ...)
|
|
80
|
+
const hcp = yield apiAfterNewKey.healthcarePartyApi.getHealthcareParty(delegateUser.healthcarePartyId);
|
|
81
|
+
// User can create new data, using its new keyPair
|
|
82
|
+
const newRecord = yield apiAfterNewKey.calendarItemApi.newInstance(u, new CalendarItem_1.CalendarItem({ id: `${u.id}-ci`, title: 'CI' }), {
|
|
83
|
+
additionalDelegates: { [hcp.id]: 'WRITE' },
|
|
84
|
+
});
|
|
85
|
+
const entity = yield apiAfterNewKey.calendarItemApi.createCalendarItemWithHcParty(u, newRecord);
|
|
86
|
+
(0, chai_1.expect)(entity.id).to.be.not.null;
|
|
87
|
+
(0, chai_1.expect)(entity.rev).to.be.not.null;
|
|
88
|
+
// But user can not decrypt data he previously created
|
|
89
|
+
const initialRecordAfterNewKey = yield apiAfterNewKey.calendarItemApi.getCalendarItemWithUser(u, initialRecord.id);
|
|
90
|
+
(0, chai_1.expect)(initialRecordAfterNewKey.id).to.be.equal(savedInitialRecord.id);
|
|
91
|
+
(0, chai_1.expect)(initialRecordAfterNewKey.rev).to.be.equal(savedInitialRecord.rev);
|
|
92
|
+
(0, chai_1.expect)(initialRecordAfterNewKey.title).to.be.undefined;
|
|
93
|
+
// Delegate user will therefore give user access back to data he previously created
|
|
94
|
+
// Hcp gets his maintenance tasks
|
|
95
|
+
yield delegateApi.cryptoApi.forceReload();
|
|
96
|
+
const maintenanceTask = KeyPairUpdateRequest_1.KeyPairUpdateRequest.fromMaintenanceTask(yield _getHcpKeyUpdateMaintenanceTask(delegateApi));
|
|
97
|
+
(0, chai_1.expect)(maintenanceTask.concernedDataOwnerId).equals(patient.id);
|
|
98
|
+
(0, chai_1.expect)(maintenanceTask.newPublicKey).equals(publicKey);
|
|
99
|
+
yield delegateApi.icureMaintenanceTaskApi.applyKeyPairUpdate(maintenanceTask);
|
|
100
|
+
const updatedDataOwner = yield delegateApi.dataOwnerApi.getCryptoActorStub(maintenanceTask.concernedDataOwnerId);
|
|
101
|
+
(0, chai_1.expect)(updatedDataOwner.type).to.be.equal('patient');
|
|
102
|
+
(0, chai_1.expect)(updatedDataOwner.stub).to.not.be.undefined;
|
|
103
|
+
(0, chai_1.expect)(updatedDataOwner.stub).to.not.be.null;
|
|
104
|
+
(0, chai_1.expect)(updatedDataOwner.stub.aesExchangeKeys[previousPubKey][delegateUser.healthcarePartyId][publicKey.slice(-32)]).to.be.not.undefined;
|
|
105
|
+
(0, chai_1.expect)(updatedDataOwner.stub.aesExchangeKeys[previousPubKey][delegateUser.healthcarePartyId][publicKey.slice(-32)]).to.be.not.null;
|
|
106
|
+
const apiAfterSharedBack = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, {
|
|
107
|
+
username: env.dataOwnerDetails[test_utils_1.patUsername].user,
|
|
108
|
+
password: env.dataOwnerDetails[test_utils_1.patUsername].password,
|
|
109
|
+
}, new TestCryptoStrategies_1.TestCryptoStrategies(newKey), crypto_1.webcrypto, fetch, {
|
|
110
|
+
storage: new TestStorage_1.TestStorage(),
|
|
111
|
+
keyStorage: new TestStorage_1.TestKeyStorage(),
|
|
112
|
+
});
|
|
113
|
+
yield apiAfterSharedBack.cryptoApi.forceReload();
|
|
114
|
+
const decryptedAesWithShareBack = yield apiAfterSharedBack.cryptoApi.exchangeKeys.getDecryptionExchangeKeysFor(patient.id, delegateHcp.id);
|
|
115
|
+
(0, chai_1.expect)(decryptedAesWithShareBack).to.have.length(2);
|
|
116
|
+
const shareBackKeysRaw = yield Promise.all(decryptedAesWithShareBack.map((k) => api.cryptoApi.primitives.AES.exportKey(k, 'raw').then((x) => (0, icc_x_api_1.ua2hex)(x))));
|
|
117
|
+
// Patient can decrypt the new hcPartyKey
|
|
118
|
+
(0, chai_1.expect)(shareBackKeysRaw).to.not.contain(null);
|
|
119
|
+
(0, chai_1.expect)(shareBackKeysRaw).to.not.contain(undefined);
|
|
120
|
+
(0, chai_1.expect)(shareBackKeysRaw).to.contain(oldExchangeKeyRaw);
|
|
121
|
+
(0, chai_1.expect)(shareBackKeysRaw).to.contain(newExchangeKeyRaw);
|
|
122
|
+
// User can access his previous data again
|
|
123
|
+
yield apiAfterSharedBack.cryptoApi.forceReload();
|
|
124
|
+
const initialRecordAfterSharedBack = yield apiAfterSharedBack.calendarItemApi.getCalendarItemWithUser(u, initialRecord.id);
|
|
125
|
+
(0, chai_1.expect)(initialRecordAfterSharedBack.id).to.be.equal(savedInitialRecord.id);
|
|
126
|
+
(0, chai_1.expect)(initialRecordAfterSharedBack.rev).to.be.equal(savedInitialRecord.rev);
|
|
127
|
+
(0, chai_1.expect)(initialRecordAfterSharedBack.title).to.be.equal(savedInitialRecord.title);
|
|
128
|
+
}));
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
// TODO test that EXACTLY ONE maintenance task is created for each delegator AND delegate in a exchange key with the data owner with the new key
|
|
132
|
+
//# sourceMappingURL=delegate-ci-to-patient-with-missing-keys-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegate-ci-to-patient-with-missing-keys-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/delegate-ci-to-patient-with-missing-keys-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kDAA2D;AAC3D,sEAAkE;AAClE,0DAAyH;AACzH,iCAA4C;AAE5C,mCAAkC;AAClC,4BAAyB;AAEzB,+BAA6B;AAC7B,8GAA0G;AAC1G,uDAA8I;AAC9I,yDAAqE;AACrE,2EAAuE;AACvE,8FAA0F;AAC1F,mDAAmE;AAEnE,SAAe,+BAA+B,CAAC,WAAiB;;QAC9D,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,cAAc,EAAE,CAAA;QAC/D,MAAM,aAAa,GAAiC,MAAM,WAAW,CAAC,kBAAkB,CAAC,gCAAgC,CACvH,YAAa,EACb,SAAS,EACT,SAAS,EACT,IAAI,mCAA0B,CAAC;YAC7B,MAAM,EAAE,IAAI,+DAA8B,CAAC;gBACzC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,MAAM;aACpC,CAAC;SACH,CAAC,CACH,CAAA;QAED,OAAO,aAAa,CAAC,IAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAQ,GAAG,CAAC,CAAC,OAAQ,CAAC,CAAC,aAAa,CAAC,IAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACpG,CAAC;CAAA;AAED,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AAEtB,IAAI,GAAyB,CAAA;AAE7B,IAAA,gBAAQ,EAAC,0CAA0C,EAAE;;QACnD,IAAA,cAAM,EAAC;;gBACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;gBACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;gBACrD,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CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;QAClF,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA;AAEF,gJAAgJ","sourcesContent":["import { Apis, IcureApi, ua2hex } from '../../../icc-x-api'\nimport { CalendarItem } from '../../../icc-api/model/CalendarItem'\nimport { FilterChainMaintenanceTask, MaintenanceTask, PaginatedListMaintenanceTask } from '../../../icc-api/model/models'\nimport { before, describe, it } from 'mocha'\n\nimport { webcrypto } from 'crypto'\nimport 'isomorphic-fetch'\n\nimport { expect } from 'chai'\nimport { MaintenanceTaskAfterDateFilter } from '../../../icc-x-api/filters/MaintenanceTaskAfterDateFilter'\nimport { getApiAndAddPrivateKeysForUser, getEnvironmentInitializer, hcp1Username, patUsername, setLocalStorage } from '../../utils/test_utils'\nimport { TestKeyStorage, TestStorage } from '../../utils/TestStorage'\nimport { TestCryptoStrategies } from '../../utils/TestCryptoStrategies'\nimport { KeyPairUpdateRequest } from '../../../icc-x-api/maintenance/KeyPairUpdateRequest'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nasync function _getHcpKeyUpdateMaintenanceTask(delegateApi: Apis): Promise<MaintenanceTask> {\n const delegateUser = await delegateApi.userApi.getCurrentUser()\n const notifications: PaginatedListMaintenanceTask = await delegateApi.maintenanceTaskApi.filterMaintenanceTasksByWithUser(\n delegateUser!,\n undefined,\n undefined,\n new FilterChainMaintenanceTask({\n filter: new MaintenanceTaskAfterDateFilter({\n date: new Date().getTime() - 100000,\n }),\n })\n )\n\n return notifications.rows!.sort((a, b) => a.created! - b.created!)[notifications.rows!.length - 1]\n}\n\nsetLocalStorage(fetch)\n\nlet env: TestVars | undefined\n\ndescribe('Full battery of tests on crypto and keys', async function () {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it(`Create calendar item as a patient`, async () => {\n const previousPubKey = env!.dataOwnerDetails[patUsername].publicKey\n const api = await getApiAndAddPrivateKeysForUser(env!.iCureUrl, env!.dataOwnerDetails[patUsername])\n const u = await api.userApi.getCurrentUser()\n\n const delegateApi = await getApiAndAddPrivateKeysForUser(env!.iCureUrl, env!.dataOwnerDetails[hcp1Username])\n const delegateUser = await delegateApi.userApi.getCurrentUser()\n const delegateHcp = await delegateApi.healthcarePartyApi.getHealthcareParty(delegateUser.healthcarePartyId!)\n\n const patient = await api.patientApi.getPatientWithUser(u, u.patientId!)\n\n // Create a Record to share with delegateHcp: this will trigger the creation of a new aes exchange key as well\n const initialRecord = await api.calendarItemApi.newInstance(u, new CalendarItem({ id: `${u.id}-ci-initial`, title: 'CI-INITIAL' }), {\n additionalDelegates: { [delegateHcp!.id!]: 'WRITE' },\n })\n const savedInitialRecord = await api.calendarItemApi.createCalendarItemWithHcParty(u, initialRecord)\n\n // Decrypting this AES Key to compare it with AES key decrypted with new key in the next steps\n await api.cryptoApi.forceReload()\n const decryptedAesWithPreviousKey = await api.cryptoApi.exchangeKeys.getDecryptionExchangeKeysFor(patient.id!, delegateHcp.id!)\n expect(decryptedAesWithPreviousKey).to.have.length(1)\n const oldExchangeKeyRaw = ua2hex(await api.cryptoApi.primitives.AES.exportKey(decryptedAesWithPreviousKey[0], 'raw'))\n\n // And creates a new one\n const newKey = await api.cryptoApi.primitives.RSA.generateKeyPair()\n const publicKey = ua2hex(await api.cryptoApi.primitives.RSA.exportKey(newKey.publicKey, 'spki'))\n const apiAfterNewKey = await IcureApi.initialise(\n env!.iCureUrl,\n { username: env!.dataOwnerDetails[patUsername].user, password: env!.dataOwnerDetails[patUsername].password },\n new TestCryptoStrategies(newKey),\n webcrypto as unknown as Crypto,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n const user = await apiAfterNewKey.userApi.getCurrentUser()\n await apiAfterNewKey.icureMaintenanceTaskApi.createMaintenanceTasksForNewKeypair(user, newKey)\n // Api with new key should not be able to decrypt past exchange key with delegateHcp\n await apiAfterNewKey.cryptoApi.forceReload()\n const decryptedAesAfterShareBackRequest = await apiAfterNewKey.cryptoApi.exchangeKeys.getDecryptionExchangeKeysFor(patient.id!, delegateHcp.id!)\n expect(decryptedAesAfterShareBackRequest).to.have.length(1)\n const newExchangeKeyRaw = ua2hex(await api.cryptoApi.primitives.AES.exportKey(decryptedAesAfterShareBackRequest[0], 'raw'))\n\n // User can get not encrypted information from iCure (HCP, ...)\n const hcp = await apiAfterNewKey.healthcarePartyApi.getHealthcareParty(delegateUser!.healthcarePartyId!)\n\n // User can create new data, using its new keyPair\n const newRecord = await apiAfterNewKey.calendarItemApi.newInstance(u, new CalendarItem({ id: `${u.id}-ci`, title: 'CI' }), {\n additionalDelegates: { [hcp!.id!]: 'WRITE' },\n })\n const entity = await apiAfterNewKey.calendarItemApi.createCalendarItemWithHcParty(u, newRecord)\n expect(entity.id).to.be.not.null\n expect(entity.rev).to.be.not.null\n\n // But user can not decrypt data he previously created\n const initialRecordAfterNewKey = await apiAfterNewKey.calendarItemApi.getCalendarItemWithUser(u, initialRecord.id!)\n expect(initialRecordAfterNewKey.id).to.be.equal(savedInitialRecord.id)\n expect(initialRecordAfterNewKey.rev).to.be.equal(savedInitialRecord.rev)\n expect(initialRecordAfterNewKey.title).to.be.undefined\n\n // Delegate user will therefore give user access back to data he previously created\n\n // Hcp gets his maintenance tasks\n await delegateApi.cryptoApi.forceReload()\n const maintenanceTask = KeyPairUpdateRequest.fromMaintenanceTask(await _getHcpKeyUpdateMaintenanceTask(delegateApi))\n\n expect(maintenanceTask.concernedDataOwnerId).equals(patient.id)\n expect(maintenanceTask.newPublicKey).equals(publicKey)\n\n await delegateApi.icureMaintenanceTaskApi.applyKeyPairUpdate(maintenanceTask)\n const updatedDataOwner = await delegateApi.dataOwnerApi.getCryptoActorStub(maintenanceTask.concernedDataOwnerId)\n\n expect(updatedDataOwner.type).to.be.equal('patient')\n expect(updatedDataOwner.stub).to.not.be.undefined\n expect(updatedDataOwner.stub).to.not.be.null\n expect(updatedDataOwner.stub.aesExchangeKeys![previousPubKey][delegateUser!.healthcarePartyId!][publicKey.slice(-32)]).to.be.not.undefined\n expect(updatedDataOwner.stub.aesExchangeKeys![previousPubKey][delegateUser!.healthcarePartyId!][publicKey.slice(-32)]).to.be.not.null\n\n const apiAfterSharedBack = await IcureApi.initialise(\n env!.iCureUrl,\n {\n username: env!.dataOwnerDetails[patUsername].user,\n password: env!.dataOwnerDetails[patUsername].password,\n },\n new TestCryptoStrategies(newKey),\n webcrypto as unknown as Crypto,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n await apiAfterSharedBack.cryptoApi.forceReload()\n const decryptedAesWithShareBack = await apiAfterSharedBack.cryptoApi.exchangeKeys.getDecryptionExchangeKeysFor(patient.id!, delegateHcp.id!)\n expect(decryptedAesWithShareBack).to.have.length(2)\n const shareBackKeysRaw = await Promise.all(\n decryptedAesWithShareBack.map((k) => api.cryptoApi.primitives.AES.exportKey(k, 'raw').then((x) => ua2hex(x)))\n )\n\n // Patient can decrypt the new hcPartyKey\n expect(shareBackKeysRaw).to.not.contain(null)\n expect(shareBackKeysRaw).to.not.contain(undefined)\n expect(shareBackKeysRaw).to.contain(oldExchangeKeyRaw)\n expect(shareBackKeysRaw).to.contain(newExchangeKeyRaw)\n\n // User can access his previous data again\n await apiAfterSharedBack.cryptoApi.forceReload()\n\n const initialRecordAfterSharedBack = await apiAfterSharedBack.calendarItemApi.getCalendarItemWithUser(u, initialRecord.id!)\n expect(initialRecordAfterSharedBack.id).to.be.equal(savedInitialRecord.id)\n expect(initialRecordAfterSharedBack.rev).to.be.equal(savedInitialRecord.rev)\n expect(initialRecordAfterSharedBack.title).to.be.equal(savedInitialRecord.title)\n })\n})\n\n// TODO test that EXACTLY ONE maintenance task is created for each delegator AND delegate in a exchange key with the data owner with the new key\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|