spec-3nweb-server 1.8.5 → 1.8.7
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/resources/store.d.ts +2 -2
- package/build/3nstorage/resources/store.js +1 -1
- package/build/3nstorage/resources/users.d.ts +3 -3
- package/build/3nstorage/resources/users.js +1 -1
- package/build/3nstorage/resources/utils.d.ts +6 -0
- package/build/3nstorage/resources/utils.js +41 -0
- package/build/3nstorage/routes/owner/archive-obj-version.js +8 -10
- package/build/3nstorage/routes/owner/cancel-trans.js +5 -4
- package/build/3nstorage/routes/owner/delete-obj.js +7 -8
- package/build/3nstorage/routes/owner/get-archived-obj-ver.js +11 -13
- package/build/3nstorage/routes/owner/get-current-obj.js +7 -6
- package/build/3nstorage/routes/owner/get-obj-status.js +8 -8
- package/build/3nstorage/routes/owner/put-current-obj.js +25 -55
- package/build/3nstorage/routes/owner/session-params.js +2 -0
- package/build/asmail/resources/utils.d.ts +6 -0
- package/build/asmail/resources/utils.js +36 -0
- package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
- package/build/asmail/routes/delivery/pre-flight.js +9 -26
- package/build/asmail/routes/delivery/provide-recipient-pubkey.js +4 -3
- package/build/asmail/routes/delivery/put-metadata.js +13 -21
- package/build/asmail/routes/delivery/put-obj.js +19 -25
- package/build/asmail/routes/delivery/restart-session.d.ts +4 -8
- package/build/asmail/routes/delivery/restart-session.js +10 -23
- package/build/asmail/routes/delivery/sender-authorization.js +5 -5
- package/build/asmail/routes/delivery/start-session.js +9 -24
- package/build/asmail/routes/retrieval/get-message-meta.js +4 -7
- package/build/asmail/routes/retrieval/get-message-obj.js +10 -7
- package/build/asmail/routes/retrieval/list-messages.js +4 -4
- package/build/asmail/routes/retrieval/remove-message.js +3 -2
- package/build/mock/tls-options.js +46 -44
- 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/resources/utils.ts +45 -0
- package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +71 -0
- package/ts-code/3nstorage/routes/owner/cancel-trans.ts +60 -0
- package/ts-code/3nstorage/routes/owner/delete-obj.ts +99 -0
- package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +109 -0
- package/ts-code/3nstorage/routes/owner/get-current-obj.ts +124 -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 +257 -0
- package/ts-code/3nstorage/routes/owner/session-params.ts +50 -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/resources/utils.ts +41 -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 +51 -0
- package/ts-code/asmail/routes/delivery/pre-flight.ts +118 -0
- package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
- package/ts-code/asmail/routes/delivery/put-metadata.ts +85 -0
- package/ts-code/asmail/routes/delivery/put-obj.ts +152 -0
- package/ts-code/asmail/routes/delivery/restart-session.ts +117 -0
- package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
- package/ts-code/asmail/routes/delivery/start-session.ts +136 -0
- package/ts-code/asmail/routes/retrieval/get-message-meta.ts +50 -0
- package/ts-code/asmail/routes/retrieval/get-message-obj.ts +106 -0
- package/ts-code/asmail/routes/retrieval/list-messages.ts +68 -0
- package/ts-code/asmail/routes/retrieval/remove-message.ts +48 -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,206 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016, 2019 - 2020 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 { Component } from './component';
|
|
19
|
+
import { addUserIn } from './mailerid';
|
|
20
|
+
import { User } from '../pkl';
|
|
21
|
+
import { resolve as resolveUrl } from 'url';
|
|
22
|
+
import { get3NStorageServiceUrl } from '../3nstorage';
|
|
23
|
+
import * as fs from '../../../lib-common/async-fs-node';
|
|
24
|
+
import { Obj } from '../3nstorage';
|
|
25
|
+
import { bytesEqual } from '../bytes-equal';
|
|
26
|
+
import { ObjStatusInfo } from '../../../3nstorage/resources/store';
|
|
27
|
+
import { ObjVersionFile } from '../../../lib-common/objs-on-disk/obj-file';
|
|
28
|
+
import { join } from 'path';
|
|
29
|
+
import { joinByteArrs } from '../../../lib-common/buffer-utils';
|
|
30
|
+
import { userDataInRootFolder } from '../../../lib-server/resources/server-data-folders';
|
|
31
|
+
|
|
32
|
+
async function rmFolderContent(folder: string): Promise<void> {
|
|
33
|
+
await fs.rmDirWithContent(folder);
|
|
34
|
+
await fs.mkdir(folder);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class StorageComponent extends Component {
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
signupDomains: string[],
|
|
41
|
+
public midServiceDomain: string
|
|
42
|
+
) {
|
|
43
|
+
super(
|
|
44
|
+
{
|
|
45
|
+
rootFolder: (null as any),
|
|
46
|
+
domain: midServiceDomain,
|
|
47
|
+
signup: {},
|
|
48
|
+
enabledServices: {
|
|
49
|
+
mailerId: true,
|
|
50
|
+
storage: true
|
|
51
|
+
},
|
|
52
|
+
mailerId: {
|
|
53
|
+
certs: (null as any)
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
signupDomains
|
|
57
|
+
);
|
|
58
|
+
Object.seal(this);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async addUser(userId: string, configureDNS = true): Promise<User> {
|
|
62
|
+
if (configureDNS) { this.dns.configureFor(userId); }
|
|
63
|
+
let user = await addUserIn(this.url, userId);
|
|
64
|
+
user.midUrl = this.midUrl;
|
|
65
|
+
user.storageOwnerUrl = await this.getStorageOwnerUrl();
|
|
66
|
+
return user;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get midUrl(): string {
|
|
70
|
+
return resolveUrl(this.url, 'mailerid/');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get storageUrl(): string {
|
|
74
|
+
return resolveUrl(this.url, '3nstorage/');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async getStorageOwnerUrl(): Promise<string> {
|
|
78
|
+
let storageOwnerUrl = await get3NStorageServiceUrl(
|
|
79
|
+
this.storageUrl, 'owner');
|
|
80
|
+
if (!storageOwnerUrl.endsWith('/')) { storageOwnerUrl += '/'; }
|
|
81
|
+
return storageOwnerUrl;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private storeFolder(userId: string): string {
|
|
85
|
+
return join(userDataInRootFolder(this.conf.rootFolder, userId), 'store');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private async checkTransactionPresence(
|
|
89
|
+
transFolder: string, transactionId: string|undefined
|
|
90
|
+
): Promise<boolean> {
|
|
91
|
+
const transFile = 'transaction';
|
|
92
|
+
try {
|
|
93
|
+
const lst = await fs.readdir(transFolder);
|
|
94
|
+
expect(lst).toContain(transFile);
|
|
95
|
+
} catch (exc) {
|
|
96
|
+
if ((exc as fs.FileException).notFound) { return false; }
|
|
97
|
+
else { throw exc; }
|
|
98
|
+
}
|
|
99
|
+
if (transactionId) {
|
|
100
|
+
const trans = JSON.parse(await fs.readFile(
|
|
101
|
+
join(transFolder, transFile), { encoding: 'utf8' }));
|
|
102
|
+
return (trans.transactionId === transactionId);
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
rootTransactionExists(
|
|
108
|
+
userId: string, transactionId?: string
|
|
109
|
+
): Promise<boolean> {
|
|
110
|
+
return this.checkTransactionPresence(
|
|
111
|
+
join(this.storeFolder(userId), 'root', 'transaction'), transactionId);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
transactionExists(
|
|
115
|
+
userId: string, objId: string, transactionId?: string
|
|
116
|
+
): Promise<boolean> {
|
|
117
|
+
return this.checkTransactionPresence(
|
|
118
|
+
join(this.storeFolder(userId),'transactions', objId), transactionId);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private async checkCurrentObjPresence(
|
|
122
|
+
objFolder: string, ver: number|undefined, obj: Obj|undefined
|
|
123
|
+
): Promise<boolean> {
|
|
124
|
+
let status: ObjStatusInfo;
|
|
125
|
+
try {
|
|
126
|
+
status = JSON.parse(await fs.readFile(
|
|
127
|
+
objFolder+'/status', { encoding: 'utf8' }));
|
|
128
|
+
} catch (exc) {
|
|
129
|
+
if ((<fs.FileException> exc).notFound) { return false; }
|
|
130
|
+
else { throw exc; }
|
|
131
|
+
}
|
|
132
|
+
if (status.state !== 'current') { return false; }
|
|
133
|
+
const currVer = status.currentVersion;
|
|
134
|
+
if ((ver !== undefined) && (currVer !== ver)) { return false; }
|
|
135
|
+
if (obj) {
|
|
136
|
+
const filePath = join(objFolder, `${currVer}.v`);
|
|
137
|
+
const file = await ObjVersionFile.forExisting(filePath)
|
|
138
|
+
.catch((exc: fs.FileException) => {
|
|
139
|
+
if (exc.notFound) { return undefined; }
|
|
140
|
+
throw exc;
|
|
141
|
+
});
|
|
142
|
+
if (!file) { return false; }
|
|
143
|
+
const headerInFile = await file.readHeader();
|
|
144
|
+
if (!headerInFile
|
|
145
|
+
|| !bytesEqual(headerInFile, obj.header)) { return false; }
|
|
146
|
+
const diff = obj.diff;
|
|
147
|
+
if (file.getBaseVersion() === undefined) {
|
|
148
|
+
if (diff) { return false; }
|
|
149
|
+
const segsInFile = joinByteArrs(
|
|
150
|
+
await file.readSegs(0, file.getTotalSegsLen()));
|
|
151
|
+
if (!bytesEqual(segsInFile, obj.segs)) { return false; }
|
|
152
|
+
} else {
|
|
153
|
+
if (!diff) { return false; }
|
|
154
|
+
if (file.getBaseVersion() !== diff.baseVersion) { return false; }
|
|
155
|
+
if (file.getTotalSegsLen() !== diff.segsSize) { return false; }
|
|
156
|
+
let ofs = 0;
|
|
157
|
+
for (const [ isNew, dsOfs, len ] of diff.sections) {
|
|
158
|
+
if (isNew === 0) {
|
|
159
|
+
const sections = await file.segsLocations(ofs, len);
|
|
160
|
+
for (const section of sections) {
|
|
161
|
+
if (section.type !== 'base') { return false; }
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
if (!bytesEqual(
|
|
165
|
+
joinByteArrs(await file.readSegs(ofs, len)),
|
|
166
|
+
obj.segs.subarray(dsOfs, dsOfs+len))) { return false; }
|
|
167
|
+
}
|
|
168
|
+
ofs += len;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
currentRootObjExists(
|
|
176
|
+
userId: string, ver?: number, obj?: Obj
|
|
177
|
+
): Promise<boolean> {
|
|
178
|
+
return this.checkCurrentObjPresence(
|
|
179
|
+
join(this.storeFolder(userId), 'root'), ver, obj);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
currentObjExists(
|
|
183
|
+
userId: string, objId: string, ver?: number, obj?: Obj
|
|
184
|
+
): Promise<boolean> {
|
|
185
|
+
return this.checkCurrentObjPresence(
|
|
186
|
+
join(this.storeFolder(userId), 'objects', objId), ver, obj);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async clearStorage(userId: string): Promise<void> {
|
|
190
|
+
let storeFolder = this.storeFolder(userId);
|
|
191
|
+
await rmFolderContent(join(storeFolder, 'transactions'));
|
|
192
|
+
await rmFolderContent(join(storeFolder, 'objects'));
|
|
193
|
+
await rmFolderContent(join(storeFolder, 'root'));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async restartAndClearStorageFor(userId: string): Promise<void> {
|
|
197
|
+
await this.clearStorage(userId);
|
|
198
|
+
await this.restart();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
Object.freeze(StorageComponent.prototype);
|
|
203
|
+
Object.freeze(StorageComponent);
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016, 2020 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 { Component } from './component';
|
|
19
|
+
import { resolve as resolveUrl } from 'url';
|
|
20
|
+
import { addSingleUserSignup } from '../../../lib';
|
|
21
|
+
|
|
22
|
+
export class AdminComponent extends Component {
|
|
23
|
+
|
|
24
|
+
constructor(signupDomains: string[]) {
|
|
25
|
+
super(
|
|
26
|
+
{
|
|
27
|
+
rootFolder: (null as any),
|
|
28
|
+
domain: (null as any),
|
|
29
|
+
signup: {},
|
|
30
|
+
enabledServices: {}
|
|
31
|
+
},
|
|
32
|
+
signupDomains
|
|
33
|
+
);
|
|
34
|
+
Object.seal(this);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get signupUrl(): string {
|
|
38
|
+
return resolveUrl(this.url, 'signup/');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
createSingleUserSignupTokenFor(userId: string): Promise<string> {
|
|
42
|
+
return addSingleUserSignup(this.dataFolder, userId);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
Object.freeze(AdminComponent.prototype);
|
|
47
|
+
Object.freeze(AdminComponent);
|
|
48
|
+
|
|
49
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016 - 2017, 2019 - 2020, 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 { Component } from './component';
|
|
19
|
+
import { addUserIn } from './mailerid';
|
|
20
|
+
import { User } from '../pkl';
|
|
21
|
+
import { resolve as resolveUrl } from 'url';
|
|
22
|
+
import { getASMailServiceUrl } from '../asmail';
|
|
23
|
+
import * as fs from '../../../lib-common/async-fs-node';
|
|
24
|
+
import { Msg } from '../asmail';
|
|
25
|
+
import * as retrievalApi from '../../../lib-common/service-api/asmail/retrieval';
|
|
26
|
+
import { bytesEqual } from '../bytes-equal';
|
|
27
|
+
import { join } from 'path';
|
|
28
|
+
import { ObjVersionFile } from '../../../lib-common/objs-on-disk/obj-file';
|
|
29
|
+
import { joinByteArrs } from '../../../lib-common/buffer-utils';
|
|
30
|
+
import { userDataInRootFolder } from '../../../lib-server/resources/server-data-folders';
|
|
31
|
+
|
|
32
|
+
export class ASMailComponent extends Component {
|
|
33
|
+
|
|
34
|
+
constructor(
|
|
35
|
+
signupDomains: string[],
|
|
36
|
+
public midServiceDomain: string
|
|
37
|
+
) {
|
|
38
|
+
super(
|
|
39
|
+
{
|
|
40
|
+
rootFolder: (null as any),
|
|
41
|
+
domain: midServiceDomain,
|
|
42
|
+
signup: {},
|
|
43
|
+
enabledServices: {
|
|
44
|
+
mailerId: true,
|
|
45
|
+
asmail: true
|
|
46
|
+
},
|
|
47
|
+
mailerId: {
|
|
48
|
+
certs: (null as any)
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
signupDomains
|
|
52
|
+
);
|
|
53
|
+
Object.seal(this);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async addUser(userId: string, configureDNS = true): Promise<User> {
|
|
57
|
+
if (configureDNS) { this.dns.configureFor(userId); }
|
|
58
|
+
let user = await addUserIn(this.url, userId);
|
|
59
|
+
user.midUrl = this.midUrl;
|
|
60
|
+
return user;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get midUrl(): string {
|
|
64
|
+
return resolveUrl(this.url, 'mailerid/');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get asmailUrl(): string {
|
|
68
|
+
return resolveUrl(this.url, 'asmail/');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getConfUrl(): Promise<string> {
|
|
72
|
+
return getASMailServiceUrl(this.asmailUrl, 'config');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getDeliveryUrl(): Promise<string> {
|
|
76
|
+
return getASMailServiceUrl(this.asmailUrl, 'delivery');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getRetrievalUrl(): Promise<string> {
|
|
80
|
+
return getASMailServiceUrl(this.asmailUrl, 'retrieval');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private inboxFolder(userId: string): string {
|
|
84
|
+
return join(userDataInRootFolder(this.conf.rootFolder, userId), 'mail');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private msgFolder(
|
|
88
|
+
userId: string, msgId: string, deliveryComplete: boolean
|
|
89
|
+
): string {
|
|
90
|
+
return join(this.inboxFolder(userId),
|
|
91
|
+
(deliveryComplete ? 'messages' : 'delivery'), msgId);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// XXX adopt new file access
|
|
95
|
+
async msgExists(userId: string, msgId: string, deliveryComplete: boolean,
|
|
96
|
+
msg?: Msg): Promise<boolean> {
|
|
97
|
+
let meta: retrievalApi.msgMetadata.Reply
|
|
98
|
+
let msgFolder = this.msgFolder(userId, msgId, deliveryComplete);
|
|
99
|
+
try {
|
|
100
|
+
let metaFile = join(msgFolder, 'meta.json');
|
|
101
|
+
meta = JSON.parse(await fs.readFile(metaFile, { encoding: 'utf8' }));
|
|
102
|
+
} catch (exc) {
|
|
103
|
+
if ((exc as fs.FileException).notFound) { return false; }
|
|
104
|
+
else { throw exc; }
|
|
105
|
+
}
|
|
106
|
+
let extMeta = meta.extMeta;
|
|
107
|
+
if (!deliveryComplete || ! msg) { return true; }
|
|
108
|
+
|
|
109
|
+
// check meta
|
|
110
|
+
if (msg.cryptoMeta.pid) {
|
|
111
|
+
expect(extMeta.pid).withContext('correct key-pair id in meta').toBe(msg.cryptoMeta.pid);
|
|
112
|
+
}
|
|
113
|
+
if (msg.cryptoMeta.recipientKid) {
|
|
114
|
+
expect(extMeta.recipientKid).withContext('correct recipient key id in meta').toBe(msg.cryptoMeta.recipientKid);
|
|
115
|
+
}
|
|
116
|
+
if (msg.cryptoMeta.senderPKey) {
|
|
117
|
+
expect(extMeta.senderPKey).withContext('correct sender\'s public key').toBe(msg.cryptoMeta.senderPKey);
|
|
118
|
+
}
|
|
119
|
+
expect(extMeta.objIds.length).withContext('correct number of message objects in meta').toBe(msg.msgObjs.length);
|
|
120
|
+
expect(Object.keys(meta.objs).length).withContext('correct number of message object sizes in meta').toBe(msg.msgObjs.length);
|
|
121
|
+
|
|
122
|
+
for (let i=0; i < msg.msgObjs.length; i+=1) {
|
|
123
|
+
// check meta info for each object
|
|
124
|
+
let obj = msg.msgObjs[i];
|
|
125
|
+
let objId = obj.objId!;
|
|
126
|
+
expect(extMeta.objIds[i]).toBe(objId);
|
|
127
|
+
expect(meta.objs[objId].size.header).withContext('header length of a message object').toBe(obj.header.length);
|
|
128
|
+
expect(meta.objs[objId].size.segments).withContext('segments length of a message object').toBe(obj.segs.length);
|
|
129
|
+
expect(meta.objs[objId].completed).withContext('completness flag of a message object').toBe(true);
|
|
130
|
+
|
|
131
|
+
// check object file
|
|
132
|
+
const filePath = join(msgFolder, objId);
|
|
133
|
+
const file = await ObjVersionFile.forExisting(filePath)
|
|
134
|
+
.catch((exc: fs.FileException) => {
|
|
135
|
+
if (exc.notFound) { return undefined; }
|
|
136
|
+
throw exc;
|
|
137
|
+
});
|
|
138
|
+
if (!file) { return false; }
|
|
139
|
+
const headerInFile = await file.readHeader();
|
|
140
|
+
if (!headerInFile
|
|
141
|
+
|| !bytesEqual(headerInFile, obj.header)) { return false; }
|
|
142
|
+
const segsInFile = joinByteArrs(
|
|
143
|
+
await file.readSegs(0, file.getTotalSegsLen()));
|
|
144
|
+
if (!bytesEqual(segsInFile, obj.segs)) { return false; }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
Object.freeze(ASMailComponent.prototype);
|
|
152
|
+
Object.freeze(ASMailComponent);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016, 2020 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 { ServerRunner } from '../server-runner';
|
|
19
|
+
import { mkdir, rmDirWithContent, writeFile } from '../../../lib-common/async-fs-node';
|
|
20
|
+
import { FileException } from '../../../lib-common/exceptions/file';
|
|
21
|
+
import { accountsApp as makeAdminApp, Configurations, servicesApp as makeServicesApp } from '../../../services';
|
|
22
|
+
import { DNSMock } from '../../../mock/dns';
|
|
23
|
+
import * as dns from 'dns';
|
|
24
|
+
import { AppWithWSs } from '../../../lib-server/web-sockets/app';
|
|
25
|
+
import { join } from 'path';
|
|
26
|
+
import { makeMultiDomainSignupCtx } from '../../../signup/signup-tokens';
|
|
27
|
+
|
|
28
|
+
const DEFAULT_SERVICE_PORT = 8088;
|
|
29
|
+
const DEFAULT_DATA_FOLDER = join(__dirname, '/../../../../test-data');
|
|
30
|
+
|
|
31
|
+
export abstract class Component extends ServerRunner {
|
|
32
|
+
|
|
33
|
+
dns: DNSMock;
|
|
34
|
+
|
|
35
|
+
constructor(
|
|
36
|
+
protected conf: Configurations,
|
|
37
|
+
private signupDomains: string[],
|
|
38
|
+
servicePort = DEFAULT_SERVICE_PORT,
|
|
39
|
+
protected dataFolder = DEFAULT_DATA_FOLDER
|
|
40
|
+
) {
|
|
41
|
+
super(servicePort);
|
|
42
|
+
this.conf.rootFolder = this.dataFolder;
|
|
43
|
+
this.conf.signup!.noTokenFile = join(
|
|
44
|
+
this.dataFolder, 'no-tokens-signup.json');
|
|
45
|
+
if (this.conf.mailerId) {
|
|
46
|
+
const certs = this.conf.mailerId.certs;
|
|
47
|
+
this.conf.mailerId.certs = join(
|
|
48
|
+
this.dataFolder, (certs ? certs : 'mid-certs.json'));
|
|
49
|
+
}
|
|
50
|
+
const urlWithoutProto = this.url.substring(this.url.indexOf('://')+3);
|
|
51
|
+
this.dns = new DNSMock(urlWithoutProto+'mailerid/');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async prepToRun(): Promise<AppWithWSs> {
|
|
55
|
+
|
|
56
|
+
// prepare data folders
|
|
57
|
+
try {
|
|
58
|
+
await mkdir(this.dataFolder);
|
|
59
|
+
// write to-tokens signup file
|
|
60
|
+
const noTokenCtx = makeMultiDomainSignupCtx(this.signupDomains);
|
|
61
|
+
await writeFile(
|
|
62
|
+
this.conf.signup!.noTokenFile!, JSON.stringify(noTokenCtx),
|
|
63
|
+
{ encoding: 'utf8' }
|
|
64
|
+
);
|
|
65
|
+
} catch (exc) {
|
|
66
|
+
if (!(exc as FileException).alreadyExists) { throw exc; }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// inject dns mock
|
|
70
|
+
(dns as any).resolveTxt = this.dns.resolveTxt;
|
|
71
|
+
|
|
72
|
+
// setup servers
|
|
73
|
+
const app = new AppWithWSs();
|
|
74
|
+
app.use(makeAdminApp(this.conf));
|
|
75
|
+
app.use(makeServicesApp(this.conf));
|
|
76
|
+
|
|
77
|
+
return app;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async clean(): Promise<void> {
|
|
81
|
+
await rmDirWithContent(this.dataFolder).catch((exc: FileException) => {
|
|
82
|
+
if (!exc.notFound) { throw exc; }
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
Object.freeze(Component.prototype);
|
|
88
|
+
Object.freeze(Component);
|
|
89
|
+
|
|
90
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (C) 2016, 2020 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 { Component } from './component';
|
|
19
|
+
import { resolve as resolveUrl } from 'url';
|
|
20
|
+
import { doJsonRequest, RequestOpts } from '../xhr-utils';
|
|
21
|
+
import * as signup from '../../../lib-common/admin-api/signup';
|
|
22
|
+
import { User } from '../pkl';
|
|
23
|
+
import * as random from '../../../lib-common/random-node';
|
|
24
|
+
import { box } from 'ecma-nacl';
|
|
25
|
+
import { use } from '../../../lib-common/jwkeys';
|
|
26
|
+
import { base64 } from '../../../lib-common/buffer-utils';
|
|
27
|
+
import { getProvPath } from '../mailerid';
|
|
28
|
+
|
|
29
|
+
export async function addUserIn(rootServerUrl: string, userId: string): Promise<User> {
|
|
30
|
+
let reqOpts: RequestOpts = {
|
|
31
|
+
url: resolveUrl(resolveUrl(
|
|
32
|
+
rootServerUrl, 'signup/'), signup.addUser.URL_END),
|
|
33
|
+
method: 'POST'
|
|
34
|
+
};
|
|
35
|
+
let user: User = {
|
|
36
|
+
id: userId,
|
|
37
|
+
loginDefaultSKey: await random.bytes(box.KEY_LENGTH),
|
|
38
|
+
loginLabeledSKey: {
|
|
39
|
+
k: await random.bytes(box.KEY_LENGTH),
|
|
40
|
+
kid: await random.stringOfB64Chars(12)
|
|
41
|
+
},
|
|
42
|
+
midUrl: (undefined as any),
|
|
43
|
+
storageOwnerUrl: (undefined as any)
|
|
44
|
+
};
|
|
45
|
+
let req: signup.addUser.Request = {
|
|
46
|
+
userId: user.id,
|
|
47
|
+
storage: {
|
|
48
|
+
kdParams: {}
|
|
49
|
+
},
|
|
50
|
+
mailerId: {
|
|
51
|
+
defaultPKey: {
|
|
52
|
+
pkey: {
|
|
53
|
+
alg: box.JWK_ALG_NAME,
|
|
54
|
+
kid: '_',
|
|
55
|
+
use: use.MID_PKLOGIN,
|
|
56
|
+
k: base64.pack(box.generate_pubkey(user.loginDefaultSKey))
|
|
57
|
+
},
|
|
58
|
+
kdParams: {}
|
|
59
|
+
},
|
|
60
|
+
otherPKeys: [ {
|
|
61
|
+
alg: box.JWK_ALG_NAME,
|
|
62
|
+
kid: user.loginLabeledSKey.kid,
|
|
63
|
+
use: use.MID_PKLOGIN,
|
|
64
|
+
k: base64.pack(box.generate_pubkey(user.loginLabeledSKey.k))
|
|
65
|
+
} ]
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
let rep = await doJsonRequest<string[]>(reqOpts, req);
|
|
69
|
+
if (rep.status !== signup.addUser.SC.ok) {
|
|
70
|
+
throw new Error(`Fail to add user ${userId}`);
|
|
71
|
+
}
|
|
72
|
+
return user;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class MailerIdComponent extends Component {
|
|
76
|
+
|
|
77
|
+
constructor(
|
|
78
|
+
signupDomains: string[],
|
|
79
|
+
public midServiceDomain: string
|
|
80
|
+
) {
|
|
81
|
+
super(
|
|
82
|
+
{
|
|
83
|
+
rootFolder: (null as any),
|
|
84
|
+
domain: midServiceDomain,
|
|
85
|
+
signup: {},
|
|
86
|
+
enabledServices: {
|
|
87
|
+
mailerId: true
|
|
88
|
+
},
|
|
89
|
+
mailerId: {
|
|
90
|
+
certs: (null as any)
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
signupDomains
|
|
94
|
+
);
|
|
95
|
+
Object.seal(this);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
addUser(userId: string): Promise<User> {
|
|
99
|
+
return addUserIn(this.url, userId);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get midUrl(): string {
|
|
103
|
+
return resolveUrl(this.url, 'mailerid/');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
getProvUrl(): Promise<string> {
|
|
107
|
+
return getProvPath(this.midUrl);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
Object.freeze(MailerIdComponent.prototype);
|
|
112
|
+
Object.freeze(MailerIdComponent);
|
|
113
|
+
|
|
114
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
import * as https from "https";
|
|
19
|
+
import { sslOpts } from '../../mock/tls-options';
|
|
20
|
+
import { AppWithWSs } from '../../lib-server/web-sockets/app';
|
|
21
|
+
import { sleep } from "../../lib-common/processes";
|
|
22
|
+
|
|
23
|
+
// allow client test calls to trust above self-signed cert
|
|
24
|
+
https.globalAgent.options.ca = sslOpts.cert;
|
|
25
|
+
|
|
26
|
+
export type ServerState = 'stopped' | 'starting' | 'running' | 'stopping';
|
|
27
|
+
|
|
28
|
+
export abstract class ServerRunner {
|
|
29
|
+
|
|
30
|
+
protected state: ServerState = 'stopped';
|
|
31
|
+
protected app: AppWithWSs = (undefined as any);
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
protected servicePort: number
|
|
35
|
+
) {}
|
|
36
|
+
|
|
37
|
+
abstract prepToRun(): Promise<AppWithWSs>;
|
|
38
|
+
|
|
39
|
+
abstract clean(): Promise<void>;
|
|
40
|
+
|
|
41
|
+
isRunning(): boolean {
|
|
42
|
+
return (this.state === 'running');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async start(): Promise<void> {
|
|
46
|
+
if (this.state !== 'stopped') { throw new Error(
|
|
47
|
+
`Home server is already in ${this.state} state.`); }
|
|
48
|
+
this.state = 'starting';
|
|
49
|
+
this.app = await this.prepToRun();
|
|
50
|
+
await this.app.start(sslOpts, this.servicePort);
|
|
51
|
+
await sleep(100);
|
|
52
|
+
this.state = 'running';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async stop(doCleanup = true): Promise<void> {
|
|
56
|
+
if (this.state !== 'running') { throw new Error(
|
|
57
|
+
`Home server is in ${this.state} state instead of running state`); }
|
|
58
|
+
this.state = 'stopping';
|
|
59
|
+
await this.app.stop();
|
|
60
|
+
this.app = (undefined as any);
|
|
61
|
+
if (doCleanup) {
|
|
62
|
+
await this.clean();
|
|
63
|
+
}
|
|
64
|
+
this.state = 'stopped';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async restart(): Promise<void> {
|
|
68
|
+
if (this.isRunning()) {
|
|
69
|
+
await this.stop(false);
|
|
70
|
+
}
|
|
71
|
+
await this.start();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
protected get url(): string {
|
|
75
|
+
return `https://localhost:${this.servicePort}/`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
Object.freeze(ServerRunner.prototype);
|
|
80
|
+
Object.freeze(ServerRunner);
|
|
81
|
+
|
|
82
|
+
Object.freeze(exports);
|