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.
Files changed (324) hide show
  1. package/.gitlab-ci-linux.yml +50 -0
  2. package/.gitlab-ci-mac.yml +29 -0
  3. package/.gitlab-ci-windows.yml +29 -0
  4. package/.gitlab-ci.yml +63 -0
  5. package/build/3nstorage/routes/owner/archive-obj-version.js +2 -2
  6. package/build/3nstorage/routes/owner/cancel-trans.js +2 -2
  7. package/build/3nstorage/routes/owner/delete-obj.js +2 -2
  8. package/build/3nstorage/routes/owner/get-current-obj.js +3 -4
  9. package/build/3nstorage/routes/owner/param-setter.js +2 -6
  10. package/build/asmail/routes/config/param-setter.js +2 -2
  11. package/build/asmail/routes/delivery/finalize-delivery.js +2 -2
  12. package/build/asmail/routes/delivery/put-obj.js +2 -2
  13. package/build/asmail/routes/delivery/sender-authorization.js +2 -2
  14. package/build/asmail/routes/retrieval/remove-message.js +2 -2
  15. package/build/cli/signup-cmd.js +0 -1
  16. package/build/lib-server/routes/sessions/close.js +2 -2
  17. package/build/lib-server/routes/sessions/mid-auth.js +2 -5
  18. package/build/main.js +12 -15
  19. package/build/mock/tls-options.js +46 -44
  20. package/build/signup/routes/add.js +4 -4
  21. package/build/tests/admin-proto/signup.d.ts +1 -0
  22. package/build/tests/admin-proto/signup.js +235 -0
  23. package/build/tests/jasmine.d.ts +1 -0
  24. package/build/tests/jasmine.js +32 -0
  25. package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
  26. package/build/tests/libs-for-tests/3nstorage.js +123 -0
  27. package/build/tests/libs-for-tests/asmail.d.ts +22 -0
  28. package/build/tests/libs-for-tests/asmail.js +179 -0
  29. package/build/tests/libs-for-tests/assert.d.ts +1 -0
  30. package/build/tests/libs-for-tests/assert.js +26 -0
  31. package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
  32. package/build/tests/libs-for-tests/async-jasmine.js +77 -0
  33. package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
  34. package/build/tests/libs-for-tests/bytes-equal.js +34 -0
  35. package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
  36. package/build/tests/libs-for-tests/json-copy.js +45 -0
  37. package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
  38. package/build/tests/libs-for-tests/json-equal.js +67 -0
  39. package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
  40. package/build/tests/libs-for-tests/mailerid.js +114 -0
  41. package/build/tests/libs-for-tests/pkl.d.ts +28 -0
  42. package/build/tests/libs-for-tests/pkl.js +89 -0
  43. package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
  44. package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
  45. package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
  46. package/build/tests/libs-for-tests/server-components/admin.js +43 -0
  47. package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
  48. package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
  49. package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
  50. package/build/tests/libs-for-tests/server-components/component.js +77 -0
  51. package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
  52. package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
  53. package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
  54. package/build/tests/libs-for-tests/server-runner.js +69 -0
  55. package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
  56. package/build/tests/libs-for-tests/spec-assembly.js +55 -0
  57. package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
  58. package/build/tests/libs-for-tests/ws-utils.js +59 -0
  59. package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
  60. package/build/tests/libs-for-tests/xhr-utils.js +154 -0
  61. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
  62. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
  63. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
  64. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
  65. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
  66. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
  67. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
  68. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
  69. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
  70. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
  71. package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
  72. package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
  73. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
  74. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
  75. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
  76. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
  77. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
  78. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
  79. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
  80. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
  81. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
  82. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
  83. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
  84. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
  85. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
  86. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
  87. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
  88. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
  89. package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
  90. package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
  91. package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
  92. package/build/tests/protocols/3nstorage/owner.js +138 -0
  93. package/build/tests/protocols/asmail/config.d.ts +1 -0
  94. package/build/tests/protocols/asmail/config.js +117 -0
  95. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
  96. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
  97. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
  98. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
  99. package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
  100. package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
  101. package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
  102. package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
  103. package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
  104. package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
  105. package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
  106. package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
  107. package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
  108. package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
  109. package/build/tests/protocols/asmail/delivery.d.ts +1 -0
  110. package/build/tests/protocols/asmail/delivery.js +46 -0
  111. package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
  112. package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
  113. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
  114. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
  115. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
  116. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
  117. package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
  118. package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
  119. package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
  120. package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
  121. package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
  122. package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
  123. package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
  124. package/build/tests/protocols/asmail/retrieval.js +92 -0
  125. package/build/tests/protocols/mailerid.d.ts +1 -0
  126. package/build/tests/protocols/mailerid.js +210 -0
  127. package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
  128. package/build/tests/shared-checks/check-mid-login.js +131 -0
  129. package/build/tests/shared-checks/requests.d.ts +20 -0
  130. package/build/tests/shared-checks/requests.js +123 -0
  131. package/package.json +1 -1
  132. package/packing/create-deb.sh +57 -0
  133. package/packing/deb/lib/systemd/system/3nweb.service +11 -0
  134. package/packing/deb/postinst +44 -0
  135. package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
  136. package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
  137. package/publish-task.sh +10 -0
  138. package/push-to-github.sh +105 -0
  139. package/ts-code/3nstorage/3nstorage-app.ts +99 -0
  140. package/ts-code/3nstorage/owner.ts +178 -0
  141. package/ts-code/3nstorage/resources/sessions.ts +37 -0
  142. package/ts-code/3nstorage/resources/store.ts +896 -0
  143. package/ts-code/3nstorage/resources/users.ts +258 -0
  144. package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +73 -0
  145. package/ts-code/3nstorage/routes/owner/cancel-trans.ts +58 -0
  146. package/ts-code/3nstorage/routes/owner/delete-obj.ts +103 -0
  147. package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +111 -0
  148. package/ts-code/3nstorage/routes/owner/get-current-obj.ts +122 -0
  149. package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
  150. package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
  151. package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
  152. package/ts-code/3nstorage/routes/owner/put-current-obj.ts +284 -0
  153. package/ts-code/3nstorage/routes/owner/session-params.ts +49 -0
  154. package/ts-code/3nstorage/shared.ts +43 -0
  155. package/ts-code/asmail/asmail-app.ts +91 -0
  156. package/ts-code/asmail/config.ts +96 -0
  157. package/ts-code/asmail/delivery.ts +94 -0
  158. package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
  159. package/ts-code/asmail/resources/inbox.ts +696 -0
  160. package/ts-code/asmail/resources/recipients.ts +495 -0
  161. package/ts-code/asmail/resources/sessions.ts +37 -0
  162. package/ts-code/asmail/retrieval.ts +96 -0
  163. package/ts-code/asmail/routes/config/param-getter.ts +49 -0
  164. package/ts-code/asmail/routes/config/param-setter.ts +49 -0
  165. package/ts-code/asmail/routes/delivery/finalize-delivery.ts +50 -0
  166. package/ts-code/asmail/routes/delivery/pre-flight.ts +132 -0
  167. package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
  168. package/ts-code/asmail/routes/delivery/put-metadata.ts +94 -0
  169. package/ts-code/asmail/routes/delivery/put-obj.ts +166 -0
  170. package/ts-code/asmail/routes/delivery/restart-session.ts +130 -0
  171. package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
  172. package/ts-code/asmail/routes/delivery/start-session.ts +151 -0
  173. package/ts-code/asmail/routes/retrieval/get-message-meta.ts +53 -0
  174. package/ts-code/asmail/routes/retrieval/get-message-obj.ts +109 -0
  175. package/ts-code/asmail/routes/retrieval/list-messages.ts +70 -0
  176. package/ts-code/asmail/routes/retrieval/remove-message.ts +47 -0
  177. package/ts-code/cli/index.ts +82 -0
  178. package/ts-code/cli/run-cmd.ts +81 -0
  179. package/ts-code/cli/show-sample-config.ts +78 -0
  180. package/ts-code/cli/signup-cmd.ts +229 -0
  181. package/ts-code/cli/user-cmd.ts +68 -0
  182. package/ts-code/cli/utils.ts +105 -0
  183. package/ts-code/config/default-confs.ts +22 -0
  184. package/ts-code/config/from-yaml.ts +35 -0
  185. package/ts-code/config/letsencrypt.ts +77 -0
  186. package/ts-code/config/signup.ts +137 -0
  187. package/ts-code/lib-common/admin-api/signup.ts +120 -0
  188. package/ts-code/lib-common/assert.ts +22 -0
  189. package/ts-code/lib-common/async-fs-node.ts +656 -0
  190. package/ts-code/lib-common/buffer-utils.ts +124 -0
  191. package/ts-code/lib-common/byte-streaming/common.ts +166 -0
  192. package/ts-code/lib-common/bytes-equal.ts +25 -0
  193. package/ts-code/lib-common/canonical-address.ts +92 -0
  194. package/ts-code/lib-common/exceptions/error.ts +44 -0
  195. package/ts-code/lib-common/exceptions/file.ts +84 -0
  196. package/ts-code/lib-common/exceptions/http.ts +69 -0
  197. package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
  198. package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
  199. package/ts-code/lib-common/json-equal.ts +55 -0
  200. package/ts-code/lib-common/json-utils.ts +130 -0
  201. package/ts-code/lib-common/jwkeys.ts +246 -0
  202. package/ts-code/lib-common/map-of-sets.ts +60 -0
  203. package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
  204. package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
  205. package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
  206. package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
  207. package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
  208. package/ts-code/lib-common/processes.ts +501 -0
  209. package/ts-code/lib-common/random-node.ts +79 -0
  210. package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
  211. package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
  212. package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
  213. package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
  214. package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
  215. package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
  216. package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
  217. package/ts-code/lib-common/service-api/locker.ts +44 -0
  218. package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
  219. package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
  220. package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
  221. package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
  222. package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
  223. package/ts-code/lib-common/session-encryptor.ts +54 -0
  224. package/ts-code/lib-common/time-window-cache.ts +74 -0
  225. package/ts-code/lib-common/transferable.d.ts +30 -0
  226. package/ts-code/lib-server/conf-util.ts +35 -0
  227. package/ts-code/lib-server/mid-access.ts +45 -0
  228. package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
  229. package/ts-code/lib-server/middleware/error-handler.ts +79 -0
  230. package/ts-code/lib-server/pkl-access.ts +46 -0
  231. package/ts-code/lib-server/resources/dns.ts +151 -0
  232. package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
  233. package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
  234. package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
  235. package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
  236. package/ts-code/lib-server/resources/sessions.ts +232 -0
  237. package/ts-code/lib-server/resources/user-files.ts +147 -0
  238. package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
  239. package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
  240. package/ts-code/lib-server/routes/sessions/close.ts +27 -0
  241. package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
  242. package/ts-code/lib-server/routes/sessions/start.ts +116 -0
  243. package/ts-code/lib-server/web-sockets/app.ts +339 -0
  244. package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
  245. package/ts-code/lib.ts +29 -0
  246. package/ts-code/locker/locker-app.ts +60 -0
  247. package/ts-code/locker/resources/lockers.ts +17 -0
  248. package/ts-code/locker/resources/sessions.ts +37 -0
  249. package/ts-code/locker/routes/create-locker.ts +47 -0
  250. package/ts-code/mailerId/mailerId-app.ts +107 -0
  251. package/ts-code/mailerId/resources/certifier.ts +181 -0
  252. package/ts-code/mailerId/resources/sessions.ts +44 -0
  253. package/ts-code/mailerId/resources/users.ts +88 -0
  254. package/ts-code/mailerId/routes/certify.ts +68 -0
  255. package/ts-code/main.ts +304 -0
  256. package/ts-code/mock/dns.ts +106 -0
  257. package/ts-code/mock/mock-as-child-proc.ts +130 -0
  258. package/ts-code/mock/node-child-ipc.ts +69 -0
  259. package/ts-code/mock/run-in-proc.ts +111 -0
  260. package/ts-code/mock/tls-options.ts +73 -0
  261. package/ts-code/services.ts +138 -0
  262. package/ts-code/signup/resources/users.ts +429 -0
  263. package/ts-code/signup/routes/add.ts +65 -0
  264. package/ts-code/signup/routes/get-available-addresses.ts +49 -0
  265. package/ts-code/signup/routes/get-available-domains.ts +45 -0
  266. package/ts-code/signup/signup-app.ts +54 -0
  267. package/ts-code/signup/signup-tokens.ts +148 -0
  268. package/ts-code/tests/admin-proto/signup.ts +277 -0
  269. package/ts-code/tests/jasmine.ts +37 -0
  270. package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
  271. package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
  272. package/ts-code/tests/libs-for-tests/assert.ts +22 -0
  273. package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
  274. package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
  275. package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
  276. package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
  277. package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
  278. package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
  279. package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
  280. package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
  281. package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
  282. package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
  283. package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
  284. package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
  285. package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
  286. package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
  287. package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
  288. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
  289. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
  290. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
  291. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
  292. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
  293. package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
  294. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
  295. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
  296. package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
  297. package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
  298. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
  299. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
  300. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
  301. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
  302. package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
  303. package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
  304. package/ts-code/tests/protocols/asmail/config.ts +172 -0
  305. package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
  306. package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
  307. package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
  308. package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
  309. package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
  310. package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
  311. package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
  312. package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
  313. package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
  314. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
  315. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
  316. package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
  317. package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
  318. package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
  319. package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
  320. package/ts-code/tests/protocols/mailerid.ts +271 -0
  321. package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
  322. package/ts-code/tests/shared-checks/requests.ts +135 -0
  323. package/ts-code/tsconfig.json +11 -0
  324. package/ts-code/web3n.d.ts +1068 -0
@@ -0,0 +1,197 @@
1
+ /*
2
+ Copyright (C) 2016 - 2017, 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 { beforeEachAsync, itAsync } from '../../../../libs-for-tests/async-jasmine';
19
+ import { SpecDescribe, TestSetup, User, msg, ASMailComponent, startSession, sendMsg, Obj } from '../test-utils';
20
+ import { resolve as resolveUrl } from 'url';
21
+ import { msgObj as api, HTTP_HEADER, ERR_SC } from '../../../../../lib-common/service-api/asmail/retrieval';
22
+ import { RequestOpts, Reply, doBodylessRequest } from '../../../../libs-for-tests/xhr-utils';
23
+ import { expectNonAcceptanceOfBadSessionId } from '../../../../shared-checks/requests';
24
+ import { copy } from '../../../../libs-for-tests/json-copy';
25
+ import { bytesEqual } from '../../../../libs-for-tests/bytes-equal';
26
+
27
+ const obj1 = msg.msgObjs[0];
28
+ const obj2 = msg.msgObjs[1];
29
+
30
+ export const specs: SpecDescribe = {
31
+ description: `Request to get message object`
32
+ };
33
+
34
+ function checkReplyExpectation(rep: Reply<Uint8Array>, obj: Obj,
35
+ headerPresent: boolean, expectedSegsBytes: Uint8Array): void {
36
+ // status
37
+ expect(rep.status).withContext('status for returned bytes').toBe(api.SC.ok);
38
+
39
+ // object's header length http header
40
+ const headerLen = obj.header.length;
41
+ if (headerPresent) {
42
+ expect(parseInt(rep.headers!.get(HTTP_HEADER.objHeaderLength)!)).withContext('object header size must be given in the reply header').toBe(headerLen);
43
+ }
44
+
45
+ // segments length header
46
+ expect(parseInt(rep.headers!.get(HTTP_HEADER.objSegmentsLength)!)).withContext('object segments size must be given in the reply header').toBe(obj.segs.length);
47
+
48
+ // check body
49
+ if (headerPresent) {
50
+ expect(bytesEqual(rep.data.subarray(0, headerLen), obj.header)).withContext('reply should have header bytes at the front').toBe(true);
51
+ expect(bytesEqual(rep.data.subarray(headerLen), expectedSegsBytes)).withContext('reply should have proper segments bytes, following header bytes').toBe(true);
52
+ } else {
53
+ expect(bytesEqual(rep.data, expectedSegsBytes)).withContext('reply should have proper segments bytes').toBe(true);
54
+ }
55
+ }
56
+
57
+ specs.definition = (setup: () => TestSetup) => (() => {
58
+
59
+ let asmailServer: ASMailComponent;
60
+ let retrievalUrl: string;
61
+ let deliveryUrl: string;
62
+ let user1: User;
63
+ let reqOpts: RequestOpts
64
+ let msgId: string;
65
+
66
+ beforeEachAsync(async () => {
67
+ asmailServer = setup().asmailServer;
68
+ retrievalUrl = await asmailServer.getRetrievalUrl();
69
+ deliveryUrl = await asmailServer.getDeliveryUrl();
70
+ user1 = setup().user1;
71
+ msgId = await sendMsg(deliveryUrl, user1.id, msg);
72
+ const sessionId = await startSession(user1, retrievalUrl);
73
+ reqOpts = {
74
+ url: resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj1.objId,
75
+ { header: true })),
76
+ method: 'GET',
77
+ responseType: 'arraybuffer',
78
+ sessionId,
79
+ responseHeaders: [ HTTP_HEADER.objHeaderLength,
80
+ HTTP_HEADER.objSegmentsLength ]
81
+ };
82
+ });
83
+
84
+ itAsync('fails when message does not exist', async () => {
85
+ const opts = copy(reqOpts);
86
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd('unknown-message', 'some-obj'));
87
+ const rep = await doBodylessRequest<Uint8Array>(opts);
88
+ expect(rep.status).toBe(api.SC.unknownMsgOrObj);
89
+ });
90
+
91
+ itAsync('fails when object does not exist', async () => {
92
+ const unknownObj = 'unknown-obj';
93
+ const opts = copy(reqOpts);
94
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, unknownObj));
95
+ const rep = await doBodylessRequest<Uint8Array>(opts);
96
+ expect(rep.status).toBe(api.SC.unknownMsgOrObj);
97
+ });
98
+
99
+ itAsync('will not accept bad parameters', async () => {
100
+ const opts = copy(reqOpts);
101
+ const objId = msg.msgObjs[0].objId;
102
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, objId,
103
+ { ofs: -34 }));
104
+ let rep = await doBodylessRequest<Uint8Array>(opts);
105
+ expect(rep.status).toBe(ERR_SC.malformed);
106
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, objId,
107
+ { limit: -34 }));
108
+ rep = await doBodylessRequest<Uint8Array>(opts);
109
+ expect(rep.status).toBe(ERR_SC.malformed);
110
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, objId,
111
+ { ofs: 10, limit: 0 }));
112
+ rep = await doBodylessRequest<Uint8Array>(opts);
113
+ expect(rep.status).toBe(ERR_SC.malformed);
114
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, objId,
115
+ { header: true, ofs: 10 }));
116
+ rep = await doBodylessRequest<Uint8Array>(opts);
117
+ expect(rep.status).toBe(ERR_SC.malformed);
118
+ });
119
+
120
+ itAsync('returns header and all segments', async () => {
121
+ const opts = copy(reqOpts);
122
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj1.objId,
123
+ { header: true }));
124
+ const rep = await doBodylessRequest<Uint8Array>(opts);
125
+ checkReplyExpectation(rep, obj1, true, obj1.segs);
126
+ });
127
+
128
+ itAsync('returns header without segments', async () => {
129
+ const opts = copy(reqOpts);
130
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj1.objId, { header: true, limit: 0 }));
131
+ const rep = await doBodylessRequest<Uint8Array>(opts);
132
+ checkReplyExpectation(rep, obj1, true, new Uint8Array(0));
133
+ });
134
+
135
+ itAsync('returns all segments without header', async () => {
136
+ const opts = copy(reqOpts);
137
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj1.objId));
138
+ const rep = await doBodylessRequest<Uint8Array>(opts);
139
+ checkReplyExpectation(rep, obj1, false, obj1.segs);
140
+ });
141
+
142
+ itAsync('returns chunk, when offset and limit are given', async () => {
143
+ const opts = copy(reqOpts);
144
+ // with non-overflowing limit
145
+ for (let offset=0; offset<=obj2.segs.length; offset+=512) {
146
+ const chunkLen = Math.min(512, obj2.segs.length - offset);
147
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj2.objId,
148
+ { ofs: offset, limit: chunkLen }));
149
+ const rep = await doBodylessRequest<Uint8Array>(opts);
150
+ checkReplyExpectation(rep, obj2, false, obj2.segs.subarray(offset, offset+chunkLen));
151
+ }
152
+ // with overflowing limit
153
+ const offset = obj2.segs.length - 100;
154
+ const requestedLen = 300
155
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj2.objId,
156
+ { ofs: offset, limit: requestedLen }));
157
+ const rep = await doBodylessRequest<Uint8Array>(opts);
158
+ checkReplyExpectation(rep, obj2, false, obj2.segs.subarray(offset));
159
+ });
160
+
161
+ itAsync('reads segments from start, when offset is not given', async () => {
162
+ const opts = copy(reqOpts);
163
+ // with non-overflowing length
164
+ const chunkLen = 512;
165
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj2.objId,
166
+ { limit: chunkLen }));
167
+ let rep = await doBodylessRequest<Uint8Array>(opts);
168
+ checkReplyExpectation(rep, obj2, false, obj2.segs.subarray(0, chunkLen));
169
+ // with overflowing length
170
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj2.objId,
171
+ { limit: obj2.segs.length+300 }));
172
+ rep = await doBodylessRequest<Uint8Array>(opts);
173
+ checkReplyExpectation(rep, obj2, false, obj2.segs);
174
+ });
175
+
176
+ itAsync('reads segments to the end, when limit is not given', async () => {
177
+ const opts = copy(reqOpts);
178
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj2.objId,
179
+ { ofs: 1234 }));
180
+ const rep = await doBodylessRequest<Uint8Array>(opts);
181
+ checkReplyExpectation(rep, obj2, false, obj2.segs.subarray(1234));
182
+ });
183
+
184
+ itAsync('no-bytes read', async () => {
185
+ const opts = copy(reqOpts);
186
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId, obj2.objId,
187
+ { ofs: obj2.segs.length, limit: 500 }));
188
+ const rep = await doBodylessRequest<Uint8Array>(opts);
189
+ checkReplyExpectation(rep, obj2, false, new Uint8Array(0));
190
+ });
191
+
192
+ itAsync(`requires open session`, async () => {
193
+ const opts = copy(reqOpts);
194
+ await expectNonAcceptanceOfBadSessionId(opts);
195
+ });
196
+
197
+ });
@@ -0,0 +1,110 @@
1
+ /*
2
+ Copyright (C) 2016 - 2017б 2022 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 { beforeEachAsync, itAsync } from '../../../../libs-for-tests/async-jasmine';
19
+ import { SpecDescribe, TestSetup, User, msg, startSession, sendMsg } from '../test-utils';
20
+ import { resolve as resolveUrl } from 'url';
21
+ import { listMsgs as api } from '../../../../../lib-common/service-api/asmail/retrieval';
22
+ import { RequestOpts, doBodylessRequest } from '../../../../libs-for-tests/xhr-utils';
23
+ import { expectNonAcceptanceOfBadSessionId } from '../../../../shared-checks/requests';
24
+ import { copy } from '../../../../libs-for-tests/json-copy';
25
+ import { msgSendingSteps } from '../../../../libs-for-tests/asmail';
26
+
27
+ export const specs: SpecDescribe = {
28
+ description: `Request to list messages in inbox`
29
+ };
30
+
31
+ specs.definition = (setup: () => TestSetup) => (() => {
32
+
33
+ let retrievalUrl: string;
34
+ let deliveryUrl: string;
35
+ let user1: User;
36
+ let reqOpts: RequestOpts
37
+
38
+ beforeEachAsync(async () => {
39
+ retrievalUrl = await setup().asmailServer.getRetrievalUrl();
40
+ deliveryUrl = await setup().asmailServer.getDeliveryUrl();
41
+ user1 = setup().user1;
42
+ const sessionId = await startSession(user1, retrievalUrl);
43
+ reqOpts = {
44
+ url: resolveUrl(retrievalUrl, api.EXPRESS_URL_END),
45
+ method: 'GET',
46
+ responseType: 'json',
47
+ sessionId
48
+ };
49
+ });
50
+
51
+ // TODO add to this route time limits for listing
52
+
53
+ itAsync('lists messages in inbox', async () => {
54
+ const opts = copy(reqOpts);
55
+
56
+ // some number of messages at the start of test
57
+ let rep = await doBodylessRequest<api.Reply>(opts);
58
+ expect(rep.status).withContext('normal status reply').toBe(api.SC.ok);
59
+ expect(Array.isArray(rep.data)).toBe(true);
60
+ const initNumOfMsgs = rep.data.length;
61
+
62
+ // add one message, and see a change
63
+ const msgId = await sendMsg(deliveryUrl, user1.id, msg);
64
+ rep = await doBodylessRequest<api.Reply>(opts);
65
+ expect(rep.status).withContext('normal status reply').toBe(api.SC.ok);
66
+ expect(Array.isArray(rep.data)).toBe(true);
67
+ expect(rep.data).toContain(msgId);
68
+ expect(rep.data.length).toBe(initNumOfMsgs + 1);
69
+
70
+ });
71
+
72
+ itAsync(`requires open session`, async () => {
73
+ const opts = copy(reqOpts);
74
+ await expectNonAcceptanceOfBadSessionId(opts);
75
+ });
76
+
77
+ itAsync(`doesn't list messages that ain't completely sent`, async () => {
78
+ const opts = copy(reqOpts);
79
+ let lst = (await doBodylessRequest<api.Reply>(opts)).data;
80
+ const initMsgNum = lst.length;
81
+
82
+ // start prolonged message sending
83
+ const longSending = msgSendingSteps(deliveryUrl, user1.id, msg);
84
+ const { value: msgId1 } = (await longSending.next());
85
+ lst = (await doBodylessRequest<api.Reply>(opts)).data;
86
+ expect(lst.length).toBe(initMsgNum);
87
+ expect(lst).not.toContain(msgId1);
88
+
89
+ // add one message completely before listing
90
+ const msgId2 = await sendMsg(deliveryUrl, user1.id, msg);
91
+ lst = (await doBodylessRequest<api.Reply>(opts)).data;
92
+ expect(lst.length).toBe(initMsgNum + 1);
93
+ expect(lst).toContain(msgId2);
94
+
95
+ let done: boolean;
96
+ do {
97
+ done = !!(await longSending.next()).done;
98
+ if (!done) {
99
+ expect((await doBodylessRequest<api.Reply>(opts)).data)
100
+ .not.toContain(msgId1);
101
+ }
102
+ } while (!done);
103
+
104
+ // listing message only when it is completely sent
105
+ lst = (await doBodylessRequest<api.Reply>(opts)).data;
106
+ expect(lst.length).toBe(initMsgNum + 2);
107
+ expect(lst).toContain(msgId1);
108
+ });
109
+
110
+ });
@@ -0,0 +1,74 @@
1
+ /*
2
+ Copyright (C) 2016 - 2017, 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 { beforeEachAsync, itAsync } from '../../../../libs-for-tests/async-jasmine';
19
+ import { SpecDescribe, TestSetup, User, msg, ASMailComponent, startSession, sendMsg } from '../test-utils';
20
+ import { resolve as resolveUrl } from 'url';
21
+ import { rmMsg as api } from '../../../../../lib-common/service-api/asmail/retrieval';
22
+ import { RequestOpts, doBodylessRequest } from '../../../../libs-for-tests/xhr-utils';
23
+ import { expectNonAcceptanceOfBadSessionId } from '../../../../shared-checks/requests';
24
+ import { copy } from '../../../../libs-for-tests/json-copy';
25
+
26
+ export const specs: SpecDescribe = {
27
+ description: `Request to remove message from inbox`
28
+ };
29
+
30
+ specs.definition = (setup: () => TestSetup) => (() => {
31
+
32
+ let asmailServer: ASMailComponent;
33
+ let retrievalUrl: string;
34
+ let deliveryUrl: string;
35
+ let user1: User;
36
+ let reqOpts: RequestOpts
37
+
38
+ beforeEachAsync(async () => {
39
+ asmailServer = setup().asmailServer;
40
+ retrievalUrl = await asmailServer.getRetrievalUrl();
41
+ deliveryUrl = await asmailServer.getDeliveryUrl();
42
+ user1 = setup().user1;
43
+ const sessionId = await startSession(user1, retrievalUrl);
44
+ reqOpts = {
45
+ url: resolveUrl(retrievalUrl, api.genUrlEnd('some-msg')),
46
+ method: 'DELETE',
47
+ sessionId
48
+ };
49
+ });
50
+
51
+ itAsync('removes messages from inbox', async () => {
52
+ const msgId = await sendMsg(deliveryUrl, user1.id, msg);
53
+ expect(await asmailServer.msgExists(user1.id, msgId, true)).toBeTruthy();
54
+
55
+ const opts = copy(reqOpts);
56
+ opts.url = resolveUrl(retrievalUrl, api.genUrlEnd(msgId));
57
+
58
+ const rep = await doBodylessRequest<void>(opts);
59
+ expect(rep.status).withContext('status when message was found and removed').toBe(api.SC.ok);
60
+ expect(await asmailServer.msgExists(user1.id, msgId, true)).withContext('message should be removed from the server').toBeFalsy();
61
+ });
62
+
63
+ itAsync(`returns an error when message is unknown`, async () => {
64
+ const opts = copy(reqOpts);
65
+ const rep = await doBodylessRequest<void>(opts);
66
+ expect(rep.status).withContext('status for unknown message').toBe(api.SC.unknownMsg);
67
+ });
68
+
69
+ itAsync(`requires open session`, async () => {
70
+ const opts = copy(reqOpts);
71
+ await expectNonAcceptanceOfBadSessionId(opts);
72
+ });
73
+
74
+ });
@@ -0,0 +1,60 @@
1
+ /*
2
+ Copyright (C) 2017 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 { ASMailComponent } from '../../../libs-for-tests/server-components/asmail';
19
+ import { User, doMailerIdLogin } from '../../../libs-for-tests/mailerid';
20
+ import { GenericSpecDescribe } from '../../../libs-for-tests/spec-assembly';
21
+ import { bytesSync as randomBytes } from '../../../../lib-common/random-node';
22
+ import { Msg, Obj } from '../../../libs-for-tests/asmail';
23
+ import { resolve as resolveUrl } from 'url';
24
+ import * as api from '../../../../lib-common/service-api/asmail/retrieval';
25
+
26
+ export { ASMailComponent } from '../../../libs-for-tests/server-components/asmail';
27
+ export { User } from '../../../libs-for-tests/mailerid';
28
+ export { sendMsg, Obj } from '../../../libs-for-tests/asmail';
29
+
30
+ export interface TestSetup {
31
+ asmailServer: ASMailComponent;
32
+ user1: User;
33
+ user2: User;
34
+ }
35
+
36
+ export type SpecDescribe = GenericSpecDescribe<TestSetup>;
37
+
38
+ export const obj1: Obj = {
39
+ objId: 'aaaa',
40
+ header: randomBytes(100),
41
+ segs: randomBytes(573)
42
+ };
43
+ export const obj2: Obj = {
44
+ objId: 'bbbb',
45
+ header: randomBytes(100),
46
+ segs: randomBytes(20*1024 + 7)
47
+ };
48
+ export const msg: Msg = {
49
+ cryptoMeta: { pid: 'xxxx' },
50
+ msgObjs: [ obj1, obj2 ]
51
+ }
52
+
53
+ export async function startSession(user: User, retrievalUrl: string): Promise<string> {
54
+ return await doMailerIdLogin(
55
+ resolveUrl(retrievalUrl, api.midLogin.MID_URL_PART),
56
+ user
57
+ );
58
+ }
59
+
60
+ Object.freeze(exports);
@@ -0,0 +1,115 @@
1
+ /*
2
+ Copyright (C) 2016, 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 { afterAllAsync, beforeAllAsync, itAsync } from '../../libs-for-tests/async-jasmine';
19
+ import { ASMailComponent } from '../../libs-for-tests/server-components/asmail';
20
+ import { User } from '../../libs-for-tests/mailerid';
21
+ import { RequestOpts, doBodylessRequest } from '../../libs-for-tests/xhr-utils';
22
+ import { expectNonAcceptanceOfBadSessionId, expectNonAcceptanceOfNonEmptyBody } from '../../shared-checks/requests';
23
+ import { midLoginSpecs } from '../../shared-checks/check-mid-login';
24
+ import { resolve as resolveUrl } from 'url';
25
+ import * as api from '../../../lib-common/service-api/asmail/retrieval';
26
+ import { bytesSync as randomBytes } from '../../../lib-common/random-node';
27
+ import { Msg } from '../../libs-for-tests/asmail';
28
+ import { addSpecsFrom } from '../../libs-for-tests/spec-assembly';
29
+ import { join as joinPaths } from 'path';
30
+ import { startSession } from './retrieval/test-utils';
31
+
32
+ const SPECS_FOLDER = joinPaths(__dirname, './retrieval/specs');
33
+
34
+ describe('ASMail retrieval service', () => {
35
+
36
+ let asmailServer: ASMailComponent;
37
+ const midServiceDomain = 'localhost';
38
+ const signupDomains = [ 'company.inc', 'personal.net' ];
39
+ let user1: User;
40
+ let user2: User;
41
+ let retrievalUrl: string;
42
+ let deliveryUrl: string;
43
+
44
+ const msg: Msg = {
45
+ cryptoMeta: {
46
+ pid: 'ephemeral pair id'
47
+ },
48
+ msgObjs: [ {
49
+ objId: 'aaaa',
50
+ header: randomBytes(100),
51
+ segs: randomBytes(573)
52
+ }, {
53
+ objId: 'bbbb',
54
+ header: randomBytes(100),
55
+ segs: randomBytes(2*1024 + 7)
56
+ } ]
57
+ };
58
+
59
+ beforeAllAsync(async () => {
60
+ asmailServer = new ASMailComponent(signupDomains, midServiceDomain);
61
+ await asmailServer.start();
62
+ retrievalUrl = await asmailServer.getRetrievalUrl();
63
+ if (!retrievalUrl.endsWith('/')) { retrievalUrl += '/'; }
64
+ deliveryUrl = await asmailServer.getDeliveryUrl();
65
+ if (!deliveryUrl.endsWith('/')) { deliveryUrl += '/'; }
66
+ user1 = await asmailServer.addUser(
67
+ `Bob Johnson @${signupDomains[0]}`
68
+ );
69
+ user2 = await asmailServer.addUser(
70
+ `William Young @${signupDomains[1]}`
71
+ );
72
+ });
73
+
74
+ afterAllAsync(async () => {
75
+ await asmailServer.stop();
76
+ asmailServer = (undefined as any);
77
+ });
78
+
79
+ describe('session', () => {
80
+
81
+ describe('MailerId login', midLoginSpecs(
82
+ () => resolveUrl(retrievalUrl, api.midLogin.MID_URL_PART),
83
+ () => user1
84
+ ));
85
+
86
+ itAsync('closing session', async () => {
87
+ const sessionId = await startSession(user1, retrievalUrl);
88
+
89
+ const reqOpts: RequestOpts = {
90
+ url: resolveUrl(retrievalUrl, api.closeSession.URL_END),
91
+ method: 'POST',
92
+ sessionId
93
+ };
94
+
95
+ // normal closing of a session
96
+ let rep = await doBodylessRequest<void>(reqOpts);
97
+ expect(rep.status).withContext('status for successful closing of session').toBe(200);
98
+
99
+ // repeated call should see invalid session response
100
+ rep = await doBodylessRequest<void>(reqOpts);
101
+ expect(rep.status).toBe(api.ERR_SC.needAuth);
102
+
103
+ reqOpts.sessionId = await startSession(user1, retrievalUrl);
104
+
105
+ await expectNonAcceptanceOfNonEmptyBody(reqOpts);
106
+
107
+ await expectNonAcceptanceOfBadSessionId(reqOpts);
108
+
109
+ });
110
+
111
+ });
112
+
113
+ addSpecsFrom(SPECS_FOLDER, () => ({ asmailServer, user1, user2 }));
114
+
115
+ });