@enbox/dwn-sdk-js 0.0.1 → 0.0.3
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/README.md +52 -301
- package/dist/bundles/dwn.js +19 -21
- package/dist/esm/generated/precompiled-validators.js +2764 -1773
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +27 -3
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +17 -6
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +245 -69
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +4 -4
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/dwn.js +10 -8
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/enums/dwn-interface-method.js +4 -2
- package/dist/esm/src/enums/dwn-interface-method.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +1 -0
- package/dist/esm/src/handlers/messages-subscribe.js +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +116 -0
- package/dist/esm/src/handlers/messages-sync.js.map +1 -0
- package/dist/esm/src/handlers/protocols-configure.js +149 -16
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +2 -2
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +143 -0
- package/dist/esm/src/handlers/records-count.js.map +1 -0
- package/dist/esm/src/handlers/records-query.js +4 -0
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +4 -6
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +17 -18
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +9 -5
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +2 -7
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +1 -0
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/{messages-query.js → messages-sync.js} +11 -12
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-configure.js +153 -30
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +1 -0
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +91 -0
- package/dist/esm/src/interfaces/records-count.js.map +1 -0
- package/dist/esm/src/interfaces/records-read.js +15 -1
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +64 -15
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js.map +1 -1
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +30 -0
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +24 -0
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +1 -1
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/schema-validator.js +0 -1
- package/dist/esm/src/schema-validator.js.map +1 -1
- package/dist/esm/src/smt/smt-store-level.js +125 -0
- package/dist/esm/src/smt/smt-store-level.js.map +1 -0
- package/dist/esm/src/smt/smt-store-memory.js +67 -0
- package/dist/esm/src/smt/smt-store-memory.js.map +1 -0
- package/dist/esm/src/smt/smt-utils.js +146 -0
- package/dist/esm/src/smt/smt-utils.js.map +1 -0
- package/dist/esm/src/smt/sparse-merkle-tree.js +622 -0
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -0
- package/dist/esm/src/state-index/state-index-level.js +228 -0
- package/dist/esm/src/state-index/state-index-level.js.map +1 -0
- package/dist/esm/src/store/data-store-level.js +6 -6
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level.js +375 -17
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +56 -0
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +19 -16
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/encryption-types.js +2 -0
- package/dist/esm/src/types/encryption-types.js.map +1 -0
- package/dist/esm/src/types/message-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +0 -2
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/types/records-types.js +2 -0
- package/dist/esm/src/types/records-types.js.map +1 -1
- package/dist/esm/src/types/smt-types.js +5 -0
- package/dist/esm/src/types/smt-types.js.map +1 -0
- package/dist/esm/src/types/state-index.js +2 -0
- package/dist/esm/src/types/state-index.js.map +1 -0
- package/dist/esm/src/utils/cid.js +2 -1
- package/dist/esm/src/utils/cid.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +84 -29
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +22 -31
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +3 -3
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +4 -4
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/private-key-signer.js +4 -3
- package/dist/esm/src/utils/private-key-signer.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +82 -9
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +82 -26
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +4 -3
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +3 -2
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +1 -1
- package/dist/esm/src/utils/url.js +1 -1
- package/dist/esm/src/utils/url.js.map +1 -1
- package/dist/esm/tests/core/auth.spec.js +2 -2
- package/dist/esm/tests/core/auth.spec.js.map +1 -1
- package/dist/esm/tests/core/message-reply.spec.js +3 -3
- package/dist/esm/tests/core/message-reply.spec.js.map +1 -1
- package/dist/esm/tests/core/message.spec.js +13 -13
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +3 -3
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +27 -37
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/{event-log → event-stream}/event-emitter-stream.spec.js +14 -15
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +1 -0
- package/dist/esm/tests/{event-log → event-stream}/event-stream.spec.js +13 -15
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +281 -135
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +57 -59
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +32 -34
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +73 -95
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +1645 -0
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-create-action.spec.js +25 -27
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +42 -44
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +53 -55
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune.spec.js +126 -100
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-tags.spec.js +272 -272
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +35 -37
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +112 -112
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +78 -76
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +528 -0
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js +545 -152
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +70 -72
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +313 -0
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-delete.spec.js +106 -109
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +863 -463
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +439 -209
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +292 -97
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +481 -483
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +31 -11
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +5 -5
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +64 -134
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-query.spec.js +4 -6
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +3 -5
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +9 -11
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-read.spec.js +76 -7
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +7 -9
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +244 -48
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +15 -18
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +114 -0
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -0
- package/dist/esm/tests/protocols/permission-request.spec.js +43 -7
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +9 -11
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +90 -92
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +17 -19
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +27 -29
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +37 -39
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +163 -163
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +143 -0
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -0
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +741 -0
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -0
- package/dist/esm/tests/state-index/state-index-level.spec.js +254 -0
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -0
- package/dist/esm/tests/store/blockstore-level.spec.js +136 -0
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -0
- package/dist/esm/tests/store/blockstore-mock.spec.js +29 -28
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +23 -25
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +544 -194
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +4 -4
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +147 -73
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/store-dependent-tests.spec.js +1 -0
- package/dist/esm/tests/store-dependent-tests.spec.js.map +1 -1
- package/dist/esm/tests/test-stores.js +5 -5
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +9 -8
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +8 -11
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +167 -13
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +233 -0
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -0
- package/dist/esm/tests/utils/encryption.spec.js +34 -85
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +67 -69
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/hd-key.spec.js +3 -3
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
- package/dist/esm/tests/utils/jws.spec.js +54 -3
- package/dist/esm/tests/utils/jws.spec.js.map +1 -1
- package/dist/esm/tests/utils/memory-cache.spec.js +6 -9
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +63 -29
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/object.spec.js +3 -3
- package/dist/esm/tests/utils/object.spec.js.map +1 -1
- package/dist/esm/tests/utils/poller.js +1 -1
- package/dist/esm/tests/utils/poller.js.map +1 -1
- package/dist/esm/tests/utils/private-key-signer.spec.js +6 -6
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +37 -5
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +7 -7
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +7 -7
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +47 -28
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/utils/time.spec.js +7 -7
- package/dist/esm/tests/utils/time.spec.js.map +1 -1
- package/dist/esm/tests/utils/url.spec.js +25 -27
- package/dist/esm/tests/utils/url.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +4 -4
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +15 -3
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -8
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +8 -18
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +3 -3
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +9 -9
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +106 -0
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +18 -18
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/esm/tests/vectors/protocol-definitions/email.json +1 -1
- package/dist/esm/tests/vectors/protocol-definitions/friend-role.json +2 -4
- package/dist/esm/tests/vectors/protocol-definitions/slack.json +2 -6
- package/dist/esm/tests/vectors/protocol-definitions/thread-role.json +2 -6
- package/dist/types/generated/precompiled-validators.d.ts +82 -64
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +27 -3
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/message-reply.d.ts +1 -1
- package/dist/types/src/core/message.d.ts +3 -3
- package/dist/types/src/core/message.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +4 -4
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts +43 -2
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/records-grant-authorization.d.ts +2 -2
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/resumable-task-manager.d.ts +1 -0
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +8 -8
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/enums/dwn-interface-method.d.ts +5 -3
- package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-sync.d.ts +21 -0
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -0
- package/dist/types/src/handlers/protocols-configure.d.ts +24 -4
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +43 -0
- package/dist/types/src/handlers/records-count.d.ts.map +1 -0
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +5 -5
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +72 -37
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-read.d.ts +2 -2
- package/dist/types/src/interfaces/messages-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +2 -2
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-sync.d.ts +16 -0
- package/dist/types/src/interfaces/messages-sync.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts +22 -2
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-query.d.ts +2 -2
- package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-count.d.ts +27 -0
- package/dist/types/src/interfaces/records-count.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-delete.d.ts +2 -2
- package/dist/types/src/interfaces/records-delete.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-query.d.ts +2 -2
- package/dist/types/src/interfaces/records-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-read.d.ts +4 -2
- package/dist/types/src/interfaces/records-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +2 -2
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +37 -15
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/jose/algorithms/signing/ed25519.d.ts.map +1 -1
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts +5 -1
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts.map +1 -1
- package/dist/types/src/jose/jws/general/builder.d.ts +3 -3
- package/dist/types/src/jose/jws/general/builder.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts +11 -0
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-request.d.ts +11 -0
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +4 -4
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/schema-validator.d.ts +1 -1
- package/dist/types/src/schema-validator.d.ts.map +1 -1
- package/dist/types/src/smt/smt-store-level.d.ts +32 -0
- package/dist/types/src/smt/smt-store-level.d.ts.map +1 -0
- package/dist/types/src/smt/smt-store-memory.d.ts +22 -0
- package/dist/types/src/smt/smt-store-memory.d.ts.map +1 -0
- package/dist/types/src/smt/smt-utils.d.ts +58 -0
- package/dist/types/src/smt/smt-utils.d.ts.map +1 -0
- package/dist/types/src/smt/sparse-merkle-tree.d.ts +124 -0
- package/dist/types/src/smt/sparse-merkle-tree.d.ts.map +1 -0
- package/dist/types/src/state-index/state-index-level.d.ts +83 -0
- package/dist/types/src/state-index/state-index-level.d.ts.map +1 -0
- package/dist/types/src/store/data-store-level.d.ts +1 -2
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/index-level.d.ts +98 -2
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/level-wrapper.d.ts.map +1 -1
- package/dist/types/src/store/message-store-level.d.ts +5 -0
- package/dist/types/src/store/message-store-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +7 -7
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/data-store.d.ts +2 -3
- package/dist/types/src/types/data-store.d.ts.map +1 -1
- package/dist/types/src/types/encryption-types.d.ts +48 -0
- package/dist/types/src/types/encryption-types.d.ts.map +1 -0
- package/dist/types/src/types/jose-types.d.ts +9 -40
- package/dist/types/src/types/jose-types.d.ts.map +1 -1
- package/dist/types/src/types/message-store.d.ts +5 -0
- package/dist/types/src/types/message-store.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +19 -0
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +16 -11
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +1 -2
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +2 -2
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +49 -5
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +23 -7
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/signer.d.ts +1 -1
- package/dist/types/src/types/signer.d.ts.map +1 -1
- package/dist/types/src/types/smt-types.d.ts +81 -0
- package/dist/types/src/types/smt-types.d.ts.map +1 -0
- package/dist/types/src/types/state-index.d.ts +90 -0
- package/dist/types/src/types/state-index.d.ts.map +1 -0
- package/dist/types/src/utils/cid.d.ts +1 -2
- package/dist/types/src/utils/cid.d.ts.map +1 -1
- package/dist/types/src/utils/data-stream.d.ts +14 -7
- package/dist/types/src/utils/data-stream.d.ts.map +1 -1
- package/dist/types/src/utils/encryption.d.ts +2 -3
- package/dist/types/src/utils/encryption.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +4 -4
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/jws.d.ts +7 -7
- package/dist/types/src/utils/jws.d.ts.map +1 -1
- package/dist/types/src/utils/private-key-signer.d.ts +4 -4
- package/dist/types/src/utils/private-key-signer.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +46 -3
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +33 -6
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/src/utils/secp256k1.d.ts +11 -11
- package/dist/types/src/utils/secp256k1.d.ts.map +1 -1
- package/dist/types/src/utils/secp256r1.d.ts +8 -8
- package/dist/types/src/utils/secp256r1.d.ts.map +1 -1
- package/dist/types/src/utils/time.d.ts +1 -1
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts +5 -0
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/protocols-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/protocols/permission-grant.spec.d.ts +2 -0
- package/dist/types/tests/protocols/permission-grant.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -1
- package/dist/types/tests/smt/smt-store-level.spec.d.ts +2 -0
- package/dist/types/tests/smt/smt-store-level.spec.d.ts.map +1 -0
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts +2 -0
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts.map +1 -0
- package/dist/types/tests/state-index/state-index-level.spec.d.ts +2 -0
- package/dist/types/tests/state-index/state-index-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/blockstore-level.spec.d.ts +2 -0
- package/dist/types/tests/store/blockstore-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/message-store.spec.d.ts.map +1 -1
- package/dist/types/tests/test-stores.d.ts +4 -4
- package/dist/types/tests/test-stores.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +2 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/encryption-callbacks.spec.d.ts +2 -0
- package/dist/types/tests/utils/encryption-callbacks.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/test-data-generator.d.ts +31 -28
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/dist/types/tests/validation/json-schemas/records/records-read.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/records/records-read.spec.d.ts.map +1 -0
- package/package.json +26 -45
- package/src/core/dwn-error.ts +27 -3
- package/src/core/message-reply.ts +1 -1
- package/src/core/message.ts +5 -5
- package/src/core/messages-grant-authorization.ts +22 -8
- package/src/core/protocol-authorization.ts +345 -68
- package/src/core/records-grant-authorization.ts +2 -2
- package/src/core/resumable-task-manager.ts +4 -5
- package/src/dwn.ts +25 -20
- package/src/enums/dwn-interface-method.ts +5 -3
- package/src/handlers/messages-subscribe.ts +1 -1
- package/src/handlers/messages-sync.ts +129 -0
- package/src/handlers/protocols-configure.ts +195 -17
- package/src/handlers/protocols-query.ts +7 -5
- package/src/handlers/records-count.ts +184 -0
- package/src/handlers/records-query.ts +4 -0
- package/src/handlers/records-read.ts +4 -8
- package/src/handlers/records-write.ts +20 -21
- package/src/index.ts +74 -37
- package/src/interfaces/messages-read.ts +6 -5
- package/src/interfaces/messages-subscribe.ts +7 -6
- package/src/interfaces/messages-sync.ts +59 -0
- package/src/interfaces/protocols-configure.ts +211 -33
- package/src/interfaces/protocols-query.ts +7 -6
- package/src/interfaces/records-count.ts +106 -0
- package/src/interfaces/records-delete.ts +2 -2
- package/src/interfaces/records-query.ts +2 -2
- package/src/interfaces/records-read.ts +26 -3
- package/src/interfaces/records-subscribe.ts +2 -2
- package/src/interfaces/records-write.ts +115 -46
- package/src/jose/algorithms/signing/ed25519.ts +13 -12
- package/src/jose/algorithms/signing/signature-algorithms.ts +6 -1
- package/src/jose/jws/general/builder.ts +3 -3
- package/src/jose/jws/general/verifier.ts +3 -3
- package/src/protocols/permission-grant.ts +51 -0
- package/src/protocols/permission-request.ts +37 -0
- package/src/protocols/permissions.ts +5 -5
- package/src/schema-validator.ts +11 -3
- package/src/smt/smt-store-level.ts +143 -0
- package/src/smt/smt-store-memory.ts +53 -0
- package/src/smt/smt-utils.ts +149 -0
- package/src/smt/sparse-merkle-tree.ts +698 -0
- package/src/state-index/state-index-level.ts +241 -0
- package/src/store/data-store-level.ts +8 -7
- package/src/store/index-level.ts +415 -19
- package/src/store/level-wrapper.ts +1 -1
- package/src/store/message-store-level.ts +62 -0
- package/src/store/storage-controller.ts +21 -19
- package/src/types/data-store.ts +2 -4
- package/src/types/encryption-types.ts +52 -0
- package/src/types/jose-types.ts +10 -42
- package/src/types/message-store.ts +11 -0
- package/src/types/message-types.ts +21 -0
- package/src/types/messages-types.ts +21 -15
- package/src/types/method-handler.ts +1 -2
- package/src/types/permission-types.ts +2 -2
- package/src/types/protocols-types.ts +55 -6
- package/src/types/records-types.ts +26 -7
- package/src/types/signer.ts +1 -1
- package/src/types/smt-types.ts +95 -0
- package/src/types/state-index.ts +100 -0
- package/src/utils/cid.ts +3 -4
- package/src/utils/data-stream.ts +75 -38
- package/src/utils/encryption.ts +24 -39
- package/src/utils/hd-key.ts +6 -6
- package/src/utils/jws.ts +9 -9
- package/src/utils/private-key-signer.ts +9 -8
- package/src/utils/protocols.ts +132 -6
- package/src/utils/records.ts +118 -29
- package/src/utils/secp256k1.ts +23 -21
- package/src/utils/secp256r1.ts +17 -15
- package/src/utils/time.ts +1 -1
- package/src/utils/url.ts +1 -1
- package/dist/cjs/index.js +0 -36749
- package/dist/cjs/package.json +0 -1
- package/dist/esm/src/event-log/event-emitter-stream.js.map +0 -1
- package/dist/esm/src/event-log/event-log-level.js +0 -63
- package/dist/esm/src/event-log/event-log-level.js.map +0 -1
- package/dist/esm/src/handlers/messages-query.js +0 -71
- package/dist/esm/src/handlers/messages-query.js.map +0 -1
- package/dist/esm/src/interfaces/messages-query.js.map +0 -1
- package/dist/esm/src/types/event-log.js +0 -2
- package/dist/esm/src/types/event-log.js.map +0 -1
- package/dist/esm/tests/event-log/event-emitter-stream.spec.js.map +0 -1
- package/dist/esm/tests/event-log/event-log-level.spec.js +0 -44
- package/dist/esm/tests/event-log/event-log-level.spec.js.map +0 -1
- package/dist/esm/tests/event-log/event-log.spec.js +0 -236
- package/dist/esm/tests/event-log/event-log.spec.js.map +0 -1
- package/dist/esm/tests/event-log/event-stream.spec.js.map +0 -1
- package/dist/esm/tests/handlers/messages-query.spec.js +0 -349
- package/dist/esm/tests/handlers/messages-query.spec.js.map +0 -1
- package/dist/esm/tests/interfaces/messagess-query.spec.js +0 -127
- package/dist/esm/tests/interfaces/messagess-query.spec.js.map +0 -1
- package/dist/esm/tests/scenarios/messages-query.spec.js +0 -395
- package/dist/esm/tests/scenarios/messages-query.spec.js.map +0 -1
- package/dist/types/src/event-log/event-emitter-stream.d.ts.map +0 -1
- package/dist/types/src/event-log/event-log-level.d.ts +0 -35
- package/dist/types/src/event-log/event-log-level.d.ts.map +0 -1
- package/dist/types/src/handlers/messages-query.d.ts +0 -17
- package/dist/types/src/handlers/messages-query.d.ts.map +0 -1
- package/dist/types/src/interfaces/messages-query.d.ts +0 -16
- package/dist/types/src/interfaces/messages-query.d.ts.map +0 -1
- package/dist/types/src/types/event-log.d.ts +0 -52
- package/dist/types/src/types/event-log.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-log-level.spec.d.ts +0 -2
- package/dist/types/tests/event-log/event-log-level.spec.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-log.spec.d.ts +0 -2
- package/dist/types/tests/event-log/event-log.spec.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/handlers/messages-query.spec.d.ts +0 -2
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +0 -1
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts +0 -2
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts.map +0 -1
- package/dist/types/tests/scenarios/messages-query.spec.d.ts +0 -2
- package/dist/types/tests/scenarios/messages-query.spec.d.ts.map +0 -1
- package/src/event-log/event-log-level.ts +0 -72
- package/src/handlers/messages-query.ts +0 -67
- package/src/interfaces/messages-query.ts +0 -60
- package/src/types/event-log.ts +0 -52
- /package/dist/esm/src/{event-log → event-stream}/event-emitter-stream.js +0 -0
- /package/dist/types/src/{event-log → event-stream}/event-emitter-stream.d.ts +0 -0
- /package/dist/types/tests/{event-log → event-stream}/event-emitter-stream.spec.d.ts +0 -0
- /package/dist/types/tests/{event-log → event-stream}/event-stream.spec.d.ts +0 -0
- /package/src/{event-log → event-stream}/event-emitter-stream.ts +0 -0
|
@@ -7,22 +7,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import anyoneCollaborateProtocolDefinition from '../vectors/protocol-definitions/anyone-collaborate.json'
|
|
11
|
-
import authorCanProtocolDefinition from '../vectors/protocol-definitions/author-can.json'
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import recipientCanProtocol from '../vectors/protocol-definitions/recipient-can.json' assert { type: 'json' };
|
|
10
|
+
import anyoneCollaborateProtocolDefinition from '../vectors/protocol-definitions/anyone-collaborate.json' with { type: 'json' };
|
|
11
|
+
import authorCanProtocolDefinition from '../vectors/protocol-definitions/author-can.json' with { type: 'json' };
|
|
12
|
+
import credentialIssuanceProtocolDefinition from '../vectors/protocol-definitions/credential-issuance.json' with { type: 'json' };
|
|
13
|
+
import dexProtocolDefinition from '../vectors/protocol-definitions/dex.json' with { type: 'json' };
|
|
14
|
+
import emailProtocolDefinition from '../vectors/protocol-definitions/email.json' with { type: 'json' };
|
|
15
|
+
import friendRoleProtocolDefinition from '../vectors/protocol-definitions/friend-role.json' with { type: 'json' };
|
|
16
|
+
import messageProtocolDefinition from '../vectors/protocol-definitions/message.json' with { type: 'json' };
|
|
17
|
+
import minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' with { type: 'json' };
|
|
18
|
+
import nestedProtocol from '../vectors/protocol-definitions/nested.json' with { type: 'json' };
|
|
19
|
+
import privateProtocol from '../vectors/protocol-definitions/private-protocol.json' with { type: 'json' };
|
|
20
|
+
import recipientCanProtocol from '../vectors/protocol-definitions/recipient-can.json' with { type: 'json' };
|
|
22
21
|
import sinon from 'sinon';
|
|
23
|
-
import socialMediaProtocolDefinition from '../vectors/protocol-definitions/social-media.json'
|
|
24
|
-
import threadRoleProtocolDefinition from '../vectors/protocol-definitions/thread-role.json'
|
|
25
|
-
import chai, { expect } from 'chai';
|
|
22
|
+
import socialMediaProtocolDefinition from '../vectors/protocol-definitions/social-media.json' with { type: 'json' };
|
|
23
|
+
import threadRoleProtocolDefinition from '../vectors/protocol-definitions/thread-role.json' with { type: 'json' };
|
|
26
24
|
import { ArrayUtility } from '../../src/utils/array.js';
|
|
27
25
|
import { base64url } from 'multiformats/bases/base64';
|
|
28
26
|
import { Cid } from '../../src/utils/cid.js';
|
|
@@ -41,18 +39,18 @@ import { TestEventStream } from '../test-event-stream.js';
|
|
|
41
39
|
import { TestStores } from '../test-stores.js';
|
|
42
40
|
import { TestStubGenerator } from '../utils/test-stub-generator.js';
|
|
43
41
|
import { Time } from '../../src/utils/time.js';
|
|
44
|
-
import {
|
|
42
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
45
43
|
import { DataStoreLevel, DwnConstant, DwnInterfaceName, DwnMethodName, KeyDerivationScheme, MessageStoreLevel, PermissionsProtocol, RecordsDelete, RecordsQuery } from '../../src/index.js';
|
|
46
44
|
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
45
|
+
import { DwnError, DwnErrorCode } from '../../src/core/dwn-error.js';
|
|
47
46
|
import { Encryption, EncryptionAlgorithm } from '../../src/utils/encryption.js';
|
|
48
|
-
chai.use(chaiAsPromised);
|
|
49
47
|
export function testRecordsWriteHandler() {
|
|
50
|
-
describe('RecordsWriteHandler.handle()', () =>
|
|
48
|
+
describe('RecordsWriteHandler.handle()', () => {
|
|
51
49
|
let didResolver;
|
|
52
50
|
let messageStore;
|
|
53
51
|
let dataStore;
|
|
54
52
|
let resumableTaskStore;
|
|
55
|
-
let
|
|
53
|
+
let stateIndex;
|
|
56
54
|
let eventStream;
|
|
57
55
|
let dwn;
|
|
58
56
|
beforeEach(() => {
|
|
@@ -61,24 +59,24 @@ export function testRecordsWriteHandler() {
|
|
|
61
59
|
describe('functional tests', () => {
|
|
62
60
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
63
61
|
// so that different test suites can reuse the same backend store for testing
|
|
64
|
-
|
|
62
|
+
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
65
63
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
66
64
|
const stores = TestStores.get();
|
|
67
65
|
messageStore = stores.messageStore;
|
|
68
66
|
dataStore = stores.dataStore;
|
|
69
67
|
resumableTaskStore = stores.resumableTaskStore;
|
|
70
|
-
|
|
68
|
+
stateIndex = stores.stateIndex;
|
|
71
69
|
eventStream = TestEventStream.get();
|
|
72
|
-
dwn = yield Dwn.create({ didResolver, messageStore, dataStore,
|
|
70
|
+
dwn = yield Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
73
71
|
}));
|
|
74
72
|
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
75
73
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
76
74
|
yield messageStore.clear();
|
|
77
75
|
yield dataStore.clear();
|
|
78
76
|
yield resumableTaskStore.clear();
|
|
79
|
-
yield
|
|
77
|
+
yield stateIndex.clear();
|
|
80
78
|
}));
|
|
81
|
-
|
|
79
|
+
afterAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
82
80
|
yield dwn.close();
|
|
83
81
|
}));
|
|
84
82
|
it('should call preProcessingForCoreRecordsWrite after authorization and before storage', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -91,12 +89,12 @@ export function testRecordsWriteHandler() {
|
|
|
91
89
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
92
90
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
93
91
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
94
|
-
expect(reply.status.code).
|
|
92
|
+
expect(reply.status.code).toBe(400);
|
|
95
93
|
// expect that authorization and preProcessingForCoreRecordsWrite are both called once
|
|
96
|
-
expect(authorizationSpy.calledOnce).
|
|
97
|
-
expect(preProcessingForCoreRecordsWriteSpy.calledOnce).
|
|
94
|
+
expect(authorizationSpy.calledOnce).toBe(true);
|
|
95
|
+
expect(preProcessingForCoreRecordsWriteSpy.calledOnce).toBe(true);
|
|
98
96
|
// expect that processMessageWithDataStream is NOT called since preProcessingForCoreRecordsWrite failed before reaching it
|
|
99
|
-
expect(processDataStreamSpy.called).
|
|
97
|
+
expect(processDataStreamSpy.called).toBe(false);
|
|
100
98
|
}));
|
|
101
99
|
it('should only be able to overwrite existing record if new record has a later `messageTimestamp` value', () => __awaiter(this, void 0, void 0, function* () {
|
|
102
100
|
var _a, _b, _c;
|
|
@@ -106,7 +104,7 @@ export function testRecordsWriteHandler() {
|
|
|
106
104
|
const recordsWriteMessageData = yield TestDataGenerator.generateRecordsWrite({ author, data: data1 });
|
|
107
105
|
const tenant = author.did;
|
|
108
106
|
const recordsWriteReply = yield dwn.processMessage(tenant, recordsWriteMessageData.message, { dataStream: recordsWriteMessageData.dataStream });
|
|
109
|
-
expect(recordsWriteReply.status.code).
|
|
107
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
110
108
|
const recordId = recordsWriteMessageData.message.recordId;
|
|
111
109
|
const recordsQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
112
110
|
author,
|
|
@@ -114,9 +112,9 @@ export function testRecordsWriteHandler() {
|
|
|
114
112
|
});
|
|
115
113
|
// verify the message written can be queried
|
|
116
114
|
const recordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
117
|
-
expect(recordsQueryReply.status.code).
|
|
118
|
-
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
119
|
-
expect(recordsQueryReply.entries[0].encodedData).
|
|
115
|
+
expect(recordsQueryReply.status.code).toBe(200);
|
|
116
|
+
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
117
|
+
expect(recordsQueryReply.entries[0].encodedData).toBe(base64url.baseEncode(data1));
|
|
120
118
|
// generate and write a new RecordsWrite to overwrite the existing record
|
|
121
119
|
// a new RecordsWrite by default will have a later `messageTimestamp`
|
|
122
120
|
const newDataBytes = Encoder.stringToBytes('new data');
|
|
@@ -127,22 +125,22 @@ export function testRecordsWriteHandler() {
|
|
|
127
125
|
data: newDataBytes
|
|
128
126
|
});
|
|
129
127
|
// sanity check that old data and new data are different
|
|
130
|
-
expect(newDataEncoded).
|
|
128
|
+
expect(newDataEncoded).not.toBe(Encoder.bytesToBase64Url(recordsWriteMessageData.dataBytes));
|
|
131
129
|
const newRecordsWriteReply = yield dwn.processMessage(tenant, newRecordsWrite.message, { dataStream: newRecordsWrite.dataStream });
|
|
132
|
-
expect(newRecordsWriteReply.status.code).
|
|
130
|
+
expect(newRecordsWriteReply.status.code).toBe(202);
|
|
133
131
|
// verify new record has overwritten the existing record
|
|
134
132
|
const newRecordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
135
|
-
expect(newRecordsQueryReply.status.code).
|
|
136
|
-
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
137
|
-
expect(newRecordsQueryReply.entries[0].encodedData).
|
|
133
|
+
expect(newRecordsQueryReply.status.code).toBe(200);
|
|
134
|
+
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
|
|
135
|
+
expect(newRecordsQueryReply.entries[0].encodedData).toBe(newDataEncoded);
|
|
138
136
|
// try to write the older message to store again and verify that it is not accepted
|
|
139
137
|
const thirdRecordsWriteReply = yield dwn.processMessage(tenant, recordsWriteMessageData.message, { dataStream: recordsWriteMessageData.dataStream });
|
|
140
|
-
expect(thirdRecordsWriteReply.status.code).
|
|
138
|
+
expect(thirdRecordsWriteReply.status.code).toBe(409); // expecting to fail
|
|
141
139
|
// expecting unchanged
|
|
142
140
|
const thirdRecordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
143
|
-
expect(thirdRecordsQueryReply.status.code).
|
|
144
|
-
expect((_c = thirdRecordsQueryReply.entries) === null || _c === void 0 ? void 0 : _c.length).
|
|
145
|
-
expect(thirdRecordsQueryReply.entries[0].encodedData).
|
|
141
|
+
expect(thirdRecordsQueryReply.status.code).toBe(200);
|
|
142
|
+
expect((_c = thirdRecordsQueryReply.entries) === null || _c === void 0 ? void 0 : _c.length).toBe(1);
|
|
143
|
+
expect(thirdRecordsQueryReply.entries[0].encodedData).toBe(newDataEncoded);
|
|
146
144
|
}));
|
|
147
145
|
it('should only be able to overwrite existing record if new message CID is larger when `messageTimestamp` value is the same', () => __awaiter(this, void 0, void 0, function* () {
|
|
148
146
|
var _a, _b, _c;
|
|
@@ -156,7 +154,7 @@ export function testRecordsWriteHandler() {
|
|
|
156
154
|
// setting up a stub DID resolver
|
|
157
155
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
158
156
|
const originatingMessageWriteReply = yield dwn.processMessage(tenant, originatingMessageData.message, { dataStream: originatingMessageData.dataStream });
|
|
159
|
-
expect(originatingMessageWriteReply.status.code).
|
|
157
|
+
expect(originatingMessageWriteReply.status.code).toBe(202);
|
|
160
158
|
// generate two new RecordsWrite messages with the same `messageTimestamp` value
|
|
161
159
|
const dateModified = Time.getCurrentTimestamp();
|
|
162
160
|
const recordsWrite1 = yield TestDataGenerator.generateFromRecordsWrite({
|
|
@@ -184,7 +182,7 @@ export function testRecordsWriteHandler() {
|
|
|
184
182
|
}
|
|
185
183
|
// write the message with the smaller lexicographical message CID first
|
|
186
184
|
const recordsWriteReply = yield dwn.processMessage(tenant, olderWrite.message, { dataStream: olderWrite.dataStream });
|
|
187
|
-
expect(recordsWriteReply.status.code).
|
|
185
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
188
186
|
// query to fetch the record
|
|
189
187
|
const recordsQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
190
188
|
author,
|
|
@@ -192,29 +190,29 @@ export function testRecordsWriteHandler() {
|
|
|
192
190
|
});
|
|
193
191
|
// verify the data is written
|
|
194
192
|
const recordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
195
|
-
expect(recordsQueryReply.status.code).
|
|
196
|
-
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
193
|
+
expect(recordsQueryReply.status.code).toBe(200);
|
|
194
|
+
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
197
195
|
expect(recordsQueryReply.entries[0].descriptor.dataCid)
|
|
198
|
-
.
|
|
196
|
+
.toBe(olderWrite.message.descriptor.dataCid);
|
|
199
197
|
// attempt to write the message with larger lexicographical message CID
|
|
200
198
|
const newRecordsWriteReply = yield dwn.processMessage(tenant, newerWrite.message, { dataStream: newerWrite.dataStream });
|
|
201
|
-
expect(newRecordsWriteReply.status.code).
|
|
199
|
+
expect(newRecordsWriteReply.status.code).toBe(202);
|
|
202
200
|
// verify new record has overwritten the existing record
|
|
203
201
|
const newRecordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
204
|
-
expect(newRecordsQueryReply.status.code).
|
|
205
|
-
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
202
|
+
expect(newRecordsQueryReply.status.code).toBe(200);
|
|
203
|
+
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
|
|
206
204
|
expect(newRecordsQueryReply.entries[0].descriptor.dataCid)
|
|
207
|
-
.
|
|
205
|
+
.toBe(newerWrite.message.descriptor.dataCid);
|
|
208
206
|
// try to write the message with smaller lexicographical message CID again
|
|
209
207
|
const thirdRecordsWriteReply = yield dwn.processMessage(tenant, olderWrite.message, { dataStream: DataStream.fromBytes(olderWrite.dataBytes) } // need to create data stream again since it's already used above
|
|
210
208
|
);
|
|
211
|
-
expect(thirdRecordsWriteReply.status.code).
|
|
209
|
+
expect(thirdRecordsWriteReply.status.code).toBe(409); // expecting to fail
|
|
212
210
|
// verify the message in store is still the one with larger lexicographical message CID
|
|
213
211
|
const thirdRecordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
214
|
-
expect(thirdRecordsQueryReply.status.code).
|
|
215
|
-
expect((_c = thirdRecordsQueryReply.entries) === null || _c === void 0 ? void 0 : _c.length).
|
|
212
|
+
expect(thirdRecordsQueryReply.status.code).toBe(200);
|
|
213
|
+
expect((_c = thirdRecordsQueryReply.entries) === null || _c === void 0 ? void 0 : _c.length).toBe(1);
|
|
216
214
|
expect(thirdRecordsQueryReply.entries[0].descriptor.dataCid)
|
|
217
|
-
.
|
|
215
|
+
.toBe(newerWrite.message.descriptor.dataCid); // expecting unchanged
|
|
218
216
|
}));
|
|
219
217
|
it('#690 - should allow data format of a flat-space record to be updated to any value', () => __awaiter(this, void 0, void 0, function* () {
|
|
220
218
|
var _a;
|
|
@@ -222,7 +220,7 @@ export function testRecordsWriteHandler() {
|
|
|
222
220
|
const tenant = initialWriteData.author.did;
|
|
223
221
|
TestStubGenerator.stubDidResolver(didResolver, [initialWriteData.author]);
|
|
224
222
|
const initialWriteReply = yield dwn.processMessage(tenant, initialWriteData.message, { dataStream: initialWriteData.dataStream });
|
|
225
|
-
expect(initialWriteReply.status.code).
|
|
223
|
+
expect(initialWriteReply.status.code).toBe(202);
|
|
226
224
|
const newDataFormat = 'any-new-data-format';
|
|
227
225
|
const newDataBytes = TestDataGenerator.randomBytes(100);
|
|
228
226
|
const updateWrite = yield RecordsWrite.createFrom({
|
|
@@ -233,22 +231,22 @@ export function testRecordsWriteHandler() {
|
|
|
233
231
|
});
|
|
234
232
|
const newDataStream = DataStream.fromBytes(newDataBytes);
|
|
235
233
|
const updateReply = yield dwn.processMessage(tenant, updateWrite.message, { dataStream: newDataStream });
|
|
236
|
-
expect(updateReply.status.code).
|
|
234
|
+
expect(updateReply.status.code).toBe(202);
|
|
237
235
|
// verify the data format of the record is updated
|
|
238
236
|
const recordsRead = yield RecordsRead.create({
|
|
239
237
|
filter: { recordId: initialWriteData.message.recordId },
|
|
240
238
|
signer: Jws.createSigner(initialWriteData.author),
|
|
241
239
|
});
|
|
242
240
|
const recordsReadReply = yield dwn.processMessage(tenant, recordsRead.message);
|
|
243
|
-
expect(recordsReadReply.status.code).
|
|
244
|
-
expect((_a = recordsReadReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor.dataFormat).
|
|
241
|
+
expect(recordsReadReply.status.code).toBe(200);
|
|
242
|
+
expect((_a = recordsReadReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor.dataFormat).toBe(newDataFormat);
|
|
245
243
|
}));
|
|
246
244
|
it('should not allow changes to immutable properties', () => __awaiter(this, void 0, void 0, function* () {
|
|
247
245
|
const initialWriteData = yield TestDataGenerator.generateRecordsWrite();
|
|
248
246
|
const tenant = initialWriteData.author.did;
|
|
249
247
|
TestStubGenerator.stubDidResolver(didResolver, [initialWriteData.author]);
|
|
250
248
|
const initialWriteReply = yield dwn.processMessage(tenant, initialWriteData.message, { dataStream: initialWriteData.dataStream });
|
|
251
|
-
expect(initialWriteReply.status.code).
|
|
249
|
+
expect(initialWriteReply.status.code).toBe(202);
|
|
252
250
|
const recordId = initialWriteData.message.recordId;
|
|
253
251
|
const dateCreated = initialWriteData.message.descriptor.dateCreated;
|
|
254
252
|
const schema = initialWriteData.message.descriptor.schema;
|
|
@@ -261,8 +259,8 @@ export function testRecordsWriteHandler() {
|
|
|
261
259
|
dataFormat: initialWriteData.message.descriptor.dataFormat
|
|
262
260
|
});
|
|
263
261
|
let reply = yield dwn.processMessage(tenant, childMessageData.message, { dataStream: childMessageData.dataStream });
|
|
264
|
-
expect(reply.status.code).
|
|
265
|
-
expect(reply.status.detail).
|
|
262
|
+
expect(reply.status.code).toBe(400);
|
|
263
|
+
expect(reply.status.detail).toContain('dateCreated is an immutable property');
|
|
266
264
|
// schema test
|
|
267
265
|
childMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
268
266
|
author: initialWriteData.author,
|
|
@@ -272,8 +270,8 @@ export function testRecordsWriteHandler() {
|
|
|
272
270
|
dataFormat: initialWriteData.message.descriptor.dataFormat
|
|
273
271
|
});
|
|
274
272
|
reply = yield dwn.processMessage(tenant, childMessageData.message, { dataStream: childMessageData.dataStream });
|
|
275
|
-
expect(reply.status.code).
|
|
276
|
-
expect(reply.status.detail).
|
|
273
|
+
expect(reply.status.code).toBe(400);
|
|
274
|
+
expect(reply.status.detail).toContain('schema is an immutable property');
|
|
277
275
|
}));
|
|
278
276
|
it('should inherit data from previous RecordsWrite given a matching dataCid and dataSize and no dataStream', () => __awaiter(this, void 0, void 0, function* () {
|
|
279
277
|
const { message, author, dataStream, dataBytes } = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -282,24 +280,24 @@ export function testRecordsWriteHandler() {
|
|
|
282
280
|
const tenant = author.did;
|
|
283
281
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
284
282
|
const initialWriteReply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
285
|
-
expect(initialWriteReply.status.code).
|
|
283
|
+
expect(initialWriteReply.status.code).toBe(202);
|
|
286
284
|
const write2 = yield RecordsWrite.createFrom({
|
|
287
285
|
recordsWriteMessage: message,
|
|
288
286
|
published: true,
|
|
289
287
|
signer: Jws.createSigner(author),
|
|
290
288
|
});
|
|
291
289
|
const writeUpdateReply = yield dwn.processMessage(tenant, write2.message);
|
|
292
|
-
expect(writeUpdateReply.status.code).
|
|
290
|
+
expect(writeUpdateReply.status.code).toBe(202);
|
|
293
291
|
const readMessage = yield RecordsRead.create({
|
|
294
292
|
filter: {
|
|
295
293
|
recordId: message.recordId,
|
|
296
294
|
}
|
|
297
295
|
});
|
|
298
296
|
const readMessageReply = yield dwn.processMessage(tenant, readMessage.message);
|
|
299
|
-
expect(readMessageReply.status.code).
|
|
300
|
-
expect(readMessageReply.entry.recordsWrite).
|
|
297
|
+
expect(readMessageReply.status.code).toBe(200);
|
|
298
|
+
expect(readMessageReply.entry.recordsWrite).toBeDefined();
|
|
301
299
|
const data = yield DataStream.toBytes(readMessageReply.entry.data);
|
|
302
|
-
expect(data).
|
|
300
|
+
expect(data).toEqual(dataBytes);
|
|
303
301
|
}));
|
|
304
302
|
it('should allow an initial `RecordsWrite` to be written without supplying data', () => __awaiter(this, void 0, void 0, function* () {
|
|
305
303
|
//scenario: you have an initial write without the data and a subsequent write with data to be able to write.
|
|
@@ -309,15 +307,15 @@ export function testRecordsWriteHandler() {
|
|
|
309
307
|
const { recordsWrite } = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
310
308
|
// simulate synchronize of pruned initial `RecordsWrite`
|
|
311
309
|
const reply = yield dwn.processMessage(alice.did, recordsWrite.message);
|
|
312
|
-
expect(reply.status.code).
|
|
310
|
+
expect(reply.status.code).toBe(204);
|
|
313
311
|
// verify `RecordsWrite` inserted is not returned with a query
|
|
314
312
|
const recordsQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
315
313
|
author: alice,
|
|
316
314
|
filter: { recordId: recordsWrite.message.recordId }
|
|
317
315
|
});
|
|
318
316
|
const recordsQueryReply = yield dwn.processMessage(alice.did, recordsQueryMessageData.message);
|
|
319
|
-
expect(recordsQueryReply.status.code).
|
|
320
|
-
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
317
|
+
expect(recordsQueryReply.status.code).toBe(200);
|
|
318
|
+
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
|
|
321
319
|
// generate and write a new `RecordsWrite` to overwrite the existing record
|
|
322
320
|
const newDataBytes = Encoder.stringToBytes('new data');
|
|
323
321
|
const newDataEncoded = Encoder.bytesToBase64Url(newDataBytes);
|
|
@@ -327,12 +325,12 @@ export function testRecordsWriteHandler() {
|
|
|
327
325
|
data: newDataBytes
|
|
328
326
|
});
|
|
329
327
|
const newRecordsWriteReply = yield dwn.processMessage(alice.did, newRecordsWrite.message, { dataStream: newRecordsWrite.dataStream });
|
|
330
|
-
expect(newRecordsWriteReply.status.code).
|
|
328
|
+
expect(newRecordsWriteReply.status.code).toBe(202);
|
|
331
329
|
// verify new `RecordsWrite` has overwritten the existing record with new data
|
|
332
330
|
const newRecordsQueryReply = yield dwn.processMessage(alice.did, recordsQueryMessageData.message);
|
|
333
|
-
expect(newRecordsQueryReply.status.code).
|
|
334
|
-
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
335
|
-
expect(newRecordsQueryReply.entries[0].encodedData).
|
|
331
|
+
expect(newRecordsQueryReply.status.code).toBe(200);
|
|
332
|
+
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
|
|
333
|
+
expect(newRecordsQueryReply.entries[0].encodedData).toBe(newDataEncoded);
|
|
336
334
|
}));
|
|
337
335
|
it('should not allow non-initial writes to be written without supplying data', () => __awaiter(this, void 0, void 0, function* () {
|
|
338
336
|
//scenario: you have an initial write without the data and a subsequent write with data to be able to write.
|
|
@@ -342,15 +340,15 @@ export function testRecordsWriteHandler() {
|
|
|
342
340
|
// write a record into the dwn
|
|
343
341
|
const { recordsWrite, dataStream, dataBytes } = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
344
342
|
const reply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
345
|
-
expect(reply.status.code).
|
|
343
|
+
expect(reply.status.code).toBe(202);
|
|
346
344
|
// verify `RecordsWrite` inserted can be queried
|
|
347
345
|
const recordsQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
348
346
|
author: alice,
|
|
349
347
|
filter: { recordId: recordsWrite.message.recordId }
|
|
350
348
|
});
|
|
351
349
|
const recordsQueryReply = yield dwn.processMessage(alice.did, recordsQueryMessageData.message);
|
|
352
|
-
expect(recordsQueryReply.status.code).
|
|
353
|
-
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
350
|
+
expect(recordsQueryReply.status.code).toBe(200);
|
|
351
|
+
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
354
352
|
// generate and write a new `RecordsWrite` to overwrite the existing record
|
|
355
353
|
const newDataBytes = Encoder.stringToBytes('new data');
|
|
356
354
|
const newRecordsWrite = yield TestDataGenerator.generateFromRecordsWrite({
|
|
@@ -360,14 +358,14 @@ export function testRecordsWriteHandler() {
|
|
|
360
358
|
});
|
|
361
359
|
// records write should be rejected.
|
|
362
360
|
const newRecordsWriteReply = yield dwn.processMessage(alice.did, newRecordsWrite.message);
|
|
363
|
-
expect(newRecordsWriteReply.status.code).
|
|
364
|
-
expect(newRecordsWriteReply.status.detail).
|
|
361
|
+
expect(newRecordsWriteReply.status.code).toBe(400);
|
|
362
|
+
expect(newRecordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsWriteDataCidMismatch);
|
|
365
363
|
// verify the original `RecordsWrite` and data are still available
|
|
366
364
|
const newRecordsQueryReply = yield dwn.processMessage(alice.did, recordsQueryMessageData.message);
|
|
367
|
-
expect(newRecordsQueryReply.status.code).
|
|
368
|
-
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
365
|
+
expect(newRecordsQueryReply.status.code).toBe(200);
|
|
366
|
+
expect((_b = newRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
|
|
369
367
|
const originalEncodedData = Encoder.bytesToBase64Url(dataBytes);
|
|
370
|
-
expect(newRecordsQueryReply.entries[0].encodedData).
|
|
368
|
+
expect(newRecordsQueryReply.entries[0].encodedData).toBe(originalEncodedData);
|
|
371
369
|
}));
|
|
372
370
|
describe('should inherit data from previous RecordsWrite given a matching dataCid and dataSize and no dataStream', () => {
|
|
373
371
|
it('with data above the threshold for encodedData', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -378,24 +376,24 @@ export function testRecordsWriteHandler() {
|
|
|
378
376
|
const tenant = author.did;
|
|
379
377
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
380
378
|
const initialWriteReply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
381
|
-
expect(initialWriteReply.status.code).
|
|
379
|
+
expect(initialWriteReply.status.code).toBe(202);
|
|
382
380
|
const write2 = yield RecordsWrite.createFrom({
|
|
383
381
|
recordsWriteMessage: message,
|
|
384
382
|
published: true,
|
|
385
383
|
signer: Jws.createSigner(author),
|
|
386
384
|
});
|
|
387
385
|
const writeUpdateReply = yield dwn.processMessage(tenant, write2.message);
|
|
388
|
-
expect(writeUpdateReply.status.code).
|
|
386
|
+
expect(writeUpdateReply.status.code).toBe(202);
|
|
389
387
|
const readMessage = yield RecordsRead.create({
|
|
390
388
|
filter: {
|
|
391
389
|
recordId: message.recordId,
|
|
392
390
|
}
|
|
393
391
|
});
|
|
394
392
|
const readMessageReply = yield dwn.processMessage(tenant, readMessage.message);
|
|
395
|
-
expect(readMessageReply.status.code).
|
|
396
|
-
expect(readMessageReply.entry.recordsWrite).
|
|
393
|
+
expect(readMessageReply.status.code).toBe(200);
|
|
394
|
+
expect(readMessageReply.entry.recordsWrite).toBeDefined();
|
|
397
395
|
const data = yield DataStream.toBytes(readMessageReply.entry.data);
|
|
398
|
-
expect(data).
|
|
396
|
+
expect(data).toEqual(dataBytes);
|
|
399
397
|
}));
|
|
400
398
|
it('with data equal to or below the threshold for encodedData', () => __awaiter(this, void 0, void 0, function* () {
|
|
401
399
|
const { message, author, dataStream, dataBytes } = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -405,24 +403,24 @@ export function testRecordsWriteHandler() {
|
|
|
405
403
|
const tenant = author.did;
|
|
406
404
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
407
405
|
const initialWriteReply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
408
|
-
expect(initialWriteReply.status.code).
|
|
406
|
+
expect(initialWriteReply.status.code).toBe(202);
|
|
409
407
|
const write2 = yield RecordsWrite.createFrom({
|
|
410
408
|
recordsWriteMessage: message,
|
|
411
409
|
published: true,
|
|
412
410
|
signer: Jws.createSigner(author),
|
|
413
411
|
});
|
|
414
412
|
const writeUpdateReply = yield dwn.processMessage(tenant, write2.message);
|
|
415
|
-
expect(writeUpdateReply.status.code).
|
|
413
|
+
expect(writeUpdateReply.status.code).toBe(202);
|
|
416
414
|
const readMessage = yield RecordsRead.create({
|
|
417
415
|
filter: {
|
|
418
416
|
recordId: message.recordId,
|
|
419
417
|
}
|
|
420
418
|
});
|
|
421
419
|
const readMessageReply = yield dwn.processMessage(tenant, readMessage.message);
|
|
422
|
-
expect(readMessageReply.status.code).
|
|
423
|
-
expect(readMessageReply.entry.recordsWrite).
|
|
420
|
+
expect(readMessageReply.status.code).toBe(200);
|
|
421
|
+
expect(readMessageReply.entry.recordsWrite).toBeDefined();
|
|
424
422
|
const data = yield DataStream.toBytes(readMessageReply.entry.data);
|
|
425
|
-
expect(data).
|
|
423
|
+
expect(data).toEqual(dataBytes);
|
|
426
424
|
}));
|
|
427
425
|
});
|
|
428
426
|
describe('should return 400 if actual data size mismatches with `dataSize` in descriptor', () => {
|
|
@@ -448,8 +446,8 @@ export function testRecordsWriteHandler() {
|
|
|
448
446
|
message.recordId = recordId;
|
|
449
447
|
message.authorization = { signature };
|
|
450
448
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
451
|
-
expect(reply.status.code).
|
|
452
|
-
expect(reply.status.detail).
|
|
449
|
+
expect(reply.status.code).toBe(400);
|
|
450
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataSizeMismatch);
|
|
453
451
|
}));
|
|
454
452
|
it('with only `dataSize` larger than encodedData threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
455
453
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -473,8 +471,8 @@ export function testRecordsWriteHandler() {
|
|
|
473
471
|
message.recordId = recordId;
|
|
474
472
|
message.authorization = { signature };
|
|
475
473
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
476
|
-
expect(reply.status.code).
|
|
477
|
-
expect(reply.status.detail).
|
|
474
|
+
expect(reply.status.code).toBe(400);
|
|
475
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataSizeMismatch);
|
|
478
476
|
}));
|
|
479
477
|
it('with only dataStream larger than encodedData threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
480
478
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -498,8 +496,8 @@ export function testRecordsWriteHandler() {
|
|
|
498
496
|
message.recordId = recordId;
|
|
499
497
|
message.authorization = { signature };
|
|
500
498
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
501
|
-
expect(reply.status.code).
|
|
502
|
-
expect(reply.status.detail).
|
|
499
|
+
expect(reply.status.code).toBe(400);
|
|
500
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataSizeMismatch);
|
|
503
501
|
}));
|
|
504
502
|
it('with both `dataSize` and dataStream below than encodedData threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
505
503
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -522,8 +520,8 @@ export function testRecordsWriteHandler() {
|
|
|
522
520
|
message.recordId = recordId;
|
|
523
521
|
message.authorization = { signature };
|
|
524
522
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
525
|
-
expect(reply.status.code).
|
|
526
|
-
expect(reply.status.detail).
|
|
523
|
+
expect(reply.status.code).toBe(400);
|
|
524
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataSizeMismatch);
|
|
527
525
|
}));
|
|
528
526
|
});
|
|
529
527
|
it('should return 400 for data CID mismatch with both dataStream and `dataSize` larger than encodedData threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -534,8 +532,8 @@ export function testRecordsWriteHandler() {
|
|
|
534
532
|
});
|
|
535
533
|
const dataStream = DataStream.fromBytes(TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded + 1)); // mismatch data stream
|
|
536
534
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
537
|
-
expect(reply.status.code).
|
|
538
|
-
expect(reply.status.detail).
|
|
535
|
+
expect(reply.status.code).toBe(400);
|
|
536
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataCidMismatch);
|
|
539
537
|
}));
|
|
540
538
|
it('should return 400 for data CID mismatch with `dataSize` larger than encodedData threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
541
539
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -545,8 +543,8 @@ export function testRecordsWriteHandler() {
|
|
|
545
543
|
});
|
|
546
544
|
const dataStream = DataStream.fromBytes(TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded)); // mismatch data stream
|
|
547
545
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
548
|
-
expect(reply.status.code).
|
|
549
|
-
expect(reply.status.detail).
|
|
546
|
+
expect(reply.status.code).toBe(400);
|
|
547
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataCidMismatch);
|
|
550
548
|
}));
|
|
551
549
|
it('should return 400 for data CID mismatch with dataStream larger than encodedData threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
552
550
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -556,8 +554,8 @@ export function testRecordsWriteHandler() {
|
|
|
556
554
|
});
|
|
557
555
|
const dataStream = DataStream.fromBytes(TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded + 1)); // mismatch data stream
|
|
558
556
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
559
|
-
expect(reply.status.code).
|
|
560
|
-
expect(reply.status.detail).
|
|
557
|
+
expect(reply.status.code).toBe(400);
|
|
558
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataCidMismatch);
|
|
561
559
|
}));
|
|
562
560
|
it('should return 400 for data CID mismatch with both dataStream and `dataSize` below than encodedData threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
563
561
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -567,8 +565,8 @@ export function testRecordsWriteHandler() {
|
|
|
567
565
|
});
|
|
568
566
|
const dataStream = DataStream.fromBytes(TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded)); // mismatch data stream
|
|
569
567
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
570
|
-
expect(reply.status.code).
|
|
571
|
-
expect(reply.status.detail).
|
|
568
|
+
expect(reply.status.code).toBe(400);
|
|
569
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteDataCidMismatch);
|
|
572
570
|
}));
|
|
573
571
|
it('#359 - should not allow access of data by referencing a different`dataCid` in "modify" `RecordsWrite` with large data', () => __awaiter(this, void 0, void 0, function* () {
|
|
574
572
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -582,11 +580,11 @@ export function testRecordsWriteHandler() {
|
|
|
582
580
|
data,
|
|
583
581
|
});
|
|
584
582
|
const write1Reply = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
585
|
-
expect(write1Reply.status.code).
|
|
583
|
+
expect(write1Reply.status.code).toBe(202);
|
|
586
584
|
// alice writes another record (which will be modified later)
|
|
587
585
|
const write2 = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
588
586
|
const write2Reply = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
589
|
-
expect(write2Reply.status.code).
|
|
587
|
+
expect(write2Reply.status.code).toBe(202);
|
|
590
588
|
// modify write2 by referencing the `dataCid` in write1 (which should not be allowed)
|
|
591
589
|
const write2Change = yield TestDataGenerator.generateRecordsWrite({
|
|
592
590
|
author: alice,
|
|
@@ -601,8 +599,8 @@ export function testRecordsWriteHandler() {
|
|
|
601
599
|
dataSize
|
|
602
600
|
});
|
|
603
601
|
const write2ChangeReply = yield dwn.processMessage(alice.did, write2Change.message);
|
|
604
|
-
expect(write2ChangeReply.status.code).
|
|
605
|
-
expect(write2ChangeReply.status.detail).
|
|
602
|
+
expect(write2ChangeReply.status.code).toBe(400); // should be disallowed
|
|
603
|
+
expect(write2ChangeReply.status.detail).toContain(DwnErrorCode.RecordsWriteDataCidMismatch);
|
|
606
604
|
// further sanity test to make sure the change is not written, ie. write2 still has the original data
|
|
607
605
|
const read = yield RecordsRead.create({
|
|
608
606
|
filter: {
|
|
@@ -611,9 +609,9 @@ export function testRecordsWriteHandler() {
|
|
|
611
609
|
signer: Jws.createSigner(alice)
|
|
612
610
|
});
|
|
613
611
|
const readReply = yield dwn.processMessage(alice.did, read.message);
|
|
614
|
-
expect(readReply.status.code).
|
|
612
|
+
expect(readReply.status.code).toBe(200);
|
|
615
613
|
const readDataBytes = yield DataStream.toBytes(readReply.entry.data);
|
|
616
|
-
expect(ArrayUtility.byteArraysEqual(readDataBytes, write2.dataBytes)).
|
|
614
|
+
expect(ArrayUtility.byteArraysEqual(readDataBytes, write2.dataBytes)).toBe(true);
|
|
617
615
|
}));
|
|
618
616
|
it('#359 - should not allow access of data by referencing a different`dataCid` in "modify" `RecordsWrite`', () => __awaiter(this, void 0, void 0, function* () {
|
|
619
617
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -627,11 +625,11 @@ export function testRecordsWriteHandler() {
|
|
|
627
625
|
data,
|
|
628
626
|
});
|
|
629
627
|
const write1Reply = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
630
|
-
expect(write1Reply.status.code).
|
|
628
|
+
expect(write1Reply.status.code).toBe(202);
|
|
631
629
|
// alice writes another record (which will be modified later)
|
|
632
630
|
const write2 = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
633
631
|
const write2Reply = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
634
|
-
expect(write2Reply.status.code).
|
|
632
|
+
expect(write2Reply.status.code).toBe(202);
|
|
635
633
|
// modify write2 by referencing the `dataCid` in write1 (which should not be allowed)
|
|
636
634
|
const write2Change = yield TestDataGenerator.generateRecordsWrite({
|
|
637
635
|
author: alice,
|
|
@@ -646,8 +644,8 @@ export function testRecordsWriteHandler() {
|
|
|
646
644
|
dataSize
|
|
647
645
|
});
|
|
648
646
|
const write2ChangeReply = yield dwn.processMessage(alice.did, write2Change.message);
|
|
649
|
-
expect(write2ChangeReply.status.code).
|
|
650
|
-
expect(write2ChangeReply.status.detail).
|
|
647
|
+
expect(write2ChangeReply.status.code).toBe(400); // should be disallowed
|
|
648
|
+
expect(write2ChangeReply.status.detail).toContain(DwnErrorCode.RecordsWriteDataCidMismatch);
|
|
651
649
|
// further sanity test to make sure the change is not written, ie. write2 still has the original data
|
|
652
650
|
const read = yield RecordsRead.create({
|
|
653
651
|
filter: {
|
|
@@ -656,9 +654,9 @@ export function testRecordsWriteHandler() {
|
|
|
656
654
|
signer: Jws.createSigner(alice)
|
|
657
655
|
});
|
|
658
656
|
const readReply = yield dwn.processMessage(alice.did, read.message);
|
|
659
|
-
expect(readReply.status.code).
|
|
657
|
+
expect(readReply.status.code).toBe(200);
|
|
660
658
|
const readDataBytes = yield DataStream.toBytes(readReply.entry.data);
|
|
661
|
-
expect(ArrayUtility.byteArraysEqual(readDataBytes, write2.dataBytes)).
|
|
659
|
+
expect(ArrayUtility.byteArraysEqual(readDataBytes, write2.dataBytes)).toBe(true);
|
|
662
660
|
}));
|
|
663
661
|
describe('initial write & subsequent write tests', () => {
|
|
664
662
|
describe('createFrom()', () => {
|
|
@@ -675,7 +673,7 @@ export function testRecordsWriteHandler() {
|
|
|
675
673
|
// setting up a stub DID resolver
|
|
676
674
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
677
675
|
const reply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
678
|
-
expect(reply.status.code).
|
|
676
|
+
expect(reply.status.code).toBe(202);
|
|
679
677
|
// changing the `published` property
|
|
680
678
|
const newWrite = yield RecordsWrite.createFrom({
|
|
681
679
|
recordsWriteMessage: recordsWrite.message,
|
|
@@ -683,18 +681,18 @@ export function testRecordsWriteHandler() {
|
|
|
683
681
|
signer: Jws.createSigner(author)
|
|
684
682
|
});
|
|
685
683
|
const newWriteReply = yield dwn.processMessage(tenant, newWrite.message);
|
|
686
|
-
expect(newWriteReply.status.code).
|
|
684
|
+
expect(newWriteReply.status.code).toBe(202);
|
|
687
685
|
// verify the new record state can be queried
|
|
688
686
|
const recordsQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
689
687
|
author,
|
|
690
688
|
filter: { recordId: message.recordId }
|
|
691
689
|
});
|
|
692
690
|
const recordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
693
|
-
expect(recordsQueryReply.status.code).
|
|
694
|
-
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
695
|
-
expect(recordsQueryReply.entries[0].descriptor.published).
|
|
691
|
+
expect(recordsQueryReply.status.code).toBe(200);
|
|
692
|
+
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
693
|
+
expect(recordsQueryReply.entries[0].descriptor.published).toBe(true);
|
|
696
694
|
// very importantly verify the original data is still returned
|
|
697
|
-
expect(recordsQueryReply.entries[0].encodedData).
|
|
695
|
+
expect(recordsQueryReply.entries[0].encodedData).toBe(encodedData);
|
|
698
696
|
}));
|
|
699
697
|
it('should inherit parent published state when using createFrom() to create RecordsWrite', () => __awaiter(this, void 0, void 0, function* () {
|
|
700
698
|
var _a;
|
|
@@ -705,7 +703,7 @@ export function testRecordsWriteHandler() {
|
|
|
705
703
|
// setting up a stub DID resolver
|
|
706
704
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
707
705
|
const reply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
708
|
-
expect(reply.status.code).
|
|
706
|
+
expect(reply.status.code).toBe(202);
|
|
709
707
|
const newData = Encoder.stringToBytes('new data');
|
|
710
708
|
const newWrite = yield RecordsWrite.createFrom({
|
|
711
709
|
recordsWriteMessage: recordsWrite.message,
|
|
@@ -713,19 +711,19 @@ export function testRecordsWriteHandler() {
|
|
|
713
711
|
signer: Jws.createSigner(author)
|
|
714
712
|
});
|
|
715
713
|
const newWriteReply = yield dwn.processMessage(tenant, newWrite.message, { dataStream: DataStream.fromBytes(newData) });
|
|
716
|
-
expect(newWriteReply.status.code).
|
|
714
|
+
expect(newWriteReply.status.code).toBe(202);
|
|
717
715
|
// verify the new record state can be queried
|
|
718
716
|
const recordsQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
719
717
|
author,
|
|
720
718
|
filter: { recordId: message.recordId }
|
|
721
719
|
});
|
|
722
720
|
const recordsQueryReply = yield dwn.processMessage(tenant, recordsQueryMessageData.message);
|
|
723
|
-
expect(recordsQueryReply.status.code).
|
|
724
|
-
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
721
|
+
expect(recordsQueryReply.status.code).toBe(200);
|
|
722
|
+
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
725
723
|
const recordsWriteReturned = recordsQueryReply.entries[0];
|
|
726
|
-
expect(recordsWriteReturned.encodedData).
|
|
727
|
-
expect(recordsWriteReturned.descriptor.published).
|
|
728
|
-
expect(recordsWriteReturned.descriptor.datePublished).
|
|
724
|
+
expect(recordsWriteReturned.encodedData).toBe(Encoder.bytesToBase64Url(newData));
|
|
725
|
+
expect(recordsWriteReturned.descriptor.published).toBe(true);
|
|
726
|
+
expect(recordsWriteReturned.descriptor.datePublished).toBe(message.descriptor.datePublished);
|
|
729
727
|
}));
|
|
730
728
|
});
|
|
731
729
|
it('should fail with 400 if modifying a record but its initial write cannot be found in DB', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -737,8 +735,8 @@ export function testRecordsWriteHandler() {
|
|
|
737
735
|
const tenant = author.did;
|
|
738
736
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
739
737
|
const reply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
740
|
-
expect(reply.status.code).
|
|
741
|
-
expect(reply.status.detail).
|
|
738
|
+
expect(reply.status.code).toBe(400);
|
|
739
|
+
expect(reply.status.detail).toContain(DwnErrorCode.RecordsWriteGetInitialWriteNotFound);
|
|
742
740
|
}));
|
|
743
741
|
it('should return 400 if `dateCreated` and `messageTimestamp` are not the same in an initial write', () => __awaiter(this, void 0, void 0, function* () {
|
|
744
742
|
const { author, message, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -748,8 +746,8 @@ export function testRecordsWriteHandler() {
|
|
|
748
746
|
const tenant = author.did;
|
|
749
747
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
750
748
|
const reply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
751
|
-
expect(reply.status.code).
|
|
752
|
-
expect(reply.status.detail).
|
|
749
|
+
expect(reply.status.code).toBe(400);
|
|
750
|
+
expect(reply.status.detail).toContain('must match dateCreated');
|
|
753
751
|
}));
|
|
754
752
|
it('should return 400 if `contextId` in an initial protocol-base write mismatches with the expected deterministic `contextId`', () => __awaiter(this, void 0, void 0, function* () {
|
|
755
753
|
// generate a message with protocol so that computed contextId is also computed and included in message
|
|
@@ -757,45 +755,45 @@ export function testRecordsWriteHandler() {
|
|
|
757
755
|
message.contextId = yield TestDataGenerator.randomCborSha256Cid(); // make contextId mismatch from computed value
|
|
758
756
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
759
757
|
const reply = yield dwn.processMessage('unused-tenant-DID', message, { dataStream });
|
|
760
|
-
expect(reply.status.code).
|
|
761
|
-
expect(reply.status.detail).
|
|
758
|
+
expect(reply.status.code).toBe(400);
|
|
759
|
+
expect(reply.status.detail).toContain('does not match deterministic contextId');
|
|
762
760
|
}));
|
|
763
|
-
describe('
|
|
764
|
-
it('should add an
|
|
761
|
+
describe('state index', () => {
|
|
762
|
+
it('should add an entry to the state index on initial write', () => __awaiter(this, void 0, void 0, function* () {
|
|
765
763
|
const { message, author, dataStream } = yield TestDataGenerator.generateRecordsWrite();
|
|
766
764
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
767
765
|
const reply = yield dwn.processMessage(author.did, message, { dataStream });
|
|
768
|
-
expect(reply.status.code).
|
|
769
|
-
const
|
|
770
|
-
expect(events.length).
|
|
766
|
+
expect(reply.status.code).toBe(202);
|
|
767
|
+
const events = yield stateIndex.getLeaves(author.did, []);
|
|
768
|
+
expect(events.length).toBe(1);
|
|
771
769
|
const messageCid = yield Message.getCid(message);
|
|
772
|
-
expect(events[0]).
|
|
770
|
+
expect(events[0]).toBe(messageCid);
|
|
773
771
|
}));
|
|
774
772
|
it('should only keep first write and latest write when subsequent writes happen', () => __awaiter(this, void 0, void 0, function* () {
|
|
775
773
|
const { message, author, dataStream, recordsWrite } = yield TestDataGenerator.generateRecordsWrite();
|
|
776
774
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
777
775
|
const reply = yield dwn.processMessage(author.did, message, { dataStream });
|
|
778
|
-
expect(reply.status.code).
|
|
776
|
+
expect(reply.status.code).toBe(202);
|
|
779
777
|
const newWrite = yield RecordsWrite.createFrom({
|
|
780
778
|
recordsWriteMessage: recordsWrite.message,
|
|
781
779
|
published: true,
|
|
782
780
|
signer: Jws.createSigner(author)
|
|
783
781
|
});
|
|
784
782
|
const newWriteReply = yield dwn.processMessage(author.did, newWrite.message);
|
|
785
|
-
expect(newWriteReply.status.code).
|
|
783
|
+
expect(newWriteReply.status.code).toBe(202);
|
|
786
784
|
const newestWrite = yield RecordsWrite.createFrom({
|
|
787
785
|
recordsWriteMessage: recordsWrite.message,
|
|
788
786
|
published: true,
|
|
789
787
|
signer: Jws.createSigner(author)
|
|
790
788
|
});
|
|
791
789
|
const newestWriteReply = yield dwn.processMessage(author.did, newestWrite.message);
|
|
792
|
-
expect(newestWriteReply.status.code).
|
|
793
|
-
const
|
|
794
|
-
expect(events.length).
|
|
790
|
+
expect(newestWriteReply.status.code).toBe(202);
|
|
791
|
+
const events = yield stateIndex.getLeaves(author.did, []);
|
|
792
|
+
expect(events.length).toBe(2);
|
|
795
793
|
const deletedMessageCid = yield Message.getCid(newWrite.message);
|
|
796
794
|
for (const messageCid of events) {
|
|
797
795
|
if (messageCid === deletedMessageCid) {
|
|
798
|
-
|
|
796
|
+
throw new Error(`${messageCid} should not exist`);
|
|
799
797
|
}
|
|
800
798
|
}
|
|
801
799
|
}));
|
|
@@ -816,7 +814,7 @@ export function testRecordsWriteHandler() {
|
|
|
816
814
|
// setting up a stub DID resolver
|
|
817
815
|
TestStubGenerator.stubDidResolver(didResolver, [alice, bob]);
|
|
818
816
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
819
|
-
expect(protocolsConfigureReply.status.code).
|
|
817
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
820
818
|
// generate a `RecordsWrite` message from bob
|
|
821
819
|
const bobData = Encoder.stringToBytes('data from bob');
|
|
822
820
|
const emailFromBob = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -828,16 +826,16 @@ export function testRecordsWriteHandler() {
|
|
|
828
826
|
data: bobData
|
|
829
827
|
});
|
|
830
828
|
const bobWriteReply = yield dwn.processMessage(alice.did, emailFromBob.message, { dataStream: emailFromBob.dataStream });
|
|
831
|
-
expect(bobWriteReply.status.code).
|
|
829
|
+
expect(bobWriteReply.status.code).toBe(202);
|
|
832
830
|
// verify bob's message got written to the DB
|
|
833
831
|
const messageDataForQueryingBobsWrite = yield TestDataGenerator.generateRecordsQuery({
|
|
834
832
|
author: alice,
|
|
835
833
|
filter: { recordId: emailFromBob.message.recordId }
|
|
836
834
|
});
|
|
837
835
|
const bobRecordsQueryReply = yield dwn.processMessage(alice.did, messageDataForQueryingBobsWrite.message);
|
|
838
|
-
expect(bobRecordsQueryReply.status.code).
|
|
839
|
-
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
840
|
-
expect(bobRecordsQueryReply.entries[0].encodedData).
|
|
836
|
+
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
837
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
838
|
+
expect(bobRecordsQueryReply.entries[0].encodedData).toBe(Encoder.bytesToBase64Url(bobData));
|
|
841
839
|
}));
|
|
842
840
|
it('should allow co-update with allow-anyone rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
843
841
|
// scenario: Alice creates a record on her DWN, and Bob (anyone) is able to update it. Bob is not able to
|
|
@@ -850,7 +848,7 @@ export function testRecordsWriteHandler() {
|
|
|
850
848
|
protocolDefinition
|
|
851
849
|
});
|
|
852
850
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
853
|
-
expect(protocolsConfigureReply.status.code).
|
|
851
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
854
852
|
// Alice creates a doc
|
|
855
853
|
const docRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
856
854
|
author: alice,
|
|
@@ -859,7 +857,7 @@ export function testRecordsWriteHandler() {
|
|
|
859
857
|
protocolPath: 'doc'
|
|
860
858
|
});
|
|
861
859
|
const docRecordsReply = yield dwn.processMessage(alice.did, docRecord.message, { dataStream: docRecord.dataStream });
|
|
862
|
-
expect(docRecordsReply.status.code).
|
|
860
|
+
expect(docRecordsReply.status.code).toBe(202);
|
|
863
861
|
// Bob updates Alice's doc
|
|
864
862
|
const bobsData = yield TestDataGenerator.randomBytes(10);
|
|
865
863
|
const docUpdateRecord = yield TestDataGenerator.generateFromRecordsWrite({
|
|
@@ -868,7 +866,7 @@ export function testRecordsWriteHandler() {
|
|
|
868
866
|
data: bobsData
|
|
869
867
|
});
|
|
870
868
|
const docUpdateRecordsReply = yield dwn.processMessage(alice.did, docUpdateRecord.message, { dataStream: docUpdateRecord.dataStream });
|
|
871
|
-
expect(docUpdateRecordsReply.status.code).
|
|
869
|
+
expect(docUpdateRecordsReply.status.code).toBe(202);
|
|
872
870
|
// Bob tries and fails to create a new record
|
|
873
871
|
const bobDocRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
874
872
|
author: bob,
|
|
@@ -877,8 +875,8 @@ export function testRecordsWriteHandler() {
|
|
|
877
875
|
protocolPath: 'doc'
|
|
878
876
|
});
|
|
879
877
|
const bobDocRecordsReply = yield dwn.processMessage(alice.did, bobDocRecord.message, { dataStream: bobDocRecord.dataStream });
|
|
880
|
-
expect(bobDocRecordsReply.status.code).
|
|
881
|
-
expect(bobDocRecordsReply.status.detail).
|
|
878
|
+
expect(bobDocRecordsReply.status.code).toBe(401);
|
|
879
|
+
expect(bobDocRecordsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
882
880
|
}));
|
|
883
881
|
describe('recipient rules', () => {
|
|
884
882
|
it('should allow write with ancestor recipient rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -898,7 +896,7 @@ export function testRecordsWriteHandler() {
|
|
|
898
896
|
// setting up a stub DID resolver
|
|
899
897
|
TestStubGenerator.stubDidResolver(didResolver, [alice, vcIssuer, carol]);
|
|
900
898
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
901
|
-
expect(protocolsConfigureReply.status.code).
|
|
899
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
902
900
|
// write a credential application to Alice's DWN to simulate that she has sent a credential application to a VC issuer
|
|
903
901
|
const encodedCredentialApplication = new TextEncoder().encode('credential application data');
|
|
904
902
|
const credentialApplication = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -911,7 +909,7 @@ export function testRecordsWriteHandler() {
|
|
|
911
909
|
data: encodedCredentialApplication
|
|
912
910
|
});
|
|
913
911
|
const credentialApplicationReply = yield dwn.processMessage(alice.did, credentialApplication.message, { dataStream: credentialApplication.dataStream });
|
|
914
|
-
expect(credentialApplicationReply.status.code).
|
|
912
|
+
expect(credentialApplicationReply.status.code).toBe(202);
|
|
915
913
|
// generate a credential application response message from VC issuer
|
|
916
914
|
const encodedCredentialResponse = new TextEncoder().encode('credential response data');
|
|
917
915
|
const credentialResponse = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -925,17 +923,17 @@ export function testRecordsWriteHandler() {
|
|
|
925
923
|
data: encodedCredentialResponse
|
|
926
924
|
});
|
|
927
925
|
const credentialResponseReply = yield dwn.processMessage(alice.did, credentialResponse.message, { dataStream: credentialResponse.dataStream });
|
|
928
|
-
expect(credentialResponseReply.status.code).
|
|
926
|
+
expect(credentialResponseReply.status.code).toBe(202);
|
|
929
927
|
// verify VC issuer's message got written to the DB
|
|
930
928
|
const messageDataForQueryingCredentialResponse = yield TestDataGenerator.generateRecordsQuery({
|
|
931
929
|
author: alice,
|
|
932
930
|
filter: { recordId: credentialResponse.message.recordId }
|
|
933
931
|
});
|
|
934
932
|
const applicationResponseQueryReply = yield dwn.processMessage(alice.did, messageDataForQueryingCredentialResponse.message);
|
|
935
|
-
expect(applicationResponseQueryReply.status.code).
|
|
936
|
-
expect((_a = applicationResponseQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
933
|
+
expect(applicationResponseQueryReply.status.code).toBe(200);
|
|
934
|
+
expect((_a = applicationResponseQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
937
935
|
expect(applicationResponseQueryReply.entries[0].encodedData)
|
|
938
|
-
.
|
|
936
|
+
.toBe(base64url.baseEncode(encodedCredentialResponse));
|
|
939
937
|
}));
|
|
940
938
|
it('should allow co-update with ancestor recipient rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
941
939
|
// scenario: Alice creates a post with Bob as recipient. Alice adds a `post/tag` to the post. Bob is able to update
|
|
@@ -948,7 +946,7 @@ export function testRecordsWriteHandler() {
|
|
|
948
946
|
protocolDefinition
|
|
949
947
|
});
|
|
950
948
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
951
|
-
expect(protocolsConfigureReply.status.code).
|
|
949
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
952
950
|
// Alice creates a post with Bob as recipient
|
|
953
951
|
const docRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
954
952
|
author: alice,
|
|
@@ -957,7 +955,7 @@ export function testRecordsWriteHandler() {
|
|
|
957
955
|
protocolPath: 'post'
|
|
958
956
|
});
|
|
959
957
|
const docRecordsReply = yield dwn.processMessage(alice.did, docRecord.message, { dataStream: docRecord.dataStream });
|
|
960
|
-
expect(docRecordsReply.status.code).
|
|
958
|
+
expect(docRecordsReply.status.code).toBe(202);
|
|
961
959
|
// Alice creates a post/tag
|
|
962
960
|
const tagRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
963
961
|
author: alice,
|
|
@@ -967,7 +965,7 @@ export function testRecordsWriteHandler() {
|
|
|
967
965
|
parentContextId: docRecord.message.contextId,
|
|
968
966
|
});
|
|
969
967
|
const tagRecordsReply = yield dwn.processMessage(alice.did, tagRecord.message, { dataStream: tagRecord.dataStream });
|
|
970
|
-
expect(tagRecordsReply.status.code).
|
|
968
|
+
expect(tagRecordsReply.status.code).toBe(202);
|
|
971
969
|
// Bob updates Alice's post
|
|
972
970
|
const bobsData = yield TestDataGenerator.randomBytes(10);
|
|
973
971
|
const tagUpdateRecord = yield TestDataGenerator.generateFromRecordsWrite({
|
|
@@ -976,7 +974,7 @@ export function testRecordsWriteHandler() {
|
|
|
976
974
|
data: bobsData
|
|
977
975
|
});
|
|
978
976
|
const tagUpdateRecordsReply = yield dwn.processMessage(alice.did, tagUpdateRecord.message, { dataStream: tagUpdateRecord.dataStream });
|
|
979
|
-
expect(tagUpdateRecordsReply.status.code).
|
|
977
|
+
expect(tagUpdateRecordsReply.status.code).toBe(202);
|
|
980
978
|
// Bob tries and fails to create a new record
|
|
981
979
|
const bobTagRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
982
980
|
author: bob,
|
|
@@ -986,8 +984,8 @@ export function testRecordsWriteHandler() {
|
|
|
986
984
|
parentContextId: docRecord.message.contextId,
|
|
987
985
|
});
|
|
988
986
|
const bobTagRecordsReply = yield dwn.processMessage(alice.did, bobTagRecord.message, { dataStream: bobTagRecord.dataStream });
|
|
989
|
-
expect(bobTagRecordsReply.status.code).
|
|
990
|
-
expect(bobTagRecordsReply.status.detail).
|
|
987
|
+
expect(bobTagRecordsReply.status.code).toBe(401);
|
|
988
|
+
expect(bobTagRecordsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
991
989
|
}));
|
|
992
990
|
it('should allow co-update with direct recipient rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
993
991
|
// scenario:
|
|
@@ -1005,7 +1003,7 @@ export function testRecordsWriteHandler() {
|
|
|
1005
1003
|
// setting up a stub DID resolver
|
|
1006
1004
|
TestStubGenerator.stubDidResolver(didResolver, [alice, bob, carol]);
|
|
1007
1005
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1008
|
-
expect(protocolsConfigureReply.status.code).
|
|
1006
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1009
1007
|
// Alice creates a 'post' with Bob as recipient
|
|
1010
1008
|
const recordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
1011
1009
|
author: alice,
|
|
@@ -1014,22 +1012,22 @@ export function testRecordsWriteHandler() {
|
|
|
1014
1012
|
protocolPath: 'post',
|
|
1015
1013
|
});
|
|
1016
1014
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream: recordsWrite.dataStream });
|
|
1017
|
-
expect(recordsWriteReply.status.code).
|
|
1015
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
1018
1016
|
// Carol is unable to update the 'post'
|
|
1019
1017
|
const carolRecordsWrite = yield TestDataGenerator.generateFromRecordsWrite({
|
|
1020
1018
|
author: carol,
|
|
1021
1019
|
existingWrite: recordsWrite.recordsWrite
|
|
1022
1020
|
});
|
|
1023
1021
|
const carolRecordsWriteReply = yield dwn.processMessage(alice.did, carolRecordsWrite.message);
|
|
1024
|
-
expect(carolRecordsWriteReply.status.code).
|
|
1025
|
-
expect(carolRecordsWriteReply.status.detail).
|
|
1022
|
+
expect(carolRecordsWriteReply.status.code).toBe(401);
|
|
1023
|
+
expect(carolRecordsWriteReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
1026
1024
|
// Bob is able to update the post
|
|
1027
1025
|
const bobRecordsWrite = yield TestDataGenerator.generateFromRecordsWrite({
|
|
1028
1026
|
author: bob,
|
|
1029
1027
|
existingWrite: recordsWrite.recordsWrite,
|
|
1030
1028
|
});
|
|
1031
1029
|
const bobRecordsWriteReply = yield dwn.processMessage(alice.did, bobRecordsWrite.message, { dataStream: bobRecordsWrite.dataStream });
|
|
1032
|
-
expect(bobRecordsWriteReply.status.code).
|
|
1030
|
+
expect(bobRecordsWriteReply.status.code).toBe(202);
|
|
1033
1031
|
}));
|
|
1034
1032
|
});
|
|
1035
1033
|
describe('author action rules', () => {
|
|
@@ -1049,7 +1047,7 @@ export function testRecordsWriteHandler() {
|
|
|
1049
1047
|
protocolDefinition
|
|
1050
1048
|
});
|
|
1051
1049
|
const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1052
|
-
expect(protocolsConfigureReply.status.code).
|
|
1050
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1053
1051
|
// Alice writes image to bob's DWN
|
|
1054
1052
|
const encodedImage = new TextEncoder().encode('cafe-aesthetic.jpg');
|
|
1055
1053
|
const imageRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1061,7 +1059,7 @@ export function testRecordsWriteHandler() {
|
|
|
1061
1059
|
data: encodedImage
|
|
1062
1060
|
});
|
|
1063
1061
|
const imageReply = yield dwn.processMessage(bob.did, imageRecordsWrite.message, { dataStream: imageRecordsWrite.dataStream });
|
|
1064
|
-
expect(imageReply.status.code).
|
|
1062
|
+
expect(imageReply.status.code).toBe(202);
|
|
1065
1063
|
// AliceImposter attempts and fails to caption Alice's image
|
|
1066
1064
|
const encodedCaptionImposter = new TextEncoder().encode('bad vibes! >:(');
|
|
1067
1065
|
const captionImposter = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1074,8 +1072,8 @@ export function testRecordsWriteHandler() {
|
|
|
1074
1072
|
data: encodedCaptionImposter
|
|
1075
1073
|
});
|
|
1076
1074
|
const captionReply = yield dwn.processMessage(bob.did, captionImposter.message, { dataStream: captionImposter.dataStream });
|
|
1077
|
-
expect(captionReply.status.code).
|
|
1078
|
-
expect(captionReply.status.detail).
|
|
1075
|
+
expect(captionReply.status.code).toBe(401);
|
|
1076
|
+
expect(captionReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
1079
1077
|
// Alice is able to add a caption to her image
|
|
1080
1078
|
const encodedCaption = new TextEncoder().encode('coffee and work vibes!');
|
|
1081
1079
|
const captionRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1088,17 +1086,17 @@ export function testRecordsWriteHandler() {
|
|
|
1088
1086
|
data: encodedCaption
|
|
1089
1087
|
});
|
|
1090
1088
|
const captionResponse = yield dwn.processMessage(bob.did, captionRecordsWrite.message, { dataStream: captionRecordsWrite.dataStream });
|
|
1091
|
-
expect(captionResponse.status.code).
|
|
1089
|
+
expect(captionResponse.status.code).toBe(202);
|
|
1092
1090
|
// Verify Alice's caption got written to the DB
|
|
1093
1091
|
const messageDataForQueryingCaptionResponse = yield TestDataGenerator.generateRecordsQuery({
|
|
1094
1092
|
author: alice,
|
|
1095
1093
|
filter: { recordId: captionRecordsWrite.message.recordId }
|
|
1096
1094
|
});
|
|
1097
1095
|
const applicationResponseQueryReply = yield dwn.processMessage(bob.did, messageDataForQueryingCaptionResponse.message);
|
|
1098
|
-
expect(applicationResponseQueryReply.status.code).
|
|
1099
|
-
expect((_a = applicationResponseQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
1096
|
+
expect(applicationResponseQueryReply.status.code).toBe(200);
|
|
1097
|
+
expect((_a = applicationResponseQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
1100
1098
|
expect(applicationResponseQueryReply.entries[0].encodedData)
|
|
1101
|
-
.
|
|
1099
|
+
.toBe(base64url.baseEncode(encodedCaption));
|
|
1102
1100
|
}));
|
|
1103
1101
|
it('should allow co-update with ancestor author rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
1104
1102
|
// scenario: Bob authors a post on Alice's DWN. Alice adds a comment to the post. Bob is able to update the comment,
|
|
@@ -1111,7 +1109,7 @@ export function testRecordsWriteHandler() {
|
|
|
1111
1109
|
protocolDefinition
|
|
1112
1110
|
});
|
|
1113
1111
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1114
|
-
expect(protocolsConfigureReply.status.code).
|
|
1112
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1115
1113
|
// Bob creates a post
|
|
1116
1114
|
const postRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1117
1115
|
author: bob,
|
|
@@ -1120,7 +1118,7 @@ export function testRecordsWriteHandler() {
|
|
|
1120
1118
|
protocolPath: 'post'
|
|
1121
1119
|
});
|
|
1122
1120
|
const postRecordsReply = yield dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
|
|
1123
|
-
expect(postRecordsReply.status.code).
|
|
1121
|
+
expect(postRecordsReply.status.code).toBe(202);
|
|
1124
1122
|
// Alice creates a post/comment
|
|
1125
1123
|
const commentRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1126
1124
|
author: alice,
|
|
@@ -1130,7 +1128,7 @@ export function testRecordsWriteHandler() {
|
|
|
1130
1128
|
parentContextId: postRecord.message.contextId,
|
|
1131
1129
|
});
|
|
1132
1130
|
const commentRecordsReply = yield dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
|
|
1133
|
-
expect(commentRecordsReply.status.code).
|
|
1131
|
+
expect(commentRecordsReply.status.code).toBe(202);
|
|
1134
1132
|
// Bob updates Alice's comment
|
|
1135
1133
|
const bobsData = yield TestDataGenerator.randomBytes(10);
|
|
1136
1134
|
const postUpdateRecord = yield TestDataGenerator.generateFromRecordsWrite({
|
|
@@ -1139,7 +1137,7 @@ export function testRecordsWriteHandler() {
|
|
|
1139
1137
|
data: bobsData
|
|
1140
1138
|
});
|
|
1141
1139
|
const commentUpdateRecordsReply = yield dwn.processMessage(alice.did, postUpdateRecord.message, { dataStream: postUpdateRecord.dataStream });
|
|
1142
|
-
expect(commentUpdateRecordsReply.status.code).
|
|
1140
|
+
expect(commentUpdateRecordsReply.status.code).toBe(202);
|
|
1143
1141
|
// Bob tries and fails to create a new comment
|
|
1144
1142
|
const bobPostRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1145
1143
|
author: bob,
|
|
@@ -1149,8 +1147,8 @@ export function testRecordsWriteHandler() {
|
|
|
1149
1147
|
parentContextId: postRecord.message.contextId,
|
|
1150
1148
|
});
|
|
1151
1149
|
const bobPostRecordsReply = yield dwn.processMessage(alice.did, bobPostRecord.message, { dataStream: bobPostRecord.dataStream });
|
|
1152
|
-
expect(bobPostRecordsReply.status.code).
|
|
1153
|
-
expect(bobPostRecordsReply.status.detail).
|
|
1150
|
+
expect(bobPostRecordsReply.status.code).toBe(401);
|
|
1151
|
+
expect(bobPostRecordsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
1154
1152
|
}));
|
|
1155
1153
|
});
|
|
1156
1154
|
describe('role rules', () => {
|
|
@@ -1165,7 +1163,7 @@ export function testRecordsWriteHandler() {
|
|
|
1165
1163
|
protocolDefinition
|
|
1166
1164
|
});
|
|
1167
1165
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1168
|
-
expect(protocolsConfigureReply.status.code).
|
|
1166
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1169
1167
|
// Alice writes a 'friend' root-level role record with Bob as recipient
|
|
1170
1168
|
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1171
1169
|
author: alice,
|
|
@@ -1175,14 +1173,14 @@ export function testRecordsWriteHandler() {
|
|
|
1175
1173
|
data: new TextEncoder().encode('Bob is my friend'),
|
|
1176
1174
|
});
|
|
1177
1175
|
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
1178
|
-
expect(friendRoleReply.status.code).
|
|
1176
|
+
expect(friendRoleReply.status.code).toBe(202);
|
|
1179
1177
|
// Alice updates Bob's 'friend' record
|
|
1180
1178
|
const updateFriendRecord = yield TestDataGenerator.generateFromRecordsWrite({
|
|
1181
1179
|
author: alice,
|
|
1182
1180
|
existingWrite: friendRoleRecord.recordsWrite,
|
|
1183
1181
|
});
|
|
1184
1182
|
const updateFriendReply = yield dwn.processMessage(alice.did, updateFriendRecord.message, { dataStream: updateFriendRecord.dataStream });
|
|
1185
|
-
expect(updateFriendReply.status.code).
|
|
1183
|
+
expect(updateFriendReply.status.code).toBe(202);
|
|
1186
1184
|
}));
|
|
1187
1185
|
it('should reject role RecordsWrite if recipient is undefined', () => __awaiter(this, void 0, void 0, function* () {
|
|
1188
1186
|
// scenario: Alice writes a root-level role record with no recipient and it is rejected
|
|
@@ -1193,7 +1191,7 @@ export function testRecordsWriteHandler() {
|
|
|
1193
1191
|
protocolDefinition
|
|
1194
1192
|
});
|
|
1195
1193
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1196
|
-
expect(protocolsConfigureReply.status.code).
|
|
1194
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1197
1195
|
// Alice writes a 'friend' root-level role record with no recipient
|
|
1198
1196
|
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1199
1197
|
author: alice,
|
|
@@ -1202,8 +1200,8 @@ export function testRecordsWriteHandler() {
|
|
|
1202
1200
|
data: new TextEncoder().encode('Bob is my friend'),
|
|
1203
1201
|
});
|
|
1204
1202
|
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
1205
|
-
expect(friendRoleReply.status.code).
|
|
1206
|
-
expect(friendRoleReply.status.detail).
|
|
1203
|
+
expect(friendRoleReply.status.code).toBe(400);
|
|
1204
|
+
expect(friendRoleReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationRoleMissingRecipient);
|
|
1207
1205
|
}));
|
|
1208
1206
|
it('should allow a new root-level role record to be created for the same recipient if their old one was deleted', () => __awaiter(this, void 0, void 0, function* () {
|
|
1209
1207
|
// scenario: Alice adds Bob to the 'friend' role, then deletes the role. Alice writes a new record adding Bob as a 'friend' again.
|
|
@@ -1215,7 +1213,7 @@ export function testRecordsWriteHandler() {
|
|
|
1215
1213
|
protocolDefinition
|
|
1216
1214
|
});
|
|
1217
1215
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1218
|
-
expect(protocolsConfigureReply.status.code).
|
|
1216
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1219
1217
|
// Alice writes a 'friend' root-level role record with Bob as recipient
|
|
1220
1218
|
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1221
1219
|
author: alice,
|
|
@@ -1225,14 +1223,14 @@ export function testRecordsWriteHandler() {
|
|
|
1225
1223
|
data: new TextEncoder().encode('Bob is my friend'),
|
|
1226
1224
|
});
|
|
1227
1225
|
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
1228
|
-
expect(friendRoleReply.status.code).
|
|
1226
|
+
expect(friendRoleReply.status.code).toBe(202);
|
|
1229
1227
|
// Alice deletes Bob's 'friend' role record
|
|
1230
1228
|
const deleteFriend = yield TestDataGenerator.generateRecordsDelete({
|
|
1231
1229
|
author: alice,
|
|
1232
1230
|
recordId: friendRoleRecord.message.recordId,
|
|
1233
1231
|
});
|
|
1234
1232
|
const deleteFriendReply = yield dwn.processMessage(alice.did, deleteFriend.message);
|
|
1235
|
-
expect(deleteFriendReply.status.code).
|
|
1233
|
+
expect(deleteFriendReply.status.code).toBe(202);
|
|
1236
1234
|
// Alice writes a new record adding Bob as a 'friend' again
|
|
1237
1235
|
const duplicateFriendRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1238
1236
|
author: alice,
|
|
@@ -1242,7 +1240,7 @@ export function testRecordsWriteHandler() {
|
|
|
1242
1240
|
data: new TextEncoder().encode('Bob is still my friend'),
|
|
1243
1241
|
});
|
|
1244
1242
|
const duplicateFriendReply = yield dwn.processMessage(alice.did, duplicateFriendRecord.message, { dataStream: duplicateFriendRecord.dataStream });
|
|
1245
|
-
expect(duplicateFriendReply.status.code).
|
|
1243
|
+
expect(duplicateFriendReply.status.code).toBe(202);
|
|
1246
1244
|
}));
|
|
1247
1245
|
});
|
|
1248
1246
|
describe('write context role records', () => {
|
|
@@ -1256,7 +1254,7 @@ export function testRecordsWriteHandler() {
|
|
|
1256
1254
|
protocolDefinition
|
|
1257
1255
|
});
|
|
1258
1256
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1259
|
-
expect(protocolsConfigureReply.status.code).
|
|
1257
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1260
1258
|
// Alice creates a thread
|
|
1261
1259
|
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1262
1260
|
author: alice,
|
|
@@ -1265,7 +1263,7 @@ export function testRecordsWriteHandler() {
|
|
|
1265
1263
|
protocolPath: 'thread'
|
|
1266
1264
|
});
|
|
1267
1265
|
const threadRecordReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
1268
|
-
expect(threadRecordReply.status.code).
|
|
1266
|
+
expect(threadRecordReply.status.code).toBe(202);
|
|
1269
1267
|
// Alice adds Bob as a 'thread/participant' in that thread
|
|
1270
1268
|
const participantRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1271
1269
|
author: alice,
|
|
@@ -1275,14 +1273,14 @@ export function testRecordsWriteHandler() {
|
|
|
1275
1273
|
parentContextId: threadRecord.message.contextId,
|
|
1276
1274
|
});
|
|
1277
1275
|
const participantRecordReply = yield dwn.processMessage(alice.did, participantRecord.message, { dataStream: participantRecord.dataStream });
|
|
1278
|
-
expect(participantRecordReply.status.code).
|
|
1276
|
+
expect(participantRecordReply.status.code).toBe(202);
|
|
1279
1277
|
// Alice updates Bob's role record
|
|
1280
1278
|
const participantUpdateRecord = yield TestDataGenerator.generateFromRecordsWrite({
|
|
1281
1279
|
author: alice,
|
|
1282
1280
|
existingWrite: participantRecord.recordsWrite,
|
|
1283
1281
|
});
|
|
1284
1282
|
const participantUpdateRecordReply = yield dwn.processMessage(alice.did, participantUpdateRecord.message, { dataStream: participantUpdateRecord.dataStream });
|
|
1285
|
-
expect(participantUpdateRecordReply.status.code).
|
|
1283
|
+
expect(participantUpdateRecordReply.status.code).toBe(202);
|
|
1286
1284
|
}));
|
|
1287
1285
|
it('can create the same role under different contexts', () => __awaiter(this, void 0, void 0, function* () {
|
|
1288
1286
|
// scenario: Alice creates a thread and adds Bob to the 'thread/participant' role. Alice repeats the steps with a new thread.
|
|
@@ -1294,7 +1292,7 @@ export function testRecordsWriteHandler() {
|
|
|
1294
1292
|
protocolDefinition
|
|
1295
1293
|
});
|
|
1296
1294
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1297
|
-
expect(protocolsConfigureReply.status.code).
|
|
1295
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1298
1296
|
// Alice creates the first thread
|
|
1299
1297
|
const threadRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
1300
1298
|
author: alice,
|
|
@@ -1303,7 +1301,7 @@ export function testRecordsWriteHandler() {
|
|
|
1303
1301
|
protocolPath: 'thread'
|
|
1304
1302
|
});
|
|
1305
1303
|
const threadRecordReply1 = yield dwn.processMessage(alice.did, threadRecord1.message, { dataStream: threadRecord1.dataStream });
|
|
1306
|
-
expect(threadRecordReply1.status.code).
|
|
1304
|
+
expect(threadRecordReply1.status.code).toBe(202);
|
|
1307
1305
|
// Alice adds Bob as a 'thread/participant' to the first thread
|
|
1308
1306
|
const participantRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
1309
1307
|
author: alice,
|
|
@@ -1313,7 +1311,7 @@ export function testRecordsWriteHandler() {
|
|
|
1313
1311
|
parentContextId: threadRecord1.message.contextId,
|
|
1314
1312
|
});
|
|
1315
1313
|
const participantRecordReply1 = yield dwn.processMessage(alice.did, participantRecord1.message, { dataStream: participantRecord1.dataStream });
|
|
1316
|
-
expect(participantRecordReply1.status.code).
|
|
1314
|
+
expect(participantRecordReply1.status.code).toBe(202);
|
|
1317
1315
|
// Alice creates a second thread
|
|
1318
1316
|
const threadRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
1319
1317
|
author: alice,
|
|
@@ -1322,7 +1320,7 @@ export function testRecordsWriteHandler() {
|
|
|
1322
1320
|
protocolPath: 'thread'
|
|
1323
1321
|
});
|
|
1324
1322
|
const threadRecordReply2 = yield dwn.processMessage(alice.did, threadRecord2.message, { dataStream: threadRecord2.dataStream });
|
|
1325
|
-
expect(threadRecordReply2.status.code).
|
|
1323
|
+
expect(threadRecordReply2.status.code).toBe(202);
|
|
1326
1324
|
// Alice adds Bob as a 'thread/participant' to the second thread
|
|
1327
1325
|
const participantRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
1328
1326
|
author: alice,
|
|
@@ -1332,7 +1330,7 @@ export function testRecordsWriteHandler() {
|
|
|
1332
1330
|
parentContextId: threadRecord2.message.contextId,
|
|
1333
1331
|
});
|
|
1334
1332
|
const participantRecordReply2 = yield dwn.processMessage(alice.did, participantRecord2.message, { dataStream: participantRecord2.dataStream });
|
|
1335
|
-
expect(participantRecordReply2.status.code).
|
|
1333
|
+
expect(participantRecordReply2.status.code).toBe(202);
|
|
1336
1334
|
}));
|
|
1337
1335
|
it('rejects writes to a $role record if there already exists one in the same context', () => __awaiter(this, void 0, void 0, function* () {
|
|
1338
1336
|
// scenario: Alice creates a thread and adds Bob to the 'thread/participant' role. She adds Bob to the role second time and fails
|
|
@@ -1344,7 +1342,7 @@ export function testRecordsWriteHandler() {
|
|
|
1344
1342
|
protocolDefinition
|
|
1345
1343
|
});
|
|
1346
1344
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1347
|
-
expect(protocolsConfigureReply.status.code).
|
|
1345
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1348
1346
|
// Alice creates the first thread
|
|
1349
1347
|
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1350
1348
|
author: alice,
|
|
@@ -1353,7 +1351,7 @@ export function testRecordsWriteHandler() {
|
|
|
1353
1351
|
protocolPath: 'thread'
|
|
1354
1352
|
});
|
|
1355
1353
|
const threadRecordReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
1356
|
-
expect(threadRecordReply.status.code).
|
|
1354
|
+
expect(threadRecordReply.status.code).toBe(202);
|
|
1357
1355
|
// Alice adds Bob as a 'thread/participant' to the thread
|
|
1358
1356
|
const participantRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
1359
1357
|
author: alice,
|
|
@@ -1363,7 +1361,7 @@ export function testRecordsWriteHandler() {
|
|
|
1363
1361
|
parentContextId: threadRecord.message.contextId,
|
|
1364
1362
|
});
|
|
1365
1363
|
const participantRecordReply1 = yield dwn.processMessage(alice.did, participantRecord1.message, { dataStream: participantRecord1.dataStream });
|
|
1366
|
-
expect(participantRecordReply1.status.code).
|
|
1364
|
+
expect(participantRecordReply1.status.code).toBe(202);
|
|
1367
1365
|
// Alice adds Bob as a 'thread/participant' again to the same thread
|
|
1368
1366
|
const participantRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
1369
1367
|
author: alice,
|
|
@@ -1373,8 +1371,8 @@ export function testRecordsWriteHandler() {
|
|
|
1373
1371
|
parentContextId: threadRecord.message.contextId,
|
|
1374
1372
|
});
|
|
1375
1373
|
const participantRecordReply2 = yield dwn.processMessage(alice.did, participantRecord2.message, { dataStream: participantRecord2.dataStream });
|
|
1376
|
-
expect(participantRecordReply2.status.code).
|
|
1377
|
-
expect(participantRecordReply2.status.detail).
|
|
1374
|
+
expect(participantRecordReply2.status.code).toBe(400);
|
|
1375
|
+
expect(participantRecordReply2.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationDuplicateRoleRecipient);
|
|
1378
1376
|
}));
|
|
1379
1377
|
it('allows a new context role record to be created for the same recipient in the same context if their old one was deleted', () => __awaiter(this, void 0, void 0, function* () {
|
|
1380
1378
|
// scenario: Alice creates a thread and adds Bob to the 'thread/participant' role. She deletes the role and then adds a new one.
|
|
@@ -1386,7 +1384,7 @@ export function testRecordsWriteHandler() {
|
|
|
1386
1384
|
protocolDefinition
|
|
1387
1385
|
});
|
|
1388
1386
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1389
|
-
expect(protocolsConfigureReply.status.code).
|
|
1387
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1390
1388
|
// Alice creates the first thread
|
|
1391
1389
|
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1392
1390
|
author: alice,
|
|
@@ -1395,7 +1393,7 @@ export function testRecordsWriteHandler() {
|
|
|
1395
1393
|
protocolPath: 'thread'
|
|
1396
1394
|
});
|
|
1397
1395
|
const threadRecordReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
1398
|
-
expect(threadRecordReply.status.code).
|
|
1396
|
+
expect(threadRecordReply.status.code).toBe(202);
|
|
1399
1397
|
// Alice adds Bob as a 'thread/participant' to the thread
|
|
1400
1398
|
const participantRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
1401
1399
|
author: alice,
|
|
@@ -1405,14 +1403,14 @@ export function testRecordsWriteHandler() {
|
|
|
1405
1403
|
parentContextId: threadRecord.message.contextId,
|
|
1406
1404
|
});
|
|
1407
1405
|
const participantRecordReply1 = yield dwn.processMessage(alice.did, participantRecord1.message, { dataStream: participantRecord1.dataStream });
|
|
1408
|
-
expect(participantRecordReply1.status.code).
|
|
1406
|
+
expect(participantRecordReply1.status.code).toBe(202);
|
|
1409
1407
|
// Alice deletes the participant record
|
|
1410
1408
|
const participantDelete = yield TestDataGenerator.generateRecordsDelete({
|
|
1411
1409
|
author: alice,
|
|
1412
1410
|
recordId: participantRecord1.message.recordId,
|
|
1413
1411
|
});
|
|
1414
1412
|
const participantDeleteReply = yield dwn.processMessage(alice.did, participantDelete.message);
|
|
1415
|
-
expect(participantDeleteReply.status.code).
|
|
1413
|
+
expect(participantDeleteReply.status.code).toBe(202);
|
|
1416
1414
|
// Alice creates a new 'thread/participant' record
|
|
1417
1415
|
const participantRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
1418
1416
|
author: alice,
|
|
@@ -1422,7 +1420,7 @@ export function testRecordsWriteHandler() {
|
|
|
1422
1420
|
parentContextId: threadRecord.message.contextId,
|
|
1423
1421
|
});
|
|
1424
1422
|
const participantRecordReply2 = yield dwn.processMessage(alice.did, participantRecord2.message, { dataStream: participantRecord2.dataStream });
|
|
1425
|
-
expect(participantRecordReply2.status.code).
|
|
1423
|
+
expect(participantRecordReply2.status.code).toBe(202);
|
|
1426
1424
|
}));
|
|
1427
1425
|
});
|
|
1428
1426
|
describe('role based writes', () => {
|
|
@@ -1437,7 +1435,7 @@ export function testRecordsWriteHandler() {
|
|
|
1437
1435
|
protocolDefinition
|
|
1438
1436
|
});
|
|
1439
1437
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1440
|
-
expect(protocolsConfigureReply.status.code).
|
|
1438
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1441
1439
|
// Alice writes a 'friend' $root-level role record with Bob as recipient
|
|
1442
1440
|
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1443
1441
|
author: alice,
|
|
@@ -1447,7 +1445,7 @@ export function testRecordsWriteHandler() {
|
|
|
1447
1445
|
data: new TextEncoder().encode('Bob is my friend'),
|
|
1448
1446
|
});
|
|
1449
1447
|
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
1450
|
-
expect(friendRoleReply.status.code).
|
|
1448
|
+
expect(friendRoleReply.status.code).toBe(202);
|
|
1451
1449
|
// Bob writes a 'chat' record
|
|
1452
1450
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1453
1451
|
author: bob,
|
|
@@ -1458,7 +1456,7 @@ export function testRecordsWriteHandler() {
|
|
|
1458
1456
|
protocolRole: 'friend'
|
|
1459
1457
|
});
|
|
1460
1458
|
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1461
|
-
expect(chatReply.status.code).
|
|
1459
|
+
expect(chatReply.status.code).toBe(202);
|
|
1462
1460
|
}));
|
|
1463
1461
|
it('uses a root-level role to authorize a co-update', () => __awaiter(this, void 0, void 0, function* () {
|
|
1464
1462
|
// scenario: Alice gives Bob a admin role. Bob invokes his
|
|
@@ -1471,7 +1469,7 @@ export function testRecordsWriteHandler() {
|
|
|
1471
1469
|
protocolDefinition
|
|
1472
1470
|
});
|
|
1473
1471
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1474
|
-
expect(protocolsConfigureReply.status.code).
|
|
1472
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1475
1473
|
// Alice writes a 'admin' root-level role record with Bob as recipient
|
|
1476
1474
|
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1477
1475
|
author: alice,
|
|
@@ -1481,7 +1479,7 @@ export function testRecordsWriteHandler() {
|
|
|
1481
1479
|
data: new TextEncoder().encode('Bob is my friend'),
|
|
1482
1480
|
});
|
|
1483
1481
|
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
1484
|
-
expect(friendRoleReply.status.code).
|
|
1482
|
+
expect(friendRoleReply.status.code).toBe(202);
|
|
1485
1483
|
// Alice creates a 'chat' record
|
|
1486
1484
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1487
1485
|
author: alice,
|
|
@@ -1491,7 +1489,7 @@ export function testRecordsWriteHandler() {
|
|
|
1491
1489
|
data: new TextEncoder().encode('Bob can write this cuz he is Alices friend'),
|
|
1492
1490
|
});
|
|
1493
1491
|
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1494
|
-
expect(chatReply.status.code).
|
|
1492
|
+
expect(chatReply.status.code).toBe(202);
|
|
1495
1493
|
// Bob invokes his admin role to update the 'chat' record
|
|
1496
1494
|
const chatUpdateRecord = yield TestDataGenerator.generateFromRecordsWrite({
|
|
1497
1495
|
author: bob,
|
|
@@ -1499,7 +1497,7 @@ export function testRecordsWriteHandler() {
|
|
|
1499
1497
|
protocolRole: 'admin',
|
|
1500
1498
|
});
|
|
1501
1499
|
const chatUpdateReply = yield dwn.processMessage(alice.did, chatUpdateRecord.message, { dataStream: chatUpdateRecord.dataStream });
|
|
1502
|
-
expect(chatUpdateReply.status.code).
|
|
1500
|
+
expect(chatUpdateReply.status.code).toBe(202);
|
|
1503
1501
|
}));
|
|
1504
1502
|
it('rejects root-level role authorized writes if the protocolRole is not a valid protocol path to an active role record', () => __awaiter(this, void 0, void 0, function* () {
|
|
1505
1503
|
// scenario: Bob tries to invoke the 'chat' role to write to Alice's DWN, but 'chat' is not a role.
|
|
@@ -1511,7 +1509,7 @@ export function testRecordsWriteHandler() {
|
|
|
1511
1509
|
protocolDefinition
|
|
1512
1510
|
});
|
|
1513
1511
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1514
|
-
expect(protocolsConfigureReply.status.code).
|
|
1512
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1515
1513
|
// Alice writes a 'chat' record with Bob as recipient
|
|
1516
1514
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1517
1515
|
author: alice,
|
|
@@ -1521,7 +1519,7 @@ export function testRecordsWriteHandler() {
|
|
|
1521
1519
|
data: new TextEncoder().encode('Blah blah blah'),
|
|
1522
1520
|
});
|
|
1523
1521
|
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1524
|
-
expect(chatReply.status.code).
|
|
1522
|
+
expect(chatReply.status.code).toBe(202);
|
|
1525
1523
|
// Bob tries to invoke a 'chat' role but 'chat' is not a role
|
|
1526
1524
|
const writeChatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1527
1525
|
author: bob,
|
|
@@ -1532,8 +1530,8 @@ export function testRecordsWriteHandler() {
|
|
|
1532
1530
|
protocolRole: 'chat',
|
|
1533
1531
|
});
|
|
1534
1532
|
const chatReadReply = yield dwn.processMessage(alice.did, writeChatRecord.message, { dataStream: writeChatRecord.dataStream });
|
|
1535
|
-
expect(chatReadReply.status.code).
|
|
1536
|
-
expect(chatReadReply.status.detail).
|
|
1533
|
+
expect(chatReadReply.status.code).toBe(401);
|
|
1534
|
+
expect(chatReadReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationNotARole);
|
|
1537
1535
|
}));
|
|
1538
1536
|
it('rejects root-level role authorized writes if there is no active role for the recipient', () => __awaiter(this, void 0, void 0, function* () {
|
|
1539
1537
|
// scenario: Bob tries to invoke a role to write, but he has not been given one.
|
|
@@ -1545,7 +1543,7 @@ export function testRecordsWriteHandler() {
|
|
|
1545
1543
|
protocolDefinition
|
|
1546
1544
|
});
|
|
1547
1545
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1548
|
-
expect(protocolsConfigureReply.status.code).
|
|
1546
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1549
1547
|
// Bob writes a 'chat' record invoking a friend role that he does not have
|
|
1550
1548
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1551
1549
|
author: bob,
|
|
@@ -1556,8 +1554,8 @@ export function testRecordsWriteHandler() {
|
|
|
1556
1554
|
protocolRole: 'friend'
|
|
1557
1555
|
});
|
|
1558
1556
|
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1559
|
-
expect(chatReply.status.code).
|
|
1560
|
-
expect(chatReply.status.detail).
|
|
1557
|
+
expect(chatReply.status.code).toBe(401);
|
|
1558
|
+
expect(chatReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound);
|
|
1561
1559
|
}));
|
|
1562
1560
|
it('uses a context role to authorize a write', () => __awaiter(this, void 0, void 0, function* () {
|
|
1563
1561
|
// scenario: Alice creates a thread and adds Bob to the 'thread/participant' role. Bob invokes the record to write in the thread
|
|
@@ -1569,7 +1567,7 @@ export function testRecordsWriteHandler() {
|
|
|
1569
1567
|
protocolDefinition
|
|
1570
1568
|
});
|
|
1571
1569
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1572
|
-
expect(protocolsConfigureReply.status.code).
|
|
1570
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1573
1571
|
// Alice creates a thread
|
|
1574
1572
|
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1575
1573
|
author: alice,
|
|
@@ -1578,7 +1576,7 @@ export function testRecordsWriteHandler() {
|
|
|
1578
1576
|
protocolPath: 'thread'
|
|
1579
1577
|
});
|
|
1580
1578
|
const threadRecordReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
1581
|
-
expect(threadRecordReply.status.code).
|
|
1579
|
+
expect(threadRecordReply.status.code).toBe(202);
|
|
1582
1580
|
// Alice adds Bob as a 'thread/participant' in that thread
|
|
1583
1581
|
const participantRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1584
1582
|
author: alice,
|
|
@@ -1588,7 +1586,7 @@ export function testRecordsWriteHandler() {
|
|
|
1588
1586
|
parentContextId: threadRecord.message.contextId,
|
|
1589
1587
|
});
|
|
1590
1588
|
const participantRecordReply = yield dwn.processMessage(alice.did, participantRecord.message, { dataStream: participantRecord.dataStream });
|
|
1591
|
-
expect(participantRecordReply.status.code).
|
|
1589
|
+
expect(participantRecordReply.status.code).toBe(202);
|
|
1592
1590
|
// Bob invokes the role to write to the thread
|
|
1593
1591
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1594
1592
|
author: bob,
|
|
@@ -1598,7 +1596,7 @@ export function testRecordsWriteHandler() {
|
|
|
1598
1596
|
protocolRole: 'thread/participant'
|
|
1599
1597
|
});
|
|
1600
1598
|
const chatRecordReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1601
|
-
expect(chatRecordReply.status.code).
|
|
1599
|
+
expect(chatRecordReply.status.code).toBe(202);
|
|
1602
1600
|
}));
|
|
1603
1601
|
it('uses a context role to authorize a co-update', () => __awaiter(this, void 0, void 0, function* () {
|
|
1604
1602
|
// scenario: Alice creates a thread and adds Bob to the 'thread/admin' role.
|
|
@@ -1611,7 +1609,7 @@ export function testRecordsWriteHandler() {
|
|
|
1611
1609
|
protocolDefinition
|
|
1612
1610
|
});
|
|
1613
1611
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1614
|
-
expect(protocolsConfigureReply.status.code).
|
|
1612
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1615
1613
|
// Alice creates a thread
|
|
1616
1614
|
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1617
1615
|
author: alice,
|
|
@@ -1620,7 +1618,7 @@ export function testRecordsWriteHandler() {
|
|
|
1620
1618
|
protocolPath: 'thread'
|
|
1621
1619
|
});
|
|
1622
1620
|
const threadRecordReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
1623
|
-
expect(threadRecordReply.status.code).
|
|
1621
|
+
expect(threadRecordReply.status.code).toBe(202);
|
|
1624
1622
|
// Alice adds Bob as a 'thread/participant' in that thread
|
|
1625
1623
|
const participantRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1626
1624
|
author: alice,
|
|
@@ -1630,7 +1628,7 @@ export function testRecordsWriteHandler() {
|
|
|
1630
1628
|
parentContextId: threadRecord.message.contextId,
|
|
1631
1629
|
});
|
|
1632
1630
|
const participantRecordReply = yield dwn.processMessage(alice.did, participantRecord.message, { dataStream: participantRecord.dataStream });
|
|
1633
|
-
expect(participantRecordReply.status.code).
|
|
1631
|
+
expect(participantRecordReply.status.code).toBe(202);
|
|
1634
1632
|
// Alice writes a chat message in the thread
|
|
1635
1633
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1636
1634
|
author: alice,
|
|
@@ -1639,7 +1637,7 @@ export function testRecordsWriteHandler() {
|
|
|
1639
1637
|
parentContextId: threadRecord.message.contextId,
|
|
1640
1638
|
});
|
|
1641
1639
|
const chatRecordReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1642
|
-
expect(chatRecordReply.status.code).
|
|
1640
|
+
expect(chatRecordReply.status.code).toBe(202);
|
|
1643
1641
|
// Bob invokes his admin role to co-update the chat message
|
|
1644
1642
|
const chatCoUpdateRecord = yield TestDataGenerator.generateFromRecordsWrite({
|
|
1645
1643
|
author: bob,
|
|
@@ -1647,7 +1645,7 @@ export function testRecordsWriteHandler() {
|
|
|
1647
1645
|
protocolRole: 'thread/admin',
|
|
1648
1646
|
});
|
|
1649
1647
|
const chatUpdateRecordReply = yield dwn.processMessage(alice.did, chatCoUpdateRecord.message, { dataStream: chatCoUpdateRecord.dataStream });
|
|
1650
|
-
expect(chatUpdateRecordReply.status.code).
|
|
1648
|
+
expect(chatUpdateRecordReply.status.code).toBe(202);
|
|
1651
1649
|
}));
|
|
1652
1650
|
it('rejects context role authorized writes if the protocolRole is not a valid protocol path to an active role record', () => __awaiter(this, void 0, void 0, function* () {
|
|
1653
1651
|
// scenario: Alice creates a thread and adds Bob as a participant. ALice creates another thread. Bob tries and fails to invoke his
|
|
@@ -1660,7 +1658,7 @@ export function testRecordsWriteHandler() {
|
|
|
1660
1658
|
protocolDefinition
|
|
1661
1659
|
});
|
|
1662
1660
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1663
|
-
expect(protocolsConfigureReply.status.code).
|
|
1661
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1664
1662
|
// Alice creates a thread
|
|
1665
1663
|
const threadRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
1666
1664
|
author: alice,
|
|
@@ -1669,7 +1667,7 @@ export function testRecordsWriteHandler() {
|
|
|
1669
1667
|
protocolPath: 'thread'
|
|
1670
1668
|
});
|
|
1671
1669
|
const threadRecordReply1 = yield dwn.processMessage(alice.did, threadRecord1.message, { dataStream: threadRecord1.dataStream });
|
|
1672
|
-
expect(threadRecordReply1.status.code).
|
|
1670
|
+
expect(threadRecordReply1.status.code).toBe(202);
|
|
1673
1671
|
// Alice adds Bob as a 'thread/participant' in that thread
|
|
1674
1672
|
const participantRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1675
1673
|
author: alice,
|
|
@@ -1679,7 +1677,7 @@ export function testRecordsWriteHandler() {
|
|
|
1679
1677
|
parentContextId: threadRecord1.message.contextId,
|
|
1680
1678
|
});
|
|
1681
1679
|
const participantRecordReply = yield dwn.processMessage(alice.did, participantRecord.message, { dataStream: participantRecord.dataStream });
|
|
1682
|
-
expect(participantRecordReply.status.code).
|
|
1680
|
+
expect(participantRecordReply.status.code).toBe(202);
|
|
1683
1681
|
// Alice creates a second thread
|
|
1684
1682
|
const threadRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
1685
1683
|
author: alice,
|
|
@@ -1688,7 +1686,7 @@ export function testRecordsWriteHandler() {
|
|
|
1688
1686
|
protocolPath: 'thread'
|
|
1689
1687
|
});
|
|
1690
1688
|
const threadRecordReply2 = yield dwn.processMessage(alice.did, threadRecord2.message, { dataStream: threadRecord2.dataStream });
|
|
1691
|
-
expect(threadRecordReply2.status.code).
|
|
1689
|
+
expect(threadRecordReply2.status.code).toBe(202);
|
|
1692
1690
|
// Bob invokes his role to try to write to the second thread
|
|
1693
1691
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
1694
1692
|
author: bob,
|
|
@@ -1698,8 +1696,8 @@ export function testRecordsWriteHandler() {
|
|
|
1698
1696
|
protocolRole: 'thread/participant'
|
|
1699
1697
|
});
|
|
1700
1698
|
const chatRecordReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1701
|
-
expect(chatRecordReply.status.code).
|
|
1702
|
-
expect(chatRecordReply.status.detail).
|
|
1699
|
+
expect(chatRecordReply.status.code).toBe(401);
|
|
1700
|
+
expect(chatRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound);
|
|
1703
1701
|
}));
|
|
1704
1702
|
it('rejects attempts to invoke an invalid path as a protocolRole', () => __awaiter(this, void 0, void 0, function* () {
|
|
1705
1703
|
// scenario: Bob tries to invoke 'notARealPath' as a protocolRole and fails
|
|
@@ -1711,7 +1709,7 @@ export function testRecordsWriteHandler() {
|
|
|
1711
1709
|
protocolDefinition
|
|
1712
1710
|
});
|
|
1713
1711
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1714
|
-
expect(protocolsConfigureReply.status.code).
|
|
1712
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1715
1713
|
// Bob invokes a fake protocolRole to write
|
|
1716
1714
|
const fakeRoleInvocation = yield TestDataGenerator.generateRecordsWrite({
|
|
1717
1715
|
author: bob,
|
|
@@ -1721,8 +1719,8 @@ export function testRecordsWriteHandler() {
|
|
|
1721
1719
|
protocolRole: 'notARealPath',
|
|
1722
1720
|
});
|
|
1723
1721
|
const fakeRoleInvocationReply = yield dwn.processMessage(alice.did, fakeRoleInvocation.message, { dataStream: fakeRoleInvocation.dataStream });
|
|
1724
|
-
expect(fakeRoleInvocationReply.status.code).
|
|
1725
|
-
expect(fakeRoleInvocationReply.status.detail).
|
|
1722
|
+
expect(fakeRoleInvocationReply.status.code).toBe(401);
|
|
1723
|
+
expect(fakeRoleInvocationReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationNotARole);
|
|
1726
1724
|
}));
|
|
1727
1725
|
});
|
|
1728
1726
|
});
|
|
@@ -1741,7 +1739,7 @@ export function testRecordsWriteHandler() {
|
|
|
1741
1739
|
// setting up a stub DID resolver
|
|
1742
1740
|
TestStubGenerator.stubDidResolver(didResolver, [alice, bob]);
|
|
1743
1741
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1744
|
-
expect(protocolsConfigureReply.status.code).
|
|
1742
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1745
1743
|
// generate a `RecordsWrite` message from bob
|
|
1746
1744
|
const bobData = new TextEncoder().encode('message from bob');
|
|
1747
1745
|
const messageFromBob = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1753,16 +1751,16 @@ export function testRecordsWriteHandler() {
|
|
|
1753
1751
|
data: bobData
|
|
1754
1752
|
});
|
|
1755
1753
|
const bobWriteReply = yield dwn.processMessage(alice.did, messageFromBob.message, { dataStream: messageFromBob.dataStream });
|
|
1756
|
-
expect(bobWriteReply.status.code).
|
|
1754
|
+
expect(bobWriteReply.status.code).toBe(202);
|
|
1757
1755
|
// verify bob's message got written to the DB
|
|
1758
1756
|
const messageDataForQueryingBobsWrite = yield TestDataGenerator.generateRecordsQuery({
|
|
1759
1757
|
author: alice,
|
|
1760
1758
|
filter: { recordId: messageFromBob.message.recordId }
|
|
1761
1759
|
});
|
|
1762
1760
|
const bobRecordsQueryReply = yield dwn.processMessage(alice.did, messageDataForQueryingBobsWrite.message);
|
|
1763
|
-
expect(bobRecordsQueryReply.status.code).
|
|
1764
|
-
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
1765
|
-
expect(bobRecordsQueryReply.entries[0].encodedData).
|
|
1761
|
+
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1762
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
1763
|
+
expect(bobRecordsQueryReply.entries[0].encodedData).toBe(base64url.baseEncode(bobData));
|
|
1766
1764
|
// generate a new message from bob updating the existing message
|
|
1767
1765
|
const updatedMessageBytes = Encoder.stringToBytes('updated message from bob');
|
|
1768
1766
|
const updatedMessageFromBob = yield TestDataGenerator.generateFromRecordsWrite({
|
|
@@ -1771,12 +1769,12 @@ export function testRecordsWriteHandler() {
|
|
|
1771
1769
|
data: updatedMessageBytes
|
|
1772
1770
|
});
|
|
1773
1771
|
const newWriteReply = yield dwn.processMessage(alice.did, updatedMessageFromBob.message, { dataStream: updatedMessageFromBob.dataStream });
|
|
1774
|
-
expect(newWriteReply.status.code).
|
|
1772
|
+
expect(newWriteReply.status.code).toBe(202);
|
|
1775
1773
|
// verify bob's message got written to the DB
|
|
1776
1774
|
const newRecordQueryReply = yield dwn.processMessage(alice.did, messageDataForQueryingBobsWrite.message);
|
|
1777
|
-
expect(newRecordQueryReply.status.code).
|
|
1778
|
-
expect((_b = newRecordQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
1779
|
-
expect(newRecordQueryReply.entries[0].encodedData).
|
|
1775
|
+
expect(newRecordQueryReply.status.code).toBe(200);
|
|
1776
|
+
expect((_b = newRecordQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
|
|
1777
|
+
expect(newRecordQueryReply.entries[0].encodedData).toBe(Encoder.bytesToBase64Url(updatedMessageBytes));
|
|
1780
1778
|
}));
|
|
1781
1779
|
it('should disallow overwriting existing records by a different author if author is not authorized to `co-update`', () => __awaiter(this, void 0, void 0, function* () {
|
|
1782
1780
|
// scenario: Bob writes into Alice's DWN given Alice's "message" protocol, Carol then attempts to modify the existing message
|
|
@@ -1794,7 +1792,7 @@ export function testRecordsWriteHandler() {
|
|
|
1794
1792
|
// setting up a stub DID resolver
|
|
1795
1793
|
TestStubGenerator.stubDidResolver(didResolver, [alice, bob, carol]);
|
|
1796
1794
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1797
|
-
expect(protocolsConfigureReply.status.code).
|
|
1795
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1798
1796
|
// generate a `RecordsWrite` message from bob
|
|
1799
1797
|
const bobData = new TextEncoder().encode('data from bob');
|
|
1800
1798
|
const messageFromBob = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1806,16 +1804,16 @@ export function testRecordsWriteHandler() {
|
|
|
1806
1804
|
data: bobData
|
|
1807
1805
|
});
|
|
1808
1806
|
const bobWriteReply = yield dwn.processMessage(alice.did, messageFromBob.message, { dataStream: messageFromBob.dataStream });
|
|
1809
|
-
expect(bobWriteReply.status.code).
|
|
1807
|
+
expect(bobWriteReply.status.code).toBe(202);
|
|
1810
1808
|
// verify bob's message got written to the DB
|
|
1811
1809
|
const messageDataForQueryingBobsWrite = yield TestDataGenerator.generateRecordsQuery({
|
|
1812
1810
|
author: alice,
|
|
1813
1811
|
filter: { recordId: messageFromBob.message.recordId }
|
|
1814
1812
|
});
|
|
1815
1813
|
const bobRecordsQueryReply = yield dwn.processMessage(alice.did, messageDataForQueryingBobsWrite.message);
|
|
1816
|
-
expect(bobRecordsQueryReply.status.code).
|
|
1817
|
-
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
1818
|
-
expect(bobRecordsQueryReply.entries[0].encodedData).
|
|
1814
|
+
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1815
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
1816
|
+
expect(bobRecordsQueryReply.entries[0].encodedData).toBe(base64url.baseEncode(bobData));
|
|
1819
1817
|
// generate a new message from carol updating the existing message, which should not be allowed/accepted
|
|
1820
1818
|
const modifiedMessageData = new TextEncoder().encode('modified message by carol');
|
|
1821
1819
|
const modifiedMessageFromCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1828,8 +1826,8 @@ export function testRecordsWriteHandler() {
|
|
|
1828
1826
|
recordId: messageFromBob.message.recordId,
|
|
1829
1827
|
});
|
|
1830
1828
|
const carolWriteReply = yield dwn.processMessage(alice.did, modifiedMessageFromCarol.message, { dataStream: modifiedMessageFromCarol.dataStream });
|
|
1831
|
-
expect(carolWriteReply.status.code).
|
|
1832
|
-
expect(carolWriteReply.status.detail).
|
|
1829
|
+
expect(carolWriteReply.status.code).toBe(401);
|
|
1830
|
+
expect(carolWriteReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
1833
1831
|
}));
|
|
1834
1832
|
it('should not allow to change immutable recipient', () => __awaiter(this, void 0, void 0, function* () {
|
|
1835
1833
|
// scenario: Bob writes into Alice's DWN given Alice's "message" protocol allow-anyone rule, then tries to modify immutable recipient
|
|
@@ -1848,7 +1846,7 @@ export function testRecordsWriteHandler() {
|
|
|
1848
1846
|
// setting up a stub DID resolver
|
|
1849
1847
|
TestStubGenerator.stubDidResolver(didResolver, [alice, bob]);
|
|
1850
1848
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1851
|
-
expect(protocolsConfigureReply.status.code).
|
|
1849
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1852
1850
|
// generate a `RecordsWrite` message from bob
|
|
1853
1851
|
const bobData = new TextEncoder().encode('message from bob');
|
|
1854
1852
|
const messageFromBob = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1860,16 +1858,16 @@ export function testRecordsWriteHandler() {
|
|
|
1860
1858
|
data: bobData
|
|
1861
1859
|
});
|
|
1862
1860
|
const bobWriteReply = yield dwn.processMessage(alice.did, messageFromBob.message, { dataStream: messageFromBob.dataStream });
|
|
1863
|
-
expect(bobWriteReply.status.code).
|
|
1861
|
+
expect(bobWriteReply.status.code).toBe(202);
|
|
1864
1862
|
// verify bob's message got written to the DB
|
|
1865
1863
|
const messageDataForQueryingBobsWrite = yield TestDataGenerator.generateRecordsQuery({
|
|
1866
1864
|
author: alice,
|
|
1867
1865
|
filter: { recordId: messageFromBob.message.recordId }
|
|
1868
1866
|
});
|
|
1869
1867
|
const bobRecordsQueryReply = yield dwn.processMessage(alice.did, messageDataForQueryingBobsWrite.message);
|
|
1870
|
-
expect(bobRecordsQueryReply.status.code).
|
|
1871
|
-
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
1872
|
-
expect(bobRecordsQueryReply.entries[0].encodedData).
|
|
1868
|
+
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1869
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
1870
|
+
expect(bobRecordsQueryReply.entries[0].encodedData).toBe(base64url.baseEncode(bobData));
|
|
1873
1871
|
// generate a new message from bob changing immutable recipient
|
|
1874
1872
|
const updatedMessageFromBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1875
1873
|
author: bob,
|
|
@@ -1883,8 +1881,8 @@ export function testRecordsWriteHandler() {
|
|
|
1883
1881
|
recipient: bob.did // this immutable property was Alice's DID initially
|
|
1884
1882
|
});
|
|
1885
1883
|
const newWriteReply = yield dwn.processMessage(alice.did, updatedMessageFromBob.message, { dataStream: updatedMessageFromBob.dataStream });
|
|
1886
|
-
expect(newWriteReply.status.code).
|
|
1887
|
-
expect(newWriteReply.status.detail).
|
|
1884
|
+
expect(newWriteReply.status.code).toBe(400);
|
|
1885
|
+
expect(newWriteReply.status.detail).toContain('recipient is an immutable property');
|
|
1888
1886
|
}));
|
|
1889
1887
|
it('should block unauthorized write with recipient rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
1890
1888
|
// scenario: fake VC issuer attempts write into Alice's DWN a credential response
|
|
@@ -1902,7 +1900,7 @@ export function testRecordsWriteHandler() {
|
|
|
1902
1900
|
// setting up a stub DID resolver
|
|
1903
1901
|
TestStubGenerator.stubDidResolver(didResolver, [alice, fakeVcIssuer]);
|
|
1904
1902
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1905
|
-
expect(protocolsConfigureReply.status.code).
|
|
1903
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1906
1904
|
// write a credential application to Alice's DWN to simulate that she has sent a credential application to a VC issuer
|
|
1907
1905
|
const vcIssuer = yield TestDataGenerator.generatePersona();
|
|
1908
1906
|
const encodedCredentialApplication = new TextEncoder().encode('credential application data');
|
|
@@ -1917,7 +1915,7 @@ export function testRecordsWriteHandler() {
|
|
|
1917
1915
|
});
|
|
1918
1916
|
const credentialApplicationContextId = yield credentialApplication.recordsWrite.getEntryId();
|
|
1919
1917
|
const credentialApplicationReply = yield dwn.processMessage(alice.did, credentialApplication.message, { dataStream: credentialApplication.dataStream });
|
|
1920
|
-
expect(credentialApplicationReply.status.code).
|
|
1918
|
+
expect(credentialApplicationReply.status.code).toBe(202);
|
|
1921
1919
|
// generate a credential application response message from a fake VC issuer
|
|
1922
1920
|
const encodedCredentialResponse = new TextEncoder().encode('credential response data');
|
|
1923
1921
|
const credentialResponse = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -1931,8 +1929,8 @@ export function testRecordsWriteHandler() {
|
|
|
1931
1929
|
data: encodedCredentialResponse
|
|
1932
1930
|
});
|
|
1933
1931
|
const credentialResponseReply = yield dwn.processMessage(alice.did, credentialResponse.message, { dataStream: credentialResponse.dataStream });
|
|
1934
|
-
expect(credentialResponseReply.status.code).
|
|
1935
|
-
expect(credentialResponseReply.status.detail).
|
|
1932
|
+
expect(credentialResponseReply.status.code).toBe(401);
|
|
1933
|
+
expect(credentialResponseReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
1936
1934
|
}));
|
|
1937
1935
|
it('should fail authorization if protocol definition cannot be found for a protocol-based RecordsWrite', () => __awaiter(this, void 0, void 0, function* () {
|
|
1938
1936
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -1946,8 +1944,8 @@ export function testRecordsWriteHandler() {
|
|
|
1946
1944
|
data
|
|
1947
1945
|
});
|
|
1948
1946
|
const reply = yield dwn.processMessage(alice.did, credentialApplication.message, { dataStream: credentialApplication.dataStream });
|
|
1949
|
-
expect(reply.status.code).
|
|
1950
|
-
expect(reply.status.detail).
|
|
1947
|
+
expect(reply.status.code).toBe(400);
|
|
1948
|
+
expect(reply.status.detail).toContain('unable to find protocol definition');
|
|
1951
1949
|
}));
|
|
1952
1950
|
it('should fail authorization if record schema is incorrect for a protocol-based RecordsWrite', () => __awaiter(this, void 0, void 0, function* () {
|
|
1953
1951
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -1958,7 +1956,7 @@ export function testRecordsWriteHandler() {
|
|
|
1958
1956
|
protocolDefinition
|
|
1959
1957
|
});
|
|
1960
1958
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
1961
|
-
expect(protocolConfigureReply.status.code).
|
|
1959
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
1962
1960
|
const data = Encoder.stringToBytes('any data');
|
|
1963
1961
|
const credentialApplication = yield TestDataGenerator.generateRecordsWrite({
|
|
1964
1962
|
author: alice,
|
|
@@ -1969,8 +1967,8 @@ export function testRecordsWriteHandler() {
|
|
|
1969
1967
|
data
|
|
1970
1968
|
});
|
|
1971
1969
|
const reply = yield dwn.processMessage(alice.did, credentialApplication.message, { dataStream: credentialApplication.dataStream });
|
|
1972
|
-
expect(reply.status.code).
|
|
1973
|
-
expect(reply.status.detail).
|
|
1970
|
+
expect(reply.status.code).toBe(400);
|
|
1971
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationInvalidSchema);
|
|
1974
1972
|
}));
|
|
1975
1973
|
it('should fail authorization if given `protocolPath` contains an invalid record type', () => __awaiter(this, void 0, void 0, function* () {
|
|
1976
1974
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -1981,7 +1979,7 @@ export function testRecordsWriteHandler() {
|
|
|
1981
1979
|
protocolDefinition
|
|
1982
1980
|
});
|
|
1983
1981
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
1984
|
-
expect(protocolConfigureReply.status.code).
|
|
1982
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
1985
1983
|
const data = Encoder.stringToBytes('any data');
|
|
1986
1984
|
const credentialApplication = yield TestDataGenerator.generateRecordsWrite({
|
|
1987
1985
|
author: alice,
|
|
@@ -1991,8 +1989,8 @@ export function testRecordsWriteHandler() {
|
|
|
1991
1989
|
data
|
|
1992
1990
|
});
|
|
1993
1991
|
const reply = yield dwn.processMessage(alice.did, credentialApplication.message, { dataStream: credentialApplication.dataStream });
|
|
1994
|
-
expect(reply.status.code).
|
|
1995
|
-
expect(reply.status.detail).
|
|
1992
|
+
expect(reply.status.code).toBe(400);
|
|
1993
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationInvalidType);
|
|
1996
1994
|
}));
|
|
1997
1995
|
it('should fail authorization if given `protocolPath` is mismatching with actual path', () => __awaiter(this, void 0, void 0, function* () {
|
|
1998
1996
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -2003,7 +2001,7 @@ export function testRecordsWriteHandler() {
|
|
|
2003
2001
|
protocolDefinition,
|
|
2004
2002
|
});
|
|
2005
2003
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2006
|
-
expect(protocolConfigureReply.status.code).
|
|
2004
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2007
2005
|
const data = Encoder.stringToBytes('any data');
|
|
2008
2006
|
const credentialApplication = yield TestDataGenerator.generateRecordsWrite({
|
|
2009
2007
|
author: alice,
|
|
@@ -2014,9 +2012,9 @@ export function testRecordsWriteHandler() {
|
|
|
2014
2012
|
data
|
|
2015
2013
|
});
|
|
2016
2014
|
const reply = yield dwn.processMessage(alice.did, credentialApplication.message, { dataStream: credentialApplication.dataStream });
|
|
2017
|
-
expect(reply.status.code).
|
|
2018
|
-
expect(reply.status.detail).
|
|
2019
|
-
expect(reply.status.detail).
|
|
2015
|
+
expect(reply.status.code).toBe(400);
|
|
2016
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationParentlessIncorrectProtocolPath);
|
|
2017
|
+
expect(reply.status.detail).toContain('is not valid for records with no parent');
|
|
2020
2018
|
}));
|
|
2021
2019
|
it('#690 - should only allow data format of a protocol-space record to be updated to any value allowed by the protocol configuration', () => __awaiter(this, void 0, void 0, function* () {
|
|
2022
2020
|
var _a;
|
|
@@ -2028,7 +2026,7 @@ export function testRecordsWriteHandler() {
|
|
|
2028
2026
|
protocolDefinition: protocolDefinition,
|
|
2029
2027
|
});
|
|
2030
2028
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2031
|
-
expect(protocolConfigureReply.status.code).
|
|
2029
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2032
2030
|
// write image record
|
|
2033
2031
|
const data = TestDataGenerator.randomBytes(100);
|
|
2034
2032
|
const imageRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2041,7 +2039,7 @@ export function testRecordsWriteHandler() {
|
|
|
2041
2039
|
data
|
|
2042
2040
|
});
|
|
2043
2041
|
const writeReply = yield dwn.processMessage(alice.did, imageRecordsWrite.message, { dataStream: imageRecordsWrite.dataStream });
|
|
2044
|
-
expect(writeReply.status.code).
|
|
2042
|
+
expect(writeReply.status.code).toBe(202);
|
|
2045
2043
|
// update the image to a not-allowed data format
|
|
2046
2044
|
const newDataBytes = TestDataGenerator.randomBytes(100);
|
|
2047
2045
|
const notAllowedUpdateWrite = yield RecordsWrite.createFrom({
|
|
@@ -2052,8 +2050,8 @@ export function testRecordsWriteHandler() {
|
|
|
2052
2050
|
});
|
|
2053
2051
|
const newDataStream = DataStream.fromBytes(newDataBytes);
|
|
2054
2052
|
const notAllowedUpdateWriteReply = yield dwn.processMessage(alice.did, notAllowedUpdateWrite.message, { dataStream: newDataStream });
|
|
2055
|
-
expect(notAllowedUpdateWriteReply.status.code).
|
|
2056
|
-
expect(notAllowedUpdateWriteReply.status.detail).
|
|
2053
|
+
expect(notAllowedUpdateWriteReply.status.code).toBe(400);
|
|
2054
|
+
expect(notAllowedUpdateWriteReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationIncorrectDataFormat);
|
|
2057
2055
|
// update the image to a different allowed dataFormat
|
|
2058
2056
|
const updateWrite = yield RecordsWrite.createFrom({
|
|
2059
2057
|
recordsWriteMessage: imageRecordsWrite.message,
|
|
@@ -2062,15 +2060,15 @@ export function testRecordsWriteHandler() {
|
|
|
2062
2060
|
data: newDataBytes
|
|
2063
2061
|
});
|
|
2064
2062
|
const updateReply = yield dwn.processMessage(alice.did, updateWrite.message, { dataStream: newDataStream });
|
|
2065
|
-
expect(updateReply.status.code).
|
|
2063
|
+
expect(updateReply.status.code).toBe(202);
|
|
2066
2064
|
// verify the data format of the record is updated
|
|
2067
2065
|
const recordsRead = yield RecordsRead.create({
|
|
2068
2066
|
filter: { recordId: imageRecordsWrite.message.recordId },
|
|
2069
2067
|
signer: Jws.createSigner(alice),
|
|
2070
2068
|
});
|
|
2071
2069
|
const recordsReadReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
2072
|
-
expect(recordsReadReply.status.code).
|
|
2073
|
-
expect((_a = recordsReadReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor.dataFormat).
|
|
2070
|
+
expect(recordsReadReply.status.code).toBe(200);
|
|
2071
|
+
expect((_a = recordsReadReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor.dataFormat).toBe(protocolDefinition.types.image.dataFormats[1]);
|
|
2074
2072
|
}));
|
|
2075
2073
|
it('#690 - should allow any data format for a record if protocol definition does not explicitly specify the list of allowed data formats', () => __awaiter(this, void 0, void 0, function* () {
|
|
2076
2074
|
var _a;
|
|
@@ -2082,7 +2080,7 @@ export function testRecordsWriteHandler() {
|
|
|
2082
2080
|
protocolDefinition: protocolDefinition,
|
|
2083
2081
|
});
|
|
2084
2082
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2085
|
-
expect(protocolConfigureReply.status.code).
|
|
2083
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2086
2084
|
// write image record
|
|
2087
2085
|
const data = TestDataGenerator.randomBytes(100);
|
|
2088
2086
|
const imageRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2095,7 +2093,7 @@ export function testRecordsWriteHandler() {
|
|
|
2095
2093
|
data
|
|
2096
2094
|
});
|
|
2097
2095
|
const writeReply = yield dwn.processMessage(alice.did, imageRecordsWrite.message, { dataStream: imageRecordsWrite.dataStream });
|
|
2098
|
-
expect(writeReply.status.code).
|
|
2096
|
+
expect(writeReply.status.code).toBe(202);
|
|
2099
2097
|
// update the image to a different data format
|
|
2100
2098
|
const newDataFormat = 'any-new-data-format';
|
|
2101
2099
|
const newDataBytes = TestDataGenerator.randomBytes(100);
|
|
@@ -2107,15 +2105,15 @@ export function testRecordsWriteHandler() {
|
|
|
2107
2105
|
});
|
|
2108
2106
|
const newDataStream = DataStream.fromBytes(newDataBytes);
|
|
2109
2107
|
const updateReply = yield dwn.processMessage(alice.did, updateWrite.message, { dataStream: newDataStream });
|
|
2110
|
-
expect(updateReply.status.code).
|
|
2108
|
+
expect(updateReply.status.code).toBe(202);
|
|
2111
2109
|
// verify the data format of the record is updated
|
|
2112
2110
|
const recordsRead = yield RecordsRead.create({
|
|
2113
2111
|
filter: { recordId: imageRecordsWrite.message.recordId },
|
|
2114
2112
|
signer: Jws.createSigner(alice),
|
|
2115
2113
|
});
|
|
2116
2114
|
const recordsReadReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
2117
|
-
expect(recordsReadReply.status.code).
|
|
2118
|
-
expect((_a = recordsReadReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor.dataFormat).
|
|
2115
|
+
expect(recordsReadReply.status.code).toBe(200);
|
|
2116
|
+
expect((_a = recordsReadReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor.dataFormat).toBe(newDataFormat);
|
|
2119
2117
|
}));
|
|
2120
2118
|
it('should fail authorization if record schema is not allowed at the hierarchical level attempted for the RecordsWrite', () => __awaiter(this, void 0, void 0, function* () {
|
|
2121
2119
|
// scenario: Attempt writing of records at 3 levels in the hierarchy to cover all possible cases of missing rule sets
|
|
@@ -2129,7 +2127,7 @@ export function testRecordsWriteHandler() {
|
|
|
2129
2127
|
const credentialApplicationSchema = protocolDefinition.types.credentialApplication.schema;
|
|
2130
2128
|
const credentialResponseSchema = protocolDefinition.types.credentialResponse.schema;
|
|
2131
2129
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2132
|
-
expect(protocolConfigureReply.status.code).
|
|
2130
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2133
2131
|
// Try and fail to write a 'credentialResponse', which is not allowed at the top level of the record hierarchy
|
|
2134
2132
|
const data = Encoder.stringToBytes('any data');
|
|
2135
2133
|
const failedCredentialResponse = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2141,8 +2139,8 @@ export function testRecordsWriteHandler() {
|
|
|
2141
2139
|
data
|
|
2142
2140
|
});
|
|
2143
2141
|
const failedCredentialResponseReply = yield dwn.processMessage(alice.did, failedCredentialResponse.message, { dataStream: failedCredentialResponse.dataStream });
|
|
2144
|
-
expect(failedCredentialResponseReply.status.code).
|
|
2145
|
-
expect(failedCredentialResponseReply.status.detail).
|
|
2142
|
+
expect(failedCredentialResponseReply.status.code).toBe(400);
|
|
2143
|
+
expect(failedCredentialResponseReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMissingRuleSet);
|
|
2146
2144
|
// Successfully write a 'credentialApplication' at the top level of the of the record hierarchy
|
|
2147
2145
|
const credentialApplication = yield TestDataGenerator.generateRecordsWrite({
|
|
2148
2146
|
author: alice,
|
|
@@ -2153,7 +2151,7 @@ export function testRecordsWriteHandler() {
|
|
|
2153
2151
|
data
|
|
2154
2152
|
});
|
|
2155
2153
|
const credentialApplicationReply = yield dwn.processMessage(alice.did, credentialApplication.message, { dataStream: credentialApplication.dataStream });
|
|
2156
|
-
expect(credentialApplicationReply.status.code).
|
|
2154
|
+
expect(credentialApplicationReply.status.code).toBe(202);
|
|
2157
2155
|
// Try and fail to write another 'credentialApplication' below the first 'credentialApplication'
|
|
2158
2156
|
const failedCredentialApplication = yield TestDataGenerator.generateRecordsWrite({
|
|
2159
2157
|
author: alice,
|
|
@@ -2165,8 +2163,8 @@ export function testRecordsWriteHandler() {
|
|
|
2165
2163
|
data
|
|
2166
2164
|
});
|
|
2167
2165
|
const failedCredentialApplicationReply2 = yield dwn.processMessage(alice.did, failedCredentialApplication.message, { dataStream: failedCredentialApplication.dataStream });
|
|
2168
|
-
expect(failedCredentialApplicationReply2.status.code).
|
|
2169
|
-
expect(failedCredentialApplicationReply2.status.detail).
|
|
2166
|
+
expect(failedCredentialApplicationReply2.status.code).toBe(400);
|
|
2167
|
+
expect(failedCredentialApplicationReply2.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMissingRuleSet);
|
|
2170
2168
|
// Successfully write a 'credentialResponse' below the 'credentialApplication'
|
|
2171
2169
|
const credentialResponse = yield TestDataGenerator.generateRecordsWrite({
|
|
2172
2170
|
author: alice,
|
|
@@ -2178,7 +2176,7 @@ export function testRecordsWriteHandler() {
|
|
|
2178
2176
|
data
|
|
2179
2177
|
});
|
|
2180
2178
|
const credentialResponseReply = yield dwn.processMessage(alice.did, credentialResponse.message, { dataStream: credentialResponse.dataStream });
|
|
2181
|
-
expect(credentialResponseReply.status.code).
|
|
2179
|
+
expect(credentialResponseReply.status.code).toBe(202);
|
|
2182
2180
|
// Try and fail to write a 'credentialApplication' below 'credentialApplication/credentialResponse'
|
|
2183
2181
|
// Testing case where there is no rule set for any record type at the given level in the hierarchy
|
|
2184
2182
|
const nestedCredentialApplication = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2191,8 +2189,8 @@ export function testRecordsWriteHandler() {
|
|
|
2191
2189
|
data
|
|
2192
2190
|
});
|
|
2193
2191
|
const nestedCredentialApplicationReply = yield dwn.processMessage(alice.did, nestedCredentialApplication.message, { dataStream: nestedCredentialApplication.dataStream });
|
|
2194
|
-
expect(nestedCredentialApplicationReply.status.code).
|
|
2195
|
-
expect(nestedCredentialApplicationReply.status.detail).
|
|
2192
|
+
expect(nestedCredentialApplicationReply.status.code).toBe(400);
|
|
2193
|
+
expect(nestedCredentialApplicationReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMissingRuleSet);
|
|
2196
2194
|
}));
|
|
2197
2195
|
it('should only allow DWN owner to write if record does not have an action rule defined', () => __awaiter(this, void 0, void 0, function* () {
|
|
2198
2196
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -2204,7 +2202,7 @@ export function testRecordsWriteHandler() {
|
|
|
2204
2202
|
protocolDefinition
|
|
2205
2203
|
});
|
|
2206
2204
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2207
|
-
expect(protocolConfigureReply.status.code).
|
|
2205
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2208
2206
|
// test that Alice is allowed to write to her own DWN
|
|
2209
2207
|
const data = Encoder.stringToBytes('any data');
|
|
2210
2208
|
const aliceWriteMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2217,7 +2215,7 @@ export function testRecordsWriteHandler() {
|
|
|
2217
2215
|
data
|
|
2218
2216
|
});
|
|
2219
2217
|
let reply = yield dwn.processMessage(alice.did, aliceWriteMessageData.message, { dataStream: aliceWriteMessageData.dataStream });
|
|
2220
|
-
expect(reply.status.code).
|
|
2218
|
+
expect(reply.status.code).toBe(202);
|
|
2221
2219
|
// test that Bob is not allowed to write to Alice's DWN
|
|
2222
2220
|
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2223
2221
|
const bobWriteMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2230,8 +2228,8 @@ export function testRecordsWriteHandler() {
|
|
|
2230
2228
|
data
|
|
2231
2229
|
});
|
|
2232
2230
|
reply = yield dwn.processMessage(alice.did, bobWriteMessageData.message, { dataStream: bobWriteMessageData.dataStream });
|
|
2233
|
-
expect(reply.status.code).
|
|
2234
|
-
expect(reply.status.detail).
|
|
2231
|
+
expect(reply.status.code).toBe(401);
|
|
2232
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionRulesNotFound);
|
|
2235
2233
|
}));
|
|
2236
2234
|
it('should look up recipient path with ancestor depth of 2+ (excluding self) in action rule correctly', () => __awaiter(this, void 0, void 0, function* () {
|
|
2237
2235
|
// simulate a DEX protocol with at least 3 layers of message exchange: ask -> offer -> fulfillment
|
|
@@ -2248,7 +2246,7 @@ export function testRecordsWriteHandler() {
|
|
|
2248
2246
|
protocolDefinition: protocolDefinition
|
|
2249
2247
|
});
|
|
2250
2248
|
const protocolConfigureReply = yield dwn.processMessage(pfi.did, protocolConfig.message);
|
|
2251
|
-
expect(protocolConfigureReply.status.code).
|
|
2249
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2252
2250
|
// simulate Alice's ask and PFI's offer already occurred
|
|
2253
2251
|
const data = Encoder.stringToBytes('irrelevant');
|
|
2254
2252
|
const askMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2260,7 +2258,7 @@ export function testRecordsWriteHandler() {
|
|
|
2260
2258
|
data
|
|
2261
2259
|
});
|
|
2262
2260
|
let reply = yield dwn.processMessage(pfi.did, askMessageData.message, { dataStream: askMessageData.dataStream });
|
|
2263
|
-
expect(reply.status.code).
|
|
2261
|
+
expect(reply.status.code).toBe(202);
|
|
2264
2262
|
const offerMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
2265
2263
|
author: pfi,
|
|
2266
2264
|
recipient: alice.did,
|
|
@@ -2271,7 +2269,7 @@ export function testRecordsWriteHandler() {
|
|
|
2271
2269
|
data
|
|
2272
2270
|
});
|
|
2273
2271
|
reply = yield dwn.processMessage(pfi.did, offerMessageData.message, { dataStream: offerMessageData.dataStream });
|
|
2274
|
-
expect(reply.status.code).
|
|
2272
|
+
expect(reply.status.code).toBe(202);
|
|
2275
2273
|
// the actual test: making sure fulfillment message is accepted
|
|
2276
2274
|
const fulfillmentMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
2277
2275
|
author: alice,
|
|
@@ -2283,7 +2281,7 @@ export function testRecordsWriteHandler() {
|
|
|
2283
2281
|
data
|
|
2284
2282
|
});
|
|
2285
2283
|
reply = yield dwn.processMessage(pfi.did, fulfillmentMessageData.message, { dataStream: fulfillmentMessageData.dataStream });
|
|
2286
|
-
expect(reply.status.code).
|
|
2284
|
+
expect(reply.status.code).toBe(202);
|
|
2287
2285
|
// verify the fulfillment message is stored
|
|
2288
2286
|
const recordsQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
2289
2287
|
author: pfi,
|
|
@@ -2291,9 +2289,9 @@ export function testRecordsWriteHandler() {
|
|
|
2291
2289
|
});
|
|
2292
2290
|
// verify the data is written
|
|
2293
2291
|
const recordsQueryReply = yield dwn.processMessage(pfi.did, recordsQueryMessageData.message);
|
|
2294
|
-
expect(recordsQueryReply.status.code).
|
|
2295
|
-
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
2296
|
-
expect(recordsQueryReply.entries[0].descriptor.dataCid).
|
|
2292
|
+
expect(recordsQueryReply.status.code).toBe(200);
|
|
2293
|
+
expect((_a = recordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
2294
|
+
expect(recordsQueryReply.entries[0].descriptor.dataCid).toBe(fulfillmentMessageData.message.descriptor.dataCid);
|
|
2297
2295
|
}));
|
|
2298
2296
|
it('should fail authorization if incoming message contains `parentId` that leads to no record', () => __awaiter(this, void 0, void 0, function* () {
|
|
2299
2297
|
// 1. DEX protocol with at least 3 layers of message exchange: ask -> offer -> fulfillment
|
|
@@ -2310,7 +2308,7 @@ export function testRecordsWriteHandler() {
|
|
|
2310
2308
|
protocolDefinition: protocolDefinition
|
|
2311
2309
|
});
|
|
2312
2310
|
const protocolConfigureReply = yield dwn.processMessage(pfi.did, protocolConfig.message);
|
|
2313
|
-
expect(protocolConfigureReply.status.code).
|
|
2311
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2314
2312
|
// simulate Alice's ask
|
|
2315
2313
|
const data = Encoder.stringToBytes('irrelevant');
|
|
2316
2314
|
const askMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2322,7 +2320,7 @@ export function testRecordsWriteHandler() {
|
|
|
2322
2320
|
data
|
|
2323
2321
|
});
|
|
2324
2322
|
let reply = yield dwn.processMessage(pfi.did, askMessageData.message, { dataStream: askMessageData.dataStream });
|
|
2325
|
-
expect(reply.status.code).
|
|
2323
|
+
expect(reply.status.code).toBe(202);
|
|
2326
2324
|
// the actual test: making sure fulfillment message fails
|
|
2327
2325
|
const fulfillmentMessageData = yield TestDataGenerator.generateRecordsWrite({
|
|
2328
2326
|
author: alice,
|
|
@@ -2334,8 +2332,8 @@ export function testRecordsWriteHandler() {
|
|
|
2334
2332
|
data
|
|
2335
2333
|
});
|
|
2336
2334
|
reply = yield dwn.processMessage(pfi.did, fulfillmentMessageData.message, { dataStream: fulfillmentMessageData.dataStream });
|
|
2337
|
-
expect(reply.status.code).
|
|
2338
|
-
expect(reply.status.detail).
|
|
2335
|
+
expect(reply.status.code).toBe(400);
|
|
2336
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationIncorrectProtocolPath);
|
|
2339
2337
|
}));
|
|
2340
2338
|
it('should 400 if expected CID of `encryption` mismatches the `encryptionCid` in `authorization`', () => __awaiter(this, void 0, void 0, function* () {
|
|
2341
2339
|
const alice = yield TestDataGenerator.generatePersona();
|
|
@@ -2348,7 +2346,7 @@ export function testRecordsWriteHandler() {
|
|
|
2348
2346
|
protocolDefinition
|
|
2349
2347
|
});
|
|
2350
2348
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2351
|
-
expect(protocolsConfigureReply.status.code).
|
|
2349
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2352
2350
|
const bobMessageBytes = Encoder.stringToBytes('message from bob');
|
|
2353
2351
|
const bobMessageStream = DataStream.fromBytes(bobMessageBytes);
|
|
2354
2352
|
const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(16);
|
|
@@ -2376,10 +2374,10 @@ export function testRecordsWriteHandler() {
|
|
|
2376
2374
|
});
|
|
2377
2375
|
// replace valid `encryption` property with a mismatching one
|
|
2378
2376
|
message.encryption.initializationVector = Encoder.stringToBase64Url('any value which will result in a different CID');
|
|
2379
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore,
|
|
2377
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, stateIndex, eventStream);
|
|
2380
2378
|
const writeReply = yield recordsWriteHandler.handle({ tenant: alice.did, message, dataStream: dataStream });
|
|
2381
|
-
expect(writeReply.status.code).
|
|
2382
|
-
expect(writeReply.status.detail).
|
|
2379
|
+
expect(writeReply.status.code).toBe(400);
|
|
2380
|
+
expect(writeReply.status.detail).toContain(DwnErrorCode.RecordsWriteValidateIntegrityEncryptionCidMismatch);
|
|
2383
2381
|
}));
|
|
2384
2382
|
it('should return 400 if protocol is not normalized', () => __awaiter(this, void 0, void 0, function* () {
|
|
2385
2383
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -2408,8 +2406,8 @@ export function testRecordsWriteHandler() {
|
|
|
2408
2406
|
recordsWrite.message = Object.assign(Object.assign({}, recordsWrite.message), { attestation, authorization: { signature } });
|
|
2409
2407
|
// Send records write message
|
|
2410
2408
|
const reply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream: recordsWrite.dataStream });
|
|
2411
|
-
expect(reply.status.code).
|
|
2412
|
-
expect(reply.status.detail).
|
|
2409
|
+
expect(reply.status.code).toBe(400);
|
|
2410
|
+
expect(reply.status.detail).toContain(DwnErrorCode.UrlProtocolNotNormalized);
|
|
2413
2411
|
}));
|
|
2414
2412
|
it('#359 - should not allow access of data by referencing `dataCid` in protocol authorized `RecordsWrite`', () => __awaiter(this, void 0, void 0, function* () {
|
|
2415
2413
|
var _a, _b, _c;
|
|
@@ -2425,7 +2423,7 @@ export function testRecordsWriteHandler() {
|
|
|
2425
2423
|
data,
|
|
2426
2424
|
});
|
|
2427
2425
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
2428
|
-
expect(reply.status.code).
|
|
2426
|
+
expect(reply.status.code).toBe(202);
|
|
2429
2427
|
const protocolDefinition = socialMediaProtocolDefinition;
|
|
2430
2428
|
const protocol = protocolDefinition.protocol;
|
|
2431
2429
|
// alice has a social media protocol that allows anyone to write and read images
|
|
@@ -2434,7 +2432,7 @@ export function testRecordsWriteHandler() {
|
|
|
2434
2432
|
protocolDefinition
|
|
2435
2433
|
});
|
|
2436
2434
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2437
|
-
expect(protocolsConfigureReply.status.code).
|
|
2435
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2438
2436
|
// bob learns of metadata (ie. dataCid) of alice's secret data,
|
|
2439
2437
|
// attempts to gain unauthorized access by writing to alice's DWN through open protocol referencing the dataCid without supplying the data
|
|
2440
2438
|
// which he is allowed to do, the DWN will treat the operation as an initial-write or a record that has a later and different state.
|
|
@@ -2449,7 +2447,7 @@ export function testRecordsWriteHandler() {
|
|
|
2449
2447
|
recipient: alice.did
|
|
2450
2448
|
});
|
|
2451
2449
|
const imageReply = yield dwn.processMessage(alice.did, imageRecordsWrite.message);
|
|
2452
|
-
expect(imageReply.status.code).
|
|
2450
|
+
expect(imageReply.status.code).toBe(204); // allows write but is not readable or queryable
|
|
2453
2451
|
// verify the record is not able to be read
|
|
2454
2452
|
const bobRecordsReadData = yield RecordsRead.create({
|
|
2455
2453
|
filter: {
|
|
@@ -2458,7 +2456,7 @@ export function testRecordsWriteHandler() {
|
|
|
2458
2456
|
signer: Jws.createSigner(bob)
|
|
2459
2457
|
});
|
|
2460
2458
|
const bobRecordsReadReply = yield dwn.processMessage(alice.did, bobRecordsReadData.message);
|
|
2461
|
-
expect(bobRecordsReadReply.status.code).
|
|
2459
|
+
expect(bobRecordsReadReply.status.code).toBe(404);
|
|
2462
2460
|
// verify the record is not part of a query
|
|
2463
2461
|
const bobRecordsQuery = yield RecordsQuery.create({
|
|
2464
2462
|
filter: {
|
|
@@ -2467,8 +2465,8 @@ export function testRecordsWriteHandler() {
|
|
|
2467
2465
|
signer: Jws.createSigner(bob)
|
|
2468
2466
|
});
|
|
2469
2467
|
const bobRecordsQueryReply = yield dwn.processMessage(alice.did, bobRecordsQuery.message);
|
|
2470
|
-
expect(bobRecordsQueryReply.status.code).
|
|
2471
|
-
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
2468
|
+
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
2469
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
|
|
2472
2470
|
//further sanity query for specific recordId
|
|
2473
2471
|
const bobRecordsQueryRecordId = yield RecordsQuery.create({
|
|
2474
2472
|
filter: {
|
|
@@ -2477,8 +2475,8 @@ export function testRecordsWriteHandler() {
|
|
|
2477
2475
|
signer: Jws.createSigner(bob)
|
|
2478
2476
|
});
|
|
2479
2477
|
const bobRecordsQueryRecordIdReply = yield dwn.processMessage(alice.did, bobRecordsQueryRecordId.message);
|
|
2480
|
-
expect(bobRecordsQueryRecordIdReply.status.code).
|
|
2481
|
-
expect((_b = bobRecordsQueryRecordIdReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
2478
|
+
expect(bobRecordsQueryRecordIdReply.status.code).toBe(200);
|
|
2479
|
+
expect((_b = bobRecordsQueryRecordIdReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(0);
|
|
2482
2480
|
// attempt update recordsWrite without data, this will reject
|
|
2483
2481
|
const updateRecord = yield RecordsWrite.createFrom({
|
|
2484
2482
|
recordsWriteMessage: imageRecordsWrite.message,
|
|
@@ -2486,12 +2484,12 @@ export function testRecordsWriteHandler() {
|
|
|
2486
2484
|
published: true,
|
|
2487
2485
|
});
|
|
2488
2486
|
const updateRecordReply = yield dwn.processMessage(alice.did, updateRecord.message);
|
|
2489
|
-
expect(updateRecordReply.status.code).
|
|
2490
|
-
expect(updateRecordReply.status.detail).
|
|
2487
|
+
expect(updateRecordReply.status.code).toBe(400);
|
|
2488
|
+
expect(updateRecordReply.status.detail).toContain(DwnErrorCode.RecordsWriteMissingEncodedDataInPrevious);
|
|
2491
2489
|
// sanity still can't query
|
|
2492
2490
|
const bobRecordsQueryReply2 = yield dwn.processMessage(alice.did, bobRecordsQuery.message);
|
|
2493
|
-
expect(bobRecordsQueryReply2.status.code).
|
|
2494
|
-
expect((_c = bobRecordsQueryReply2.entries) === null || _c === void 0 ? void 0 : _c.length).
|
|
2491
|
+
expect(bobRecordsQueryReply2.status.code).toBe(200);
|
|
2492
|
+
expect((_c = bobRecordsQueryReply2.entries) === null || _c === void 0 ? void 0 : _c.length).toBe(0);
|
|
2495
2493
|
}));
|
|
2496
2494
|
it('#359 - should not allow access of data by referencing `dataCid` in protocol authorized `RecordsWrite` with large data', () => __awaiter(this, void 0, void 0, function* () {
|
|
2497
2495
|
var _a, _b, _c;
|
|
@@ -2507,7 +2505,7 @@ export function testRecordsWriteHandler() {
|
|
|
2507
2505
|
data,
|
|
2508
2506
|
});
|
|
2509
2507
|
const reply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
2510
|
-
expect(reply.status.code).
|
|
2508
|
+
expect(reply.status.code).toBe(202);
|
|
2511
2509
|
const protocolDefinition = socialMediaProtocolDefinition;
|
|
2512
2510
|
const protocol = protocolDefinition.protocol;
|
|
2513
2511
|
// alice has a social media protocol that allows anyone to write and read images
|
|
@@ -2516,7 +2514,7 @@ export function testRecordsWriteHandler() {
|
|
|
2516
2514
|
protocolDefinition
|
|
2517
2515
|
});
|
|
2518
2516
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2519
|
-
expect(protocolsConfigureReply.status.code).
|
|
2517
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2520
2518
|
// bob learns of metadata (ie. dataCid) of alice's secret data,
|
|
2521
2519
|
// attempts to gain unauthorized access by writing to alice's DWN through open protocol referencing the dataCid without supplying the data
|
|
2522
2520
|
// which he is allowed to do, the DWN will treat the operation as an initial-write or a record that has a later and different state.
|
|
@@ -2531,7 +2529,7 @@ export function testRecordsWriteHandler() {
|
|
|
2531
2529
|
recipient: alice.did
|
|
2532
2530
|
});
|
|
2533
2531
|
const imageReply = yield dwn.processMessage(alice.did, imageRecordsWrite.message);
|
|
2534
|
-
expect(imageReply.status.code).
|
|
2532
|
+
expect(imageReply.status.code).toBe(204); // allows write but is not readable or queryable
|
|
2535
2533
|
// verify the record is not able to be read
|
|
2536
2534
|
const bobRecordsReadData = yield RecordsRead.create({
|
|
2537
2535
|
filter: {
|
|
@@ -2540,7 +2538,7 @@ export function testRecordsWriteHandler() {
|
|
|
2540
2538
|
signer: Jws.createSigner(bob)
|
|
2541
2539
|
});
|
|
2542
2540
|
const bobRecordsReadReply = yield dwn.processMessage(alice.did, bobRecordsReadData.message);
|
|
2543
|
-
expect(bobRecordsReadReply.status.code).
|
|
2541
|
+
expect(bobRecordsReadReply.status.code).toBe(404);
|
|
2544
2542
|
// verify the record is not part of a query
|
|
2545
2543
|
const bobRecordsQuery = yield RecordsQuery.create({
|
|
2546
2544
|
filter: {
|
|
@@ -2549,8 +2547,8 @@ export function testRecordsWriteHandler() {
|
|
|
2549
2547
|
signer: Jws.createSigner(bob)
|
|
2550
2548
|
});
|
|
2551
2549
|
const bobRecordsQueryReply = yield dwn.processMessage(alice.did, bobRecordsQuery.message);
|
|
2552
|
-
expect(bobRecordsQueryReply.status.code).
|
|
2553
|
-
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
2550
|
+
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
2551
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
|
|
2554
2552
|
//further sanity query for specific recordId
|
|
2555
2553
|
const bobRecordsQueryRecordId = yield RecordsQuery.create({
|
|
2556
2554
|
filter: {
|
|
@@ -2559,8 +2557,8 @@ export function testRecordsWriteHandler() {
|
|
|
2559
2557
|
signer: Jws.createSigner(bob)
|
|
2560
2558
|
});
|
|
2561
2559
|
const bobRecordsQueryRecordIdReply = yield dwn.processMessage(alice.did, bobRecordsQueryRecordId.message);
|
|
2562
|
-
expect(bobRecordsQueryRecordIdReply.status.code).
|
|
2563
|
-
expect((_b = bobRecordsQueryRecordIdReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
2560
|
+
expect(bobRecordsQueryRecordIdReply.status.code).toBe(200);
|
|
2561
|
+
expect((_b = bobRecordsQueryRecordIdReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(0);
|
|
2564
2562
|
// attempt update recordsWrite without data, this will reject
|
|
2565
2563
|
const updateRecord = yield RecordsWrite.createFrom({
|
|
2566
2564
|
recordsWriteMessage: imageRecordsWrite.message,
|
|
@@ -2568,12 +2566,12 @@ export function testRecordsWriteHandler() {
|
|
|
2568
2566
|
published: true,
|
|
2569
2567
|
});
|
|
2570
2568
|
const updateRecordReply = yield dwn.processMessage(alice.did, updateRecord.message);
|
|
2571
|
-
expect(updateRecordReply.status.code).
|
|
2572
|
-
expect(updateRecordReply.status.detail).
|
|
2569
|
+
expect(updateRecordReply.status.code).toBe(400);
|
|
2570
|
+
expect(updateRecordReply.status.detail).toContain(DwnErrorCode.RecordsWriteMissingDataInPrevious);
|
|
2573
2571
|
// sanity still can't query
|
|
2574
2572
|
const bobRecordsQueryReply2 = yield dwn.processMessage(alice.did, bobRecordsQuery.message);
|
|
2575
|
-
expect(bobRecordsQueryReply2.status.code).
|
|
2576
|
-
expect((_c = bobRecordsQueryReply2.entries) === null || _c === void 0 ? void 0 : _c.length).
|
|
2573
|
+
expect(bobRecordsQueryReply2.status.code).toBe(200);
|
|
2574
|
+
expect((_c = bobRecordsQueryReply2.entries) === null || _c === void 0 ? void 0 : _c.length).toBe(0);
|
|
2577
2575
|
}));
|
|
2578
2576
|
it('should allow record with or without schema if protocol does not require schema for a record type', () => __awaiter(this, void 0, void 0, function* () {
|
|
2579
2577
|
// scenario: Alice's DWN has a protocol that allows anyone to write a record without schema
|
|
@@ -2586,7 +2584,7 @@ export function testRecordsWriteHandler() {
|
|
|
2586
2584
|
protocolDefinition
|
|
2587
2585
|
});
|
|
2588
2586
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2589
|
-
expect(protocolsConfigureReply.status.code).
|
|
2587
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2590
2588
|
// write a `RecordsWrite` message without schema
|
|
2591
2589
|
const data = TestDataGenerator.randomBytes(100);
|
|
2592
2590
|
const dataStream = DataStream.fromBytes(data);
|
|
@@ -2598,7 +2596,7 @@ export function testRecordsWriteHandler() {
|
|
|
2598
2596
|
signer: Jws.createSigner(alice)
|
|
2599
2597
|
});
|
|
2600
2598
|
const writeReply = yield dwn.processMessage(alice.did, docWrite.message, { dataStream });
|
|
2601
|
-
expect(writeReply.status.code).
|
|
2599
|
+
expect(writeReply.status.code).toBe(202);
|
|
2602
2600
|
// write a `RecordsWrite` message with schema
|
|
2603
2601
|
const data2 = TestDataGenerator.randomBytes(100);
|
|
2604
2602
|
const data2Stream = DataStream.fromBytes(data2);
|
|
@@ -2611,15 +2609,15 @@ export function testRecordsWriteHandler() {
|
|
|
2611
2609
|
signer: Jws.createSigner(alice)
|
|
2612
2610
|
});
|
|
2613
2611
|
const write2Reply = yield dwn.processMessage(alice.did, doc2Write.message, { dataStream: data2Stream });
|
|
2614
|
-
expect(write2Reply.status.code).
|
|
2612
|
+
expect(write2Reply.status.code).toBe(202);
|
|
2615
2613
|
// verify messages got written to the DB
|
|
2616
2614
|
const recordsQuery = yield RecordsQuery.create({
|
|
2617
2615
|
filter: { protocolPath: 'doc' },
|
|
2618
2616
|
signer: Jws.createSigner(alice)
|
|
2619
2617
|
});
|
|
2620
2618
|
const recordsReadReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
2621
|
-
expect(recordsReadReply.status.code).
|
|
2622
|
-
expect((_a = recordsReadReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
2619
|
+
expect(recordsReadReply.status.code).toBe(200);
|
|
2620
|
+
expect((_a = recordsReadReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(2);
|
|
2623
2621
|
}));
|
|
2624
2622
|
it('should allow authorization if protocol message size is within min and max size', () => __awaiter(this, void 0, void 0, function* () {
|
|
2625
2623
|
const alice = yield TestDataGenerator.generatePersona();
|
|
@@ -2645,7 +2643,7 @@ export function testRecordsWriteHandler() {
|
|
|
2645
2643
|
protocolDefinition,
|
|
2646
2644
|
});
|
|
2647
2645
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2648
|
-
expect(protocolConfigureReply.status.code).
|
|
2646
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2649
2647
|
// test min record size
|
|
2650
2648
|
const data = TestDataGenerator.randomBytes(1);
|
|
2651
2649
|
const testRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2656,7 +2654,7 @@ export function testRecordsWriteHandler() {
|
|
|
2656
2654
|
data
|
|
2657
2655
|
});
|
|
2658
2656
|
const reply = yield dwn.processMessage(alice.did, testRecord.message, { dataStream: testRecord.dataStream });
|
|
2659
|
-
expect(reply.status.code).
|
|
2657
|
+
expect(reply.status.code).toBe(202);
|
|
2660
2658
|
// test max record size
|
|
2661
2659
|
const data2 = TestDataGenerator.randomBytes(1000);
|
|
2662
2660
|
const testRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2667,7 +2665,7 @@ export function testRecordsWriteHandler() {
|
|
|
2667
2665
|
data: data2
|
|
2668
2666
|
});
|
|
2669
2667
|
const reply2 = yield dwn.processMessage(alice.did, testRecord2.message, { dataStream: testRecord2.dataStream });
|
|
2670
|
-
expect(reply2.status.code).
|
|
2668
|
+
expect(reply2.status.code).toBe(202);
|
|
2671
2669
|
// test beyond max size
|
|
2672
2670
|
const data3 = TestDataGenerator.randomBytes(1001);
|
|
2673
2671
|
const testRecord3 = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2678,8 +2676,8 @@ export function testRecordsWriteHandler() {
|
|
|
2678
2676
|
data: data3
|
|
2679
2677
|
});
|
|
2680
2678
|
const reply3 = yield dwn.processMessage(alice.did, testRecord3.message, { dataStream: testRecord3.dataStream });
|
|
2681
|
-
expect(reply3.status.code).
|
|
2682
|
-
expect(reply3.status.detail).
|
|
2679
|
+
expect(reply3.status.code).toBe(400);
|
|
2680
|
+
expect(reply3.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMaxSizeInvalid);
|
|
2683
2681
|
}));
|
|
2684
2682
|
it('should fail authorization if protocol message size is less than specified minimum size', () => __awaiter(this, void 0, void 0, function* () {
|
|
2685
2683
|
const alice = yield TestDataGenerator.generatePersona();
|
|
@@ -2704,7 +2702,7 @@ export function testRecordsWriteHandler() {
|
|
|
2704
2702
|
protocolDefinition,
|
|
2705
2703
|
});
|
|
2706
2704
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2707
|
-
expect(protocolConfigureReply.status.code).
|
|
2705
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2708
2706
|
const data = TestDataGenerator.randomBytes(999);
|
|
2709
2707
|
const testRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2710
2708
|
author: alice,
|
|
@@ -2714,8 +2712,8 @@ export function testRecordsWriteHandler() {
|
|
|
2714
2712
|
data
|
|
2715
2713
|
});
|
|
2716
2714
|
const reply = yield dwn.processMessage(alice.did, testRecord.message, { dataStream: testRecord.dataStream });
|
|
2717
|
-
expect(reply.status.code).
|
|
2718
|
-
expect(reply.status.detail).
|
|
2715
|
+
expect(reply.status.code).toBe(400);
|
|
2716
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMinSizeInvalid);
|
|
2719
2717
|
// test valid min record size
|
|
2720
2718
|
const data2 = TestDataGenerator.randomBytes(1000);
|
|
2721
2719
|
const testRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2726,7 +2724,7 @@ export function testRecordsWriteHandler() {
|
|
|
2726
2724
|
data: data2
|
|
2727
2725
|
});
|
|
2728
2726
|
const reply2 = yield dwn.processMessage(alice.did, testRecord2.message, { dataStream: testRecord2.dataStream });
|
|
2729
|
-
expect(reply2.status.code).
|
|
2727
|
+
expect(reply2.status.code).toBe(202);
|
|
2730
2728
|
}));
|
|
2731
2729
|
it('should fail authorization if protocol message size is more than specified maximum size', () => __awaiter(this, void 0, void 0, function* () {
|
|
2732
2730
|
const alice = yield TestDataGenerator.generatePersona();
|
|
@@ -2751,7 +2749,7 @@ export function testRecordsWriteHandler() {
|
|
|
2751
2749
|
protocolDefinition,
|
|
2752
2750
|
});
|
|
2753
2751
|
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfig.message);
|
|
2754
|
-
expect(protocolConfigureReply.status.code).
|
|
2752
|
+
expect(protocolConfigureReply.status.code).toBe(202);
|
|
2755
2753
|
const data = TestDataGenerator.randomBytes(1001);
|
|
2756
2754
|
const testRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2757
2755
|
author: alice,
|
|
@@ -2761,8 +2759,8 @@ export function testRecordsWriteHandler() {
|
|
|
2761
2759
|
data
|
|
2762
2760
|
});
|
|
2763
2761
|
const reply = yield dwn.processMessage(alice.did, testRecord.message, { dataStream: testRecord.dataStream });
|
|
2764
|
-
expect(reply.status.code).
|
|
2765
|
-
expect(reply.status.detail).
|
|
2762
|
+
expect(reply.status.code).toBe(400);
|
|
2763
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMaxSizeInvalid);
|
|
2766
2764
|
// test valid max record size
|
|
2767
2765
|
const data2 = TestDataGenerator.randomBytes(1000);
|
|
2768
2766
|
const testRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -2773,7 +2771,7 @@ export function testRecordsWriteHandler() {
|
|
|
2773
2771
|
data: data2
|
|
2774
2772
|
});
|
|
2775
2773
|
const reply2 = yield dwn.processMessage(alice.did, testRecord2.message, { dataStream: testRecord2.dataStream });
|
|
2776
|
-
expect(reply2.status.code).
|
|
2774
|
+
expect(reply2.status.code).toBe(202);
|
|
2777
2775
|
}));
|
|
2778
2776
|
it('should fail if a write references a parent that has been deleted', () => __awaiter(this, void 0, void 0, function* () {
|
|
2779
2777
|
// scenario:
|
|
@@ -2789,7 +2787,7 @@ export function testRecordsWriteHandler() {
|
|
|
2789
2787
|
protocolDefinition
|
|
2790
2788
|
});
|
|
2791
2789
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2792
|
-
expect(protocolsConfigureReply.status.code).
|
|
2790
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2793
2791
|
// 1. Alice writes foo1
|
|
2794
2792
|
const fooOptions = {
|
|
2795
2793
|
author: alice,
|
|
@@ -2800,14 +2798,14 @@ export function testRecordsWriteHandler() {
|
|
|
2800
2798
|
};
|
|
2801
2799
|
const foo1 = yield TestDataGenerator.generateRecordsWrite(fooOptions);
|
|
2802
2800
|
const foo1WriteResponse = yield dwn.processMessage(alice.did, foo1.message, { dataStream: foo1.dataStream });
|
|
2803
|
-
expect(foo1WriteResponse.status.code).
|
|
2801
|
+
expect(foo1WriteResponse.status.code).toBe(202);
|
|
2804
2802
|
// 2. Alice deletes foo1
|
|
2805
2803
|
const deleteFoo = yield TestDataGenerator.generateRecordsDelete({
|
|
2806
2804
|
author: alice,
|
|
2807
2805
|
recordId: foo1.message.recordId
|
|
2808
2806
|
});
|
|
2809
2807
|
const deleteFooReply = yield dwn.processMessage(alice.did, deleteFoo.message);
|
|
2810
|
-
expect(deleteFooReply.status.code).
|
|
2808
|
+
expect(deleteFooReply.status.code).toBe(202);
|
|
2811
2809
|
// 3. Alice tries to write a bar1 referencing the deleted foo and should fail
|
|
2812
2810
|
const barOptions = {
|
|
2813
2811
|
author: alice,
|
|
@@ -2819,8 +2817,8 @@ export function testRecordsWriteHandler() {
|
|
|
2819
2817
|
};
|
|
2820
2818
|
const bar1 = yield TestDataGenerator.generateRecordsWrite(barOptions);
|
|
2821
2819
|
const bar1WriteResponse = yield dwn.processMessage(alice.did, bar1.message, { dataStream: bar1.dataStream });
|
|
2822
|
-
expect(bar1WriteResponse.status.code).
|
|
2823
|
-
expect(bar1WriteResponse.status.detail).
|
|
2820
|
+
expect(bar1WriteResponse.status.code).toBe(400);
|
|
2821
|
+
expect(bar1WriteResponse.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationIncorrectProtocolPath);
|
|
2824
2822
|
}));
|
|
2825
2823
|
it('should fail if a write references a mismatching parent that compared to the parent in the `contextId` ', () => __awaiter(this, void 0, void 0, function* () {
|
|
2826
2824
|
// scenario:
|
|
@@ -2835,7 +2833,7 @@ export function testRecordsWriteHandler() {
|
|
|
2835
2833
|
protocolDefinition
|
|
2836
2834
|
});
|
|
2837
2835
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2838
|
-
expect(protocolsConfigureReply.status.code).
|
|
2836
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2839
2837
|
// 1. Alice writes foo1
|
|
2840
2838
|
const fooOptions = {
|
|
2841
2839
|
author: alice,
|
|
@@ -2846,7 +2844,7 @@ export function testRecordsWriteHandler() {
|
|
|
2846
2844
|
};
|
|
2847
2845
|
const foo1 = yield TestDataGenerator.generateRecordsWrite(fooOptions);
|
|
2848
2846
|
const foo1WriteResponse = yield dwn.processMessage(alice.did, foo1.message, { dataStream: foo1.dataStream });
|
|
2849
|
-
expect(foo1WriteResponse.status.code).
|
|
2847
|
+
expect(foo1WriteResponse.status.code).toBe(202);
|
|
2850
2848
|
// 2. Alice tries to write a bar1 referencing the foo1 in parentId, but contextId does not reference the same parent
|
|
2851
2849
|
const barOptions = {
|
|
2852
2850
|
author: alice,
|
|
@@ -2875,8 +2873,8 @@ export function testRecordsWriteHandler() {
|
|
|
2875
2873
|
bar1.message.recordId = recordId;
|
|
2876
2874
|
bar1.message.authorization = { signature };
|
|
2877
2875
|
const bar1WriteResponse = yield dwn.processMessage(alice.did, bar1.message);
|
|
2878
|
-
expect(bar1WriteResponse.status.code).
|
|
2879
|
-
expect(bar1WriteResponse.status.detail).
|
|
2876
|
+
expect(bar1WriteResponse.status.code).toBe(400);
|
|
2877
|
+
expect(bar1WriteResponse.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationIncorrectContextId);
|
|
2880
2878
|
}));
|
|
2881
2879
|
});
|
|
2882
2880
|
describe('grant based writes', () => {
|
|
@@ -2893,7 +2891,7 @@ export function testRecordsWriteHandler() {
|
|
|
2893
2891
|
protocolDefinition
|
|
2894
2892
|
});
|
|
2895
2893
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2896
|
-
expect(protocolsConfigureReply.status.code).
|
|
2894
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2897
2895
|
// Alice gives Bob a permission grant
|
|
2898
2896
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
2899
2897
|
signer: Jws.createSigner(alice),
|
|
@@ -2907,7 +2905,7 @@ export function testRecordsWriteHandler() {
|
|
|
2907
2905
|
});
|
|
2908
2906
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
2909
2907
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
2910
|
-
expect(permissionGrantWriteReply.status.code).
|
|
2908
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
2911
2909
|
// Bob invokes the grant in order to write a record to the protocol
|
|
2912
2910
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
2913
2911
|
author: bob,
|
|
@@ -2916,7 +2914,7 @@ export function testRecordsWriteHandler() {
|
|
|
2916
2914
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
2917
2915
|
});
|
|
2918
2916
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
2919
|
-
expect(recordsWriteReply.status.code).
|
|
2917
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
2920
2918
|
}));
|
|
2921
2919
|
it('rejects writes of protocol records with mismatching protocol grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
2922
2920
|
// scenario: Alice gives Bob a grant to write to a protocol. Bob tries and fails to
|
|
@@ -2930,7 +2928,7 @@ export function testRecordsWriteHandler() {
|
|
|
2930
2928
|
protocolDefinition
|
|
2931
2929
|
});
|
|
2932
2930
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2933
|
-
expect(protocolsConfigureReply.status.code).
|
|
2931
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2934
2932
|
// Alice gives Bob a permission grant with a different protocol than what Bob will try to write to
|
|
2935
2933
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
2936
2934
|
signer: Jws.createSigner(alice),
|
|
@@ -2944,7 +2942,7 @@ export function testRecordsWriteHandler() {
|
|
|
2944
2942
|
});
|
|
2945
2943
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
2946
2944
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
2947
|
-
expect(permissionGrantWriteReply.status.code).
|
|
2945
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
2948
2946
|
// Bob invokes the grant, failing to write to a different protocol than the grant allows
|
|
2949
2947
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
2950
2948
|
author: bob,
|
|
@@ -2953,8 +2951,8 @@ export function testRecordsWriteHandler() {
|
|
|
2953
2951
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
2954
2952
|
});
|
|
2955
2953
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
2956
|
-
expect(recordsWriteReply.status.code).
|
|
2957
|
-
expect(recordsWriteReply.status.detail).
|
|
2954
|
+
expect(recordsWriteReply.status.code).toBe(401);
|
|
2955
|
+
expect(recordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
|
|
2958
2956
|
}));
|
|
2959
2957
|
it('allows writes of protocol records with matching contextId grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
2960
2958
|
// scenario: Alice gives Bob a grant to write to a specific contextId.
|
|
@@ -2968,7 +2966,7 @@ export function testRecordsWriteHandler() {
|
|
|
2968
2966
|
protocolDefinition
|
|
2969
2967
|
});
|
|
2970
2968
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2971
|
-
expect(protocolsConfigureReply.status.code).
|
|
2969
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
2972
2970
|
// Alice creates the context that she will give Bob access to
|
|
2973
2971
|
const alicesRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
2974
2972
|
author: alice,
|
|
@@ -2979,7 +2977,7 @@ export function testRecordsWriteHandler() {
|
|
|
2979
2977
|
dataFormat: protocolDefinition.types.email.dataFormats[0],
|
|
2980
2978
|
});
|
|
2981
2979
|
const alicesRecordsWriteReply = yield dwn.processMessage(alice.did, alicesRecordsWrite.message, { dataStream: alicesRecordsWrite.dataStream });
|
|
2982
|
-
expect(alicesRecordsWriteReply.status.code).
|
|
2980
|
+
expect(alicesRecordsWriteReply.status.code).toBe(202);
|
|
2983
2981
|
// Alice gives Bob a permission grant
|
|
2984
2982
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
2985
2983
|
signer: Jws.createSigner(alice),
|
|
@@ -2994,7 +2992,7 @@ export function testRecordsWriteHandler() {
|
|
|
2994
2992
|
});
|
|
2995
2993
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
2996
2994
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
2997
|
-
expect(permissionGrantWriteReply.status.code).
|
|
2995
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
2998
2996
|
// Bob invokes the grant in order to write a record to the protocol
|
|
2999
2997
|
const bobsRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3000
2998
|
author: bob,
|
|
@@ -3006,7 +3004,7 @@ export function testRecordsWriteHandler() {
|
|
|
3006
3004
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
3007
3005
|
});
|
|
3008
3006
|
const bobsRecordsWriteReply = yield dwn.processMessage(alice.did, bobsRecordsWrite.message, { dataStream: bobsRecordsWrite.dataStream });
|
|
3009
|
-
expect(bobsRecordsWriteReply.status.code).
|
|
3007
|
+
expect(bobsRecordsWriteReply.status.code).toBe(202);
|
|
3010
3008
|
}));
|
|
3011
3009
|
it('rejects writes of protocol records with mismatching contextId grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
3012
3010
|
// scenario: Alice gives Bob a grant to write to a specific contextId. Bob tries and fails to
|
|
@@ -3020,7 +3018,7 @@ export function testRecordsWriteHandler() {
|
|
|
3020
3018
|
protocolDefinition
|
|
3021
3019
|
});
|
|
3022
3020
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
3023
|
-
expect(protocolsConfigureReply.status.code).
|
|
3021
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
3024
3022
|
// Alice creates the context that she will give Bob access to
|
|
3025
3023
|
const alicesRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3026
3024
|
author: alice,
|
|
@@ -3031,7 +3029,7 @@ export function testRecordsWriteHandler() {
|
|
|
3031
3029
|
dataFormat: protocolDefinition.types.email.dataFormats[0],
|
|
3032
3030
|
});
|
|
3033
3031
|
const alicesRecordsWriteReply = yield dwn.processMessage(alice.did, alicesRecordsWrite.message, { dataStream: alicesRecordsWrite.dataStream });
|
|
3034
|
-
expect(alicesRecordsWriteReply.status.code).
|
|
3032
|
+
expect(alicesRecordsWriteReply.status.code).toBe(202);
|
|
3035
3033
|
// Alice gives Bob a permission grant
|
|
3036
3034
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
3037
3035
|
signer: Jws.createSigner(alice),
|
|
@@ -3046,7 +3044,7 @@ export function testRecordsWriteHandler() {
|
|
|
3046
3044
|
});
|
|
3047
3045
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
3048
3046
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
3049
|
-
expect(permissionGrantWriteReply.status.code).
|
|
3047
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
3050
3048
|
// Bob invokes the grant in order to write a record to the protocol
|
|
3051
3049
|
const bobsRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3052
3050
|
author: bob,
|
|
@@ -3058,8 +3056,8 @@ export function testRecordsWriteHandler() {
|
|
|
3058
3056
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
3059
3057
|
});
|
|
3060
3058
|
const bobsRecordsWriteReply = yield dwn.processMessage(alice.did, bobsRecordsWrite.message, { dataStream: bobsRecordsWrite.dataStream });
|
|
3061
|
-
expect(bobsRecordsWriteReply.status.code).
|
|
3062
|
-
expect(bobsRecordsWriteReply.status.detail).
|
|
3059
|
+
expect(bobsRecordsWriteReply.status.code).toBe(401);
|
|
3060
|
+
expect(bobsRecordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeContextIdMismatch);
|
|
3063
3061
|
}));
|
|
3064
3062
|
it('allows writes of protocol records with matching protocolPath grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
3065
3063
|
// scenario: Alice gives Bob a grant to write to a specific protocolPath.
|
|
@@ -3073,7 +3071,7 @@ export function testRecordsWriteHandler() {
|
|
|
3073
3071
|
protocolDefinition
|
|
3074
3072
|
});
|
|
3075
3073
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
3076
|
-
expect(protocolsConfigureReply.status.code).
|
|
3074
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
3077
3075
|
// Alice gives Bob a permission grant
|
|
3078
3076
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
3079
3077
|
signer: Jws.createSigner(alice),
|
|
@@ -3088,7 +3086,7 @@ export function testRecordsWriteHandler() {
|
|
|
3088
3086
|
});
|
|
3089
3087
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
3090
3088
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
3091
|
-
expect(permissionGrantWriteReply.status.code).
|
|
3089
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
3092
3090
|
// Bob invokes the grant in order to write a record to the protocol
|
|
3093
3091
|
const bobsRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3094
3092
|
author: bob,
|
|
@@ -3097,7 +3095,7 @@ export function testRecordsWriteHandler() {
|
|
|
3097
3095
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
3098
3096
|
});
|
|
3099
3097
|
const bobsRecordsWriteReply = yield dwn.processMessage(alice.did, bobsRecordsWrite.message, { dataStream: bobsRecordsWrite.dataStream });
|
|
3100
|
-
expect(bobsRecordsWriteReply.status.code).
|
|
3098
|
+
expect(bobsRecordsWriteReply.status.code).toBe(202);
|
|
3101
3099
|
}));
|
|
3102
3100
|
it('rejects writes of protocol records with mismatching protocolPath grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
3103
3101
|
// scenario: Alice gives Bob a grant to write to a specific protocolPath. Bob tries and fails to
|
|
@@ -3111,7 +3109,7 @@ export function testRecordsWriteHandler() {
|
|
|
3111
3109
|
protocolDefinition
|
|
3112
3110
|
});
|
|
3113
3111
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
3114
|
-
expect(protocolsConfigureReply.status.code).
|
|
3112
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
3115
3113
|
// Alice gives Bob a permission grant
|
|
3116
3114
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
3117
3115
|
signer: Jws.createSigner(alice),
|
|
@@ -3126,7 +3124,7 @@ export function testRecordsWriteHandler() {
|
|
|
3126
3124
|
});
|
|
3127
3125
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
3128
3126
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
3129
|
-
expect(permissionGrantWriteReply.status.code).
|
|
3127
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
3130
3128
|
// Bob invokes the grant in order to write a record to the protocol
|
|
3131
3129
|
const bobsRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3132
3130
|
author: bob,
|
|
@@ -3135,8 +3133,8 @@ export function testRecordsWriteHandler() {
|
|
|
3135
3133
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
3136
3134
|
});
|
|
3137
3135
|
const bobsRecordsWriteReply = yield dwn.processMessage(alice.did, bobsRecordsWrite.message, { dataStream: bobsRecordsWrite.dataStream });
|
|
3138
|
-
expect(bobsRecordsWriteReply.status.code).
|
|
3139
|
-
expect(bobsRecordsWriteReply.status.detail).
|
|
3136
|
+
expect(bobsRecordsWriteReply.status.code).toBe(401);
|
|
3137
|
+
expect(bobsRecordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolPathMismatch);
|
|
3140
3138
|
}));
|
|
3141
3139
|
});
|
|
3142
3140
|
describe('grant condition published', () => {
|
|
@@ -3152,7 +3150,7 @@ export function testRecordsWriteHandler() {
|
|
|
3152
3150
|
protocolDefinition,
|
|
3153
3151
|
});
|
|
3154
3152
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
3155
|
-
expect(protocolsConfigureReply.status.code).
|
|
3153
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
3156
3154
|
// Alice creates a grant for Bob with `published` === required
|
|
3157
3155
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
3158
3156
|
signer: Jws.createSigner(alice),
|
|
@@ -3169,7 +3167,7 @@ export function testRecordsWriteHandler() {
|
|
|
3169
3167
|
});
|
|
3170
3168
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
3171
3169
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
3172
|
-
expect(permissionGrantWriteReply.status.code).
|
|
3170
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
3173
3171
|
const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
|
|
3174
3172
|
// Bob is able to write a published record
|
|
3175
3173
|
const publishedRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -3180,7 +3178,7 @@ export function testRecordsWriteHandler() {
|
|
|
3180
3178
|
permissionGrantId
|
|
3181
3179
|
});
|
|
3182
3180
|
const publishedRecordsWriteReply = yield dwn.processMessage(alice.did, publishedRecordsWrite.message, { dataStream: publishedRecordsWrite.dataStream });
|
|
3183
|
-
expect(publishedRecordsWriteReply.status.code).
|
|
3181
|
+
expect(publishedRecordsWriteReply.status.code).toBe(202);
|
|
3184
3182
|
// Bob is not able to write an unpublished record
|
|
3185
3183
|
const unpublishedRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3186
3184
|
author: bob,
|
|
@@ -3190,8 +3188,8 @@ export function testRecordsWriteHandler() {
|
|
|
3190
3188
|
permissionGrantId
|
|
3191
3189
|
});
|
|
3192
3190
|
const unpublishedRecordsWriteReply = yield dwn.processMessage(alice.did, unpublishedRecordsWrite.message, { dataStream: unpublishedRecordsWrite.dataStream });
|
|
3193
|
-
expect(unpublishedRecordsWriteReply.status.code).
|
|
3194
|
-
expect(unpublishedRecordsWriteReply.status.detail).
|
|
3191
|
+
expect(unpublishedRecordsWriteReply.status.code).toBe(401);
|
|
3192
|
+
expect(unpublishedRecordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationConditionPublicationRequired);
|
|
3195
3193
|
}));
|
|
3196
3194
|
it('Rejects published records if grant condition `published` === prohibited', () => __awaiter(this, void 0, void 0, function* () {
|
|
3197
3195
|
// scenario: Alice gives Bob a grant with condition `published` === prohibited.
|
|
@@ -3205,7 +3203,7 @@ export function testRecordsWriteHandler() {
|
|
|
3205
3203
|
protocolDefinition,
|
|
3206
3204
|
});
|
|
3207
3205
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
3208
|
-
expect(protocolsConfigureReply.status.code).
|
|
3206
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
3209
3207
|
// Alice creates a grant for Bob with `published` === prohibited
|
|
3210
3208
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
3211
3209
|
signer: Jws.createSigner(alice),
|
|
@@ -3222,7 +3220,7 @@ export function testRecordsWriteHandler() {
|
|
|
3222
3220
|
});
|
|
3223
3221
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
3224
3222
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
3225
|
-
expect(permissionGrantWriteReply.status.code).
|
|
3223
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
3226
3224
|
const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
|
|
3227
3225
|
// Bob not is able to write a published record
|
|
3228
3226
|
const publishedRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -3233,8 +3231,8 @@ export function testRecordsWriteHandler() {
|
|
|
3233
3231
|
permissionGrantId
|
|
3234
3232
|
});
|
|
3235
3233
|
const publishedRecordsWriteReply = yield dwn.processMessage(alice.did, publishedRecordsWrite.message, { dataStream: publishedRecordsWrite.dataStream });
|
|
3236
|
-
expect(publishedRecordsWriteReply.status.code).
|
|
3237
|
-
expect(publishedRecordsWriteReply.status.detail).
|
|
3234
|
+
expect(publishedRecordsWriteReply.status.code).toBe(401);
|
|
3235
|
+
expect(publishedRecordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationConditionPublicationProhibited);
|
|
3238
3236
|
// Bob is able to write an unpublished record
|
|
3239
3237
|
const unpublishedRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3240
3238
|
author: bob,
|
|
@@ -3244,7 +3242,7 @@ export function testRecordsWriteHandler() {
|
|
|
3244
3242
|
permissionGrantId
|
|
3245
3243
|
});
|
|
3246
3244
|
const unpublishedRecordsWriteReply = yield dwn.processMessage(alice.did, unpublishedRecordsWrite.message, { dataStream: unpublishedRecordsWrite.dataStream });
|
|
3247
|
-
expect(unpublishedRecordsWriteReply.status.code).
|
|
3245
|
+
expect(unpublishedRecordsWriteReply.status.code).toBe(202);
|
|
3248
3246
|
}));
|
|
3249
3247
|
it('Allows both published and unpublished records if grant condition `published` is undefined', () => __awaiter(this, void 0, void 0, function* () {
|
|
3250
3248
|
// scenario: Alice gives Bob a grant without condition `published`.
|
|
@@ -3258,7 +3256,7 @@ export function testRecordsWriteHandler() {
|
|
|
3258
3256
|
protocolDefinition,
|
|
3259
3257
|
});
|
|
3260
3258
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
3261
|
-
expect(protocolsConfigureReply.status.code).
|
|
3259
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
3262
3260
|
// Alice creates a grant for Bob with `published` === prohibited
|
|
3263
3261
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
3264
3262
|
signer: Jws.createSigner(alice),
|
|
@@ -3275,7 +3273,7 @@ export function testRecordsWriteHandler() {
|
|
|
3275
3273
|
});
|
|
3276
3274
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
3277
3275
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
3278
|
-
expect(permissionGrantWriteReply.status.code).
|
|
3276
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
3279
3277
|
const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
|
|
3280
3278
|
// Bob is able to write a published record
|
|
3281
3279
|
const publishedRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -3286,7 +3284,7 @@ export function testRecordsWriteHandler() {
|
|
|
3286
3284
|
permissionGrantId
|
|
3287
3285
|
});
|
|
3288
3286
|
const publishedRecordsWriteReply = yield dwn.processMessage(alice.did, publishedRecordsWrite.message, { dataStream: publishedRecordsWrite.dataStream });
|
|
3289
|
-
expect(publishedRecordsWriteReply.status.code).
|
|
3287
|
+
expect(publishedRecordsWriteReply.status.code).toBe(202);
|
|
3290
3288
|
// Bob is able to write an unpublished record
|
|
3291
3289
|
const unpublishedRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
3292
3290
|
author: bob,
|
|
@@ -3296,7 +3294,7 @@ export function testRecordsWriteHandler() {
|
|
|
3296
3294
|
permissionGrantId
|
|
3297
3295
|
});
|
|
3298
3296
|
const unpublishedRecordsWriteReply = yield dwn.processMessage(alice.did, unpublishedRecordsWrite.message, { dataStream: unpublishedRecordsWrite.dataStream });
|
|
3299
|
-
expect(unpublishedRecordsWriteReply.status.code).
|
|
3297
|
+
expect(unpublishedRecordsWriteReply.status.code).toBe(202);
|
|
3300
3298
|
}));
|
|
3301
3299
|
});
|
|
3302
3300
|
});
|
|
@@ -3313,7 +3311,7 @@ export function testRecordsWriteHandler() {
|
|
|
3313
3311
|
data,
|
|
3314
3312
|
});
|
|
3315
3313
|
const prunedRecordsWriteReply = yield dwn.processMessage(alice.did, prunedRecordsWrite.message);
|
|
3316
|
-
expect(prunedRecordsWriteReply.status.code).
|
|
3314
|
+
expect(prunedRecordsWriteReply.status.code).toBe(204);
|
|
3317
3315
|
// Update record to published, omitting dataStream
|
|
3318
3316
|
const recordsWrite = yield TestDataGenerator.generateFromRecordsWrite({
|
|
3319
3317
|
author: alice,
|
|
@@ -3322,8 +3320,8 @@ export function testRecordsWriteHandler() {
|
|
|
3322
3320
|
data,
|
|
3323
3321
|
});
|
|
3324
3322
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message);
|
|
3325
|
-
expect(recordsWriteReply.status.code).
|
|
3326
|
-
expect(recordsWriteReply.status.detail).
|
|
3323
|
+
expect(recordsWriteReply.status.code).toBe(400);
|
|
3324
|
+
expect(recordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsWriteMissingDataInPrevious);
|
|
3327
3325
|
}));
|
|
3328
3326
|
it('should return 400 if dataStream is not provided and previous message does not contain encodedData', () => __awaiter(this, void 0, void 0, function* () {
|
|
3329
3327
|
// scenario: A sync writes a pruned initial RecordsWrite, without a `dataStream`. Alice does another regular
|
|
@@ -3338,7 +3336,7 @@ export function testRecordsWriteHandler() {
|
|
|
3338
3336
|
data,
|
|
3339
3337
|
});
|
|
3340
3338
|
const prunedRecordsWriteReply = yield dwn.processMessage(alice.did, prunedRecordsWrite.message);
|
|
3341
|
-
expect(prunedRecordsWriteReply.status.code).
|
|
3339
|
+
expect(prunedRecordsWriteReply.status.code).toBe(204);
|
|
3342
3340
|
// Update record to published, omitting dataStream
|
|
3343
3341
|
const recordsWrite = yield TestDataGenerator.generateFromRecordsWrite({
|
|
3344
3342
|
author: alice,
|
|
@@ -3347,8 +3345,8 @@ export function testRecordsWriteHandler() {
|
|
|
3347
3345
|
data,
|
|
3348
3346
|
});
|
|
3349
3347
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message);
|
|
3350
|
-
expect(recordsWriteReply.status.code).
|
|
3351
|
-
expect(recordsWriteReply.status.detail).
|
|
3348
|
+
expect(recordsWriteReply.status.code).toBe(400);
|
|
3349
|
+
expect(recordsWriteReply.status.detail).toContain(DwnErrorCode.RecordsWriteMissingEncodedDataInPrevious);
|
|
3352
3350
|
}));
|
|
3353
3351
|
it('should return 400 if attempting a write after a delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
3354
3352
|
const { message, author, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -3358,13 +3356,13 @@ export function testRecordsWriteHandler() {
|
|
|
3358
3356
|
const tenant = author.did;
|
|
3359
3357
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
3360
3358
|
const initialWriteReply = yield dwn.processMessage(tenant, message, { dataStream });
|
|
3361
|
-
expect(initialWriteReply.status.code).
|
|
3359
|
+
expect(initialWriteReply.status.code).toBe(202);
|
|
3362
3360
|
const recordsDelete = yield RecordsDelete.create({
|
|
3363
3361
|
recordId: message.recordId,
|
|
3364
3362
|
signer: Jws.createSigner(author),
|
|
3365
3363
|
});
|
|
3366
3364
|
const deleteReply = yield dwn.processMessage(tenant, recordsDelete.message);
|
|
3367
|
-
expect(deleteReply.status.code).
|
|
3365
|
+
expect(deleteReply.status.code).toBe(202);
|
|
3368
3366
|
const newDataBytes = TestDataGenerator.randomBytes(100);
|
|
3369
3367
|
const newInvalidWrite = yield RecordsWrite.createFrom({
|
|
3370
3368
|
recordsWriteMessage: message,
|
|
@@ -3372,8 +3370,8 @@ export function testRecordsWriteHandler() {
|
|
|
3372
3370
|
data: newDataBytes
|
|
3373
3371
|
});
|
|
3374
3372
|
const newInvalidWriteReply = yield dwn.processMessage(tenant, newInvalidWrite.message, { dataStream: DataStream.fromBytes(newDataBytes) });
|
|
3375
|
-
expect(newInvalidWriteReply.status.code).
|
|
3376
|
-
expect(newInvalidWriteReply.status.detail).
|
|
3373
|
+
expect(newInvalidWriteReply.status.code).toBe(400);
|
|
3374
|
+
expect(newInvalidWriteReply.status.detail).toContain(DwnErrorCode.RecordsWriteNotAllowedAfterDelete);
|
|
3377
3375
|
}));
|
|
3378
3376
|
it('should not allow referencing data across tenants', () => __awaiter(this, void 0, void 0, function* () {
|
|
3379
3377
|
var _a, _b, _c;
|
|
@@ -3388,15 +3386,15 @@ export function testRecordsWriteHandler() {
|
|
|
3388
3386
|
data
|
|
3389
3387
|
});
|
|
3390
3388
|
const aliceWriteReply = yield dwn.processMessage(alice.did, aliceWriteData.message, { dataStream: aliceWriteData.dataStream });
|
|
3391
|
-
expect(aliceWriteReply.status.code).
|
|
3389
|
+
expect(aliceWriteReply.status.code).toBe(202);
|
|
3392
3390
|
const aliceQueryWriteAfterAliceWriteData = yield TestDataGenerator.generateRecordsQuery({
|
|
3393
3391
|
author: alice,
|
|
3394
3392
|
filter: { recordId: aliceWriteData.message.recordId }
|
|
3395
3393
|
});
|
|
3396
3394
|
const aliceQueryWriteAfterAliceWriteReply = yield dwn.processMessage(alice.did, aliceQueryWriteAfterAliceWriteData.message);
|
|
3397
|
-
expect(aliceQueryWriteAfterAliceWriteReply.status.code).
|
|
3398
|
-
expect((_a = aliceQueryWriteAfterAliceWriteReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
3399
|
-
expect(aliceQueryWriteAfterAliceWriteReply.entries[0].encodedData).
|
|
3395
|
+
expect(aliceQueryWriteAfterAliceWriteReply.status.code).toBe(200);
|
|
3396
|
+
expect((_a = aliceQueryWriteAfterAliceWriteReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
3397
|
+
expect(aliceQueryWriteAfterAliceWriteReply.entries[0].encodedData).toBe(encodedData);
|
|
3400
3398
|
// bob learns of the CID of data of alice and tries to gain unauthorized access by referencing it in his own DWN
|
|
3401
3399
|
const bobWriteData = yield TestDataGenerator.generateRecordsWrite({
|
|
3402
3400
|
author: bob,
|
|
@@ -3404,32 +3402,32 @@ export function testRecordsWriteHandler() {
|
|
|
3404
3402
|
dataSize: 4
|
|
3405
3403
|
});
|
|
3406
3404
|
const bobWriteReply = yield dwn.processMessage(bob.did, bobWriteData.message); // intentionally missing data stream
|
|
3407
|
-
expect(bobWriteReply.status.code).
|
|
3405
|
+
expect(bobWriteReply.status.code).toBe(204); // NOTE: allows write here but does not allow read or query later
|
|
3408
3406
|
const aliceQueryWriteAfterBobWriteData = yield TestDataGenerator.generateRecordsQuery({
|
|
3409
3407
|
author: alice,
|
|
3410
3408
|
filter: { recordId: aliceWriteData.message.recordId }
|
|
3411
3409
|
});
|
|
3412
3410
|
const aliceQueryWriteAfterBobWriteReply = yield dwn.processMessage(alice.did, aliceQueryWriteAfterBobWriteData.message);
|
|
3413
|
-
expect(aliceQueryWriteAfterBobWriteReply.status.code).
|
|
3414
|
-
expect((_b = aliceQueryWriteAfterBobWriteReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
3415
|
-
expect(aliceQueryWriteAfterBobWriteReply.entries[0].encodedData).
|
|
3411
|
+
expect(aliceQueryWriteAfterBobWriteReply.status.code).toBe(200);
|
|
3412
|
+
expect((_b = aliceQueryWriteAfterBobWriteReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
|
|
3413
|
+
expect(aliceQueryWriteAfterBobWriteReply.entries[0].encodedData).toBe(encodedData);
|
|
3416
3414
|
// verify that bob has not gained access to alice's data
|
|
3417
3415
|
const bobQueryAfterBobWriteData = yield TestDataGenerator.generateRecordsQuery({
|
|
3418
3416
|
author: bob,
|
|
3419
3417
|
filter: { recordId: bobWriteData.message.recordId }
|
|
3420
3418
|
});
|
|
3421
3419
|
const bobQueryAfterBobWriteReply = yield dwn.processMessage(bob.did, bobQueryAfterBobWriteData.message);
|
|
3422
|
-
expect(bobQueryAfterBobWriteReply.status.code).
|
|
3423
|
-
expect((_c = bobQueryAfterBobWriteReply.entries) === null || _c === void 0 ? void 0 : _c.length).
|
|
3420
|
+
expect(bobQueryAfterBobWriteReply.status.code).toBe(200);
|
|
3421
|
+
expect((_c = bobQueryAfterBobWriteReply.entries) === null || _c === void 0 ? void 0 : _c.length).toBe(0);
|
|
3424
3422
|
}));
|
|
3425
|
-
describe('encodedData threshold', () =>
|
|
3423
|
+
describe('encodedData threshold', () => {
|
|
3426
3424
|
it('should call cloneAndAddEncodedData if dataSize is less than or equal to the threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
3427
3425
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
3428
3426
|
const dataBytes = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded);
|
|
3429
3427
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: dataBytes });
|
|
3430
3428
|
const processEncoded = sinon.spy(RecordsWriteHandler.prototype, 'cloneAndAddEncodedData');
|
|
3431
3429
|
const writeMessage = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
3432
|
-
expect(writeMessage.status.code).
|
|
3430
|
+
expect(writeMessage.status.code).toBe(202);
|
|
3433
3431
|
sinon.assert.calledOnce(processEncoded);
|
|
3434
3432
|
}));
|
|
3435
3433
|
it('should not call cloneAndAddEncodedData if dataSize is greater than the threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -3438,7 +3436,7 @@ export function testRecordsWriteHandler() {
|
|
|
3438
3436
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: dataBytes });
|
|
3439
3437
|
const processEncoded = sinon.spy(RecordsWriteHandler.prototype, 'cloneAndAddEncodedData');
|
|
3440
3438
|
const writeMessage = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
3441
|
-
expect(writeMessage.status.code).
|
|
3439
|
+
expect(writeMessage.status.code).toBe(202);
|
|
3442
3440
|
sinon.assert.notCalled(processEncoded);
|
|
3443
3441
|
}));
|
|
3444
3442
|
it('should have encodedData field if dataSize is less than or equal to the threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -3446,30 +3444,30 @@ export function testRecordsWriteHandler() {
|
|
|
3446
3444
|
const dataBytes = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded);
|
|
3447
3445
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: dataBytes });
|
|
3448
3446
|
const writeMessage = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
3449
|
-
expect(writeMessage.status.code).
|
|
3447
|
+
expect(writeMessage.status.code).toBe(202);
|
|
3450
3448
|
const messageCid = yield Message.getCid(message);
|
|
3451
3449
|
const storedMessage = yield messageStore.get(alice.did, messageCid);
|
|
3452
|
-
expect(storedMessage.encodedData).
|
|
3450
|
+
expect(storedMessage.encodedData).toBeDefined();
|
|
3453
3451
|
}));
|
|
3454
3452
|
it('should not have encodedData field if dataSize greater than threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
3455
3453
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
3456
3454
|
const dataBytes = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded + 1);
|
|
3457
3455
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: dataBytes });
|
|
3458
3456
|
const writeMessage = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
3459
|
-
expect(writeMessage.status.code).
|
|
3457
|
+
expect(writeMessage.status.code).toBe(202);
|
|
3460
3458
|
const messageCid = yield Message.getCid(message);
|
|
3461
3459
|
const storedMessage = yield messageStore.get(alice.did, messageCid);
|
|
3462
|
-
expect(storedMessage.encodedData).
|
|
3460
|
+
expect(storedMessage.encodedData).toBeUndefined();
|
|
3463
3461
|
}));
|
|
3464
3462
|
it('should retain original RecordsWrite message but without the encodedData if data is under threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
3465
3463
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
3466
3464
|
const dataBytes = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded);
|
|
3467
3465
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: dataBytes });
|
|
3468
3466
|
const writeMessage = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
3469
|
-
expect(writeMessage.status.code).
|
|
3467
|
+
expect(writeMessage.status.code).toBe(202);
|
|
3470
3468
|
const messageCid = yield Message.getCid(message);
|
|
3471
3469
|
const storedMessage = yield messageStore.get(alice.did, messageCid);
|
|
3472
|
-
expect(storedMessage.encodedData).
|
|
3470
|
+
expect(storedMessage.encodedData).toBeDefined();
|
|
3473
3471
|
const updatedDataBytes = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded);
|
|
3474
3472
|
const newWrite = yield RecordsWrite.createFrom({
|
|
3475
3473
|
recordsWriteMessage: message,
|
|
@@ -3479,13 +3477,13 @@ export function testRecordsWriteHandler() {
|
|
|
3479
3477
|
});
|
|
3480
3478
|
const updateDataStream = DataStream.fromBytes(updatedDataBytes);
|
|
3481
3479
|
const writeMessage2 = yield dwn.processMessage(alice.did, newWrite.message, { dataStream: updateDataStream });
|
|
3482
|
-
expect(writeMessage2.status.code).
|
|
3480
|
+
expect(writeMessage2.status.code).toBe(202);
|
|
3483
3481
|
const originalWrite = yield messageStore.get(alice.did, messageCid);
|
|
3484
|
-
expect(originalWrite.encodedData).
|
|
3482
|
+
expect(originalWrite.encodedData).toBeUndefined();
|
|
3485
3483
|
const newestWrite = yield messageStore.get(alice.did, yield Message.getCid(newWrite.message));
|
|
3486
|
-
expect(newestWrite.encodedData).
|
|
3484
|
+
expect(newestWrite.encodedData).toBeDefined();
|
|
3487
3485
|
}));
|
|
3488
|
-
})
|
|
3486
|
+
});
|
|
3489
3487
|
});
|
|
3490
3488
|
describe('authorization validation tests', () => {
|
|
3491
3489
|
it('should return 400 if `recordId` in payload of the message signature mismatches with `recordId` in the message', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -3501,10 +3499,10 @@ export function testRecordsWriteHandler() {
|
|
|
3501
3499
|
const didResolver = TestStubGenerator.createDidResolverStub(author);
|
|
3502
3500
|
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
3503
3501
|
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
3504
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub,
|
|
3502
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, stateIndex, eventStream);
|
|
3505
3503
|
const reply = yield recordsWriteHandler.handle({ tenant, message, dataStream: dataStream });
|
|
3506
|
-
expect(reply.status.code).
|
|
3507
|
-
expect(reply.status.detail).
|
|
3504
|
+
expect(reply.status.code).toBe(400);
|
|
3505
|
+
expect(reply.status.detail).toContain('does not match recordId in authorization');
|
|
3508
3506
|
}));
|
|
3509
3507
|
it('should return 400 if `contextId` in payload of message signature mismatches with `contextId` in the message', () => __awaiter(this, void 0, void 0, function* () {
|
|
3510
3508
|
// generate a message with protocol so that computed contextId is also computed and included in message
|
|
@@ -3520,10 +3518,10 @@ export function testRecordsWriteHandler() {
|
|
|
3520
3518
|
const didResolver = sinon.createStubInstance(UniversalResolver);
|
|
3521
3519
|
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
3522
3520
|
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
3523
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub,
|
|
3521
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, stateIndex, eventStream);
|
|
3524
3522
|
const reply = yield recordsWriteHandler.handle({ tenant, message, dataStream: dataStream });
|
|
3525
|
-
expect(reply.status.code).
|
|
3526
|
-
expect(reply.status.detail).
|
|
3523
|
+
expect(reply.status.code).toBe(400);
|
|
3524
|
+
expect(reply.status.detail).toContain('does not match contextId in authorization');
|
|
3527
3525
|
}));
|
|
3528
3526
|
it('should return 401 if `authorization` signature check fails', () => __awaiter(this, void 0, void 0, function* () {
|
|
3529
3527
|
const { author, message, dataStream } = yield TestDataGenerator.generateRecordsWrite();
|
|
@@ -3534,9 +3532,9 @@ export function testRecordsWriteHandler() {
|
|
|
3534
3532
|
const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona);
|
|
3535
3533
|
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
3536
3534
|
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
3537
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub,
|
|
3535
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, stateIndex, eventStream);
|
|
3538
3536
|
const reply = yield recordsWriteHandler.handle({ tenant, message, dataStream: dataStream });
|
|
3539
|
-
expect(reply.status.code).
|
|
3537
|
+
expect(reply.status.code).toBe(401);
|
|
3540
3538
|
}));
|
|
3541
3539
|
it('should return 401 if an unauthorized author is attempting write', () => __awaiter(this, void 0, void 0, function* () {
|
|
3542
3540
|
const author = yield TestDataGenerator.generatePersona();
|
|
@@ -3545,10 +3543,10 @@ export function testRecordsWriteHandler() {
|
|
|
3545
3543
|
const didResolver = TestStubGenerator.createDidResolverStub(author);
|
|
3546
3544
|
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
3547
3545
|
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
3548
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub,
|
|
3546
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, stateIndex, eventStream);
|
|
3549
3547
|
const tenant = yield (yield TestDataGenerator.generatePersona()).did; // unauthorized tenant
|
|
3550
3548
|
const reply = yield recordsWriteHandler.handle({ tenant, message, dataStream: dataStream });
|
|
3551
|
-
expect(reply.status.code).
|
|
3549
|
+
expect(reply.status.code).toBe(401);
|
|
3552
3550
|
}));
|
|
3553
3551
|
});
|
|
3554
3552
|
describe('attestation validation tests', () => {
|
|
@@ -3571,19 +3569,19 @@ export function testRecordsWriteHandler() {
|
|
|
3571
3569
|
const didResolver = TestStubGenerator.createDidResolverStub(author);
|
|
3572
3570
|
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
3573
3571
|
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
3574
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub,
|
|
3572
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStoreStub, dataStoreStub, stateIndex, eventStream);
|
|
3575
3573
|
const reply = yield recordsWriteHandler.handle({ tenant, message, dataStream: dataStream });
|
|
3576
|
-
expect(reply.status.code).
|
|
3577
|
-
expect(reply.status.detail).
|
|
3574
|
+
expect(reply.status.code).toBe(400);
|
|
3575
|
+
expect(reply.status.detail).toContain(`Only 'descriptorCid' is allowed in attestation payload`);
|
|
3578
3576
|
}));
|
|
3579
3577
|
it('should fail validation with 400 if more than 1 attester is given ', () => __awaiter(this, void 0, void 0, function* () {
|
|
3580
3578
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
3581
3579
|
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
3582
3580
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, attesters: [alice, bob] });
|
|
3583
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore,
|
|
3581
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, stateIndex, eventStream);
|
|
3584
3582
|
const writeReply = yield recordsWriteHandler.handle({ tenant: alice.did, message, dataStream: dataStream });
|
|
3585
|
-
expect(writeReply.status.code).
|
|
3586
|
-
expect(writeReply.status.detail).
|
|
3583
|
+
expect(writeReply.status.code).toBe(400);
|
|
3584
|
+
expect(writeReply.status.detail).toContain('implementation only supports 1 attester');
|
|
3587
3585
|
}));
|
|
3588
3586
|
it('should fail validation with 400 if the `attestation` does not include the correct `descriptorCid`', () => __awaiter(this, void 0, void 0, function* () {
|
|
3589
3587
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -3591,10 +3589,10 @@ export function testRecordsWriteHandler() {
|
|
|
3591
3589
|
// create another write and use its `attestation` value instead, that `attestation` will point to an entirely different `descriptorCid`
|
|
3592
3590
|
const anotherWrite = yield TestDataGenerator.generateRecordsWrite({ attesters: [alice] });
|
|
3593
3591
|
message.attestation = anotherWrite.message.attestation;
|
|
3594
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore,
|
|
3592
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, stateIndex, eventStream);
|
|
3595
3593
|
const writeReply = yield recordsWriteHandler.handle({ tenant: alice.did, message, dataStream: dataStream });
|
|
3596
|
-
expect(writeReply.status.code).
|
|
3597
|
-
expect(writeReply.status.detail).
|
|
3594
|
+
expect(writeReply.status.code).toBe(400);
|
|
3595
|
+
expect(writeReply.status.detail).toContain('does not match expected descriptorCid');
|
|
3598
3596
|
}));
|
|
3599
3597
|
it('should fail validation with 400 if expected CID of `attestation` mismatches the `attestationCid` in `authorization`', () => __awaiter(this, void 0, void 0, function* () {
|
|
3600
3598
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -3604,16 +3602,16 @@ export function testRecordsWriteHandler() {
|
|
|
3604
3602
|
const descriptorCid = yield Cid.computeCid(message.descriptor);
|
|
3605
3603
|
const attestationNotReferencedByAuthorization = yield RecordsWrite['createAttestation'](descriptorCid, Jws.createSigners([bob]));
|
|
3606
3604
|
message.attestation = attestationNotReferencedByAuthorization;
|
|
3607
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore,
|
|
3605
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, stateIndex, eventStream);
|
|
3608
3606
|
const writeReply = yield recordsWriteHandler.handle({ tenant: alice.did, message, dataStream: dataStream });
|
|
3609
|
-
expect(writeReply.status.code).
|
|
3610
|
-
expect(writeReply.status.detail).
|
|
3607
|
+
expect(writeReply.status.code).toBe(400);
|
|
3608
|
+
expect(writeReply.status.detail).toContain('does not match attestationCid');
|
|
3611
3609
|
}));
|
|
3612
3610
|
});
|
|
3613
3611
|
describe('unknown error', () => {
|
|
3614
3612
|
it('should throw if `recordsWriteHandler.processMessageWithoutDataStream()` throws unknown error', () => __awaiter(this, void 0, void 0, function* () {
|
|
3615
3613
|
// simulate an initial write to test non-data path, as initial writes without data are always accepted (bot not readable)
|
|
3616
|
-
// https://github.com/
|
|
3614
|
+
// https://github.com/enboxorg/enbox/issues/628
|
|
3617
3615
|
const { author, message: initialWriteMessage, recordsWrite: initialWrite } = yield TestDataGenerator.generateRecordsWrite();
|
|
3618
3616
|
yield Time.minimalSleep();
|
|
3619
3617
|
const { message, dataStream } = yield TestDataGenerator.generateFromRecordsWrite({ author, existingWrite: initialWrite });
|
|
@@ -3622,16 +3620,16 @@ export function testRecordsWriteHandler() {
|
|
|
3622
3620
|
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
3623
3621
|
messageStoreStub.query.resolves({ messages: [initialWriteMessage] });
|
|
3624
3622
|
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
3625
|
-
const recordsWriteHandler = new RecordsWriteHandler(didResolverStub, messageStoreStub, dataStoreStub,
|
|
3623
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolverStub, messageStoreStub, dataStoreStub, stateIndex, eventStream);
|
|
3626
3624
|
// simulate throwing unexpected error
|
|
3627
3625
|
sinon.stub(recordsWriteHandler, 'processMessageWithoutDataStream').throws(new Error('an unknown error in recordsWriteHandler.processMessageWithoutDataStream()'));
|
|
3628
3626
|
sinon.stub(recordsWriteHandler, 'processMessageWithDataStream').throws(new Error('an unknown error in recordsWriteHandler.processMessageWithDataStream()'));
|
|
3629
3627
|
let handlerPromise = recordsWriteHandler.handle({ tenant, message, dataStream: dataStream }); // with data stream
|
|
3630
|
-
yield expect(handlerPromise).
|
|
3628
|
+
yield expect(handlerPromise).rejects.toThrow('an unknown error in recordsWriteHandler.processMessageWithDataStream()');
|
|
3631
3629
|
handlerPromise = recordsWriteHandler.handle({ tenant, message }); // without data stream
|
|
3632
|
-
yield expect(handlerPromise).
|
|
3630
|
+
yield expect(handlerPromise).rejects.toThrow('an unknown error in recordsWriteHandler.processMessageWithoutDataStream()');
|
|
3633
3631
|
}));
|
|
3634
3632
|
});
|
|
3635
|
-
})
|
|
3633
|
+
});
|
|
3636
3634
|
}
|
|
3637
3635
|
//# sourceMappingURL=records-write.spec.js.map
|