spec-3nweb-server 1.8.4 → 1.8.6
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/.gitlab-ci-linux.yml +50 -0
- package/.gitlab-ci-mac.yml +29 -0
- package/.gitlab-ci-windows.yml +29 -0
- package/.gitlab-ci.yml +63 -0
- package/build/3nstorage/routes/owner/archive-obj-version.js +2 -2
- package/build/3nstorage/routes/owner/cancel-trans.js +2 -2
- package/build/3nstorage/routes/owner/delete-obj.js +2 -2
- package/build/3nstorage/routes/owner/get-current-obj.js +3 -4
- package/build/3nstorage/routes/owner/param-setter.js +2 -6
- package/build/asmail/routes/config/param-setter.js +2 -2
- package/build/asmail/routes/delivery/finalize-delivery.js +2 -2
- package/build/asmail/routes/delivery/put-obj.js +2 -2
- package/build/asmail/routes/delivery/sender-authorization.js +2 -2
- package/build/asmail/routes/retrieval/remove-message.js +2 -2
- package/build/cli/signup-cmd.js +0 -1
- package/build/lib-server/routes/sessions/close.js +2 -2
- package/build/lib-server/routes/sessions/mid-auth.js +2 -5
- package/build/main.js +12 -15
- package/build/mock/tls-options.js +46 -44
- package/build/signup/routes/add.js +4 -4
- package/build/tests/admin-proto/signup.d.ts +1 -0
- package/build/tests/admin-proto/signup.js +235 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +32 -0
- package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
- package/build/tests/libs-for-tests/3nstorage.js +123 -0
- package/build/tests/libs-for-tests/asmail.d.ts +22 -0
- package/build/tests/libs-for-tests/asmail.js +179 -0
- package/build/tests/libs-for-tests/assert.d.ts +1 -0
- package/build/tests/libs-for-tests/assert.js +26 -0
- package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
- package/build/tests/libs-for-tests/async-jasmine.js +77 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +34 -0
- package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
- package/build/tests/libs-for-tests/json-copy.js +45 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
- package/build/tests/libs-for-tests/json-equal.js +67 -0
- package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
- package/build/tests/libs-for-tests/mailerid.js +114 -0
- package/build/tests/libs-for-tests/pkl.d.ts +28 -0
- package/build/tests/libs-for-tests/pkl.js +89 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
- package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
- package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
- package/build/tests/libs-for-tests/server-components/admin.js +43 -0
- package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
- package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
- package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
- package/build/tests/libs-for-tests/server-components/component.js +77 -0
- package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
- package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
- package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
- package/build/tests/libs-for-tests/server-runner.js +69 -0
- package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
- package/build/tests/libs-for-tests/spec-assembly.js +55 -0
- package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
- package/build/tests/libs-for-tests/ws-utils.js +59 -0
- package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
- package/build/tests/libs-for-tests/xhr-utils.js +154 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
- package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
- package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
- package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
- package/build/tests/protocols/3nstorage/owner.js +138 -0
- package/build/tests/protocols/asmail/config.d.ts +1 -0
- package/build/tests/protocols/asmail/config.js +117 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
- package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
- package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
- package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
- package/build/tests/protocols/asmail/delivery.d.ts +1 -0
- package/build/tests/protocols/asmail/delivery.js +46 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
- package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
- package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
- package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
- package/build/tests/protocols/asmail/retrieval.js +92 -0
- package/build/tests/protocols/mailerid.d.ts +1 -0
- package/build/tests/protocols/mailerid.js +210 -0
- package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
- package/build/tests/shared-checks/check-mid-login.js +131 -0
- package/build/tests/shared-checks/requests.d.ts +20 -0
- package/build/tests/shared-checks/requests.js +123 -0
- package/package.json +1 -1
- package/packing/create-deb.sh +57 -0
- package/packing/deb/lib/systemd/system/3nweb.service +11 -0
- package/packing/deb/postinst +44 -0
- package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
- package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
- package/publish-task.sh +10 -0
- package/push-to-github.sh +105 -0
- package/ts-code/3nstorage/3nstorage-app.ts +99 -0
- package/ts-code/3nstorage/owner.ts +178 -0
- package/ts-code/3nstorage/resources/sessions.ts +37 -0
- package/ts-code/3nstorage/resources/store.ts +896 -0
- package/ts-code/3nstorage/resources/users.ts +258 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +73 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +58 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +103 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +111 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +122 -0
- package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
- package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
- package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
- package/ts-code/3nstorage/routes/owner/put-current-obj.ts +284 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +49 -0
- package/ts-code/3nstorage/shared.ts +43 -0
- package/ts-code/asmail/asmail-app.ts +91 -0
- package/ts-code/asmail/config.ts +96 -0
- package/ts-code/asmail/delivery.ts +94 -0
- package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
- package/ts-code/asmail/resources/inbox.ts +696 -0
- package/ts-code/asmail/resources/recipients.ts +495 -0
- package/ts-code/asmail/resources/sessions.ts +37 -0
- package/ts-code/asmail/retrieval.ts +96 -0
- package/ts-code/asmail/routes/config/param-getter.ts +49 -0
- package/ts-code/asmail/routes/config/param-setter.ts +49 -0
- package/ts-code/asmail/routes/delivery/finalize-delivery.ts +50 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +132 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +94 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +166 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +130 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +151 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +53 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +109 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +70 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +47 -0
- package/ts-code/cli/index.ts +82 -0
- package/ts-code/cli/run-cmd.ts +81 -0
- package/ts-code/cli/show-sample-config.ts +78 -0
- package/ts-code/cli/signup-cmd.ts +229 -0
- package/ts-code/cli/user-cmd.ts +68 -0
- package/ts-code/cli/utils.ts +105 -0
- package/ts-code/config/default-confs.ts +22 -0
- package/ts-code/config/from-yaml.ts +35 -0
- package/ts-code/config/letsencrypt.ts +77 -0
- package/ts-code/config/signup.ts +137 -0
- package/ts-code/lib-common/admin-api/signup.ts +120 -0
- package/ts-code/lib-common/assert.ts +22 -0
- package/ts-code/lib-common/async-fs-node.ts +656 -0
- package/ts-code/lib-common/buffer-utils.ts +124 -0
- package/ts-code/lib-common/byte-streaming/common.ts +166 -0
- package/ts-code/lib-common/bytes-equal.ts +25 -0
- package/ts-code/lib-common/canonical-address.ts +92 -0
- package/ts-code/lib-common/exceptions/error.ts +44 -0
- package/ts-code/lib-common/exceptions/file.ts +84 -0
- package/ts-code/lib-common/exceptions/http.ts +69 -0
- package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
- package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
- package/ts-code/lib-common/json-equal.ts +55 -0
- package/ts-code/lib-common/json-utils.ts +130 -0
- package/ts-code/lib-common/jwkeys.ts +246 -0
- package/ts-code/lib-common/map-of-sets.ts +60 -0
- package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
- package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
- package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
- package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
- package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
- package/ts-code/lib-common/processes.ts +501 -0
- package/ts-code/lib-common/random-node.ts +79 -0
- package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
- package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
- package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
- package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
- package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
- package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
- package/ts-code/lib-common/service-api/locker.ts +44 -0
- package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
- package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
- package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
- package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
- package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
- package/ts-code/lib-common/session-encryptor.ts +54 -0
- package/ts-code/lib-common/time-window-cache.ts +74 -0
- package/ts-code/lib-common/transferable.d.ts +30 -0
- package/ts-code/lib-server/conf-util.ts +35 -0
- package/ts-code/lib-server/mid-access.ts +45 -0
- package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
- package/ts-code/lib-server/middleware/error-handler.ts +79 -0
- package/ts-code/lib-server/pkl-access.ts +46 -0
- package/ts-code/lib-server/resources/dns.ts +151 -0
- package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
- package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
- package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
- package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
- package/ts-code/lib-server/resources/sessions.ts +232 -0
- package/ts-code/lib-server/resources/user-files.ts +147 -0
- package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
- package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
- package/ts-code/lib-server/routes/sessions/close.ts +27 -0
- package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
- package/ts-code/lib-server/routes/sessions/start.ts +116 -0
- package/ts-code/lib-server/web-sockets/app.ts +339 -0
- package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
- package/ts-code/lib.ts +29 -0
- package/ts-code/locker/locker-app.ts +60 -0
- package/ts-code/locker/resources/lockers.ts +17 -0
- package/ts-code/locker/resources/sessions.ts +37 -0
- package/ts-code/locker/routes/create-locker.ts +47 -0
- package/ts-code/mailerId/mailerId-app.ts +107 -0
- package/ts-code/mailerId/resources/certifier.ts +181 -0
- package/ts-code/mailerId/resources/sessions.ts +44 -0
- package/ts-code/mailerId/resources/users.ts +88 -0
- package/ts-code/mailerId/routes/certify.ts +68 -0
- package/ts-code/main.ts +304 -0
- package/ts-code/mock/dns.ts +106 -0
- package/ts-code/mock/mock-as-child-proc.ts +130 -0
- package/ts-code/mock/node-child-ipc.ts +69 -0
- package/ts-code/mock/run-in-proc.ts +111 -0
- package/ts-code/mock/tls-options.ts +73 -0
- package/ts-code/services.ts +138 -0
- package/ts-code/signup/resources/users.ts +429 -0
- package/ts-code/signup/routes/add.ts +65 -0
- package/ts-code/signup/routes/get-available-addresses.ts +49 -0
- package/ts-code/signup/routes/get-available-domains.ts +45 -0
- package/ts-code/signup/signup-app.ts +54 -0
- package/ts-code/signup/signup-tokens.ts +148 -0
- package/ts-code/tests/admin-proto/signup.ts +277 -0
- package/ts-code/tests/jasmine.ts +37 -0
- package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
- package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
- package/ts-code/tests/libs-for-tests/assert.ts +22 -0
- package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
- package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
- package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
- package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
- package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
- package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
- package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
- package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
- package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
- package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
- package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
- package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
- package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
- package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
- package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
- package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
- package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
- package/ts-code/tests/protocols/asmail/config.ts +172 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
- package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
- package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
- package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
- package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
- package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
- package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
- package/ts-code/tests/protocols/mailerid.ts +271 -0
- package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
- package/ts-code/tests/shared-checks/requests.ts +135 -0
- package/ts-code/tsconfig.json +11 -0
- package/ts-code/web3n.d.ts +1068 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2020 - 2021 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { toCanonicalAddress } from '../lib-common/canonical-address';
|
|
19
|
+
import { assert } from '../lib-common/assert';
|
|
20
|
+
import { bytes as randomBytes } from '../lib-common/random-node';
|
|
21
|
+
import { base64urlSafe } from '../lib-common/buffer-utils';
|
|
22
|
+
import { tokensInRootFolder } from '../lib-server/resources/server-data-folders';
|
|
23
|
+
import { join } from 'path';
|
|
24
|
+
import { compareVectors } from 'ecma-nacl';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export type SignupContext = SingleUserSignupCtx | MultiDomainSignupCtx;
|
|
28
|
+
|
|
29
|
+
export interface SingleUserSignupCtx {
|
|
30
|
+
token: string;
|
|
31
|
+
type: 'single-user';
|
|
32
|
+
userId: string;
|
|
33
|
+
validTill?: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MultiDomainSignupCtx {
|
|
37
|
+
token?: string;
|
|
38
|
+
type: 'multi-domain';
|
|
39
|
+
domains: string[];
|
|
40
|
+
validTill?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function canCreateUser(userId: string, ctx: SignupContext): boolean {
|
|
44
|
+
if (ctx.validTill) {
|
|
45
|
+
const now = Math.floor(Date.now()/1000);
|
|
46
|
+
if (now > ctx.validTill) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const cAddr = toCanonicalAddress(userId);
|
|
51
|
+
if (ctx.type === 'single-user') {
|
|
52
|
+
return (cAddr === ctx.userId);
|
|
53
|
+
} else if (ctx.type === 'multi-domain') {
|
|
54
|
+
return !!ctx.domains.find(d => cAddr.endsWith(`@${d}`));
|
|
55
|
+
} else {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function addressesForName(
|
|
61
|
+
name: string, ctx: SignupContext
|
|
62
|
+
): string[]|undefined {
|
|
63
|
+
if (ctx.validTill) {
|
|
64
|
+
const now = Math.floor(Date.now()/1000);
|
|
65
|
+
if (now > ctx.validTill) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (ctx.type === 'single-user') {
|
|
70
|
+
const userId = `${name}${ctx.userId.substring(ctx.userId.indexOf('@'))}`;
|
|
71
|
+
return ((toCanonicalAddress(userId) === ctx.userId) ?
|
|
72
|
+
[ userId ] : [] );
|
|
73
|
+
} else if (ctx.type === 'multi-domain') {
|
|
74
|
+
return ctx.domains.map(d => `${name}@${d}`);
|
|
75
|
+
} else {
|
|
76
|
+
throw Error(`Unknown signup context type ${(ctx as any).type}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function makeSingleUserSignupCtx(
|
|
81
|
+
token: string, userId: string, validitySecs?: number
|
|
82
|
+
): SingleUserSignupCtx {
|
|
83
|
+
const ctx: SingleUserSignupCtx = {
|
|
84
|
+
token,
|
|
85
|
+
type: 'single-user',
|
|
86
|
+
userId: toCanonicalAddress(userId)
|
|
87
|
+
};
|
|
88
|
+
if (validitySecs) {
|
|
89
|
+
ctx.validTill = Math.floor(Date.now()/1000) + validitySecs;
|
|
90
|
+
}
|
|
91
|
+
return ctx;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function makeMultiDomainSignupCtx(
|
|
95
|
+
signupDomains: string[], token?: string, validitySecs?: number
|
|
96
|
+
): MultiDomainSignupCtx {
|
|
97
|
+
assert(Array.isArray(signupDomains));
|
|
98
|
+
const ctx: MultiDomainSignupCtx = {
|
|
99
|
+
token,
|
|
100
|
+
type: 'multi-domain',
|
|
101
|
+
domains: signupDomains.map(d => toCanonicalAddress(d).substring(1))
|
|
102
|
+
};
|
|
103
|
+
if (validitySecs) {
|
|
104
|
+
ctx.validTill = Math.floor(Date.now()/1000) + validitySecs;
|
|
105
|
+
}
|
|
106
|
+
return ctx;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const TOKEN_BYTES_LEN = 30;
|
|
110
|
+
const TOKEN_FILE_NAME_LEN = 10;
|
|
111
|
+
|
|
112
|
+
export async function generateToken(): Promise<string> {
|
|
113
|
+
const tokenBytes = await randomBytes(TOKEN_BYTES_LEN);
|
|
114
|
+
const token = base64urlSafe.pack(tokenBytes);
|
|
115
|
+
return token;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function parseToken(
|
|
119
|
+
token: string
|
|
120
|
+
): { tokenBytes: Buffer; tokenFile: string; }|undefined {
|
|
121
|
+
try {
|
|
122
|
+
const tokenBytes = base64urlSafe.open(token) as Buffer;
|
|
123
|
+
const tokenFile = tokenFileName(token);
|
|
124
|
+
return { tokenBytes, tokenFile };
|
|
125
|
+
} catch (err) {
|
|
126
|
+
return; // explicit undefined
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function tokenFileName(token: string): string {
|
|
131
|
+
return token.substring(0, TOKEN_FILE_NAME_LEN);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function tokenPath(rootFolder: string, token: string): string {
|
|
135
|
+
return join(tokensInRootFolder(rootFolder), tokenFileName(token));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function areTokensSame(t1: Buffer, t2: string): boolean {
|
|
139
|
+
try {
|
|
140
|
+
const t2Bytes = base64urlSafe.open(t2);
|
|
141
|
+
return compareVectors(t1, t2Bytes);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016, 2020 - 2021, 2025 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { afterEachAsync, beforeEachAsync, itAsync } from '../libs-for-tests/async-jasmine';
|
|
19
|
+
import { AdminComponent } from '../libs-for-tests/server-components/admin';
|
|
20
|
+
import { doJsonRequest, RequestOpts } from '../libs-for-tests/xhr-utils';
|
|
21
|
+
import * as signupApi from '../../lib-common/admin-api/signup';
|
|
22
|
+
import { expectNonAcceptanceOfBadJsonRequest } from '../shared-checks/requests';
|
|
23
|
+
import { use } from '../../lib-common/jwkeys';
|
|
24
|
+
import { box } from 'ecma-nacl';
|
|
25
|
+
|
|
26
|
+
describe('Admin', () => {
|
|
27
|
+
|
|
28
|
+
describe('signup subsystem', () => {
|
|
29
|
+
|
|
30
|
+
let admin: AdminComponent;
|
|
31
|
+
const signupDomains = [ 'first.org', 'second.org' ];
|
|
32
|
+
|
|
33
|
+
beforeEachAsync(async () => {
|
|
34
|
+
admin = new AdminComponent(signupDomains);
|
|
35
|
+
await admin.start();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEachAsync(async () => {
|
|
39
|
+
await admin.stop();
|
|
40
|
+
admin = (undefined as any);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
itAsync('tells available addresses for a given name', async () => {
|
|
44
|
+
|
|
45
|
+
const REQ_SIZE_LIMIT = 1024;
|
|
46
|
+
|
|
47
|
+
const name = 'Bob Marley ';
|
|
48
|
+
|
|
49
|
+
const reqOpts: RequestOpts= {
|
|
50
|
+
url: admin.signupUrl + signupApi.availableAddressesForName.URL_END,
|
|
51
|
+
method: 'POST',
|
|
52
|
+
responseType: 'json'
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// request with ok name
|
|
56
|
+
let req: signupApi.availableAddressesForName.Request = { name };
|
|
57
|
+
const rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
58
|
+
expect(rep.status).withContext('status code for OK reply').toBe(signupApi.availableAddressesForName.SC.ok);
|
|
59
|
+
expect(Array.isArray(rep.data)).withContext('OK reply is an array').toBe(true);
|
|
60
|
+
expect(rep.data.length).withContext('with no users, all domains should used as options for available addresses').toBe(signupDomains.length);
|
|
61
|
+
for (const domain of signupDomains) {
|
|
62
|
+
expect(rep.data).toContain(name+'@'+domain);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// requests with bad names and with bad json's
|
|
66
|
+
const badNames = [ name+'@something', // char '@' not allowed in name
|
|
67
|
+
5, null, undefined, {} ]; // non-strings
|
|
68
|
+
const badJSONs: any[] = [ name, 5, null, undefined, [ name ],
|
|
69
|
+
{ a: 1 } ];
|
|
70
|
+
for (const badName of badNames) {
|
|
71
|
+
req = { name: <string> badName };
|
|
72
|
+
badJSONs.push(req);
|
|
73
|
+
}
|
|
74
|
+
await expectNonAcceptanceOfBadJsonRequest(reqOpts,
|
|
75
|
+
REQ_SIZE_LIMIT, badJSONs);
|
|
76
|
+
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
itAsync('tells available domains', async () => {
|
|
80
|
+
|
|
81
|
+
const REQ_SIZE_LIMIT = 1024;
|
|
82
|
+
|
|
83
|
+
const reqOpts: RequestOpts= {
|
|
84
|
+
url: admin.signupUrl + signupApi.availableDomains.URL_END,
|
|
85
|
+
method: 'POST',
|
|
86
|
+
responseType: 'json'
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const req: signupApi.availableDomains.Request = {};
|
|
90
|
+
const rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
91
|
+
expect(rep.status).withContext('status code for OK reply').toBe(signupApi.availableDomains.SC.ok);
|
|
92
|
+
expect(Array.isArray(rep.data)).withContext('OK reply is an array').toBe(true);
|
|
93
|
+
expect(rep.data.length).withContext('with no token, all domains should be given as options').toBe(signupDomains.length);
|
|
94
|
+
for (const domain of signupDomains) {
|
|
95
|
+
expect(rep.data).toContain(domain);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// requests with bad json's
|
|
99
|
+
const badJSONs: any[] = [ { signupToken: 4 } ];
|
|
100
|
+
await expectNonAcceptanceOfBadJsonRequest(
|
|
101
|
+
reqOpts, REQ_SIZE_LIMIT, badJSONs);
|
|
102
|
+
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
async function getAvailableAddressesFor(name: string): Promise<string[]> {
|
|
106
|
+
const reqOpts: RequestOpts= {
|
|
107
|
+
url: admin.signupUrl + signupApi.availableAddressesForName.URL_END,
|
|
108
|
+
method: 'POST',
|
|
109
|
+
responseType: 'json'
|
|
110
|
+
};
|
|
111
|
+
const req: signupApi.availableAddressesForName.Request = { name };
|
|
112
|
+
const rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
113
|
+
expect(rep.status).toBe(signupApi.availableAddressesForName.SC.ok);
|
|
114
|
+
return rep.data;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function makeAddUserReq(
|
|
118
|
+
userId: string, signupToken?: string
|
|
119
|
+
): signupApi.addUser.Request {
|
|
120
|
+
return {
|
|
121
|
+
userId,
|
|
122
|
+
storage: {
|
|
123
|
+
kdParams: {}
|
|
124
|
+
},
|
|
125
|
+
mailerId: {
|
|
126
|
+
defaultPKey: {
|
|
127
|
+
pkey: {
|
|
128
|
+
alg: box.JWK_ALG_NAME,
|
|
129
|
+
kid: (Buffer.alloc(12)).toString('base64'),
|
|
130
|
+
use: use.MID_PKLOGIN,
|
|
131
|
+
k: (Buffer.alloc(box.KEY_LENGTH)).toString('base64')
|
|
132
|
+
},
|
|
133
|
+
kdParams: {}
|
|
134
|
+
},
|
|
135
|
+
otherPKeys: [ {
|
|
136
|
+
alg: box.JWK_ALG_NAME,
|
|
137
|
+
kid: (Buffer.alloc(12)).toString('base64'),
|
|
138
|
+
use: use.MID_PKLOGIN,
|
|
139
|
+
k: (Buffer.alloc(box.KEY_LENGTH)).toString('base64')
|
|
140
|
+
} ]
|
|
141
|
+
},
|
|
142
|
+
signupToken
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function makeBadAddUserReq(goodId: string): any[] {
|
|
147
|
+
const name = 'Bob Marley';
|
|
148
|
+
const badJSONs: any[] = [ name, 5, null, undefined, [ name ],
|
|
149
|
+
{ a: 1 } ];
|
|
150
|
+
const badIds = [ 'bad domain str',
|
|
151
|
+
'', ' ', '\t', '\n', // these are all equivalent to empty string
|
|
152
|
+
5, null, undefined, {} ]; // non-strings
|
|
153
|
+
for (const id of badIds) {
|
|
154
|
+
const req = makeAddUserReq(<string> id);
|
|
155
|
+
badJSONs.push(req);
|
|
156
|
+
}
|
|
157
|
+
let req = makeAddUserReq(goodId);
|
|
158
|
+
delete (req as any).userId;
|
|
159
|
+
badJSONs.push(req);
|
|
160
|
+
req = makeAddUserReq(goodId);
|
|
161
|
+
delete (req as any).storage;
|
|
162
|
+
badJSONs.push(req);
|
|
163
|
+
req = makeAddUserReq(goodId);
|
|
164
|
+
delete req.storage.kdParams;
|
|
165
|
+
badJSONs.push(req);
|
|
166
|
+
req = makeAddUserReq(goodId);
|
|
167
|
+
delete (req as any).mailerId;
|
|
168
|
+
badJSONs.push(req);
|
|
169
|
+
req = makeAddUserReq(goodId);
|
|
170
|
+
delete (req.mailerId as any).defaultPKey;
|
|
171
|
+
badJSONs.push(req);
|
|
172
|
+
req = makeAddUserReq(goodId);
|
|
173
|
+
delete (req.mailerId.defaultPKey.pkey as any).alg;
|
|
174
|
+
badJSONs.push(req);
|
|
175
|
+
req = makeAddUserReq(goodId);
|
|
176
|
+
delete (req.mailerId.defaultPKey.pkey as any).k;
|
|
177
|
+
badJSONs.push(req);
|
|
178
|
+
req = makeAddUserReq(goodId);
|
|
179
|
+
delete (req.mailerId.defaultPKey.pkey as any).kid;
|
|
180
|
+
badJSONs.push(req);
|
|
181
|
+
req = makeAddUserReq(goodId);
|
|
182
|
+
delete (req.mailerId.defaultPKey.pkey as any).use;
|
|
183
|
+
badJSONs.push(req);
|
|
184
|
+
req = makeAddUserReq(goodId);
|
|
185
|
+
delete req.mailerId.defaultPKey.kdParams;
|
|
186
|
+
badJSONs.push(req);
|
|
187
|
+
req = makeAddUserReq(goodId);
|
|
188
|
+
delete (req.mailerId as any).otherPKeys;
|
|
189
|
+
badJSONs.push(req);
|
|
190
|
+
req = makeAddUserReq(goodId);
|
|
191
|
+
req.mailerId.otherPKeys.shift();
|
|
192
|
+
badJSONs.push(req);
|
|
193
|
+
req = makeAddUserReq(goodId);
|
|
194
|
+
delete (req.mailerId.otherPKeys[0] as any).alg;
|
|
195
|
+
badJSONs.push(req);
|
|
196
|
+
req = makeAddUserReq(goodId);
|
|
197
|
+
delete (req.mailerId.otherPKeys[0] as any).k;
|
|
198
|
+
badJSONs.push(req);
|
|
199
|
+
req = makeAddUserReq(goodId);
|
|
200
|
+
delete (req.mailerId.otherPKeys[0] as any).kid;
|
|
201
|
+
badJSONs.push(req);
|
|
202
|
+
req = makeAddUserReq(goodId);
|
|
203
|
+
delete (req.mailerId.otherPKeys[0] as any).use;
|
|
204
|
+
badJSONs.push(req);
|
|
205
|
+
return badJSONs;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function addNewUser(
|
|
209
|
+
userId: string, signupToken?: string
|
|
210
|
+
): Promise<void> {
|
|
211
|
+
const reqOpts: RequestOpts= {
|
|
212
|
+
url: admin.signupUrl + signupApi.addUser.URL_END,
|
|
213
|
+
method: 'POST'
|
|
214
|
+
};
|
|
215
|
+
const req = makeAddUserReq(userId, signupToken);
|
|
216
|
+
let rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
217
|
+
expect(rep.status).withContext('status when user is added').toBe(signupApi.addUser.SC.ok);
|
|
218
|
+
rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
219
|
+
expect(rep.status).withContext('status when user already exists').toBe(signupApi.addUser.SC.userAlreadyExists);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
itAsync('adds new user', async () => {
|
|
223
|
+
|
|
224
|
+
const REQ_SIZE_LIMIT = 4*1024;
|
|
225
|
+
|
|
226
|
+
const reqOpts: RequestOpts= {
|
|
227
|
+
url: admin.signupUrl + signupApi.addUser.URL_END,
|
|
228
|
+
method: 'POST'
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const name = 'Bob Marley ';
|
|
232
|
+
let addresses = await getAvailableAddressesFor(name);
|
|
233
|
+
let numOfAvailableAddresses = addresses.length;
|
|
234
|
+
expect(numOfAvailableAddresses).toBe(signupDomains.length);
|
|
235
|
+
|
|
236
|
+
// requests with bad json's
|
|
237
|
+
const badJSONs = makeBadAddUserReq(addresses[0]);
|
|
238
|
+
await expectNonAcceptanceOfBadJsonRequest(reqOpts,
|
|
239
|
+
REQ_SIZE_LIMIT, badJSONs);
|
|
240
|
+
|
|
241
|
+
// normal adding users
|
|
242
|
+
for (const userId of addresses) {
|
|
243
|
+
expect(addresses).toContain(userId);
|
|
244
|
+
await addNewUser(userId);
|
|
245
|
+
numOfAvailableAddresses -= 1;
|
|
246
|
+
addresses = await getAvailableAddressesFor(name);
|
|
247
|
+
expect(addresses.length).toBe(numOfAvailableAddresses);
|
|
248
|
+
expect(addresses).not.toContain(userId);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
itAsync(`adds new user with token`, async () => {
|
|
254
|
+
const reqOpts: RequestOpts= {
|
|
255
|
+
url: admin.signupUrl + signupApi.addUser.URL_END,
|
|
256
|
+
method: 'POST'
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// note that new id has other domain that isn't set anywhere
|
|
260
|
+
const userId = 'Pink Floyd @home.town';
|
|
261
|
+
|
|
262
|
+
// let's try to do this without any token
|
|
263
|
+
let req = makeAddUserReq(userId);
|
|
264
|
+
let rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
265
|
+
expect(rep.status).withContext('status when no token given').toBe(signupApi.addUser.SC.unauthorized);
|
|
266
|
+
|
|
267
|
+
// create token, here setup code uses spec-server specific code
|
|
268
|
+
const token = await admin.createSingleUserSignupTokenFor(userId);
|
|
269
|
+
req = makeAddUserReq(userId, token);
|
|
270
|
+
rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
271
|
+
expect(rep.status).withContext('status when user is added').toBe(signupApi.addUser.SC.ok);
|
|
272
|
+
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// NOTE: due to bad definition file, typescript below is not very type-strict.
|
|
19
|
+
|
|
20
|
+
const jas = new (require('jasmine'))();
|
|
21
|
+
|
|
22
|
+
jas.loadConfig({
|
|
23
|
+
spec_dir: 'build/tests',
|
|
24
|
+
spec_files: [
|
|
25
|
+
'admin-proto/**/*.js',
|
|
26
|
+
'protocols/mailerid.js',
|
|
27
|
+
'protocols/3nstorage/*.js',
|
|
28
|
+
'protocols/asmail/*.js',
|
|
29
|
+
],
|
|
30
|
+
random: false
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
jas.configureDefaultReporter({
|
|
34
|
+
showColors: true
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
jas.execute();
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016, 2019 3NSoft Inc.
|
|
3
|
+
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
7
|
+
version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but
|
|
10
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
See the GNU General Public License for more details.
|
|
13
|
+
|
|
14
|
+
You should have received a copy of the GNU General Public License along with
|
|
15
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { RequestOpts, doBodylessRequest, doBinaryRequest } from './xhr-utils';
|
|
19
|
+
import { resolve as resolveUrl } from 'url';
|
|
20
|
+
import * as api from '../../lib-common/service-api/3nstorage/owner';
|
|
21
|
+
import { utf8 } from '../../lib-common/buffer-utils';
|
|
22
|
+
import { assert } from './assert';
|
|
23
|
+
|
|
24
|
+
export async function get3NStorageServiceUrl(
|
|
25
|
+
storageUrl: string, service: 'owner'|'shared'
|
|
26
|
+
): Promise<string> {
|
|
27
|
+
let reqOpts: RequestOpts= {
|
|
28
|
+
url: storageUrl,
|
|
29
|
+
method: 'GET',
|
|
30
|
+
responseType: 'json'
|
|
31
|
+
};
|
|
32
|
+
let rep = await doBodylessRequest<any>(reqOpts);
|
|
33
|
+
assert(rep.status === 200);
|
|
34
|
+
let serviceUrl: string = rep.data[service];
|
|
35
|
+
assert(typeof serviceUrl === 'string');
|
|
36
|
+
return resolveUrl(storageUrl, serviceUrl);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface BaseObj {
|
|
40
|
+
objId: string,
|
|
41
|
+
header: Uint8Array,
|
|
42
|
+
segs: Uint8Array,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Obj extends BaseObj {
|
|
46
|
+
version: number,
|
|
47
|
+
diff?: api.DiffInfo
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function cancelTransaction(ownerUrl: string, sessionId: string,
|
|
51
|
+
objId: string, transactionId: string): Promise<void> {
|
|
52
|
+
let url = resolveUrl(ownerUrl, ((objId === null) ?
|
|
53
|
+
api.cancelRootTransaction.getReqUrlEnd(transactionId) :
|
|
54
|
+
api.cancelTransaction.getReqUrlEnd(objId, transactionId)));
|
|
55
|
+
let reqOpts: RequestOpts = {
|
|
56
|
+
url,
|
|
57
|
+
method: 'POST',
|
|
58
|
+
sessionId
|
|
59
|
+
};
|
|
60
|
+
let rep = await doBodylessRequest<void>(reqOpts);
|
|
61
|
+
assert(rep.status === api.cancelTransaction.SC.ok, `Obj transaction isn't canceled: server status ${rep.status} instead of expected ${api.cancelTransaction.SC.ok}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function getSessionParams(ownerUrl: string, sessionId: string):
|
|
65
|
+
Promise<api.sessionParams.Reply> {
|
|
66
|
+
let reqOpts: RequestOpts = {
|
|
67
|
+
url: resolveUrl(ownerUrl, api.sessionParams.URL_END),
|
|
68
|
+
method: 'GET',
|
|
69
|
+
responseType: 'json',
|
|
70
|
+
sessionId
|
|
71
|
+
};
|
|
72
|
+
let rep = await doBodylessRequest<api.sessionParams.Reply>(reqOpts);
|
|
73
|
+
assert(rep.status === 200);
|
|
74
|
+
return rep.data;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param user
|
|
79
|
+
* @param objId is object's id. Null stands for root object.
|
|
80
|
+
* @param ver
|
|
81
|
+
* @param obj
|
|
82
|
+
* @return a promise, resolvable object is writen.
|
|
83
|
+
*/
|
|
84
|
+
export async function saveObj(
|
|
85
|
+
ownerUrl: string, sessionId: string,
|
|
86
|
+
objId: string|null, ver: number, obj: Obj
|
|
87
|
+
): Promise<void> {
|
|
88
|
+
|
|
89
|
+
const header = obj.header.length;
|
|
90
|
+
const diffBytes = (obj.diff ?
|
|
91
|
+
utf8.pack(JSON.stringify(obj.diff)) : undefined);
|
|
92
|
+
const diff = (diffBytes ? diffBytes.length : undefined);
|
|
93
|
+
const opts: RequestOpts = {
|
|
94
|
+
method: 'PUT',
|
|
95
|
+
responseType: 'json',
|
|
96
|
+
sessionId
|
|
97
|
+
};
|
|
98
|
+
if (diffBytes) {
|
|
99
|
+
const urlEnd = (objId ?
|
|
100
|
+
api.currentObj.firstPutReqUrlEnd(objId, { ver, diff, header }) :
|
|
101
|
+
api.currentRootObj.firstPutReqUrlEnd({ ver, diff, header }));
|
|
102
|
+
opts.url = resolveUrl(ownerUrl, urlEnd);
|
|
103
|
+
const rep = await doBinaryRequest<api.currentObj.ReplyToPut>(
|
|
104
|
+
opts, [ diffBytes, obj.header ]);
|
|
105
|
+
assert(rep.status === api.currentObj.SC.okPut, `Obj header isn't saved: server status ${rep.status} instead of expected ${api.currentObj.SC.okPut}`);
|
|
106
|
+
const trans = rep.data.transactionId!;
|
|
107
|
+
let ofs = 0;
|
|
108
|
+
for (const [ isNew, dOfs, len ] of obj.diff!.sections) {
|
|
109
|
+
const last = ((dOfs+len) === obj.segs.length);
|
|
110
|
+
if (isNew === 1) {
|
|
111
|
+
const urlEnd = (objId ?
|
|
112
|
+
api.currentObj.secondPutReqUrlEnd(objId, { ofs, trans, last }) :
|
|
113
|
+
api.currentRootObj.secondPutReqUrlEnd({ ofs, trans, last }));
|
|
114
|
+
opts.url = resolveUrl(ownerUrl, urlEnd);
|
|
115
|
+
const rep = await doBinaryRequest<api.currentObj.ReplyToPut>(
|
|
116
|
+
opts, obj.segs.subarray(dOfs, dOfs+len));
|
|
117
|
+
assert(rep.status === api.currentObj.SC.okPut, `Obj segments sections isn't saved: server status ${rep.status} instead of expected ${api.currentObj.SC.okPut}`);
|
|
118
|
+
}
|
|
119
|
+
ofs += len;
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
const urlOpts: api.PutObjFirstQueryOpts = { ver, header, last: true };
|
|
123
|
+
const urlEnd = (objId ?
|
|
124
|
+
api.currentObj.firstPutReqUrlEnd(objId, urlOpts) :
|
|
125
|
+
api.currentRootObj.firstPutReqUrlEnd(urlOpts));
|
|
126
|
+
opts.url = resolveUrl(ownerUrl, urlEnd);
|
|
127
|
+
const rep = await doBinaryRequest<api.currentObj.ReplyToPut>(
|
|
128
|
+
opts, [ obj.header, obj.segs ]);
|
|
129
|
+
assert(rep.status === api.currentObj.SC.okPut, `Complete obj isn't saved: server status ${rep.status} instead of expected ${api.currentObj.SC.okPut}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function removeObj(ownerUrl: string, sessionId: string,
|
|
134
|
+
objId: string): Promise<void> {
|
|
135
|
+
const opts: RequestOpts = {
|
|
136
|
+
url: resolveUrl(ownerUrl, api.currentObj.getReqUrlEnd(objId)),
|
|
137
|
+
method: 'DELETE',
|
|
138
|
+
sessionId
|
|
139
|
+
};
|
|
140
|
+
const rep = await doBodylessRequest(opts);
|
|
141
|
+
assert(rep.status === api.currentObj.SC.okDelete, `Obj isn't removed: server status ${rep.status} instead of expected ${api.currentObj.SC.okDelete}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Object.freeze(exports);
|