@icure/api 8.0.8 → 8.0.10
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/model/models.d.ts +1 -0
- package/icc-api/model/models.js +1 -0
- package/icc-api/model/models.js.map +1 -1
- package/icc-x-api/crypto/BaseExchangeDataManager.js +1 -1
- package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
- package/icc-x-api/crypto/BaseExchangeKeysManager.js +7 -3
- package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
- package/icc-x-api/crypto/ExchangeDataManager.js +3 -2
- package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
- package/icc-x-api/crypto/KeyRecovery.js +6 -5
- package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
- package/icc-x-api/crypto/RSA.d.ts +4 -1
- package/icc-x-api/crypto/RSA.js +6 -1
- package/icc-x-api/crypto/RSA.js.map +1 -1
- package/icc-x-api/crypto/SecureDelegationsManager.js +2 -1
- package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
- package/icc-x-api/crypto/ShamirKeysManager.js +8 -9
- package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
- package/icc-x-api/crypto/TransferKeysManager.js +4 -3
- package/icc-x-api/crypto/TransferKeysManager.js.map +1 -1
- package/icc-x-api/crypto/UserEncryptionKeysManager.js +4 -4
- package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -1
- package/icc-x-api/crypto/UserSignatureKeysManager.js +9 -5
- package/icc-x-api/crypto/UserSignatureKeysManager.js.map +1 -1
- package/icc-x-api/crypto/utils.d.ts +13 -4
- package/icc-x-api/crypto/utils.js +27 -9
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.js +16 -14
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +2 -2
- package/icc-x-api/icc-calendar-item-x-api.js +17 -17
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.js +12 -11
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +2 -2
- package/icc-x-api/icc-contact-x-api.js +23 -20
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-data-owner-x-api.js +1 -1
- package/icc-x-api/icc-data-owner-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.js +17 -16
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.js +13 -12
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.js +18 -16
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-icure-maintenance-x-api.js +4 -3
- package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.js +12 -11
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.js +11 -11
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.js +14 -14
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.js +28 -27
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.js +11 -10
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-recovery-x-api.js +3 -2
- package/icc-x-api/icc-recovery-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.js +9 -8
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/icc-topic-x-api.js +13 -13
- package/icc-x-api/icc-topic-x-api.js.map +1 -1
- package/icc-x-api/storage/IcureStorageFacade.js +4 -1
- package/icc-x-api/storage/IcureStorageFacade.js.map +1 -1
- package/icc-x-api/utils/EntityWithDelegationTypeName.d.ts +17 -1
- package/icc-x-api/utils/EntityWithDelegationTypeName.js +33 -15
- package/icc-x-api/utils/EntityWithDelegationTypeName.js.map +1 -1
- package/package.json +1 -1
- package/test/icc-api/api/IccAnonymousAccessApi.d.ts +1 -0
- package/test/icc-api/api/IccAnonymousAccessApi.js +58 -0
- package/test/icc-api/api/IccAnonymousAccessApi.js.map +1 -0
- package/test/icc-api/api/IccDocumentApi.d.ts +1 -0
- package/test/icc-api/api/IccDocumentApi.js +208 -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/IccRecoveryDataApi.d.ts +1 -0
- package/test/icc-api/api/IccRecoveryDataApi.js +95 -0
- package/test/icc-api/api/IccRecoveryDataApi.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 +96 -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 +46 -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 +224 -0
- package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -0
- package/test/icc-x-api/autofix-anonymity-test.d.ts +1 -0
- package/test/icc-x-api/autofix-anonymity-test.js +108 -0
- package/test/icc-x-api/autofix-anonymity-test.js.map +1 -0
- package/test/icc-x-api/confidential-entities-test.d.ts +1 -0
- package/test/icc-x-api/confidential-entities-test.js +110 -0
- package/test/icc-x-api/confidential-entities-test.js.map +1 -0
- package/test/icc-x-api/crud/comprehensive-crud-test.d.ts +1 -0
- package/test/icc-x-api/crud/comprehensive-crud-test.js +276 -0
- package/test/icc-x-api/crud/comprehensive-crud-test.js.map +1 -0
- package/test/icc-x-api/crud/entities-crud-test-interface.d.ts +16 -0
- package/test/icc-x-api/crud/entities-crud-test-interface.js +422 -0
- package/test/icc-x-api/crud/entities-crud-test-interface.js.map +1 -0
- package/test/icc-x-api/crypto/anonymous-delegations-test.d.ts +1 -0
- package/test/icc-x-api/crypto/anonymous-delegations-test.js +588 -0
- package/test/icc-x-api/crypto/anonymous-delegations-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 +302 -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 +166 -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/exchange-data-manager-test.d.ts +1 -0
- package/test/icc-x-api/crypto/exchange-data-manager-test.js +690 -0
- package/test/icc-x-api/crypto/exchange-data-manager-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 +457 -0
- package/test/icc-x-api/crypto/full-crypto-test.js.map +1 -0
- package/test/icc-x-api/crypto/secure-delegations-manager-test.d.ts +1 -0
- package/test/icc-x-api/crypto/secure-delegations-manager-test.js +266 -0
- package/test/icc-x-api/crypto/secure-delegations-manager-test.js.map +1 -0
- package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.d.ts +1 -0
- package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js +393 -0
- package/test/icc-x-api/crypto/secure-delegations-metadata-decryptor-test.js.map +1 -0
- package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.d.ts +1 -0
- package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js +213 -0
- package/test/icc-x-api/crypto/security-metadata-decryptor-chain-test.js.map +1 -0
- package/test/icc-x-api/crypto/shamir.d.ts +2 -0
- package/test/icc-x-api/crypto/shamir.js +166 -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 +71 -0
- package/test/icc-x-api/crypto/share-to-newly-created-patient-from-hcp.js.map +1 -0
- package/test/icc-x-api/crypto/signature-keys-manager-test.d.ts +1 -0
- package/test/icc-x-api/crypto/signature-keys-manager-test.js +44 -0
- package/test/icc-x-api/crypto/signature-keys-manager-test.js.map +1 -0
- package/test/icc-x-api/crypto/user-encryption-keys-manager-test.d.ts +1 -0
- package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js +246 -0
- package/test/icc-x-api/crypto/user-encryption-keys-manager-test.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 +106 -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 +47 -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 +150 -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 +279 -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 +98 -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 +153 -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 +99 -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 +221 -0
- package/test/icc-x-api/icc-maintenance-task-x-api-test.js.map +1 -0
- package/test/icc-x-api/icc-message-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-message-x-api.js +328 -0
- package/test/icc-x-api/icc-message-x-api.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 +158 -0
- package/test/icc-x-api/icc-patient-x-api-test.js.map +1 -0
- package/test/icc-x-api/icc-recovery-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-recovery-x-api.js +170 -0
- package/test/icc-x-api/icc-recovery-x-api.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 +100 -0
- package/test/icc-x-api/icc-time-table-x-api.js.map +1 -0
- package/test/icc-x-api/icc-topic-x-api.d.ts +1 -0
- package/test/icc-x-api/icc-topic-x-api.js +269 -0
- package/test/icc-x-api/icc-topic-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 +99 -0
- package/test/icc-x-api/icc-user-x-api-test.js.map +1 -0
- package/test/icc-x-api/patient-user.d.ts +2 -0
- package/test/icc-x-api/patient-user.js +104 -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 +48 -0
- package/test/icc-x-api/storage/storage.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 +376 -0
- package/test/icc-x-api/test-legacy-data-support.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/icc-x-api/utils/lru-temporised-async-cache-test.d.ts +1 -0
- package/test/icc-x-api/utils/lru-temporised-async-cache-test.js +364 -0
- package/test/icc-x-api/utils/lru-temporised-async-cache-test.js.map +1 -0
- package/test/support/CSM-185.d.ts +1 -0
- package/test/support/CSM-185.js +124 -0
- package/test/support/CSM-185.js.map +1 -0
- package/test/support/CSM-243.d.ts +1 -0
- package/test/support/CSM-243.js +120 -0
- package/test/support/CSM-243.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 +112 -0
- package/test/support/CSM-93.js.map +1 -0
- package/test/utils/FakeDataOwnerApi.d.ts +32 -0
- package/test/utils/FakeDataOwnerApi.js +136 -0
- package/test/utils/FakeDataOwnerApi.js.map +1 -0
- package/test/utils/FakeEncryptionKeysManager.d.ts +35 -0
- package/test/utils/FakeEncryptionKeysManager.js +87 -0
- package/test/utils/FakeEncryptionKeysManager.js.map +1 -0
- package/test/utils/FakeExchangeDataApi.d.ts +30 -0
- package/test/utils/FakeExchangeDataApi.js +74 -0
- package/test/utils/FakeExchangeDataApi.js.map +1 -0
- package/test/utils/FakeExchangeDataManager.d.ts +40 -0
- package/test/utils/FakeExchangeDataManager.js +89 -0
- package/test/utils/FakeExchangeDataManager.js.map +1 -0
- package/test/utils/FakeExchangeDataMapManager.d.ts +12 -0
- package/test/utils/FakeExchangeDataMapManager.js +38 -0
- package/test/utils/FakeExchangeDataMapManager.js.map +1 -0
- package/test/utils/FakeGenericApi.d.ts +16 -0
- package/test/utils/FakeGenericApi.js +65 -0
- package/test/utils/FakeGenericApi.js.map +1 -0
- package/test/utils/FakeSignatureKeysManager.d.ts +16 -0
- package/test/utils/FakeSignatureKeysManager.js +54 -0
- package/test/utils/FakeSignatureKeysManager.js.map +1 -0
- package/test/utils/TestApi.d.ts +3 -0
- package/test/utils/TestApi.js +30 -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 +42 -0
- package/test/utils/TestCryptoStrategies.js +80 -0
- package/test/utils/TestCryptoStrategies.js.map +1 -0
- package/test/utils/TestStorage.d.ts +23 -0
- package/test/utils/TestStorage.js +61 -0
- package/test/utils/TestStorage.js.map +1 -0
- package/test/utils/test_utils.d.ts +76 -0
- package/test/utils/test_utils.js +419 -0
- package/test/utils/test_utils.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
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 UserSignatureKeysManager_1 = require("../../../icc-x-api/crypto/UserSignatureKeysManager");
|
|
13
|
+
const IcureStorageFacade_1 = require("../../../icc-x-api/storage/IcureStorageFacade");
|
|
14
|
+
const TestStorage_1 = require("../../utils/TestStorage");
|
|
15
|
+
const DefaultStorageEntryKeysFactory_1 = require("../../../icc-x-api/storage/DefaultStorageEntryKeysFactory");
|
|
16
|
+
const FakeDataOwnerApi_1 = require("../../utils/FakeDataOwnerApi");
|
|
17
|
+
const CryptoPrimitives_1 = require("../../../icc-x-api/crypto/CryptoPrimitives");
|
|
18
|
+
const crypto_1 = require("crypto");
|
|
19
|
+
const DataOwnerTypeEnum_1 = require("../../../icc-api/model/DataOwnerTypeEnum");
|
|
20
|
+
const icc_x_api_1 = require("../../../icc-x-api");
|
|
21
|
+
const chai_1 = require("chai");
|
|
22
|
+
const utils_1 = require("../../../icc-x-api/crypto/utils");
|
|
23
|
+
describe('SignatureKeysManager', () => {
|
|
24
|
+
it('should be able to store a key pair in local storage and reload it', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const iCureStorage = new IcureStorageFacade_1.IcureStorageFacade(new TestStorage_1.TestKeyStorage(), new TestStorage_1.TestStorage(), new DefaultStorageEntryKeysFactory_1.DefaultStorageEntryKeysFactory());
|
|
26
|
+
const primitives = new CryptoPrimitives_1.CryptoPrimitives(crypto_1.webcrypto);
|
|
27
|
+
const dataOwnerApi = new FakeDataOwnerApi_1.FakeDataOwnerApi({ id: primitives.randomUuid(), type: DataOwnerTypeEnum_1.DataOwnerTypeEnum.Hcp });
|
|
28
|
+
const manager1 = new UserSignatureKeysManager_1.UserSignatureKeysManager(iCureStorage, dataOwnerApi, primitives);
|
|
29
|
+
const pair1 = yield manager1.getOrCreateSignatureKeyPair();
|
|
30
|
+
const manager2 = new UserSignatureKeysManager_1.UserSignatureKeysManager(iCureStorage, dataOwnerApi, primitives);
|
|
31
|
+
const pair2 = yield manager2.getOrCreateSignatureKeyPair();
|
|
32
|
+
const private1 = (0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey(pair1.keyPair.privateKey, 'pkcs8'));
|
|
33
|
+
const private2 = (0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey(pair2.keyPair.privateKey, 'pkcs8'));
|
|
34
|
+
(0, chai_1.expect)(private1).to.equal(private2);
|
|
35
|
+
const public1 = (0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey(pair1.keyPair.publicKey, 'spki'));
|
|
36
|
+
const public2 = (0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey(pair2.keyPair.publicKey, 'spki'));
|
|
37
|
+
(0, chai_1.expect)(public1).to.equal(public2);
|
|
38
|
+
const verification1 = (0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey((yield manager1.getSignatureVerificationKey((0, utils_1.fingerprintV1)(public1))), 'spki'));
|
|
39
|
+
const verification2 = (0, icc_x_api_1.ua2hex)(yield primitives.RSA.exportKey((yield manager2.getSignatureVerificationKey((0, utils_1.fingerprintV1)(public1))), 'spki'));
|
|
40
|
+
(0, chai_1.expect)(verification1).to.equal(public1);
|
|
41
|
+
(0, chai_1.expect)(verification2).to.equal(public1);
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=signature-keys-manager-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature-keys-manager-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/signature-keys-manager-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iGAA6F;AAC7F,sFAAkF;AAClF,yDAAqE;AACrE,8GAA0G;AAC1G,mEAA+D;AAC/D,iFAA6E;AAC7E,mCAAkC;AAClC,gFAA4E;AAC5E,kDAA2C;AAC3C,+BAA6B;AAC7B,2DAA+D;AAE/D,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,EAAE,CAAC,mEAAmE,EAAE,GAAS,EAAE;QACjF,MAAM,YAAY,GAAG,IAAI,uCAAkB,CAAC,IAAI,4BAAc,EAAE,EAAE,IAAI,yBAAW,EAAE,EAAE,IAAI,+DAA8B,EAAE,CAAC,CAAA;QAC1H,MAAM,UAAU,GAAG,IAAI,mCAAgB,CAAC,kBAAgB,CAAC,CAAA;QACzD,MAAM,YAAY,GAAG,IAAI,mCAAgB,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,qCAAiB,CAAC,GAAG,EAAE,CAAC,CAAA;QACvG,MAAM,QAAQ,GAAG,IAAI,mDAAwB,CAAC,YAAY,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;QACrF,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,2BAA2B,EAAE,CAAA;QAC1D,MAAM,QAAQ,GAAG,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AO,CAAC,CAAC,CAAE,EAAE,MAAM,CAAC,CAAC,CAAA;QAC3I,IAAA,aAAM,EAAC,aAAa,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACvC,IAAA,aAAM,EAAC,aAAa,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { UserSignatureKeysManager } from '../../../icc-x-api/crypto/UserSignatureKeysManager'\nimport { IcureStorageFacade } from '../../../icc-x-api/storage/IcureStorageFacade'\nimport { TestKeyStorage, TestStorage } from '../../utils/TestStorage'\nimport { DefaultStorageEntryKeysFactory } from '../../../icc-x-api/storage/DefaultStorageEntryKeysFactory'\nimport { FakeDataOwnerApi } from '../../utils/FakeDataOwnerApi'\nimport { CryptoPrimitives } from '../../../icc-x-api/crypto/CryptoPrimitives'\nimport { webcrypto } from 'crypto'\nimport { DataOwnerTypeEnum } from '../../../icc-api/model/DataOwnerTypeEnum'\nimport { ua2hex } from '../../../icc-x-api'\nimport { expect } from 'chai'\nimport { fingerprintV1 } from '../../../icc-x-api/crypto/utils'\n\ndescribe('SignatureKeysManager', () => {\n it('should be able to store a key pair in local storage and reload it', async () => {\n const iCureStorage = new IcureStorageFacade(new TestKeyStorage(), new TestStorage(), new DefaultStorageEntryKeysFactory())\n const primitives = new CryptoPrimitives(webcrypto as any)\n const dataOwnerApi = new FakeDataOwnerApi({ id: primitives.randomUuid(), type: DataOwnerTypeEnum.Hcp })\n const manager1 = new UserSignatureKeysManager(iCureStorage, dataOwnerApi, primitives)\n const pair1 = await manager1.getOrCreateSignatureKeyPair()\n const manager2 = new UserSignatureKeysManager(iCureStorage, dataOwnerApi, primitives)\n const pair2 = await manager2.getOrCreateSignatureKeyPair()\n const private1 = ua2hex(await primitives.RSA.exportKey(pair1.keyPair.privateKey, 'pkcs8'))\n const private2 = ua2hex(await primitives.RSA.exportKey(pair2.keyPair.privateKey, 'pkcs8'))\n expect(private1).to.equal(private2)\n const public1 = ua2hex(await primitives.RSA.exportKey(pair1.keyPair.publicKey, 'spki'))\n const public2 = ua2hex(await primitives.RSA.exportKey(pair2.keyPair.publicKey, 'spki'))\n expect(public1).to.equal(public2)\n const verification1 = ua2hex(await primitives.RSA.exportKey((await manager1.getSignatureVerificationKey(fingerprintV1(public1)))!, 'spki'))\n const verification2 = ua2hex(await primitives.RSA.exportKey((await manager2.getSignatureVerificationKey(fingerprintV1(public1)))!, 'spki'))\n expect(verification1).to.equal(public1)\n expect(verification2).to.equal(public1)\n })\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|
|
@@ -0,0 +1,246 @@
|
|
|
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 mocha_1 = require("mocha");
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
require("isomorphic-fetch");
|
|
15
|
+
const chai_1 = require("chai");
|
|
16
|
+
const test_utils_1 = require("../../utils/test_utils");
|
|
17
|
+
const TestStorage_1 = require("../../utils/TestStorage");
|
|
18
|
+
const TestCryptoStrategies_1 = require("../../utils/TestCryptoStrategies");
|
|
19
|
+
const types_1 = require("@icure/test-setup/types");
|
|
20
|
+
const icc_x_api_1 = require("../../../icc-x-api");
|
|
21
|
+
const apiV6_1 = require("@icure/apiV6");
|
|
22
|
+
(0, test_utils_1.setLocalStorage)(fetch);
|
|
23
|
+
let env;
|
|
24
|
+
(0, mocha_1.describe)('Key manager', function () {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
this.timeout(600000);
|
|
27
|
+
(0, mocha_1.before)(function () {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
30
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
(0, mocha_1.it)(`Should not ask crypto strategies to recover available keys`, () => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const apis = yield (0, test_utils_1.createHcpHierarchyApis)(env);
|
|
35
|
+
const storageWithoutParentKey = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
36
|
+
{
|
|
37
|
+
dataOwnerId: apis.grandCredentials.dataOwnerId,
|
|
38
|
+
pairs: [
|
|
39
|
+
{ keyPair: { privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }, shaVersion: icc_x_api_1.ShaVersion.Sha1 },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
dataOwnerId: apis.childCredentials.dataOwnerId,
|
|
44
|
+
pairs: [
|
|
45
|
+
{ keyPair: { privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }, shaVersion: icc_x_api_1.ShaVersion.Sha1 },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
const cryptoStrats = new TestCryptoStrategies_1.TestCryptoStrategies(undefined, {}, undefined, {
|
|
50
|
+
[apis.parentCredentials.dataOwnerId]: {
|
|
51
|
+
pair: { privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey },
|
|
52
|
+
shaVersion: icc_x_api_1.ShaVersion.Sha1,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: apis.childCredentials.user, password: apis.childCredentials.password }, cryptoStrats, crypto_1.webcrypto, fetch, {
|
|
56
|
+
storage: storageWithoutParentKey.storage,
|
|
57
|
+
keyStorage: storageWithoutParentKey.keyStorage,
|
|
58
|
+
entryKeysFactory: storageWithoutParentKey.keyFactory,
|
|
59
|
+
});
|
|
60
|
+
(0, chai_1.expect)(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(1);
|
|
61
|
+
const params = cryptoStrats.recoverAndVerifyCallsParams[0];
|
|
62
|
+
(0, chai_1.expect)(params).to.have.length(3);
|
|
63
|
+
(0, chai_1.expect)(params[0].dataOwner.dataOwner.id).to.equal(apis.grandCredentials.dataOwnerId);
|
|
64
|
+
(0, chai_1.expect)(params[0].unavailableKeys).to.be.empty;
|
|
65
|
+
(0, chai_1.expect)(params[0].unknownKeys).to.be.empty;
|
|
66
|
+
(0, chai_1.expect)(params[1].dataOwner.dataOwner.id).to.equal(apis.parentCredentials.dataOwnerId);
|
|
67
|
+
(0, chai_1.expect)(params[1].unavailableKeys).to.have.members([apis.parentCredentials.publicKey]);
|
|
68
|
+
(0, chai_1.expect)(params[1].unknownKeys).to.have.members([apis.parentCredentials.publicKey]);
|
|
69
|
+
(0, chai_1.expect)(params[2].dataOwner.dataOwner.id).to.equal(apis.childCredentials.dataOwnerId);
|
|
70
|
+
(0, chai_1.expect)(params[2].unavailableKeys).to.be.empty;
|
|
71
|
+
(0, chai_1.expect)(params[2].unknownKeys).to.be.empty;
|
|
72
|
+
}));
|
|
73
|
+
(0, mocha_1.it)('Should not ask crypto strategies to recover keys if all keys are available', () => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const apis = yield (0, test_utils_1.createHcpHierarchyApis)(env);
|
|
75
|
+
const storageWithoutParentKey = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
76
|
+
{
|
|
77
|
+
dataOwnerId: apis.grandCredentials.dataOwnerId,
|
|
78
|
+
pairs: [
|
|
79
|
+
{ keyPair: { privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }, shaVersion: icc_x_api_1.ShaVersion.Sha1 },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
dataOwnerId: apis.parentCredentials.dataOwnerId,
|
|
84
|
+
pairs: [
|
|
85
|
+
{ keyPair: { privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey }, shaVersion: icc_x_api_1.ShaVersion.Sha1 },
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
dataOwnerId: apis.childCredentials.dataOwnerId,
|
|
90
|
+
pairs: [
|
|
91
|
+
{ keyPair: { privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }, shaVersion: icc_x_api_1.ShaVersion.Sha1 },
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
95
|
+
const cryptoStrats = new TestCryptoStrategies_1.TestCryptoStrategies();
|
|
96
|
+
yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: apis.childCredentials.user, password: apis.childCredentials.password }, cryptoStrats, crypto_1.webcrypto, fetch, {
|
|
97
|
+
storage: storageWithoutParentKey.storage,
|
|
98
|
+
keyStorage: storageWithoutParentKey.keyStorage,
|
|
99
|
+
entryKeysFactory: storageWithoutParentKey.keyFactory,
|
|
100
|
+
});
|
|
101
|
+
(0, chai_1.expect)(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(0);
|
|
102
|
+
}));
|
|
103
|
+
(0, mocha_1.it)('Should allow to retrieve all keys for a data owner and his parents', () => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const apis = yield (0, test_utils_1.createHcpHierarchyApis)(env);
|
|
105
|
+
const keysData = yield apis.childApi.cryptoApi.getEncryptionDecryptionKeypairsForDataOwnerHierarchy();
|
|
106
|
+
function checkKey(userDetails, key) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const exportedPrivateKey = (0, apiV6_1.ua2hex)(yield apis.childApi.cryptoApi.primitives.RSA.exportKey(key.privateKey, 'pkcs8'));
|
|
109
|
+
const exportedPublicKey = (0, apiV6_1.ua2hex)(yield apis.childApi.cryptoApi.primitives.RSA.exportKey(key.publicKey, 'spki'));
|
|
110
|
+
(0, chai_1.expect)(exportedPublicKey).to.equal(userDetails.publicKey);
|
|
111
|
+
(0, chai_1.expect)(exportedPrivateKey).to.equal(userDetails.privateKey);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
(0, chai_1.expect)(keysData.self.dataOwnerId).to.equal(apis.childCredentials.dataOwnerId);
|
|
115
|
+
(0, chai_1.expect)(keysData.self.keys).to.have.length(1);
|
|
116
|
+
(0, chai_1.expect)(keysData.self.keys[0].verified).to.be.true;
|
|
117
|
+
yield checkKey(apis.childCredentials, keysData.self.keys[0].pair);
|
|
118
|
+
(0, chai_1.expect)(keysData.parents).to.have.length(2);
|
|
119
|
+
(0, chai_1.expect)(keysData.parents[0].dataOwnerId).to.equal(apis.grandCredentials.dataOwnerId);
|
|
120
|
+
(0, chai_1.expect)(keysData.parents[0].keys).to.have.length(1);
|
|
121
|
+
yield checkKey(apis.grandCredentials, keysData.parents[0].keys[0].pair);
|
|
122
|
+
(0, chai_1.expect)(keysData.parents[1].dataOwnerId).to.equal(apis.parentCredentials.dataOwnerId);
|
|
123
|
+
(0, chai_1.expect)(keysData.parents[1].keys).to.have.length(1);
|
|
124
|
+
yield checkKey(apis.parentCredentials, keysData.parents[1].keys[0].pair);
|
|
125
|
+
}));
|
|
126
|
+
(0, mocha_1.it)('If a HCP has no key yet, but the parent does the crypto strategies should first ask to recover the keys for the parent then ask for the generation of a new key to the data owner', () => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const hcpsInfo = yield (0, test_utils_1.createNewHcpWithoutKeyAndParentWithKey)(env);
|
|
128
|
+
const cryptoStrats = new (class {
|
|
129
|
+
constructor() {
|
|
130
|
+
this.generateNewKeyCalled = false;
|
|
131
|
+
this.recoverCalled = false;
|
|
132
|
+
this.generatedKeyPair = undefined;
|
|
133
|
+
}
|
|
134
|
+
generateNewKeyForDataOwner(self, cryptoPrimitives) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
if (this.generateNewKeyCalled)
|
|
137
|
+
throw new Error('generateNewKeyForDataOwner called twice');
|
|
138
|
+
if (!this.recoverCalled)
|
|
139
|
+
throw new Error('generateNewKeyForDataOwner called before recoverAndVerifySelfHierarchyKeys');
|
|
140
|
+
this.generateNewKeyCalled = true;
|
|
141
|
+
(0, chai_1.expect)(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId);
|
|
142
|
+
return (this.generatedKeyPair = yield cryptoPrimitives.RSA.generateKeyPair(icc_x_api_1.ShaVersion.Sha256));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
recoverAndVerifySelfHierarchyKeys(keysData, cryptoPrimitives) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
if (this.recoverCalled)
|
|
148
|
+
throw new Error('recoverAndVerifySelfHierarchyKeys called twice');
|
|
149
|
+
this.recoverCalled = true;
|
|
150
|
+
(0, chai_1.expect)(keysData).to.have.length(2);
|
|
151
|
+
(0, chai_1.expect)(keysData[0].dataOwner.dataOwner.id).to.equal(hcpsInfo.parentCredentials.dataOwnerId);
|
|
152
|
+
(0, chai_1.expect)(keysData[0].unknownKeys).to.have.members([hcpsInfo.parentCredentials.publicKey]);
|
|
153
|
+
(0, chai_1.expect)(keysData[0].unavailableKeys).to.have.members([hcpsInfo.parentCredentials.publicKey]);
|
|
154
|
+
(0, chai_1.expect)(keysData[1].dataOwner.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId);
|
|
155
|
+
(0, chai_1.expect)(keysData[1].unknownKeys).to.be.empty;
|
|
156
|
+
(0, chai_1.expect)(keysData[1].unavailableKeys).to.be.empty;
|
|
157
|
+
return {
|
|
158
|
+
[hcpsInfo.parentCredentials.dataOwnerId]: {
|
|
159
|
+
recoveredKeys: {
|
|
160
|
+
[hcpsInfo.parentCredentials.publicKey.slice(-32)]: yield cryptoPrimitives.RSA.importKeyPair('pkcs8', (0, icc_x_api_1.hex2ua)(hcpsInfo.parentCredentials.privateKey), 'spki', (0, icc_x_api_1.hex2ua)(hcpsInfo.parentCredentials.publicKey), icc_x_api_1.ShaVersion.Sha1),
|
|
161
|
+
},
|
|
162
|
+
keyAuthenticity: {},
|
|
163
|
+
},
|
|
164
|
+
[hcpsInfo.childDataOwnerId]: {
|
|
165
|
+
recoveredKeys: {},
|
|
166
|
+
keyAuthenticity: {},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
verifyDelegatePublicKeys(delegate, publicKeys, cryptoPrimitives) {
|
|
172
|
+
throw new Error('This method should not be called by this test');
|
|
173
|
+
}
|
|
174
|
+
dataOwnerRequiresAnonymousDelegation(dataOwner) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
})();
|
|
178
|
+
const childApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: hcpsInfo.childUser, password: hcpsInfo.childPassword }, cryptoStrats, crypto_1.webcrypto, fetch, {
|
|
179
|
+
storage: new TestStorage_1.TestStorage(),
|
|
180
|
+
keyStorage: new TestStorage_1.TestKeyStorage(),
|
|
181
|
+
});
|
|
182
|
+
(0, chai_1.expect)(cryptoStrats.generateNewKeyCalled).to.be.true;
|
|
183
|
+
(0, chai_1.expect)(cryptoStrats.recoverCalled).to.be.true;
|
|
184
|
+
const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf((yield childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner));
|
|
185
|
+
(0, chai_1.expect)(keys).to.have.length(1);
|
|
186
|
+
(0, chai_1.expect)(Array.from(keys)[0]).to.equal((0, apiV6_1.ua2hex)(yield childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair.publicKey, 'spki')));
|
|
187
|
+
}));
|
|
188
|
+
(0, mocha_1.it)('If a HCP has no key yet, but the parent does and the key is available the crypto strategies should ask for the generation of a new key to the data owner', () => __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
function doTest(initialiseEmptyKeyForChild) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const hcpsInfo = yield (0, test_utils_1.createNewHcpWithoutKeyAndParentWithKey)(env, { initialiseEmptyKeyForChild });
|
|
192
|
+
const cryptoStrats = new (class {
|
|
193
|
+
constructor() {
|
|
194
|
+
this.generateNewKeyCalled = false;
|
|
195
|
+
this.generatedKeyPair = undefined;
|
|
196
|
+
}
|
|
197
|
+
generateNewKeyForDataOwner(self, cryptoPrimitives) {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
if (this.generateNewKeyCalled)
|
|
200
|
+
throw new Error('generateNewKeyForDataOwner called twice');
|
|
201
|
+
this.generateNewKeyCalled = true;
|
|
202
|
+
(0, chai_1.expect)(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId);
|
|
203
|
+
return (this.generatedKeyPair = yield cryptoPrimitives.RSA.generateKeyPair(icc_x_api_1.ShaVersion.Sha256));
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
recoverAndVerifySelfHierarchyKeys(keysData, cryptoPrimitives) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
throw new Error('This method should not be called by this test');
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
dataOwnerRequiresAnonymousDelegation(dataOwner) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
verifyDelegatePublicKeys(delegate, publicKeys, cryptoPrimitives) {
|
|
215
|
+
throw new Error('This method should not be called by this test');
|
|
216
|
+
}
|
|
217
|
+
})();
|
|
218
|
+
const storages = yield (0, TestStorage_1.testStorageWithKeys)([
|
|
219
|
+
{
|
|
220
|
+
dataOwnerId: hcpsInfo.parentCredentials.dataOwnerId,
|
|
221
|
+
pairs: [
|
|
222
|
+
{
|
|
223
|
+
keyPair: { privateKey: hcpsInfo.parentCredentials.privateKey, publicKey: hcpsInfo.parentCredentials.publicKey },
|
|
224
|
+
shaVersion: icc_x_api_1.ShaVersion.Sha1,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
]);
|
|
229
|
+
const childApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: hcpsInfo.childUser, password: hcpsInfo.childPassword }, cryptoStrats, crypto_1.webcrypto, fetch, {
|
|
230
|
+
storage: storages.storage,
|
|
231
|
+
keyStorage: storages.keyStorage,
|
|
232
|
+
entryKeysFactory: storages.keyFactory,
|
|
233
|
+
});
|
|
234
|
+
(0, chai_1.expect)(cryptoStrats.generateNewKeyCalled).to.be.true;
|
|
235
|
+
const initialisedHcp = (yield childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner;
|
|
236
|
+
const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf(initialisedHcp));
|
|
237
|
+
(0, chai_1.expect)(keys).to.have.length(1);
|
|
238
|
+
(0, chai_1.expect)(keys[0]).to.equal((0, apiV6_1.ua2hex)(yield childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair.publicKey, 'spki')));
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
yield doTest(false);
|
|
242
|
+
yield doTest(true);
|
|
243
|
+
}));
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
//# sourceMappingURL=user-encryption-keys-manager-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-encryption-keys-manager-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/crypto/user-encryption-keys-manager-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,iCAA4C;A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AAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;gBACvI,CAAC;aAAA;YACD,MAAM,MAAM,CAAC,KAAK,CAAC,CAAA;YACnB,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;QACpB,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import { v4 as uuid } from 'uuid'\nimport { User } from '../../../icc-api/model/User'\nimport { before, describe, it } from 'mocha'\n\nimport { webcrypto } from 'crypto'\nimport 'isomorphic-fetch'\nimport { expect } from 'chai'\nimport { createHcpHierarchyApis, createNewHcpWithoutKeyAndParentWithKey, getEnvironmentInitializer, setLocalStorage } from '../../utils/test_utils'\nimport { TestKeyStorage, TestStorage, testStorageWithKeys } from '../../utils/TestStorage'\nimport { TestCryptoStrategies } from '../../utils/TestCryptoStrategies'\nimport { getEnvVariables, TestVars, UserDetails } from '@icure/test-setup/types'\nimport { CryptoPrimitives, CryptoStrategies, hex2ua, IcureApi, KeyPair, ShaVersion } from '../../../icc-x-api'\nimport { ua2hex } from '@icure/apiV6'\nimport { DataOwnerWithType } from '../../../icc-api/model/DataOwnerWithType'\nimport { CryptoActorStubWithType } from '../../../icc-api/model/CryptoActorStub'\n\nsetLocalStorage(fetch)\n\nlet env: TestVars\n\ndescribe('Key manager', async function () {\n this.timeout(600000)\n\n before(async function () {\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it(`Should not ask crypto strategies to recover available keys`, async () => {\n const apis = await createHcpHierarchyApis(env)\n const storageWithoutParentKey = await testStorageWithKeys([\n {\n dataOwnerId: apis.grandCredentials.dataOwnerId,\n pairs: [\n { keyPair: { privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }, shaVersion: ShaVersion.Sha1 },\n ],\n },\n {\n dataOwnerId: apis.childCredentials.dataOwnerId,\n pairs: [\n { keyPair: { privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }, shaVersion: ShaVersion.Sha1 },\n ],\n },\n ])\n const cryptoStrats = new TestCryptoStrategies(undefined, {}, undefined, {\n [apis.parentCredentials.dataOwnerId]: {\n pair: { privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey },\n shaVersion: ShaVersion.Sha1,\n },\n })\n await IcureApi.initialise(\n env.iCureUrl,\n { username: apis.childCredentials.user, password: apis.childCredentials.password },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: storageWithoutParentKey.storage,\n keyStorage: storageWithoutParentKey.keyStorage,\n entryKeysFactory: storageWithoutParentKey.keyFactory,\n }\n )\n expect(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(1)\n const params = cryptoStrats.recoverAndVerifyCallsParams[0]\n expect(params).to.have.length(3)\n expect(params[0].dataOwner.dataOwner.id).to.equal(apis.grandCredentials.dataOwnerId)\n expect(params[0].unavailableKeys).to.be.empty\n expect(params[0].unknownKeys).to.be.empty\n expect(params[1].dataOwner.dataOwner.id).to.equal(apis.parentCredentials.dataOwnerId)\n expect(params[1].unavailableKeys).to.have.members([apis.parentCredentials.publicKey])\n expect(params[1].unknownKeys).to.have.members([apis.parentCredentials.publicKey])\n expect(params[2].dataOwner.dataOwner.id).to.equal(apis.childCredentials.dataOwnerId)\n expect(params[2].unavailableKeys).to.be.empty\n expect(params[2].unknownKeys).to.be.empty\n })\n\n it('Should not ask crypto strategies to recover keys if all keys are available', async () => {\n const apis = await createHcpHierarchyApis(env)\n const storageWithoutParentKey = await testStorageWithKeys([\n {\n dataOwnerId: apis.grandCredentials.dataOwnerId,\n pairs: [\n { keyPair: { privateKey: apis.grandCredentials.privateKey, publicKey: apis.grandCredentials.publicKey }, shaVersion: ShaVersion.Sha1 },\n ],\n },\n {\n dataOwnerId: apis.parentCredentials.dataOwnerId,\n pairs: [\n { keyPair: { privateKey: apis.parentCredentials.privateKey, publicKey: apis.parentCredentials.publicKey }, shaVersion: ShaVersion.Sha1 },\n ],\n },\n {\n dataOwnerId: apis.childCredentials.dataOwnerId,\n pairs: [\n { keyPair: { privateKey: apis.childCredentials.privateKey, publicKey: apis.childCredentials.publicKey }, shaVersion: ShaVersion.Sha1 },\n ],\n },\n ])\n const cryptoStrats = new TestCryptoStrategies()\n await IcureApi.initialise(\n env.iCureUrl,\n { username: apis.childCredentials.user, password: apis.childCredentials.password },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: storageWithoutParentKey.storage,\n keyStorage: storageWithoutParentKey.keyStorage,\n entryKeysFactory: storageWithoutParentKey.keyFactory,\n }\n )\n expect(cryptoStrats.recoverAndVerifyCallsParams).to.have.length(0)\n })\n\n it('Should allow to retrieve all keys for a data owner and his parents', async () => {\n const apis = await createHcpHierarchyApis(env)\n const keysData = await apis.childApi.cryptoApi.getEncryptionDecryptionKeypairsForDataOwnerHierarchy()\n async function checkKey(userDetails: UserDetails, key: KeyPair<CryptoKey>) {\n const exportedPrivateKey = ua2hex(await apis.childApi.cryptoApi.primitives.RSA.exportKey(key.privateKey, 'pkcs8'))\n const exportedPublicKey = ua2hex(await apis.childApi.cryptoApi.primitives.RSA.exportKey(key.publicKey, 'spki'))\n expect(exportedPublicKey).to.equal(userDetails.publicKey)\n expect(exportedPrivateKey).to.equal(userDetails.privateKey)\n }\n expect(keysData.self.dataOwnerId).to.equal(apis.childCredentials.dataOwnerId)\n expect(keysData.self.keys).to.have.length(1)\n expect(keysData.self.keys[0].verified).to.be.true\n await checkKey(apis.childCredentials, keysData.self.keys[0].pair)\n expect(keysData.parents).to.have.length(2)\n expect(keysData.parents[0].dataOwnerId).to.equal(apis.grandCredentials.dataOwnerId)\n expect(keysData.parents[0].keys).to.have.length(1)\n await checkKey(apis.grandCredentials, keysData.parents[0].keys[0].pair)\n expect(keysData.parents[1].dataOwnerId).to.equal(apis.parentCredentials.dataOwnerId)\n expect(keysData.parents[1].keys).to.have.length(1)\n await checkKey(apis.parentCredentials, keysData.parents[1].keys[0].pair)\n })\n\n it('If a HCP has no key yet, but the parent does the crypto strategies should first ask to recover the keys for the parent then ask for the generation of a new key to the data owner', async () => {\n const hcpsInfo = await createNewHcpWithoutKeyAndParentWithKey(env)\n const cryptoStrats = new (class implements CryptoStrategies {\n generateNewKeyCalled: boolean = false\n recoverCalled: boolean = false\n generatedKeyPair: KeyPair<CryptoKey> | undefined = undefined\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType, cryptoPrimitives: CryptoPrimitives): Promise<KeyPair<CryptoKey> | boolean> {\n if (this.generateNewKeyCalled) throw new Error('generateNewKeyForDataOwner called twice')\n if (!this.recoverCalled) throw new Error('generateNewKeyForDataOwner called before recoverAndVerifySelfHierarchyKeys')\n this.generateNewKeyCalled = true\n expect(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId)\n return (this.generatedKeyPair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha256))\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[],\n cryptoPrimitives: CryptoPrimitives\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n if (this.recoverCalled) throw new Error('recoverAndVerifySelfHierarchyKeys called twice')\n this.recoverCalled = true\n expect(keysData).to.have.length(2)\n expect(keysData[0].dataOwner.dataOwner.id).to.equal(hcpsInfo.parentCredentials.dataOwnerId)\n expect(keysData[0].unknownKeys).to.have.members([hcpsInfo.parentCredentials.publicKey])\n expect(keysData[0].unavailableKeys).to.have.members([hcpsInfo.parentCredentials.publicKey])\n expect(keysData[1].dataOwner.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId)\n expect(keysData[1].unknownKeys).to.be.empty\n expect(keysData[1].unavailableKeys).to.be.empty\n return {\n [hcpsInfo.parentCredentials.dataOwnerId]: {\n recoveredKeys: {\n [hcpsInfo.parentCredentials.publicKey.slice(-32)]: await cryptoPrimitives.RSA.importKeyPair(\n 'pkcs8',\n hex2ua(hcpsInfo.parentCredentials.privateKey),\n 'spki',\n hex2ua(hcpsInfo.parentCredentials.publicKey),\n ShaVersion.Sha1\n ),\n },\n keyAuthenticity: {},\n },\n [hcpsInfo.childDataOwnerId]: {\n recoveredKeys: {},\n keyAuthenticity: {},\n },\n }\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]> {\n throw new Error('This method should not be called by this test')\n }\n\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return false\n }\n })()\n const childApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcpsInfo.childUser, password: hcpsInfo.childPassword },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n expect(cryptoStrats.generateNewKeyCalled).to.be.true\n expect(cryptoStrats.recoverCalled).to.be.true\n const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf((await childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner))\n expect(keys).to.have.length(1)\n expect(Array.from(keys)[0]).to.equal(ua2hex(await childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair!.publicKey, 'spki')))\n })\n\n it('If a HCP has no key yet, but the parent does and the key is available the crypto strategies should ask for the generation of a new key to the data owner', async () => {\n async function doTest(initialiseEmptyKeyForChild: boolean) {\n const hcpsInfo = await createNewHcpWithoutKeyAndParentWithKey(env, { initialiseEmptyKeyForChild })\n const cryptoStrats = new (class implements CryptoStrategies {\n generateNewKeyCalled: boolean = false\n generatedKeyPair: KeyPair<CryptoKey> | undefined = undefined\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType, cryptoPrimitives: CryptoPrimitives): Promise<KeyPair<CryptoKey> | boolean> {\n if (this.generateNewKeyCalled) throw new Error('generateNewKeyForDataOwner called twice')\n this.generateNewKeyCalled = true\n expect(self.dataOwner.id).to.equal(hcpsInfo.childDataOwnerId)\n return (this.generatedKeyPair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha256))\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[],\n cryptoPrimitives: CryptoPrimitives\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n throw new Error('This method should not be called by this test')\n }\n\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return false\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]> {\n throw new Error('This method should not be called by this test')\n }\n })()\n const storages = await testStorageWithKeys([\n {\n dataOwnerId: hcpsInfo.parentCredentials.dataOwnerId,\n pairs: [\n {\n keyPair: { privateKey: hcpsInfo.parentCredentials.privateKey, publicKey: hcpsInfo.parentCredentials.publicKey },\n shaVersion: ShaVersion.Sha1,\n },\n ],\n },\n ])\n const childApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcpsInfo.childUser, password: hcpsInfo.childPassword },\n cryptoStrats,\n webcrypto as any,\n fetch,\n {\n storage: storages.storage,\n keyStorage: storages.keyStorage,\n entryKeysFactory: storages.keyFactory,\n }\n )\n expect(cryptoStrats.generateNewKeyCalled).to.be.true\n const initialisedHcp = (await childApi.dataOwnerApi.getCurrentDataOwner()).dataOwner\n const keys = Array.from(childApi.dataOwnerApi.getHexPublicKeysOf(initialisedHcp))\n expect(keys).to.have.length(1)\n expect(keys[0]).to.equal(ua2hex(await childApi.cryptoApi.primitives.RSA.exportKey(cryptoStrats.generatedKeyPair!.publicKey, 'spki')))\n }\n await doTest(false)\n await doTest(true)\n })\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
require("isomorphic-fetch");
|
|
13
|
+
const test_utils_1 = require("../utils/test_utils");
|
|
14
|
+
const mocha_1 = require("mocha");
|
|
15
|
+
const icc_x_api_1 = require("../../icc-x-api");
|
|
16
|
+
var initApi = test_utils_1.TestUtils.initApi;
|
|
17
|
+
const chai_1 = require("chai");
|
|
18
|
+
const types_1 = require("@icure/test-setup/types");
|
|
19
|
+
(0, test_utils_1.setLocalStorage)(fetch);
|
|
20
|
+
let env;
|
|
21
|
+
let apis;
|
|
22
|
+
let user;
|
|
23
|
+
const entityWithAttachmentApis = {
|
|
24
|
+
docMainAttachment: (apis, currentUser) => ({
|
|
25
|
+
createEntity() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return apis.documentApi.createDocument(yield apis.documentApi.newInstance(currentUser));
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
encryptAndSetAttachment(entity, attachment) {
|
|
31
|
+
return apis.documentApi.encryptAndSetDocumentAttachment(entity, attachment);
|
|
32
|
+
},
|
|
33
|
+
getAndDecryptAttachment(entity, validator) {
|
|
34
|
+
return apis.documentApi.getAndDecryptDocumentAttachment(entity, validator);
|
|
35
|
+
},
|
|
36
|
+
getEncryptedAttachment(entity) {
|
|
37
|
+
return apis.documentApi.getDocumentAttachment(entity.id, 'unused');
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
docSecondaryAttachment: (apis, currentUser) => ({
|
|
41
|
+
createEntity() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
return apis.documentApi.createDocument(yield apis.documentApi.newInstance(currentUser));
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
encryptAndSetAttachment(entity, attachment) {
|
|
47
|
+
return apis.documentApi.encryptAndSetSecondaryDocumentAttachment(entity, 'secondary', attachment);
|
|
48
|
+
},
|
|
49
|
+
getAndDecryptAttachment(entity, validator) {
|
|
50
|
+
return apis.documentApi.getAndDecryptSecondaryDocumentAttachment(entity, 'secondary', validator);
|
|
51
|
+
},
|
|
52
|
+
getEncryptedAttachment(entity) {
|
|
53
|
+
return apis.documentApi.getSecondaryAttachment(entity.id, 'secondary');
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
receipt: (apis, currentUser) => ({
|
|
57
|
+
createEntity() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return apis.receiptApi.createReceipt(yield apis.receiptApi.newInstance(currentUser, {}));
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
encryptAndSetAttachment(entity, attachment) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return apis.receiptApi.encryptAndSetReceiptAttachment(entity, 'tack', attachment);
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
getAndDecryptAttachment(entity, validator) {
|
|
68
|
+
var _a;
|
|
69
|
+
return apis.receiptApi.getAndDecryptReceiptAttachment(entity, ((_a = entity.attachmentIds) !== null && _a !== void 0 ? _a : {})['tack'], validator);
|
|
70
|
+
},
|
|
71
|
+
getEncryptedAttachment(entity) {
|
|
72
|
+
var _a;
|
|
73
|
+
return apis.receiptApi.getReceiptAttachment(entity.id, ((_a = entity.attachmentIds) !== null && _a !== void 0 ? _a : {})['tack']);
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
(0, mocha_1.before)(function () {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
this.timeout(600000);
|
|
80
|
+
const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
|
|
81
|
+
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
82
|
+
for (const [a, b] of Object.entries(env.dataOwnerDetails)) {
|
|
83
|
+
console.log(a);
|
|
84
|
+
console.log(b.password);
|
|
85
|
+
console.log('');
|
|
86
|
+
}
|
|
87
|
+
apis = yield initApi(env, test_utils_1.hcp1Username);
|
|
88
|
+
user = yield apis.userApi.getCurrentUser();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe('Entity attachment update methods', function () {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
Object.entries(entityWithAttachmentApis).forEach(([type, attachmentApiInitialiser]) => {
|
|
94
|
+
it(`should automatically encrypt and decrypt attachments (${type})`, () => __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const attachmentApi = attachmentApiInitialiser(apis, user);
|
|
96
|
+
const entity = yield attachmentApi.createEntity();
|
|
97
|
+
console.log(`entity id ${entity.id}`);
|
|
98
|
+
const attachmentContent = 'This is some secret attachment';
|
|
99
|
+
const entityWithEncrypted = yield attachmentApi.encryptAndSetAttachment(entity, (0, icc_x_api_1.utf8_2ua)(attachmentContent));
|
|
100
|
+
const decryptedAttachment = yield attachmentApi.getAndDecryptAttachment(entityWithEncrypted, (d) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
try {
|
|
102
|
+
return (0, icc_x_api_1.ua2utf8)(d) === attachmentContent;
|
|
103
|
+
}
|
|
104
|
+
catch (_c) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}));
|
|
108
|
+
(0, chai_1.expect)((0, icc_x_api_1.ua2utf8)(decryptedAttachment)).to.equal(attachmentContent);
|
|
109
|
+
const encryptedAttachment = yield attachmentApi.getEncryptedAttachment(entityWithEncrypted);
|
|
110
|
+
let conversionFailed;
|
|
111
|
+
try {
|
|
112
|
+
conversionFailed = (0, icc_x_api_1.ua2utf8)(encryptedAttachment) !== attachmentContent;
|
|
113
|
+
}
|
|
114
|
+
catch (_a) {
|
|
115
|
+
conversionFailed = true;
|
|
116
|
+
}
|
|
117
|
+
(0, chai_1.expect)(conversionFailed).to.be.true;
|
|
118
|
+
const attachmentContent2 = 'This is an updated secret attachment';
|
|
119
|
+
const entityWithEncrypted2 = yield attachmentApi.encryptAndSetAttachment(entityWithEncrypted, (0, icc_x_api_1.utf8_2ua)(attachmentContent2));
|
|
120
|
+
const decryptedAttachment2 = yield attachmentApi.getAndDecryptAttachment(entityWithEncrypted2, (d) => __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
try {
|
|
122
|
+
return (0, icc_x_api_1.ua2utf8)(d) === attachmentContent2;
|
|
123
|
+
}
|
|
124
|
+
catch (_d) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
(0, chai_1.expect)((0, icc_x_api_1.ua2utf8)(decryptedAttachment2)).to.equal(attachmentContent2);
|
|
129
|
+
const encryptedAttachment2 = yield attachmentApi.getEncryptedAttachment(entityWithEncrypted2);
|
|
130
|
+
let conversionFailed2;
|
|
131
|
+
try {
|
|
132
|
+
conversionFailed2 = (0, icc_x_api_1.ua2utf8)(encryptedAttachment2) !== attachmentContent2;
|
|
133
|
+
}
|
|
134
|
+
catch (_b) {
|
|
135
|
+
conversionFailed2 = true;
|
|
136
|
+
}
|
|
137
|
+
(0, chai_1.expect)(conversionFailed2).to.be.true;
|
|
138
|
+
}));
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
//# sourceMappingURL=entity-with-attachments-api-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-with-attachments-api-test.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GAAG,MAAM,aAAa,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAA;gBAC7F,IAAI,iBAAiB,CAAA;gBACrB,IAAI;oBACF,iBAAiB,GAAG,IAAA,mBAAO,EAAC,oBAAoB,CAAC,KAAK,kBAAkB,CAAA;iBACzE;gBAAC,WAAM;oBACN,iBAAiB,GAAG,IAAI,CAAA;iBACzB;gBACD,IAAA,aAAM,EAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;YACtC,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\nimport { getEnvironmentInitializer, hcp1Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { before } from 'mocha'\nimport * as models from '../../icc-api/model/models'\nimport { User } from '../../icc-api/model/User'\nimport { Apis, ua2utf8, utf8_2ua } from '../../icc-x-api'\nimport initApi = TestUtils.initApi\nimport { expect } from 'chai'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nlet env: TestVars\nlet apis: Apis\nlet user: User\n\ninterface EntityWithAttachmentApi<T> {\n createEntity(): Promise<T>\n encryptAndSetAttachment(entity: T, attachment: ArrayBuffer | Uint8Array): Promise<T>\n getAndDecryptAttachment(entity: T, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer>\n getEncryptedAttachment(entity: T): Promise<ArrayBuffer>\n}\n\nconst entityWithAttachmentApis = {\n docMainAttachment: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Document>>{\n async createEntity(): Promise<models.Document> {\n return apis.documentApi.createDocument(await apis.documentApi.newInstance(currentUser))\n },\n encryptAndSetAttachment(entity: models.Document, attachment: ArrayBuffer | Uint8Array): Promise<models.Document> {\n return apis.documentApi.encryptAndSetDocumentAttachment(entity, attachment)\n },\n getAndDecryptAttachment(entity: models.Document, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.documentApi.getAndDecryptDocumentAttachment(entity, validator)\n },\n getEncryptedAttachment(entity: models.Document): Promise<ArrayBuffer> {\n return apis.documentApi.getDocumentAttachment(entity.id!, 'unused')\n },\n },\n docSecondaryAttachment: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Document>>{\n async createEntity(): Promise<models.Document> {\n return apis.documentApi.createDocument(await apis.documentApi.newInstance(currentUser))\n },\n encryptAndSetAttachment(entity: models.Document, attachment: ArrayBuffer | Uint8Array): Promise<models.Document> {\n return apis.documentApi.encryptAndSetSecondaryDocumentAttachment(entity, 'secondary', attachment)\n },\n getAndDecryptAttachment(entity: models.Document, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.documentApi.getAndDecryptSecondaryDocumentAttachment(entity, 'secondary', validator)\n },\n getEncryptedAttachment(entity: models.Document): Promise<ArrayBuffer> {\n return apis.documentApi.getSecondaryAttachment(entity.id!, 'secondary')\n },\n },\n receipt: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Receipt>>{\n async createEntity(): Promise<models.Receipt> {\n return apis.receiptApi.createReceipt(await apis.receiptApi.newInstance(currentUser, {}))\n },\n async encryptAndSetAttachment(entity: models.Receipt, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n return apis.receiptApi.encryptAndSetReceiptAttachment(entity, 'tack', attachment)\n },\n getAndDecryptAttachment(entity: models.Receipt, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.receiptApi.getAndDecryptReceiptAttachment(entity, (entity.attachmentIds ?? {})['tack'], validator)\n },\n getEncryptedAttachment(entity: models.Receipt): Promise<ArrayBuffer> {\n return apis.receiptApi.getReceiptAttachment(entity.id!, (entity.attachmentIds ?? {})['tack'])\n },\n },\n}\n\nbefore(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n for (const [a, b] of Object.entries(env.dataOwnerDetails)) {\n console.log(a)\n console.log(b.password)\n console.log('')\n }\n apis = await initApi(env!, hcp1Username)\n user = await apis.userApi.getCurrentUser()\n})\n\ndescribe('Entity attachment update methods', async function () {\n Object.entries(entityWithAttachmentApis).forEach(([type, attachmentApiInitialiser]) => {\n it(`should automatically encrypt and decrypt attachments (${type})`, async () => {\n const attachmentApi = attachmentApiInitialiser(apis, user)\n const entity = await attachmentApi.createEntity()\n console.log(`entity id ${entity.id}`)\n const attachmentContent = 'This is some secret attachment'\n const entityWithEncrypted = await attachmentApi.encryptAndSetAttachment(entity, utf8_2ua(attachmentContent))\n const decryptedAttachment = await attachmentApi.getAndDecryptAttachment(entityWithEncrypted, async (d) => {\n try {\n return ua2utf8(d) === attachmentContent\n } catch {\n return false\n }\n })\n expect(ua2utf8(decryptedAttachment)).to.equal(attachmentContent)\n const encryptedAttachment = await attachmentApi.getEncryptedAttachment(entityWithEncrypted)\n let conversionFailed\n try {\n conversionFailed = ua2utf8(encryptedAttachment) !== attachmentContent\n } catch {\n conversionFailed = true\n }\n expect(conversionFailed).to.be.true\n const attachmentContent2 = 'This is an updated secret attachment'\n const entityWithEncrypted2 = await attachmentApi.encryptAndSetAttachment(entityWithEncrypted, utf8_2ua(attachmentContent2))\n const decryptedAttachment2 = await attachmentApi.getAndDecryptAttachment(entityWithEncrypted2, async (d) => {\n try {\n return ua2utf8(d) === attachmentContent2\n } catch {\n return false\n }\n })\n expect(ua2utf8(decryptedAttachment2)).to.equal(attachmentContent2)\n const encryptedAttachment2 = await attachmentApi.getEncryptedAttachment(entityWithEncrypted2)\n let conversionFailed2\n try {\n conversionFailed2 = ua2utf8(encryptedAttachment2) !== attachmentContent2\n } catch {\n conversionFailed2 = true\n }\n expect(conversionFailed2).to.be.true\n })\n })\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'mocha';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
require("mocha");
|
|
5
|
+
const filters_1 = require("../../../icc-x-api/filters/filters");
|
|
6
|
+
describe('Composition', () => {
|
|
7
|
+
it('or should return an or combining other filters', () => {
|
|
8
|
+
const builder = filters_1.Filter.patient().forHcp('me').olderThan(65).or().youngerThan(18);
|
|
9
|
+
const filter = builder.build();
|
|
10
|
+
(0, chai_1.expect)(filter.$type).to.equal('UnionFilter');
|
|
11
|
+
});
|
|
12
|
+
it('and should work with or', () => {
|
|
13
|
+
const builder = filters_1.Filter.patient().forHcp('me').olderThan(65).or().youngerThan(18).and().searchByName('dup');
|
|
14
|
+
const filter = builder.build();
|
|
15
|
+
(0, chai_1.expect)(filter.$type).to.equal('IntersectionFilter');
|
|
16
|
+
(0, chai_1.expect)(filter.filters[0].$type).to.equal('UnionFilter');
|
|
17
|
+
});
|
|
18
|
+
it('precedence of operators can be managed for and/or', () => {
|
|
19
|
+
const builder = filters_1.Filter.patient()
|
|
20
|
+
.forHcp('me')
|
|
21
|
+
.olderThan(65)
|
|
22
|
+
.or((it) => it.youngerThan(18).and().searchByName('dup'));
|
|
23
|
+
const filter = builder.build();
|
|
24
|
+
(0, chai_1.expect)(filter.$type).to.equal('UnionFilter');
|
|
25
|
+
(0, chai_1.expect)(filter.filters[0].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter');
|
|
26
|
+
(0, chai_1.expect)(filter.filters[1].$type).to.equal('IntersectionFilter');
|
|
27
|
+
});
|
|
28
|
+
it('and should work with and', () => {
|
|
29
|
+
const builder = filters_1.Filter.patient().youngerThan(65).and().olderThan(18).and().searchByName('dup');
|
|
30
|
+
const filter = builder.build();
|
|
31
|
+
(0, chai_1.expect)(filter.$type).to.equal('IntersectionFilter');
|
|
32
|
+
(0, chai_1.expect)(filter.filters[0].$type).to.equal('IntersectionFilter');
|
|
33
|
+
});
|
|
34
|
+
it('should not crash miserably on incomplete or/and', () => {
|
|
35
|
+
const builder = filters_1.Filter.patient().youngerThan(65).and();
|
|
36
|
+
const filter = builder.build();
|
|
37
|
+
(0, chai_1.expect)(filter.$type).to.equal('IntersectionFilter');
|
|
38
|
+
(0, chai_1.expect)(filter.filters[0].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter');
|
|
39
|
+
(0, chai_1.expect)(filter.filters[1].$type).to.equal('PatientByHcPartyFilter');
|
|
40
|
+
});
|
|
41
|
+
it('should not crash miserably on combination of or/and', () => {
|
|
42
|
+
const builder = filters_1.Filter.patient().youngerThan(65).and().or().olderThan(75);
|
|
43
|
+
const filter = builder.build();
|
|
44
|
+
(0, chai_1.expect)(filter.$type).to.equal('IntersectionFilter');
|
|
45
|
+
(0, chai_1.expect)(filter.filters[0].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter');
|
|
46
|
+
(0, chai_1.expect)(filter.filters[1].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../../test/icc-x-api/filters/filters.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,iBAAc;AACd,gEAA2D;AAE3D,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,OAAO,GAAG,gBAAM,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;QAChF,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAA;QAE9B,IAAA,aAAM,EAAE,MAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IACvD,CA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AAE,GAAG,EAAE;QAC7D,MAAM,OAAO,GAAG,gBAAM,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QACzE,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAA;QAE9B,IAAA,aAAM,EAAE,MAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAA;QAC5D,IAAA,aAAM,EAAE,MAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;QAC7F,IAAA,aAAM,EAAE,MAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;IAC/F,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { expect } from 'chai'\nimport 'mocha'\nimport { Filter } from '../../../icc-x-api/filters/filters'\n\ndescribe('Composition', () => {\n it('or should return an or combining other filters', () => {\n const builder = Filter.patient().forHcp('me').olderThan(65).or().youngerThan(18)\n const filter = builder.build()\n\n expect((filter as any).$type).to.equal('UnionFilter')\n })\n\n it('and should work with or', () => {\n const builder = Filter.patient().forHcp('me').olderThan(65).or().youngerThan(18).and().searchByName('dup')\n const filter = builder.build()\n\n expect((filter as any).$type).to.equal('IntersectionFilter')\n expect((filter as any).filters[0].$type).to.equal('UnionFilter')\n })\n\n it('precedence of operators can be managed for and/or', () => {\n const builder = Filter.patient()\n .forHcp('me')\n .olderThan(65)\n .or((it) => it.youngerThan(18).and().searchByName('dup'))\n const filter = builder.build()\n\n expect((filter as any).$type).to.equal('UnionFilter')\n expect((filter as any).filters[0].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter')\n expect((filter as any).filters[1].$type).to.equal('IntersectionFilter')\n })\n\n it('and should work with and', () => {\n const builder = Filter.patient().youngerThan(65).and().olderThan(18).and().searchByName('dup')\n const filter = builder.build()\n\n expect((filter as any).$type).to.equal('IntersectionFilter')\n expect((filter as any).filters[0].$type).to.equal('IntersectionFilter')\n })\n\n it('should not crash miserably on incomplete or/and', () => {\n const builder = Filter.patient().youngerThan(65).and()\n const filter = builder.build()\n\n expect((filter as any).$type).to.equal('IntersectionFilter')\n expect((filter as any).filters[0].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter')\n expect((filter as any).filters[1].$type).to.equal('PatientByHcPartyFilter')\n })\n\n it('should not crash miserably on combination of or/and', () => {\n const builder = Filter.patient().youngerThan(65).and().or().olderThan(75)\n const filter = builder.build()\n\n expect((filter as any).$type).to.equal('IntersectionFilter')\n expect((filter as any).filters[0].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter')\n expect((filter as any).filters[1].$type).to.equal('PatientByHcPartyDateOfBirthBetweenFilter')\n })\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|