spec-3nweb-server 1.8.5 → 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 (309) 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/mock/tls-options.js +46 -44
  6. package/build/tests/admin-proto/signup.d.ts +1 -0
  7. package/build/tests/admin-proto/signup.js +235 -0
  8. package/build/tests/jasmine.d.ts +1 -0
  9. package/build/tests/jasmine.js +32 -0
  10. package/build/tests/libs-for-tests/3nstorage.d.ts +22 -0
  11. package/build/tests/libs-for-tests/3nstorage.js +123 -0
  12. package/build/tests/libs-for-tests/asmail.d.ts +22 -0
  13. package/build/tests/libs-for-tests/asmail.js +179 -0
  14. package/build/tests/libs-for-tests/assert.d.ts +1 -0
  15. package/build/tests/libs-for-tests/assert.js +26 -0
  16. package/build/tests/libs-for-tests/async-jasmine.d.ts +7 -0
  17. package/build/tests/libs-for-tests/async-jasmine.js +77 -0
  18. package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
  19. package/build/tests/libs-for-tests/bytes-equal.js +34 -0
  20. package/build/tests/libs-for-tests/json-copy.d.ts +1 -0
  21. package/build/tests/libs-for-tests/json-copy.js +45 -0
  22. package/build/tests/libs-for-tests/json-equal.d.ts +4 -0
  23. package/build/tests/libs-for-tests/json-equal.js +67 -0
  24. package/build/tests/libs-for-tests/mailerid.d.ts +13 -0
  25. package/build/tests/libs-for-tests/mailerid.js +114 -0
  26. package/build/tests/libs-for-tests/pkl.d.ts +28 -0
  27. package/build/tests/libs-for-tests/pkl.js +89 -0
  28. package/build/tests/libs-for-tests/server-components/3nstorage.d.ts +20 -0
  29. package/build/tests/libs-for-tests/server-components/3nstorage.js +200 -0
  30. package/build/tests/libs-for-tests/server-components/admin.d.ts +6 -0
  31. package/build/tests/libs-for-tests/server-components/admin.js +43 -0
  32. package/build/tests/libs-for-tests/server-components/asmail.d.ts +16 -0
  33. package/build/tests/libs-for-tests/server-components/asmail.js +143 -0
  34. package/build/tests/libs-for-tests/server-components/component.d.ts +13 -0
  35. package/build/tests/libs-for-tests/server-components/component.js +77 -0
  36. package/build/tests/libs-for-tests/server-components/mailerid.d.ts +10 -0
  37. package/build/tests/libs-for-tests/server-components/mailerid.js +103 -0
  38. package/build/tests/libs-for-tests/server-runner.d.ts +15 -0
  39. package/build/tests/libs-for-tests/server-runner.js +69 -0
  40. package/build/tests/libs-for-tests/spec-assembly.d.ts +6 -0
  41. package/build/tests/libs-for-tests/spec-assembly.js +55 -0
  42. package/build/tests/libs-for-tests/ws-utils.d.ts +3 -0
  43. package/build/tests/libs-for-tests/ws-utils.js +59 -0
  44. package/build/tests/libs-for-tests/xhr-utils.d.ts +61 -0
  45. package/build/tests/libs-for-tests/xhr-utils.js +154 -0
  46. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.d.ts +2 -0
  47. package/build/tests/protocols/3nstorage/owner/specs/archive-obj-ver.js +84 -0
  48. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.d.ts +2 -0
  49. package/build/tests/protocols/3nstorage/owner/specs/archive-root-ver.js +78 -0
  50. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.d.ts +2 -0
  51. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.js +83 -0
  52. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.d.ts +2 -0
  53. package/build/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.js +77 -0
  54. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.d.ts +2 -0
  55. package/build/tests/protocols/3nstorage/owner/specs/delete-obj.js +75 -0
  56. package/build/tests/protocols/3nstorage/owner/specs/events.d.ts +2 -0
  57. package/build/tests/protocols/3nstorage/owner/specs/events.js +91 -0
  58. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.d.ts +2 -0
  59. package/build/tests/protocols/3nstorage/owner/specs/get-current-obj.js +269 -0
  60. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.d.ts +2 -0
  61. package/build/tests/protocols/3nstorage/owner/specs/get-current-root.js +262 -0
  62. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.d.ts +2 -0
  63. package/build/tests/protocols/3nstorage/owner/specs/get-obj-status.js +79 -0
  64. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.d.ts +2 -0
  65. package/build/tests/protocols/3nstorage/owner/specs/get-root-status.js +72 -0
  66. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.d.ts +2 -0
  67. package/build/tests/protocols/3nstorage/owner/specs/put-current-obj.js +287 -0
  68. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.d.ts +2 -0
  69. package/build/tests/protocols/3nstorage/owner/specs/put-current-root.js +274 -0
  70. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.d.ts +2 -0
  71. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel-root.js +73 -0
  72. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.d.ts +2 -0
  73. package/build/tests/protocols/3nstorage/owner/specs/trans-cancel.js +72 -0
  74. package/build/tests/protocols/3nstorage/owner/test-utils.d.ts +14 -0
  75. package/build/tests/protocols/3nstorage/owner/test-utils.js +54 -0
  76. package/build/tests/protocols/3nstorage/owner.d.ts +1 -0
  77. package/build/tests/protocols/3nstorage/owner.js +138 -0
  78. package/build/tests/protocols/asmail/config.d.ts +1 -0
  79. package/build/tests/protocols/asmail/config.js +117 -0
  80. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.d.ts +2 -0
  81. package/build/tests/protocols/asmail/delivery/specs/finalize-delivery.js +60 -0
  82. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.d.ts +2 -0
  83. package/build/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.js +68 -0
  84. package/build/tests/protocols/asmail/delivery/specs/put-metadata.d.ts +2 -0
  85. package/build/tests/protocols/asmail/delivery/specs/put-metadata.js +83 -0
  86. package/build/tests/protocols/asmail/delivery/specs/put-obj.d.ts +2 -0
  87. package/build/tests/protocols/asmail/delivery/specs/put-obj.js +123 -0
  88. package/build/tests/protocols/asmail/delivery/specs/restart-session.d.ts +2 -0
  89. package/build/tests/protocols/asmail/delivery/specs/restart-session.js +79 -0
  90. package/build/tests/protocols/asmail/delivery/specs/start-session.d.ts +2 -0
  91. package/build/tests/protocols/asmail/delivery/specs/start-session.js +64 -0
  92. package/build/tests/protocols/asmail/delivery/test-utils.d.ts +16 -0
  93. package/build/tests/protocols/asmail/delivery/test-utils.js +46 -0
  94. package/build/tests/protocols/asmail/delivery.d.ts +1 -0
  95. package/build/tests/protocols/asmail/delivery.js +46 -0
  96. package/build/tests/protocols/asmail/retrieval/specs/events.d.ts +2 -0
  97. package/build/tests/protocols/asmail/retrieval/specs/events.js +62 -0
  98. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.d.ts +2 -0
  99. package/build/tests/protocols/asmail/retrieval/specs/get-message-meta.js +70 -0
  100. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.d.ts +2 -0
  101. package/build/tests/protocols/asmail/retrieval/specs/get-message-obj.js +166 -0
  102. package/build/tests/protocols/asmail/retrieval/specs/list-messages.d.ts +2 -0
  103. package/build/tests/protocols/asmail/retrieval/specs/list-messages.js +96 -0
  104. package/build/tests/protocols/asmail/retrieval/specs/remove-message.d.ts +2 -0
  105. package/build/tests/protocols/asmail/retrieval/specs/remove-message.js +66 -0
  106. package/build/tests/protocols/asmail/retrieval/test-utils.d.ts +17 -0
  107. package/build/tests/protocols/asmail/retrieval/test-utils.js +46 -0
  108. package/build/tests/protocols/asmail/retrieval.d.ts +1 -0
  109. package/build/tests/protocols/asmail/retrieval.js +92 -0
  110. package/build/tests/protocols/mailerid.d.ts +1 -0
  111. package/build/tests/protocols/mailerid.js +210 -0
  112. package/build/tests/shared-checks/check-mid-login.d.ts +2 -0
  113. package/build/tests/shared-checks/check-mid-login.js +131 -0
  114. package/build/tests/shared-checks/requests.d.ts +20 -0
  115. package/build/tests/shared-checks/requests.js +123 -0
  116. package/package.json +1 -1
  117. package/packing/create-deb.sh +57 -0
  118. package/packing/deb/lib/systemd/system/3nweb.service +11 -0
  119. package/packing/deb/postinst +44 -0
  120. package/packing/deb/usr/share/doc/3nweb-server/conf-for-postinstall.yaml +19 -0
  121. package/packing/deb/usr/share/doc/3nweb-server/copyright +22 -0
  122. package/publish-task.sh +10 -0
  123. package/push-to-github.sh +105 -0
  124. package/ts-code/3nstorage/3nstorage-app.ts +99 -0
  125. package/ts-code/3nstorage/owner.ts +178 -0
  126. package/ts-code/3nstorage/resources/sessions.ts +37 -0
  127. package/ts-code/3nstorage/resources/store.ts +896 -0
  128. package/ts-code/3nstorage/resources/users.ts +258 -0
  129. package/ts-code/3nstorage/routes/owner/archive-obj-version.ts +73 -0
  130. package/ts-code/3nstorage/routes/owner/cancel-trans.ts +58 -0
  131. package/ts-code/3nstorage/routes/owner/delete-obj.ts +103 -0
  132. package/ts-code/3nstorage/routes/owner/get-archived-obj-ver.ts +111 -0
  133. package/ts-code/3nstorage/routes/owner/get-current-obj.ts +122 -0
  134. package/ts-code/3nstorage/routes/owner/get-obj-status.ts +55 -0
  135. package/ts-code/3nstorage/routes/owner/param-getter.ts +51 -0
  136. package/ts-code/3nstorage/routes/owner/param-setter.ts +50 -0
  137. package/ts-code/3nstorage/routes/owner/put-current-obj.ts +284 -0
  138. package/ts-code/3nstorage/routes/owner/session-params.ts +49 -0
  139. package/ts-code/3nstorage/shared.ts +43 -0
  140. package/ts-code/asmail/asmail-app.ts +91 -0
  141. package/ts-code/asmail/config.ts +96 -0
  142. package/ts-code/asmail/delivery.ts +94 -0
  143. package/ts-code/asmail/resources/delivery-sessions.ts +118 -0
  144. package/ts-code/asmail/resources/inbox.ts +696 -0
  145. package/ts-code/asmail/resources/recipients.ts +495 -0
  146. package/ts-code/asmail/resources/sessions.ts +37 -0
  147. package/ts-code/asmail/retrieval.ts +96 -0
  148. package/ts-code/asmail/routes/config/param-getter.ts +49 -0
  149. package/ts-code/asmail/routes/config/param-setter.ts +49 -0
  150. package/ts-code/asmail/routes/delivery/finalize-delivery.ts +50 -0
  151. package/ts-code/asmail/routes/delivery/pre-flight.ts +132 -0
  152. package/ts-code/asmail/routes/delivery/provide-recipient-pubkey.ts +58 -0
  153. package/ts-code/asmail/routes/delivery/put-metadata.ts +94 -0
  154. package/ts-code/asmail/routes/delivery/put-obj.ts +166 -0
  155. package/ts-code/asmail/routes/delivery/restart-session.ts +130 -0
  156. package/ts-code/asmail/routes/delivery/sender-authorization.ts +81 -0
  157. package/ts-code/asmail/routes/delivery/start-session.ts +151 -0
  158. package/ts-code/asmail/routes/retrieval/get-message-meta.ts +53 -0
  159. package/ts-code/asmail/routes/retrieval/get-message-obj.ts +109 -0
  160. package/ts-code/asmail/routes/retrieval/list-messages.ts +70 -0
  161. package/ts-code/asmail/routes/retrieval/remove-message.ts +47 -0
  162. package/ts-code/cli/index.ts +82 -0
  163. package/ts-code/cli/run-cmd.ts +81 -0
  164. package/ts-code/cli/show-sample-config.ts +78 -0
  165. package/ts-code/cli/signup-cmd.ts +229 -0
  166. package/ts-code/cli/user-cmd.ts +68 -0
  167. package/ts-code/cli/utils.ts +105 -0
  168. package/ts-code/config/default-confs.ts +22 -0
  169. package/ts-code/config/from-yaml.ts +35 -0
  170. package/ts-code/config/letsencrypt.ts +77 -0
  171. package/ts-code/config/signup.ts +137 -0
  172. package/ts-code/lib-common/admin-api/signup.ts +120 -0
  173. package/ts-code/lib-common/assert.ts +22 -0
  174. package/ts-code/lib-common/async-fs-node.ts +656 -0
  175. package/ts-code/lib-common/buffer-utils.ts +124 -0
  176. package/ts-code/lib-common/byte-streaming/common.ts +166 -0
  177. package/ts-code/lib-common/bytes-equal.ts +25 -0
  178. package/ts-code/lib-common/canonical-address.ts +92 -0
  179. package/ts-code/lib-common/exceptions/error.ts +44 -0
  180. package/ts-code/lib-common/exceptions/file.ts +84 -0
  181. package/ts-code/lib-common/exceptions/http.ts +69 -0
  182. package/ts-code/lib-common/ipc/generic-ipc.ts +750 -0
  183. package/ts-code/lib-common/ipc/ws-ipc.ts +117 -0
  184. package/ts-code/lib-common/json-equal.ts +55 -0
  185. package/ts-code/lib-common/json-utils.ts +130 -0
  186. package/ts-code/lib-common/jwkeys.ts +246 -0
  187. package/ts-code/lib-common/map-of-sets.ts +60 -0
  188. package/ts-code/lib-common/mid-sigs-NaCl-Ed.ts +677 -0
  189. package/ts-code/lib-common/objs-on-disk/file-layout.ts +480 -0
  190. package/ts-code/lib-common/objs-on-disk/obj-file.ts +325 -0
  191. package/ts-code/lib-common/objs-on-disk/utils.ts +201 -0
  192. package/ts-code/lib-common/objs-on-disk/v1-obj-file-format.ts +329 -0
  193. package/ts-code/lib-common/processes.ts +501 -0
  194. package/ts-code/lib-common/random-node.ts +79 -0
  195. package/ts-code/lib-common/service-api/3nstorage/owner.ts +559 -0
  196. package/ts-code/lib-common/service-api/3nstorage/root-route.ts +22 -0
  197. package/ts-code/lib-common/service-api/asmail/config.ts +144 -0
  198. package/ts-code/lib-common/service-api/asmail/delivery.ts +250 -0
  199. package/ts-code/lib-common/service-api/asmail/retrieval.ts +238 -0
  200. package/ts-code/lib-common/service-api/asmail/root-route.ts +22 -0
  201. package/ts-code/lib-common/service-api/ipc-api.ts +44 -0
  202. package/ts-code/lib-common/service-api/locker.ts +44 -0
  203. package/ts-code/lib-common/service-api/mailer-id/login.ts +80 -0
  204. package/ts-code/lib-common/service-api/mailer-id/provisioning.ts +64 -0
  205. package/ts-code/lib-common/service-api/mailer-id/root-route.ts +25 -0
  206. package/ts-code/lib-common/service-api/pub-key-login.ts +75 -0
  207. package/ts-code/lib-common/service-api/web-socket-base.ts +87 -0
  208. package/ts-code/lib-common/session-encryptor.ts +54 -0
  209. package/ts-code/lib-common/time-window-cache.ts +74 -0
  210. package/ts-code/lib-common/transferable.d.ts +30 -0
  211. package/ts-code/lib-server/conf-util.ts +35 -0
  212. package/ts-code/lib-server/mid-access.ts +45 -0
  213. package/ts-code/lib-server/middleware/body-parsers.ts +248 -0
  214. package/ts-code/lib-server/middleware/error-handler.ts +79 -0
  215. package/ts-code/lib-server/pkl-access.ts +46 -0
  216. package/ts-code/lib-server/resources/dns.ts +151 -0
  217. package/ts-code/lib-server/resources/mailerid-authorizer.ts +115 -0
  218. package/ts-code/lib-server/resources/mem-backed-sessions-factory.ts +132 -0
  219. package/ts-code/lib-server/resources/server-data-folders.ts +160 -0
  220. package/ts-code/lib-server/resources/server-key-for-pkl-challenge.ts +41 -0
  221. package/ts-code/lib-server/resources/sessions.ts +232 -0
  222. package/ts-code/lib-server/resources/user-files.ts +147 -0
  223. package/ts-code/lib-server/routes/pub-key-login/complete-exchange.ts +63 -0
  224. package/ts-code/lib-server/routes/pub-key-login/start-exchange.ts +189 -0
  225. package/ts-code/lib-server/routes/sessions/close.ts +27 -0
  226. package/ts-code/lib-server/routes/sessions/mid-auth.ts +77 -0
  227. package/ts-code/lib-server/routes/sessions/start.ts +116 -0
  228. package/ts-code/lib-server/web-sockets/app.ts +339 -0
  229. package/ts-code/lib-server/web-sockets/server-events.ts +63 -0
  230. package/ts-code/lib.ts +29 -0
  231. package/ts-code/locker/locker-app.ts +60 -0
  232. package/ts-code/locker/resources/lockers.ts +17 -0
  233. package/ts-code/locker/resources/sessions.ts +37 -0
  234. package/ts-code/locker/routes/create-locker.ts +47 -0
  235. package/ts-code/mailerId/mailerId-app.ts +107 -0
  236. package/ts-code/mailerId/resources/certifier.ts +181 -0
  237. package/ts-code/mailerId/resources/sessions.ts +44 -0
  238. package/ts-code/mailerId/resources/users.ts +88 -0
  239. package/ts-code/mailerId/routes/certify.ts +68 -0
  240. package/ts-code/main.ts +304 -0
  241. package/ts-code/mock/dns.ts +106 -0
  242. package/ts-code/mock/mock-as-child-proc.ts +130 -0
  243. package/ts-code/mock/node-child-ipc.ts +69 -0
  244. package/ts-code/mock/run-in-proc.ts +111 -0
  245. package/ts-code/mock/tls-options.ts +73 -0
  246. package/ts-code/services.ts +138 -0
  247. package/ts-code/signup/resources/users.ts +429 -0
  248. package/ts-code/signup/routes/add.ts +65 -0
  249. package/ts-code/signup/routes/get-available-addresses.ts +49 -0
  250. package/ts-code/signup/routes/get-available-domains.ts +45 -0
  251. package/ts-code/signup/signup-app.ts +54 -0
  252. package/ts-code/signup/signup-tokens.ts +148 -0
  253. package/ts-code/tests/admin-proto/signup.ts +277 -0
  254. package/ts-code/tests/jasmine.ts +37 -0
  255. package/ts-code/tests/libs-for-tests/3nstorage.ts +144 -0
  256. package/ts-code/tests/libs-for-tests/asmail.ts +220 -0
  257. package/ts-code/tests/libs-for-tests/assert.ts +22 -0
  258. package/ts-code/tests/libs-for-tests/async-jasmine.ts +89 -0
  259. package/ts-code/tests/libs-for-tests/bytes-equal.ts +25 -0
  260. package/ts-code/tests/libs-for-tests/json-copy.ts +38 -0
  261. package/ts-code/tests/libs-for-tests/json-equal.ts +55 -0
  262. package/ts-code/tests/libs-for-tests/mailerid.ts +123 -0
  263. package/ts-code/tests/libs-for-tests/pkl.ts +127 -0
  264. package/ts-code/tests/libs-for-tests/server-components/3nstorage.ts +206 -0
  265. package/ts-code/tests/libs-for-tests/server-components/admin.ts +49 -0
  266. package/ts-code/tests/libs-for-tests/server-components/asmail.ts +152 -0
  267. package/ts-code/tests/libs-for-tests/server-components/component.ts +90 -0
  268. package/ts-code/tests/libs-for-tests/server-components/mailerid.ts +114 -0
  269. package/ts-code/tests/libs-for-tests/server-runner.ts +82 -0
  270. package/ts-code/tests/libs-for-tests/spec-assembly.ts +60 -0
  271. package/ts-code/tests/libs-for-tests/ws-utils.ts +61 -0
  272. package/ts-code/tests/libs-for-tests/xhr-utils.ts +179 -0
  273. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-obj-ver.ts +100 -0
  274. package/ts-code/tests/protocols/3nstorage/owner/specs/archive-root-ver.ts +91 -0
  275. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-obj-ver.ts +99 -0
  276. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-archive-root-ver.ts +90 -0
  277. package/ts-code/tests/protocols/3nstorage/owner/specs/delete-obj.ts +84 -0
  278. package/ts-code/tests/protocols/3nstorage/owner/specs/events.ts +125 -0
  279. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-obj.ts +298 -0
  280. package/ts-code/tests/protocols/3nstorage/owner/specs/get-current-root.ts +290 -0
  281. package/ts-code/tests/protocols/3nstorage/owner/specs/get-obj-status.ts +88 -0
  282. package/ts-code/tests/protocols/3nstorage/owner/specs/get-root-status.ts +80 -0
  283. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-obj.ts +366 -0
  284. package/ts-code/tests/protocols/3nstorage/owner/specs/put-current-root.ts +329 -0
  285. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel-root.ts +86 -0
  286. package/ts-code/tests/protocols/3nstorage/owner/specs/trans-cancel.ts +86 -0
  287. package/ts-code/tests/protocols/3nstorage/owner/test-utils.ts +72 -0
  288. package/ts-code/tests/protocols/3nstorage/owner.ts +198 -0
  289. package/ts-code/tests/protocols/asmail/config.ts +172 -0
  290. package/ts-code/tests/protocols/asmail/delivery/specs/finalize-delivery.ts +69 -0
  291. package/ts-code/tests/protocols/asmail/delivery/specs/provide-recipient-pubkey.ts +88 -0
  292. package/ts-code/tests/protocols/asmail/delivery/specs/put-metadata.ts +102 -0
  293. package/ts-code/tests/protocols/asmail/delivery/specs/put-obj.ts +156 -0
  294. package/ts-code/tests/protocols/asmail/delivery/specs/restart-session.ts +97 -0
  295. package/ts-code/tests/protocols/asmail/delivery/specs/start-session.ts +79 -0
  296. package/ts-code/tests/protocols/asmail/delivery/test-utils.ts +64 -0
  297. package/ts-code/tests/protocols/asmail/delivery.ts +56 -0
  298. package/ts-code/tests/protocols/asmail/retrieval/specs/events.ts +78 -0
  299. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-meta.ts +80 -0
  300. package/ts-code/tests/protocols/asmail/retrieval/specs/get-message-obj.ts +197 -0
  301. package/ts-code/tests/protocols/asmail/retrieval/specs/list-messages.ts +110 -0
  302. package/ts-code/tests/protocols/asmail/retrieval/specs/remove-message.ts +74 -0
  303. package/ts-code/tests/protocols/asmail/retrieval/test-utils.ts +60 -0
  304. package/ts-code/tests/protocols/asmail/retrieval.ts +115 -0
  305. package/ts-code/tests/protocols/mailerid.ts +271 -0
  306. package/ts-code/tests/shared-checks/check-mid-login.ts +164 -0
  307. package/ts-code/tests/shared-checks/requests.ts +135 -0
  308. package/ts-code/tsconfig.json +11 -0
  309. package/ts-code/web3n.d.ts +1068 -0
@@ -0,0 +1,60 @@
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 { join as joinPaths } from 'path';
19
+ import { readdirSync } from 'fs';
20
+
21
+ export interface GenericSpecDescribe<TSetup> {
22
+ description: string;
23
+ definition?: (setup: () => TSetup) => (() => void);
24
+ focused?: boolean;
25
+ }
26
+
27
+ type ExportedSpecs<TSetup> =
28
+ GenericSpecDescribe<TSetup> | GenericSpecDescribe<TSetup>[]
29
+
30
+ function setupSpecs<TSetup>(specs: GenericSpecDescribe<TSetup>,
31
+ setup: () => TSetup): void {
32
+ if (!specs.definition) { return; }
33
+ if (specs.focused) {
34
+ fdescribe(specs.description, specs.definition(setup));
35
+ } else {
36
+ describe(specs.description, specs.definition(setup));
37
+ }
38
+ }
39
+
40
+ export function addSpecsFrom<TSetup>(specsFolder: string,
41
+ setup: () => TSetup): void {
42
+ for (let fName of readdirSync(specsFolder)) {
43
+ if (!fName.endsWith('.js')) { continue; }
44
+ let modPath = joinPaths(specsFolder, fName);
45
+ let specs: ExportedSpecs<TSetup> = require(modPath).specs;
46
+ if (!specs) {
47
+ console.error(`Module ${fName} is not exposing specs objects with tests`);
48
+ continue;
49
+ }
50
+ if (Array.isArray(specs)) {
51
+ for (let s of specs) {
52
+ setupSpecs(s, setup);
53
+ }
54
+ } else {
55
+ setupSpecs(specs, setup);
56
+ }
57
+ }
58
+ }
59
+
60
+ Object.freeze(exports);
@@ -0,0 +1,61 @@
1
+ /*
2
+ Copyright (C) 2017, 2019 3NSoft Inc.
3
+
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU General Public License as published by the Free Software
6
+ Foundation, either version 3 of the License, or (at your option) any later
7
+ version.
8
+
9
+ This program is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ See the GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License along with
15
+ this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import * as WebSocket from 'ws';
19
+ import { IncomingMessage } from 'http';
20
+ import { SESSION_ID_HEADER, Reply } from './xhr-utils';
21
+ import { defer } from '../../lib-common/processes';
22
+ import { makeConnectionException } from '../../lib-common/exceptions/http';
23
+ import { globalAgent as agent } from 'https';
24
+
25
+ export function openSocket(url: string, sessionId: string):
26
+ Promise<Reply<WebSocket>> {
27
+ if (!url.startsWith('wss://')) { throw new Error(
28
+ `Url protocol must be wss`); }
29
+ const headers: any = {};
30
+ headers[SESSION_ID_HEADER] = sessionId;
31
+ const ws = new WebSocket(url, { headers, agent });
32
+ const opening = defer<Reply<WebSocket>>();
33
+ const initOnError = err => opening.reject(makeConnectionException(
34
+ url, undefined,
35
+ `Cannot open websocket connection due to error: ${err.message}`));
36
+ const onNonOkReply = (req, res: IncomingMessage) => {
37
+ const errReply: Reply<WebSocket> = {
38
+ url,
39
+ method: 'GET',
40
+ status: res.statusCode!,
41
+ data: (undefined as any)
42
+ };
43
+ opening.resolve(errReply);
44
+ };
45
+ ws.on('error', initOnError);
46
+ ws.on('unexpected-response', onNonOkReply);
47
+ ws.once('open', () => {
48
+ const okReply: Reply<WebSocket> = {
49
+ url,
50
+ method: 'GET',
51
+ status: 200,
52
+ data: ws
53
+ };
54
+ opening.resolve(okReply);
55
+ ws.removeListener('error', initOnError);
56
+ ws.removeListener('unexpected-response', onNonOkReply);
57
+ });
58
+ return opening.promise;
59
+ }
60
+
61
+ Object.freeze(exports);
@@ -0,0 +1,179 @@
1
+ /*
2
+ Copyright (C) 2015 - 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 { makeHTTPException, makeConnectionException, HTTPException }
19
+ from '../../lib-common/exceptions/http';
20
+ import { BytesFIFOBuffer } from '../../lib-common/byte-streaming/common';
21
+
22
+ const xhr2 = require('xhr2');
23
+
24
+ export const SESSION_ID_HEADER = "X-Session-Id";
25
+
26
+ export interface Reply<T> {
27
+ url: string;
28
+ method: string;
29
+ status: number;
30
+ data: T;
31
+ headers?: Headers;
32
+ }
33
+
34
+ export interface RequestOpts {
35
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
36
+ url?: string;
37
+ path?: string;
38
+ responseType?: 'json' | 'arraybuffer';
39
+ sessionId?: string;
40
+ responseHeaders?: string[];
41
+ }
42
+
43
+ export interface Headers {
44
+ get(name: string): string|undefined;
45
+ }
46
+
47
+ function makeHeadersInstanceFrom(xhr: XMLHttpRequest, selectHeaders: string[]):
48
+ Headers {
49
+ const m = new Map<string, string>();
50
+ for (const h of selectHeaders) {
51
+ if (typeof h !== 'string') { continue; }
52
+ const value = xhr.getResponseHeader(h);
53
+ if (typeof value !== 'string') { continue; }
54
+ m.set(h.toLowerCase(), value);
55
+ }
56
+ return {
57
+ get(name: string): string|undefined {
58
+ return m.get(name.toLowerCase());
59
+ }
60
+ };
61
+ }
62
+
63
+ export function request<T>(contentType: string|undefined, opts: RequestOpts):
64
+ { xhr: XMLHttpRequest; promise: Promise<Reply<T>>; } {
65
+ const xhr: XMLHttpRequest = new xhr2();
66
+ const promise = new Promise<Reply<T>>((resolve, reject) => {
67
+ xhr.open(opts.method, opts.url!);
68
+ xhr.onload = () => {
69
+ let data = xhr.response;
70
+ if ((opts.responseType === 'arraybuffer') &&
71
+ (data instanceof ArrayBuffer)) {
72
+ data = new Uint8Array(data);
73
+ }
74
+ const rep: Reply<T> = {
75
+ url: opts.url!,
76
+ method: opts.method,
77
+ status: xhr.status,
78
+ data: data
79
+ };
80
+ if (Array.isArray(opts.responseHeaders)) {
81
+ rep.headers = makeHeadersInstanceFrom(xhr, opts.responseHeaders);
82
+ }
83
+ resolve(rep);
84
+ };
85
+ xhr.onerror = ev => reject(
86
+ makeConnectionException(opts.url, opts.method, 'Cannot connect', ev)
87
+ );
88
+ if (contentType) {
89
+ xhr.setRequestHeader('Content-Type', contentType);
90
+ }
91
+ if (opts.sessionId) {
92
+ xhr.setRequestHeader(SESSION_ID_HEADER, opts.sessionId);
93
+ }
94
+ if (opts.responseType) {
95
+ xhr.responseType = opts.responseType;
96
+ }
97
+ });
98
+ return { xhr, promise };
99
+ }
100
+
101
+ /**
102
+ * This assembles XMLHttpRequest with 'Content-Type: application/json' and
103
+ * sends given json.
104
+ * @param opts
105
+ * @param json
106
+ * @return a promise, resolvable to reply object
107
+ */
108
+ export function doJsonRequest<T>(opts: RequestOpts, json: any):
109
+ Promise<Reply<T>> {
110
+ const req = request<T>('application/json', opts);
111
+ const body = ((json === undefined) ? '' : JSON.stringify(json));
112
+ req.xhr.send(body);
113
+ return req.promise;
114
+ }
115
+
116
+ /**
117
+ * This assembles XMLHttpRequest with 'Content-Type: application/octet-stream'
118
+ * and sends given bytes.
119
+ * @param opts
120
+ * @param bytes
121
+ * @return a promise, resolvable to reply object
122
+ */
123
+ export function doBinaryRequest<T>(opts: RequestOpts,
124
+ bytes: Uint8Array|Uint8Array[]): Promise<Reply<T>> {
125
+ const req = request<T>('application/octet-stream', opts);
126
+ if (Array.isArray(bytes)) {
127
+ const fifo = new BytesFIFOBuffer();
128
+ for (const arr of bytes) {
129
+ fifo.push(arr);
130
+ }
131
+ req.xhr.send(fifo.getBytes(undefined));
132
+ } else {
133
+ req.xhr.send(bytes);
134
+ }
135
+ return req.promise;
136
+ }
137
+
138
+ /**
139
+ * This assembles XMLHttpRequest with 'Content-Type: text/plain'
140
+ * and sends given text
141
+ * @param opts
142
+ * @param txt
143
+ * @return a promise, resolvable to reply object
144
+ */
145
+ export function doTextRequest<T>(opts: RequestOpts, txt: string):
146
+ Promise<Reply<T>> {
147
+ const req = request<T>('text/plain', opts);
148
+ req.xhr.send(txt);
149
+ return req.promise;
150
+ }
151
+
152
+ /**
153
+ * This assembles XMLHttpRequest without 'Content-Type'.
154
+ * @param opts
155
+ * @return a promise, resolvable to reply object
156
+ */
157
+ export function doBodylessRequest<T>(opts: RequestOpts): Promise<Reply<T>> {
158
+ const req = request<T>(undefined, opts);
159
+ req.xhr.send();
160
+ return req.promise;
161
+ }
162
+
163
+ /**
164
+ * @param rep
165
+ * @param errMsg
166
+ * @return http exception based on given reply, with an optional message
167
+ */
168
+ export function makeException(rep: Reply<any>, errMsg?: string): HTTPException {
169
+ return makeHTTPException(rep.url, rep.method, rep.status, errMsg);
170
+ }
171
+
172
+ export function extractIntHeader(rep: Reply<any>, headerName: string): number {
173
+ const intHeader = parseInt(rep.headers!.get(headerName)!);
174
+ if (isNaN(intHeader)) { throw makeException(rep,
175
+ `Malformed response: header ${headerName} is missing or malformed`); }
176
+ return intHeader;
177
+ }
178
+
179
+ Object.freeze(exports);
@@ -0,0 +1,100 @@
1
+ /*
2
+ Copyright (C) 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 { startSession, SpecDescribe, TestSetup, User, StorageComponent, getObjStatus } from '../test-utils';
19
+ import { archiveObj as api } from '../../../../../lib-common/service-api/3nstorage/owner';
20
+ import { beforeEachAsync, itAsync } from '../../../../libs-for-tests/async-jasmine';
21
+ import { RequestOpts, doBodylessRequest } from '../../../../libs-for-tests/xhr-utils';
22
+ import { Obj, saveObj } from '../../../../libs-for-tests/3nstorage';
23
+ import { expectNonAcceptanceOfBadSessionId } from '../../../../shared-checks/requests';
24
+ import { bytesSync as randomBytes } from '../../../../../lib-common/random-node';
25
+ import { resolve as resolveUrl } from 'url';
26
+ import { copy } from '../../../../libs-for-tests/json-copy';
27
+
28
+ export const specs: SpecDescribe = {
29
+ description: `Request to archive object's versions`
30
+ };
31
+
32
+ const obj: Obj = {
33
+ objId: 'aaaa',
34
+ version: 1,
35
+ header: randomBytes(100),
36
+ segs: randomBytes(573)
37
+ };
38
+
39
+ specs.definition = (setup: () => TestSetup) => (() => {
40
+
41
+ let reqOpts: RequestOpts
42
+ let storageServer: StorageComponent;
43
+ let user: User;
44
+ let sessionId: string;
45
+
46
+ beforeEachAsync(async () => {
47
+ storageServer = setup().storageServer;
48
+ user = setup().user;
49
+ await storageServer.restartAndClearStorageFor(user.id);
50
+ sessionId = await startSession(user);
51
+ reqOpts = {
52
+ url: resolveUrl(
53
+ user.storageOwnerUrl,
54
+ api.postAndDelReqUrlEnd(obj.objId, obj.version)),
55
+ method: 'POST',
56
+ sessionId
57
+ };
58
+ });
59
+
60
+ itAsync('will not work outside of a valid session', async () => {
61
+ const opts = copy(reqOpts);
62
+ await expectNonAcceptanceOfBadSessionId(opts);
63
+ });
64
+
65
+ itAsync('fails when object does not exist', async () => {
66
+ const unknownObj = 'unknown-obj';
67
+ const opts = copy(reqOpts);
68
+ opts.url = resolveUrl(
69
+ user.storageOwnerUrl,
70
+ api.postAndDelReqUrlEnd(unknownObj, 42));
71
+ const rep = await doBodylessRequest(opts);
72
+ expect(rep.status).toBe(api.SC.unknownObj);
73
+ });
74
+
75
+ itAsync('fails when object version does not exist', async () => {
76
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
77
+ const opts = copy(reqOpts);
78
+ opts.url = resolveUrl(
79
+ user.storageOwnerUrl,
80
+ api.postAndDelReqUrlEnd(obj.objId, 42));
81
+ opts.responseType = 'json';
82
+ const rep = await doBodylessRequest<api.MismatchedObjVerReply>(opts);
83
+ expect(rep.status).toBe(api.SC.mismatchedObjVer);
84
+ expect(rep.data.current_version).toBe(1);
85
+ });
86
+
87
+ itAsync('sets current version archived', async () => {
88
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
89
+ let archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
90
+ expect(archived).toBeUndefined();
91
+ const rep = await doBodylessRequest(reqOpts);
92
+ expect(rep.status).toBe(api.SC.okPost);
93
+ archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
94
+ expect(archived).toContain(1);
95
+ });
96
+
97
+ });
98
+
99
+
100
+ Object.freeze(exports);
@@ -0,0 +1,91 @@
1
+ /*
2
+ Copyright (C) 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 { startSession, SpecDescribe, TestSetup, User, StorageComponent, getObjStatus } from '../test-utils';
19
+ import { archiveRoot as api } from '../../../../../lib-common/service-api/3nstorage/owner';
20
+ import { beforeEachAsync, itAsync } from '../../../../libs-for-tests/async-jasmine';
21
+ import { RequestOpts, doBodylessRequest } from '../../../../libs-for-tests/xhr-utils';
22
+ import { Obj, saveObj } from '../../../../libs-for-tests/3nstorage';
23
+ import { expectNonAcceptanceOfBadSessionId } from '../../../../shared-checks/requests';
24
+ import { bytesSync as randomBytes } from '../../../../../lib-common/random-node';
25
+ import { resolve as resolveUrl } from 'url';
26
+ import { copy } from '../../../../libs-for-tests/json-copy';
27
+
28
+ export const specs: SpecDescribe = {
29
+ description: `Request to archive root's versions`
30
+ };
31
+
32
+ const obj: Obj = {
33
+ objId: null as any,
34
+ version: 1,
35
+ header: randomBytes(100),
36
+ segs: randomBytes(573)
37
+ };
38
+
39
+ specs.definition = (setup: () => TestSetup) => (() => {
40
+
41
+ let reqOpts: RequestOpts
42
+ let storageServer: StorageComponent;
43
+ let user: User;
44
+ let sessionId: string;
45
+
46
+ beforeEachAsync(async () => {
47
+ storageServer = setup().storageServer;
48
+ user = setup().user;
49
+ await storageServer.restartAndClearStorageFor(user.id);
50
+ sessionId = await startSession(user);
51
+ reqOpts = {
52
+ url: resolveUrl(
53
+ user.storageOwnerUrl,
54
+ api.postAndDelReqUrlEnd(obj.version)),
55
+ method: 'POST',
56
+ responseType: 'json',
57
+ sessionId
58
+ };
59
+ });
60
+
61
+ itAsync('will not work outside of a valid session', async () => {
62
+ const opts = copy(reqOpts);
63
+ await expectNonAcceptanceOfBadSessionId(opts);
64
+ });
65
+
66
+ itAsync('fails when object version does not exist', async () => {
67
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
68
+ const opts = copy(reqOpts);
69
+ opts.url = resolveUrl(
70
+ user.storageOwnerUrl,
71
+ api.postAndDelReqUrlEnd(42));
72
+ opts.responseType = 'json';
73
+ const rep = await doBodylessRequest<api.MismatchedObjVerReply>(opts);
74
+ expect(rep.status).toBe(api.SC.mismatchedObjVer);
75
+ expect(rep.data.current_version).toBe(1);
76
+ });
77
+
78
+ itAsync('sets current version archived', async () => {
79
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
80
+ let archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
81
+ expect(archived).toBeUndefined();
82
+ const rep = await doBodylessRequest(reqOpts);
83
+ expect(rep.status).toBe(api.SC.okPost);
84
+ archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
85
+ expect(archived).toContain(1);
86
+ });
87
+
88
+ });
89
+
90
+
91
+ Object.freeze(exports);
@@ -0,0 +1,99 @@
1
+ /*
2
+ Copyright (C) 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 { startSession, SpecDescribe, TestSetup, User, StorageComponent, archiveObjVer, getObjStatus } from '../test-utils';
19
+ import { archiveObj as api } from '../../../../../lib-common/service-api/3nstorage/owner';
20
+ import { beforeEachAsync, itAsync } from '../../../../libs-for-tests/async-jasmine';
21
+ import { RequestOpts, doBodylessRequest } from '../../../../libs-for-tests/xhr-utils';
22
+ import { Obj, saveObj } from '../../../../libs-for-tests/3nstorage';
23
+ import { expectNonAcceptanceOfBadSessionId } from '../../../../shared-checks/requests';
24
+ import { bytesSync as randomBytes } from '../../../../../lib-common/random-node';
25
+ import { resolve as resolveUrl } from 'url';
26
+ import { copy } from '../../../../libs-for-tests/json-copy';
27
+
28
+ export const specs: SpecDescribe = {
29
+ description: `Request to archive object's versions`
30
+ };
31
+
32
+ const obj: Obj = {
33
+ objId: 'aaaa',
34
+ version: 1,
35
+ header: randomBytes(100),
36
+ segs: randomBytes(573)
37
+ };
38
+
39
+ specs.definition = (setup: () => TestSetup) => (() => {
40
+
41
+ let reqOpts: RequestOpts
42
+ let storageServer: StorageComponent;
43
+ let user: User;
44
+ let sessionId: string;
45
+
46
+ beforeEachAsync(async () => {
47
+ storageServer = setup().storageServer;
48
+ user = setup().user;
49
+ await storageServer.restartAndClearStorageFor(user.id);
50
+ sessionId = await startSession(user);
51
+ reqOpts = {
52
+ url: resolveUrl(
53
+ user.storageOwnerUrl,
54
+ api.postAndDelReqUrlEnd(obj.objId, obj.version)),
55
+ method: 'DELETE',
56
+ sessionId
57
+ };
58
+ });
59
+
60
+ itAsync('will not work outside of a valid session', async () => {
61
+ const opts = copy(reqOpts);
62
+ await expectNonAcceptanceOfBadSessionId(opts);
63
+ });
64
+
65
+ itAsync('fails when object does not exist', async () => {
66
+ const unknownObj = 'unknown-obj';
67
+ const opts = copy(reqOpts);
68
+ opts.url = resolveUrl(
69
+ user.storageOwnerUrl,
70
+ api.postAndDelReqUrlEnd(unknownObj, 42));
71
+ const rep = await doBodylessRequest(opts);
72
+ expect(rep.status).toBe(api.SC.unknownObj);
73
+ });
74
+
75
+ itAsync('fails when object version does not exist', async () => {
76
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
77
+ const opts = copy(reqOpts);
78
+ opts.url = resolveUrl(
79
+ user.storageOwnerUrl,
80
+ api.postAndDelReqUrlEnd(obj.objId, 42));
81
+ const rep = await doBodylessRequest(opts);
82
+ expect(rep.status).toBe(api.SC.unknownObjVer);
83
+ });
84
+
85
+ itAsync('Removes archived version', async () => {
86
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
87
+ await archiveObjVer(user, obj.objId, 1, sessionId);
88
+ let archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
89
+ expect(archived).toContain(1);
90
+ const rep = await doBodylessRequest(reqOpts);
91
+ expect(rep.status).toBe(api.SC.okDelete);
92
+ archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
93
+ expect(archived).toBeUndefined();
94
+ });
95
+
96
+ });
97
+
98
+
99
+ Object.freeze(exports);
@@ -0,0 +1,90 @@
1
+ /*
2
+ Copyright (C) 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 { startSession, SpecDescribe, TestSetup, User, StorageComponent, archiveObjVer, getObjStatus } from '../test-utils';
19
+ import { archiveRoot as api } from '../../../../../lib-common/service-api/3nstorage/owner';
20
+ import { beforeEachAsync, itAsync } from '../../../../libs-for-tests/async-jasmine';
21
+ import { RequestOpts, doBodylessRequest } from '../../../../libs-for-tests/xhr-utils';
22
+ import { Obj, saveObj } from '../../../../libs-for-tests/3nstorage';
23
+ import { expectNonAcceptanceOfBadSessionId } from '../../../../shared-checks/requests';
24
+ import { bytesSync as randomBytes } from '../../../../../lib-common/random-node';
25
+ import { resolve as resolveUrl } from 'url';
26
+ import { copy } from '../../../../libs-for-tests/json-copy';
27
+
28
+ export const specs: SpecDescribe = {
29
+ description: `Request to archive root's versions`
30
+ };
31
+
32
+ const obj: Obj = {
33
+ objId: null as any,
34
+ version: 1,
35
+ header: randomBytes(100),
36
+ segs: randomBytes(573)
37
+ };
38
+
39
+ specs.definition = (setup: () => TestSetup) => (() => {
40
+
41
+ let reqOpts: RequestOpts
42
+ let storageServer: StorageComponent;
43
+ let user: User;
44
+ let sessionId: string;
45
+
46
+ beforeEachAsync(async () => {
47
+ storageServer = setup().storageServer;
48
+ user = setup().user;
49
+ await storageServer.restartAndClearStorageFor(user.id);
50
+ sessionId = await startSession(user);
51
+ reqOpts = {
52
+ url: resolveUrl(
53
+ user.storageOwnerUrl,
54
+ api.postAndDelReqUrlEnd(obj.version)),
55
+ method: 'DELETE',
56
+ responseType: 'json',
57
+ sessionId
58
+ };
59
+ });
60
+
61
+ itAsync('will not work outside of a valid session', async () => {
62
+ const opts = copy(reqOpts);
63
+ await expectNonAcceptanceOfBadSessionId(opts);
64
+ });
65
+
66
+ itAsync('fails when object version does not exist', async () => {
67
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
68
+ const opts = copy(reqOpts);
69
+ opts.url = resolveUrl(
70
+ user.storageOwnerUrl,
71
+ api.postAndDelReqUrlEnd(42));
72
+ const rep = await doBodylessRequest(opts);
73
+ expect(rep.status).toBe(api.SC.unknownObjVer);
74
+ });
75
+
76
+ itAsync('Removes archived version', async () => {
77
+ await saveObj(user.storageOwnerUrl, sessionId, obj.objId, 1, obj);
78
+ await archiveObjVer(user, obj.objId, 1, sessionId);
79
+ let archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
80
+ expect(archived).toContain(1);
81
+ const rep = await doBodylessRequest(reqOpts);
82
+ expect(rep.status).toBe(api.SC.okDelete);
83
+ archived = (await getObjStatus(user, obj.objId, sessionId)).archived;
84
+ expect(archived).toBeUndefined();
85
+ });
86
+
87
+ });
88
+
89
+
90
+ Object.freeze(exports);