@webda/core 2.0.0-beta.2 → 2.0.1

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 (279) hide show
  1. package/lib/application.d.ts +5 -21
  2. package/lib/application.js +71 -84
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +121 -140
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +44 -45
  7. package/lib/core.js +239 -320
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +326 -391
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +49 -45
  12. package/lib/index.js +54 -67
  13. package/lib/index.js.map +1 -1
  14. package/lib/models/aclmodel.d.ts +2 -2
  15. package/lib/models/aclmodel.js +63 -90
  16. package/lib/models/aclmodel.js.map +1 -1
  17. package/lib/models/aclmodel.spec.js +128 -151
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +39 -17
  20. package/lib/models/coremodel.js +160 -117
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +143 -107
  23. package/lib/models/coremodel.spec.js.map +1 -1
  24. package/lib/models/deployment.js +1 -2
  25. package/lib/models/ident.d.ts +3 -3
  26. package/lib/models/ident.js +4 -9
  27. package/lib/models/ident.js.map +1 -1
  28. package/lib/models/ident.spec.js +9 -11
  29. package/lib/models/ident.spec.js.map +1 -1
  30. package/lib/models/ownermodel.d.ts +2 -2
  31. package/lib/models/ownermodel.js +39 -62
  32. package/lib/models/ownermodel.js.map +1 -1
  33. package/lib/models/ownermodel.spec.js +126 -166
  34. package/lib/models/ownermodel.spec.js.map +1 -1
  35. package/lib/models/rolemodel.d.ts +2 -2
  36. package/lib/models/rolemodel.js +24 -40
  37. package/lib/models/rolemodel.js.map +1 -1
  38. package/lib/models/rolemodel.spec.js +44 -61
  39. package/lib/models/rolemodel.spec.js.map +1 -1
  40. package/lib/models/user.d.ts +9 -9
  41. package/lib/models/user.js +3 -8
  42. package/lib/models/user.js.map +1 -1
  43. package/lib/models/user.spec.js +14 -16
  44. package/lib/models/user.spec.js.map +1 -1
  45. package/lib/queues/filequeue.d.ts +2 -2
  46. package/lib/queues/filequeue.js +72 -93
  47. package/lib/queues/filequeue.js.map +1 -1
  48. package/lib/queues/filequeue.spec.js +53 -70
  49. package/lib/queues/filequeue.spec.js.map +1 -1
  50. package/lib/queues/memoryqueue.d.ts +2 -2
  51. package/lib/queues/memoryqueue.js +37 -61
  52. package/lib/queues/memoryqueue.js.map +1 -1
  53. package/lib/queues/memoryqueue.spec.js +142 -165
  54. package/lib/queues/memoryqueue.spec.js.map +1 -1
  55. package/lib/queues/pubsubservice.d.ts +2 -2
  56. package/lib/queues/pubsubservice.js +3 -7
  57. package/lib/queues/pubsubservice.js.map +1 -1
  58. package/lib/queues/queue.spec.d.ts +1 -1
  59. package/lib/queues/queue.spec.js +42 -56
  60. package/lib/queues/queue.spec.js.map +1 -1
  61. package/lib/queues/queueservice.d.ts +4 -4
  62. package/lib/queues/queueservice.js +52 -67
  63. package/lib/queues/queueservice.js.map +1 -1
  64. package/lib/router.d.ts +3 -3
  65. package/lib/router.js +46 -47
  66. package/lib/router.js.map +1 -1
  67. package/lib/router.spec.js +64 -61
  68. package/lib/router.spec.js.map +1 -1
  69. package/lib/services/asyncevents.d.ts +2 -2
  70. package/lib/services/asyncevents.js +44 -64
  71. package/lib/services/asyncevents.js.map +1 -1
  72. package/lib/services/asyncevents.spec.js +81 -98
  73. package/lib/services/asyncevents.spec.js.map +1 -1
  74. package/lib/services/authentication.d.ts +28 -19
  75. package/lib/services/authentication.js +542 -574
  76. package/lib/services/authentication.js.map +1 -1
  77. package/lib/services/authentication.spec.js +411 -447
  78. package/lib/services/authentication.spec.js.map +1 -1
  79. package/lib/services/binary.d.ts +9 -7
  80. package/lib/services/binary.js +213 -245
  81. package/lib/services/binary.js.map +1 -1
  82. package/lib/services/binary.spec.d.ts +3 -3
  83. package/lib/services/binary.spec.js +390 -443
  84. package/lib/services/binary.spec.js.map +1 -1
  85. package/lib/services/cloudbinary.d.ts +3 -3
  86. package/lib/services/cloudbinary.js +45 -70
  87. package/lib/services/cloudbinary.js.map +1 -1
  88. package/lib/services/cloudbinary.spec.d.ts +3 -3
  89. package/lib/services/cloudbinary.spec.js +133 -162
  90. package/lib/services/cloudbinary.spec.js.map +1 -1
  91. package/lib/services/configuration.d.ts +6 -3
  92. package/lib/services/configuration.js +78 -103
  93. package/lib/services/configuration.js.map +1 -1
  94. package/lib/services/configuration.spec.js +63 -83
  95. package/lib/services/configuration.spec.js.map +1 -1
  96. package/lib/services/cron.d.ts +3 -2
  97. package/lib/services/cron.js +9 -13
  98. package/lib/services/cron.js.map +1 -1
  99. package/lib/services/cron.spec.js +18 -21
  100. package/lib/services/cron.spec.js.map +1 -1
  101. package/lib/services/cryptoservice.d.ts +258 -0
  102. package/lib/services/cryptoservice.js +312 -0
  103. package/lib/services/cryptoservice.js.map +1 -0
  104. package/lib/services/cryptoservice.spec.d.ts +1 -0
  105. package/lib/services/cryptoservice.spec.js +137 -0
  106. package/lib/services/cryptoservice.spec.js.map +1 -0
  107. package/lib/services/debugmailer.d.ts +1 -1
  108. package/lib/services/debugmailer.js +13 -34
  109. package/lib/services/debugmailer.js.map +1 -1
  110. package/lib/services/debugmailer.spec.js +16 -29
  111. package/lib/services/debugmailer.spec.js.map +1 -1
  112. package/lib/services/echo.d.ts +2 -2
  113. package/lib/services/echo.js +15 -31
  114. package/lib/services/echo.js.map +1 -1
  115. package/lib/services/echo.spec.js +27 -40
  116. package/lib/services/echo.spec.js.map +1 -1
  117. package/lib/services/filebinary.d.ts +10 -5
  118. package/lib/services/filebinary.js +171 -205
  119. package/lib/services/filebinary.js.map +1 -1
  120. package/lib/services/filebinary.spec.d.ts +2 -1
  121. package/lib/services/filebinary.spec.js +106 -117
  122. package/lib/services/filebinary.spec.js.map +1 -1
  123. package/lib/services/fileconfiguration.d.ts +2 -2
  124. package/lib/services/fileconfiguration.js +25 -43
  125. package/lib/services/fileconfiguration.js.map +1 -1
  126. package/lib/services/fileconfiguration.spec.js +79 -109
  127. package/lib/services/fileconfiguration.spec.js.map +1 -1
  128. package/lib/services/invitationservice.d.ts +10 -10
  129. package/lib/services/invitationservice.js +275 -313
  130. package/lib/services/invitationservice.js.map +1 -1
  131. package/lib/services/invitationservice.spec.js +443 -449
  132. package/lib/services/invitationservice.spec.js.map +1 -1
  133. package/lib/services/kubernetesconfiguration.d.ts +2 -2
  134. package/lib/services/kubernetesconfiguration.js +41 -59
  135. package/lib/services/kubernetesconfiguration.js.map +1 -1
  136. package/lib/services/kubernetesconfiguration.spec.js +80 -98
  137. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  138. package/lib/services/mailer.d.ts +4 -4
  139. package/lib/services/mailer.js +62 -86
  140. package/lib/services/mailer.js.map +1 -1
  141. package/lib/services/mailer.spec.js +86 -127
  142. package/lib/services/mailer.spec.js.map +1 -1
  143. package/lib/services/notificationservice.d.ts +4 -4
  144. package/lib/services/notificationservice.js +23 -42
  145. package/lib/services/notificationservice.js.map +1 -1
  146. package/lib/services/notificationservice.spec.js +47 -73
  147. package/lib/services/notificationservice.spec.js.map +1 -1
  148. package/lib/services/oauth.d.ts +32 -6
  149. package/lib/services/oauth.js +73 -78
  150. package/lib/services/oauth.js.map +1 -1
  151. package/lib/services/oauth.spec.js +128 -148
  152. package/lib/services/oauth.spec.js.map +1 -1
  153. package/lib/services/proxy.d.ts +74 -0
  154. package/lib/services/proxy.js +126 -0
  155. package/lib/services/proxy.js.map +1 -0
  156. package/lib/services/proxy.spec.d.ts +1 -0
  157. package/lib/services/proxy.spec.js +59 -0
  158. package/lib/services/proxy.spec.js.map +1 -0
  159. package/lib/services/resource.d.ts +2 -2
  160. package/lib/services/resource.js +12 -18
  161. package/lib/services/resource.js.map +1 -1
  162. package/lib/services/resource.spec.js +67 -99
  163. package/lib/services/resource.spec.js.map +1 -1
  164. package/lib/services/service.d.ts +29 -6
  165. package/lib/services/service.js +69 -39
  166. package/lib/services/service.js.map +1 -1
  167. package/lib/services/service.spec.js +62 -67
  168. package/lib/services/service.spec.js.map +1 -1
  169. package/lib/services/version.d.ts +1 -1
  170. package/lib/services/version.js +3 -8
  171. package/lib/services/version.js.map +1 -1
  172. package/lib/services/version.spec.js +11 -24
  173. package/lib/services/version.spec.js.map +1 -1
  174. package/lib/stores/aggregator.d.ts +3 -3
  175. package/lib/stores/aggregator.js +37 -57
  176. package/lib/stores/aggregator.js.map +1 -1
  177. package/lib/stores/file.d.ts +3 -3
  178. package/lib/stores/file.js +93 -131
  179. package/lib/stores/file.js.map +1 -1
  180. package/lib/stores/file.spec.d.ts +2 -2
  181. package/lib/stores/file.spec.js +262 -289
  182. package/lib/stores/file.spec.js.map +1 -1
  183. package/lib/stores/mapper.d.ts +4 -4
  184. package/lib/stores/mapper.js +111 -137
  185. package/lib/stores/mapper.js.map +1 -1
  186. package/lib/stores/mapper.spec.js +133 -150
  187. package/lib/stores/mapper.spec.js.map +1 -1
  188. package/lib/stores/memory.d.ts +67 -6
  189. package/lib/stores/memory.js +155 -117
  190. package/lib/stores/memory.js.map +1 -1
  191. package/lib/stores/memory.spec.d.ts +3 -2
  192. package/lib/stores/memory.spec.js +127 -105
  193. package/lib/stores/memory.spec.js.map +1 -1
  194. package/lib/stores/store.d.ts +40 -16
  195. package/lib/stores/store.js +847 -830
  196. package/lib/stores/store.js.map +1 -1
  197. package/lib/stores/store.spec.d.ts +6 -4
  198. package/lib/stores/store.spec.js +628 -647
  199. package/lib/stores/store.spec.js.map +1 -1
  200. package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
  201. package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
  202. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  203. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
  204. package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
  205. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  206. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
  207. package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
  208. package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
  209. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
  210. package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
  211. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  212. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
  213. package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
  214. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
  215. package/lib/stores/webdaql/query.d.ts +4 -5
  216. package/lib/stores/webdaql/query.js +16 -19
  217. package/lib/stores/webdaql/query.js.map +1 -1
  218. package/lib/stores/webdaql/query.spec.js +30 -32
  219. package/lib/stores/webdaql/query.spec.js.map +1 -1
  220. package/lib/test.d.ts +3 -3
  221. package/lib/test.js +74 -94
  222. package/lib/test.js.map +1 -1
  223. package/lib/unpackedapplication.d.ts +1 -1
  224. package/lib/unpackedapplication.js +44 -38
  225. package/lib/unpackedapplication.js.map +1 -1
  226. package/lib/utils/abstractdeployer.js +1 -5
  227. package/lib/utils/abstractdeployer.js.map +1 -1
  228. package/lib/utils/abstractdeployer.spec.js +6 -8
  229. package/lib/utils/abstractdeployer.spec.js.map +1 -1
  230. package/lib/utils/context.d.ts +61 -29
  231. package/lib/utils/context.js +133 -127
  232. package/lib/utils/context.js.map +1 -1
  233. package/lib/utils/context.spec.js +144 -153
  234. package/lib/utils/context.spec.js.map +1 -1
  235. package/lib/utils/cookie.d.ts +66 -45
  236. package/lib/utils/cookie.js +69 -158
  237. package/lib/utils/cookie.js.map +1 -1
  238. package/lib/utils/cookie.spec.js +220 -238
  239. package/lib/utils/cookie.spec.js.map +1 -1
  240. package/lib/utils/esm.d.ts +4 -0
  241. package/lib/utils/esm.js +10 -0
  242. package/lib/utils/esm.js.map +1 -0
  243. package/lib/utils/httpcontext.d.ts +3 -0
  244. package/lib/utils/httpcontext.js +48 -65
  245. package/lib/utils/httpcontext.js.map +1 -1
  246. package/lib/utils/httpcontext.spec.js +37 -56
  247. package/lib/utils/httpcontext.spec.js.map +1 -1
  248. package/lib/utils/logger.d.ts +2 -2
  249. package/lib/utils/logger.js +15 -28
  250. package/lib/utils/logger.js.map +1 -1
  251. package/lib/utils/logger.spec.js +9 -11
  252. package/lib/utils/logger.spec.js.map +1 -1
  253. package/lib/utils/serializers.js +17 -20
  254. package/lib/utils/serializers.js.map +1 -1
  255. package/lib/utils/serializers.spec.js +43 -44
  256. package/lib/utils/serializers.spec.js.map +1 -1
  257. package/lib/utils/session.d.ts +120 -0
  258. package/lib/utils/session.js +155 -0
  259. package/lib/utils/session.js.map +1 -0
  260. package/lib/utils/session.spec.d.ts +1 -0
  261. package/lib/utils/session.spec.js +66 -0
  262. package/lib/utils/session.spec.js.map +1 -0
  263. package/lib/utils/waiter.d.ts +1 -1
  264. package/lib/utils/waiter.js +32 -52
  265. package/lib/utils/waiter.js.map +1 -1
  266. package/lib/utils/waiter.spec.js +75 -92
  267. package/lib/utils/waiter.spec.js.map +1 -1
  268. package/package.json +22 -14
  269. package/test/config-invitation.json +1 -3
  270. package/test/config.json +3 -3
  271. package/test/config.old.json +1 -2
  272. package/test/moddas/annotatedservice.js +5 -5
  273. package/test/moddas/debugmailer.js +2 -3
  274. package/test/moddas/fakeservice.js +2 -3
  275. package/test/moddas/voidstore.js +6 -4
  276. package/test/models/ident.js +2 -6
  277. package/test/models/task.js +3 -7
  278. package/test/package.json +2 -1
  279. package/webda.module.json +895 -189
@@ -1,28 +1,17 @@
1
- "use strict";
2
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
6
  };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const mocha_1 = require("@testdeck/mocha");
19
- const assert = require("assert");
20
- const __1 = require("..");
21
- const test_1 = require("../test");
22
- const authentication_1 = require("./authentication");
7
+ import { suite, test } from "@testdeck/mocha";
8
+ import * as assert from "assert";
9
+ import { Authentication } from "...js";
10
+ import { WebdaTest } from "../test.js";
11
+ import { AuthenticationParameters } from "./authentication.js";
23
12
  const validationUrl = /.*\/auth\/email\/callback\?email=([^&]+)&token=([^& ]+)(&user=([^ &]+))?/;
24
13
  var userId;
25
- let AuthenticationTest = class AuthenticationTest extends test_1.WebdaTest {
14
+ let AuthenticationTest = class AuthenticationTest extends WebdaTest {
26
15
  constructor() {
27
16
  super(...arguments);
28
17
  this.events = 0;
@@ -33,476 +22,451 @@ let AuthenticationTest = class AuthenticationTest extends test_1.WebdaTest {
33
22
  getIdentStore() {
34
23
  return this.getService("Idents");
35
24
  }
36
- before() {
37
- const _super = Object.create(null, {
38
- before: { get: () => super.before }
25
+ async before() {
26
+ await super.before();
27
+ this.userStore = this.getUserStore();
28
+ this.identStore = this.getIdentStore();
29
+ assert.notStrictEqual(this.userStore, undefined);
30
+ assert.notStrictEqual(this.identStore, undefined);
31
+ await this.userStore.__clean();
32
+ await this.identStore.__clean();
33
+ this.authentication = this.getService("Authentication");
34
+ this.mailer = this.getService("DefinedMailer");
35
+ this.authentication.on("Authentication.Login", () => {
36
+ this.events++;
39
37
  });
40
- return __awaiter(this, void 0, void 0, function* () {
41
- yield _super.before.call(this);
42
- this.userStore = this.getUserStore();
43
- this.identStore = this.getIdentStore();
44
- assert.notStrictEqual(this.userStore, undefined);
45
- assert.notStrictEqual(this.identStore, undefined);
46
- yield this.userStore.__clean();
47
- yield this.identStore.__clean();
48
- this.authentication = this.getService("Authentication");
49
- this.mailer = this.getService("DefinedMailer");
50
- this.authentication.on("Authentication.Login", () => {
51
- this.events++;
52
- });
53
- this.authentication.on("Authentication.Register", evt => {
54
- this.events++;
55
- // @ts-ignore
56
- evt.user.test = "TESTOR";
57
- });
58
- this.mailer.sent = [];
38
+ this.authentication.on("Authentication.Register", evt => {
39
+ this.events++;
40
+ // @ts-ignore
41
+ evt.user.test = "TESTOR";
59
42
  });
43
+ this.mailer.sent = [];
60
44
  }
61
- registerTest2(ctx) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
64
- login: "Test2@Webda.io",
65
- password: "testtest",
66
- register: true
67
- }, {
68
- "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
69
- });
70
- ctx.newSession();
71
- ctx.getExecutor().getParameters().email.postValidation = true;
72
- yield executor.execute(ctx);
45
+ async registerTest2(ctx) {
46
+ let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
47
+ login: "Test2@Webda.io",
48
+ password: "testtest",
49
+ register: true
50
+ }, {
51
+ "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
73
52
  });
53
+ ctx.newSession();
54
+ ctx.getExecutor().getParameters().email.postValidation = true;
55
+ await executor.execute(ctx);
74
56
  }
75
- cov() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- this.authentication.addProvider("plop");
78
- this.authentication.addProvider("plop");
79
- this.authentication.addProvider("plop2");
80
- let ctx = yield this.newContext();
81
- this.authentication._listAuthentications(ctx);
82
- assert.strictEqual(ctx.getResponseBody(), JSON.stringify(["email", "plop", "plop2"]));
83
- ctx.setPathParameters({ provider: "plop" });
84
- //assert.strictEqual(this.authentication.getCallbackUrl(ctx), "/plop");
85
- assert.strictEqual(this.authentication.getUrl(), "/auth");
86
- this.authentication.getParameters().password.verifier = "VersionService";
87
- this.authentication.computeParameters();
88
- assert.strictEqual(yield this.authentication.getPasswordRecoveryInfos("bouzouf"), undefined);
89
- assert.strictEqual(this.authentication._passwordVerifier, this.getService("VersionService"));
90
- let params = new authentication_1.AuthenticationParameters({});
91
- assert.strictEqual(params.identStore, "idents");
92
- assert.strictEqual(params.userStore, "users");
93
- assert.strictEqual(params.url, "/auth");
94
- params = new authentication_1.AuthenticationParameters({
95
- identStore: "id",
96
- userStore: "us",
97
- url: "/aaa"
98
- });
99
- assert.strictEqual(params.identStore, "id");
100
- assert.strictEqual(params.userStore, "us");
101
- assert.strictEqual(params.url, "/aaa");
102
- let auth = new __1.Authentication(this.webda, "auth", { email: { mailer: "plop" } });
103
- assert.throws(() => auth.resolve(), /email authentication requires a Mailer service/);
57
+ async cov() {
58
+ this.authentication.addProvider("plop");
59
+ this.authentication.addProvider("plop");
60
+ this.authentication.addProvider("plop2");
61
+ let ctx = await this.newContext();
62
+ this.authentication._listAuthentications(ctx);
63
+ assert.strictEqual(ctx.getResponseBody(), JSON.stringify(["email", "plop", "plop2"]));
64
+ ctx.setPathParameters({ provider: "plop" });
65
+ this.authentication.getParameters().password.verifier = "VersionService";
66
+ this.authentication.computeParameters();
67
+ assert.strictEqual(await this.authentication.getPasswordRecoveryInfos("bouzouf"), undefined);
68
+ assert.strictEqual(this.authentication._passwordVerifier, this.getService("VersionService"));
69
+ let params = new AuthenticationParameters({});
70
+ assert.strictEqual(params.identStore, "idents");
71
+ assert.strictEqual(params.userStore, "users");
72
+ assert.strictEqual(params.url, "/auth");
73
+ params = new AuthenticationParameters({
74
+ identStore: "id",
75
+ userStore: "us",
76
+ url: "/aaa"
104
77
  });
78
+ assert.strictEqual(params.identStore, "id");
79
+ assert.strictEqual(params.userStore, "us");
80
+ assert.strictEqual(params.url, "/aaa");
81
+ this.authentication.getParameters().email = undefined;
82
+ assert.strictEqual(this.authentication.getUrl("./emails", ["POST"]), undefined);
83
+ let auth = new Authentication(this.webda, "auth", { email: { mailer: "plop" } });
84
+ assert.throws(() => auth.resolve(), /email authentication requires a Mailer service/);
105
85
  }
106
- register() {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- // By default service does not have postValidation enable
109
- let ctx = yield this.newContext();
110
- let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
111
- email: "test@Webda.io",
112
- password: "testtest"
113
- }, {
114
- "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
115
- });
116
- this.events = 0;
117
- // Should reject because it is login and not email
118
- yield assert.rejects(() => executor.execute(ctx), res => res == 400);
119
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
120
- login: "test@Webda.io",
121
- password: "testtest"
122
- }, {
123
- "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
124
- });
125
- // User unknown without register parameter
126
- yield assert.rejects(() => executor.execute(ctx), res => res == 404);
127
- // Set register to true
128
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
129
- login: "test@Webda.io",
130
- password: "testtest",
131
- register: true
132
- }, {
133
- "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
134
- });
135
- ctx.newSession();
136
- yield executor.execute(ctx);
137
- // Should not authentified as we need to check email
138
- assert.strictEqual(ctx.getSession().identId, undefined);
139
- // Email is sent
140
- assert.strictEqual(this.mailer.sent.length, 1);
141
- // Ident is created pending validation
142
- let ident = yield this.identStore.get("test@webda.io_email");
143
- assert.strictEqual(ident, undefined);
144
- // Not registered as postValidation is not set
145
- ctx.getExecutor().getParameters().email.postValidation = true;
146
- // With postValidation on the user will be create on first request
147
- yield this.registerTest2(ctx);
148
- assert.strictEqual(this.events, 2); // Register + Login
149
- userId = ctx.getSession().getUserId();
150
- assert.notStrictEqual(ctx.getSession().getUserId(), undefined);
151
- assert.strictEqual(this.mailer.sent.length, 2);
152
- let user = yield this.userStore.get(ctx.getSession().getUserId());
153
- assert.notStrictEqual(user, undefined);
154
- assert.notStrictEqual(user.getPassword(), undefined);
155
- assert.strictEqual(user.locale, "en");
156
- assert.strictEqual(user.test, "TESTOR"); // Verify that the listener on Register has done something
157
- // Now logout
158
- executor = this.getExecutor(ctx, "test.webda.io", "DELETE", "/auth");
159
- yield executor.execute(ctx);
160
- // Now validate first user
161
- ctx.getExecutor().getParameters().email.postValidation = false;
162
- assert.strictEqual(ctx.getSession().getUserId(), undefined);
163
- var match = this.mailer.sent[0].replacements.url.match(validationUrl);
164
- assert.notStrictEqual(match, undefined);
165
- assert.strictEqual(match[1], "test@webda.io");
166
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
167
- token: match[2],
168
- password: "testtest",
169
- login: match[1],
170
- register: true,
171
- add: "plop"
172
- });
173
- yield executor.execute(ctx);
174
- // Should create it with the dat provided
175
- assert.notStrictEqual(ctx.getSession().getUserId(), undefined);
176
- ident = yield this.identStore.get(ctx.getSession().getIdentUsed());
177
- // Email should be already validate
178
- assert.notStrictEqual(ident._validation, undefined);
179
- assert.strictEqual(this.mailer.sent.length, 2);
180
- // Resend email
181
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/validate");
182
- ctx.getSession().login(userId, "fake");
183
- // Should be to soon to resend an email
184
- yield assert.rejects(() => executor.execute(ctx), res => res == 429);
185
- ident = yield this.identStore.get("test2@webda.io_email");
186
- ident._lastValidationEmail = 10;
187
- yield ident.save();
188
- // Should be ok now to send an email
189
- yield executor.execute(ctx);
190
- assert.strictEqual(this.mailer.sent.length, 3);
191
- // Validate email for test2 now
192
- match = this.mailer.sent[1].replacements.url.match(validationUrl);
193
- assert.notStrictEqual(match, undefined);
194
- assert.strictEqual(match[1], "test2@webda.io");
195
- ctx.newSession();
196
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2]);
197
- yield executor.execute(ctx);
198
- assert.strictEqual(ctx.statusCode, 302);
199
- // Verify the skipEmailValidation parameter
200
- this.events = 0;
201
- ctx.newSession();
202
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
203
- login: "test4@webda.io",
204
- password: "testtest",
205
- register: true
206
- });
207
- ctx.getExecutor().getParameters().email.postValidation = true;
208
- ctx.getExecutor().getParameters().email.skipEmailValidation = true;
209
- yield executor.execute(ctx);
210
- // No new email has been sent
211
- assert.strictEqual(this.mailer.sent.length, 3);
212
- assert.strictEqual(this.events, 2); // Register + Login
213
- assert.notStrictEqual(ctx.getSession().getUserId(), undefined);
214
- // Register while logged-in should fail with 410
215
- yield assert.rejects(() => executor.execute(ctx), /410/);
86
+ async register() {
87
+ // By default service does not have postValidation enable
88
+ let ctx = await this.newContext();
89
+ let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
90
+ email: "test@Webda.io",
91
+ password: "testtest"
92
+ }, {
93
+ "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
216
94
  });
217
- }
218
- registerBadPassword() {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- // By default a password of 8 is needed
221
- var params = {
222
- login: "testBad@Webda.io",
223
- password: "test",
224
- register: true
225
- };
226
- let ctx = yield this.newContext(params);
227
- let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {}, {
228
- "Accept-Language": "en-GB"
229
- });
230
- // Activate post validation
231
- ctx.getExecutor().getParameters().email.postValidation = true;
232
- yield assert.rejects(() => executor.execute(ctx), /400/);
233
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
234
- login: "testBad@Webda.io",
235
- register: true
236
- }, {
237
- "Accept-Language": "en-GB"
238
- });
239
- yield assert.rejects(() => executor.execute(ctx), /400/);
95
+ this.events = 0;
96
+ // Should reject because it is login and not email
97
+ await assert.rejects(() => executor.execute(ctx), res => res == 400);
98
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
99
+ login: "test@Webda.io",
100
+ password: "testtest"
101
+ }, {
102
+ "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
240
103
  });
241
- }
242
- me() {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- let ctx = yield this.newContext();
245
- let executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/me");
246
- yield assert.rejects(() => executor.execute(ctx), res => res == 404);
247
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
248
- login: "test5@webda.io",
249
- password: "testtest",
250
- register: true,
251
- plop: "yep"
252
- });
253
- ctx.getExecutor().getParameters().email.postValidation = true;
254
- yield executor.execute(ctx);
255
- // Get me on known user
256
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/me");
257
- yield executor.execute(ctx);
258
- let user = JSON.parse(ctx.getResponseBody());
259
- assert.strictEqual(user.plop, "yep");
260
- assert.strictEqual(user.register, undefined);
261
- assert.strictEqual(user.locale, "es-ES");
262
- assert.notStrictEqual(user, undefined);
104
+ // User unknown without register parameter
105
+ await assert.rejects(() => executor.execute(ctx), res => res == 404);
106
+ // Set register to true
107
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
108
+ login: "test@Webda.io",
109
+ password: "testtest",
110
+ register: true
111
+ }, {
112
+ "Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
113
+ });
114
+ ctx.newSession();
115
+ await executor.execute(ctx);
116
+ // Should not authentified as we need to check email
117
+ assert.strictEqual(ctx.getSession().identUsed, undefined);
118
+ // Email is sent
119
+ assert.strictEqual(this.mailer.sent.length, 1);
120
+ // Ident is created pending validation
121
+ let ident = await this.identStore.get("test@webda.io_email");
122
+ assert.strictEqual(ident, undefined);
123
+ // Not registered as postValidation is not set
124
+ ctx.getExecutor().getParameters().email.postValidation = true;
125
+ // With postValidation on the user will be create on first request
126
+ await this.registerTest2(ctx);
127
+ assert.strictEqual(this.events, 2); // Register + Login
128
+ userId = ctx.getSession().userId;
129
+ assert.notStrictEqual(ctx.getSession().userId, undefined);
130
+ assert.strictEqual(this.mailer.sent.length, 2);
131
+ let user = await this.userStore.get(ctx.getSession().userId);
132
+ assert.notStrictEqual(user, undefined);
133
+ assert.notStrictEqual(user.getPassword(), undefined);
134
+ assert.strictEqual(user.locale, "en");
135
+ assert.strictEqual(user.test, "TESTOR"); // Verify that the listener on Register has done something
136
+ // Now logout
137
+ executor = this.getExecutor(ctx, "test.webda.io", "DELETE", "/auth");
138
+ await executor.execute(ctx);
139
+ // Now validate first user
140
+ ctx.getExecutor().getParameters().email.postValidation = false;
141
+ assert.strictEqual(ctx.getSession().userId, undefined);
142
+ var match = this.mailer.sent[0].replacements.url.match(validationUrl);
143
+ assert.notStrictEqual(match, undefined);
144
+ assert.strictEqual(match[1], "test@webda.io");
145
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
146
+ token: match[2],
147
+ password: "testtest",
148
+ login: match[1],
149
+ register: true,
150
+ add: "plop"
263
151
  });
152
+ await executor.execute(ctx);
153
+ // Should create it with the dat provided
154
+ assert.notStrictEqual(ctx.getSession().userId, undefined);
155
+ ident = await this.identStore.get(ctx.getSession().identUsed);
156
+ // Email should be already validate
157
+ assert.notStrictEqual(ident._validation, undefined);
158
+ assert.strictEqual(this.mailer.sent.length, 2);
159
+ // Resend email
160
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/validate");
161
+ ctx.getSession().login(userId, "fake");
162
+ // Should be to soon to resend an email
163
+ await assert.rejects(() => executor.execute(ctx), res => res == 429);
164
+ ident = await this.identStore.get("test2@webda.io_email");
165
+ ident._lastValidationEmail = 10;
166
+ await ident.save();
167
+ // Should be ok now to send an email
168
+ await executor.execute(ctx);
169
+ assert.strictEqual(this.mailer.sent.length, 3);
170
+ // Validate email for test2 now
171
+ match = this.mailer.sent[1].replacements.url.match(validationUrl);
172
+ assert.notStrictEqual(match, undefined);
173
+ assert.strictEqual(match[1], "test2@webda.io");
174
+ ctx.newSession();
175
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2]);
176
+ await executor.execute(ctx);
177
+ assert.strictEqual(ctx.statusCode, 302);
178
+ // Verify the skipEmailValidation parameter
179
+ this.events = 0;
180
+ ctx.newSession();
181
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
182
+ login: "test4@webda.io",
183
+ password: "testtest",
184
+ register: true
185
+ });
186
+ ctx.getExecutor().getParameters().email.postValidation = true;
187
+ ctx.getExecutor().getParameters().email.skipEmailValidation = true;
188
+ await executor.execute(ctx);
189
+ // No new email has been sent
190
+ assert.strictEqual(this.mailer.sent.length, 3);
191
+ assert.strictEqual(this.events, 2); // Register + Login
192
+ assert.notStrictEqual(ctx.getSession().userId, undefined);
193
+ // Register while logged-in should fail with 410
194
+ await assert.rejects(() => executor.execute(ctx), /410/);
264
195
  }
265
- login() {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- let ctx = yield this.newContext();
268
- yield this.registerTest2(ctx);
269
- ctx.newSession();
270
- this.events = 0;
271
- let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
272
- login: "test3@webda.io",
273
- password: "testtest"
274
- });
275
- yield assert.rejects(() => executor.execute(ctx), res => res == 404);
276
- assert.strictEqual(ctx.getSession().getUserId(), undefined);
277
- // As it has not been validate
278
- ctx.getHttpContext().setBody({
279
- login: "test2@webda.io",
280
- password: "testtest"
281
- });
282
- ctx.reinit();
283
- ctx.newSession();
284
- yield executor.execute(ctx);
285
- assert.strictEqual(this.events, 1); // Login
286
- assert.notStrictEqual(ctx.getSession().getUserId(), undefined);
287
- // Verify ident type
288
- let ident = yield this.identStore.get(ctx.getSession().getIdentUsed());
289
- assert.strictEqual(ident._type, "email");
290
- ctx.getHttpContext().setBody({
291
- login: "test2@webda.io",
292
- password: "bouzouf"
293
- });
294
- ctx.reinit();
295
- ctx.newSession();
296
- yield assert.rejects(() => executor.execute(ctx), res => res == 403);
297
- assert.strictEqual(ctx.getSession().getUserId(), undefined);
298
- assert.strictEqual(this.events, 1);
299
- assert.strictEqual(yield (yield this.identStore.get("test2@webda.io_email"))._failedLogin, 1);
300
- // Re log to reinit failedLogin
301
- ctx.getHttpContext().setBody({
302
- login: "test2@webda.io",
303
- password: "testtest"
304
- });
305
- ctx.reinit();
306
- ctx.newSession();
307
- yield executor.execute(ctx);
308
- assert.strictEqual(yield (yield this.identStore.get("test2@webda.io_email"))._failedLogin, 0);
196
+ async registerBadPassword() {
197
+ // By default a password of 8 is needed
198
+ var params = {
199
+ login: "testBad@Webda.io",
200
+ password: "test",
201
+ register: true
202
+ };
203
+ let ctx = await this.newContext(params);
204
+ let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {}, {
205
+ "Accept-Language": "en-GB"
206
+ });
207
+ // Activate post validation
208
+ ctx.getExecutor().getParameters().email.postValidation = true;
209
+ await assert.rejects(() => executor.execute(ctx), /400/);
210
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
211
+ login: "testBad@Webda.io",
212
+ register: true
213
+ }, {
214
+ "Accept-Language": "en-GB"
309
215
  });
216
+ await assert.rejects(() => executor.execute(ctx), /400/);
310
217
  }
311
- testPasswordRecovery() {
312
- return __awaiter(this, void 0, void 0, function* () {
313
- let tokenInfo;
314
- let ctx = yield this.newContext();
315
- yield this.registerTest2(ctx);
316
- this.mailer.sent = [];
317
- this.events = 0;
318
- userId = ctx.getSession().getUserId();
319
- ctx.newSession();
320
- let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
321
- login: userId,
322
- password: "retesttest"
323
- });
324
- tokenInfo = yield this.authentication.getPasswordRecoveryInfos(userId, -10);
325
- yield assert.rejects(() => executor.execute(ctx), /400/);
326
- // Missing the body
327
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
328
- token: tokenInfo.token,
329
- expire: 123,
330
- password: "retesttest",
331
- login: userId
332
- });
333
- yield assert.rejects(() => executor.execute(ctx), /403/);
334
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
335
- token: tokenInfo.token,
336
- expire: tokenInfo.expire,
337
- password: "retesttest",
338
- login: "unknown"
339
- });
340
- yield assert.rejects(() => executor.execute(ctx), /403/);
341
- // Missing the body
342
- ctx.getHttpContext().setBody({
343
- token: tokenInfo.token,
344
- expire: tokenInfo.expire,
345
- password: "retesttest",
346
- login: userId
347
- });
348
- ctx.reinit();
349
- yield assert.rejects(() => executor.execute(ctx), /410/);
350
- tokenInfo = yield this.authentication.getPasswordRecoveryInfos(userId);
351
- // Missing the body
352
- ctx.getHttpContext().setBody(Object.assign(Object.assign({}, tokenInfo), { login: userId, password: "a" }));
353
- ctx.reinit();
354
- yield assert.rejects(() => executor.execute(ctx), /400/);
355
- // @ts-ignore
356
- this.authentication._passwordVerifier = {
357
- validate: (p) => __awaiter(this, void 0, void 0, function* () {
358
- return p === "retesttest";
359
- })
360
- };
361
- ctx.getHttpContext().setBody(Object.assign(Object.assign({}, tokenInfo), { login: userId, password: "anyotherpass" }));
362
- ctx.reinit();
363
- yield assert.rejects(() => executor.execute(ctx), /400/);
364
- ctx.getHttpContext().setBody(Object.assign(Object.assign({}, tokenInfo), { login: userId, password: "retesttest" }));
365
- ctx.reinit();
366
- yield executor.execute(ctx);
367
- // Should be update with password retest now
368
- ctx.newSession();
369
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
370
- login: "test2@webda.io",
371
- password: "retesttest"
372
- });
373
- yield executor.execute(ctx);
374
- assert.notStrictEqual(ctx.getSession().getUserId(), undefined);
375
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/recover");
376
- yield executor.execute(ctx);
377
- assert.strictEqual(this.mailer.sent.length, 1);
378
- assert.strictEqual(this.mailer.sent[0].to, "test2@webda.io");
379
- assert.notStrictEqual(this.mailer.sent[0].replacements.infos, undefined);
380
- assert.notStrictEqual(this.mailer.sent[0].replacements.infos.expire, undefined);
381
- assert.notStrictEqual(this.mailer.sent[0].replacements.infos.token, undefined);
382
- yield assert.rejects(() => executor.execute(ctx), /429/);
383
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test66@webda.io/recover");
384
- yield assert.rejects(() => executor.execute(ctx), /404/);
218
+ async me() {
219
+ let ctx = await this.newContext();
220
+ let executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/me");
221
+ await assert.rejects(() => executor.execute(ctx), res => res == 404);
222
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
223
+ login: "test5@webda.io",
224
+ password: "testtest",
225
+ register: true,
226
+ plop: "yep"
385
227
  });
228
+ ctx.getExecutor().getParameters().email.postValidation = true;
229
+ await executor.execute(ctx);
230
+ // Get me on known user
231
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/me");
232
+ await executor.execute(ctx);
233
+ let user = JSON.parse(ctx.getResponseBody());
234
+ assert.strictEqual(user.plop, "yep");
235
+ assert.strictEqual(user.register, undefined);
236
+ assert.strictEqual(user.locale, "es-ES");
237
+ assert.notStrictEqual(user, undefined);
386
238
  }
387
- addEmailToAccount() {
388
- return __awaiter(this, void 0, void 0, function* () {
389
- // Log in as test2
390
- let ctx = yield this.newContext();
391
- yield this.registerTest2(ctx);
392
- this.mailer.sent = [];
393
- let executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate", {
394
- login: "test2@webda.io",
395
- password: "retesttest"
396
- });
397
- yield executor.execute(ctx);
398
- let ident = yield this.identStore.get("newtest@webda.io_email");
399
- assert.notStrictEqual(ident, undefined);
400
- assert.strictEqual(ident._validation, undefined);
401
- userId = ctx.getCurrentUserId();
402
- var match = this.mailer.sent[0].replacements.url.match(validationUrl);
403
- assert.notStrictEqual(match, undefined);
404
- assert.strictEqual(match[1], "newtest@webda.io");
405
- // Send another one on newtest2
406
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest2@webda.io/validate", {
407
- login: "test2@webda.io",
408
- password: "retesttest"
409
- });
410
- yield executor.execute(ctx);
411
- var match2 = this.mailer.sent[1].replacements.url.match(validationUrl);
412
- assert.notStrictEqual(match2, undefined);
413
- assert.strictEqual(match2[1], "newtest2@webda.io");
414
- // Try to validate with wrong email
415
- ctx.getSession().userId = "anotheruser";
416
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&user=" + match[4]);
417
- yield assert.rejects(() => executor.execute(ctx), /400/);
418
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
419
- yield executor.execute(ctx);
420
- assert.strictEqual(ctx.statusCode, 302);
421
- assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badUser");
422
- // Right user
423
- ctx.getSession().userId = userId;
424
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=bouzouf" + "&user=" + match[4]);
425
- yield executor.execute(ctx);
426
- assert.strictEqual(ctx.statusCode, 302);
427
- assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badToken");
428
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
429
- yield executor.execute(ctx);
430
- assert.strictEqual(ctx.statusCode, 302);
431
- assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
432
- // Check ident is added to the user
433
- ident = yield this.identStore.get("newtest@webda.io_email");
434
- assert.notStrictEqual(ident._validation, undefined);
435
- // Verify exception if same user try to revalidate
436
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
437
- yield assert.rejects(() => executor.execute(ctx), /412/);
438
- // Verify exception if different user try to validate
439
- ctx.getSession().userId = "bouzouf";
440
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
441
- yield assert.rejects(() => executor.execute(ctx), /409/);
442
- // Check register on validated email does not work
443
- ctx.newSession();
444
- executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
445
- login: "newtest@webda.io",
446
- password: "testtest",
447
- register: true
448
- });
449
- yield assert.rejects(() => executor.execute(ctx), /409/);
450
- // Validation with no user
451
- ctx.newSession();
452
- executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match2[1] + "&token=" + match2[2] + "&user=" + match2[4]);
453
- yield executor.execute(ctx);
454
- assert.strictEqual(ctx.statusCode, 302);
455
- assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
456
- yield this.identStore.delete("newtest2@webda.io_email", undefined, undefined, true);
457
- yield executor.execute(ctx);
458
- assert.ok(yield this.identStore.exists("newtest2@webda.io_email"));
239
+ async login() {
240
+ let ctx = await this.newContext();
241
+ await this.registerTest2(ctx);
242
+ ctx.newSession();
243
+ this.events = 0;
244
+ let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
245
+ login: "test3@webda.io",
246
+ password: "testtest"
247
+ });
248
+ await assert.rejects(() => executor.execute(ctx), res => res == 404);
249
+ assert.strictEqual(ctx.getSession().userId, undefined);
250
+ // As it has not been validate
251
+ ctx.getHttpContext().setBody({
252
+ login: "test2@webda.io",
253
+ password: "testtest"
459
254
  });
255
+ ctx.reinit();
256
+ ctx.newSession();
257
+ await executor.execute(ctx);
258
+ assert.strictEqual(this.events, 1); // Login
259
+ assert.notStrictEqual(ctx.getSession().userId, undefined);
260
+ // Verify ident type
261
+ let ident = await this.identStore.get(ctx.getSession().identUsed);
262
+ assert.strictEqual(ident._type, "email");
263
+ ctx.getHttpContext().setBody({
264
+ login: "test2@webda.io",
265
+ password: "bouzouf"
266
+ });
267
+ ctx.reinit();
268
+ ctx.newSession();
269
+ await assert.rejects(() => executor.execute(ctx), res => res == 403);
270
+ assert.strictEqual(ctx.getSession().userId, undefined);
271
+ assert.strictEqual(this.events, 1);
272
+ assert.strictEqual(await (await this.identStore.get("test2@webda.io_email"))._failedLogin, 1);
273
+ // Re log to reinit failedLogin
274
+ ctx.getHttpContext().setBody({
275
+ login: "test2@webda.io",
276
+ password: "testtest"
277
+ });
278
+ ctx.reinit();
279
+ ctx.newSession();
280
+ await executor.execute(ctx);
281
+ assert.strictEqual(await (await this.identStore.get("test2@webda.io_email"))._failedLogin, 0);
460
282
  }
461
- multipleCreate() {
462
- return __awaiter(this, void 0, void 0, function* () {
463
- yield this.authentication.createUserWithIdent("email", "test@test.com");
464
- yield assert.rejects(() => this.authentication.createUserWithIdent("email", "test@test.com"), /Ident is already known/);
283
+ async testPasswordRecovery() {
284
+ let tokenInfo;
285
+ let ctx = await this.newContext();
286
+ await this.registerTest2(ctx);
287
+ this.mailer.sent = [];
288
+ this.events = 0;
289
+ userId = ctx.getSession().userId;
290
+ ctx.newSession();
291
+ let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
292
+ login: userId,
293
+ password: "retesttest"
294
+ });
295
+ tokenInfo = await this.authentication.getPasswordRecoveryInfos(userId, -10);
296
+ await assert.rejects(() => executor.execute(ctx), /400/);
297
+ // Missing the body
298
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
299
+ token: tokenInfo.token,
300
+ expire: 123,
301
+ password: "retesttest",
302
+ login: userId
303
+ });
304
+ await assert.rejects(() => executor.execute(ctx), /403/);
305
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
306
+ token: tokenInfo.token,
307
+ expire: tokenInfo.expire,
308
+ password: "retesttest",
309
+ login: "unknown"
310
+ });
311
+ await assert.rejects(() => executor.execute(ctx), /403/);
312
+ // Missing the body
313
+ ctx.getHttpContext().setBody({
314
+ token: tokenInfo.token,
315
+ expire: tokenInfo.expire,
316
+ password: "retesttest",
317
+ login: userId
465
318
  });
319
+ ctx.reinit();
320
+ await assert.rejects(() => executor.execute(ctx), /410/);
321
+ tokenInfo = await this.authentication.getPasswordRecoveryInfos(userId);
322
+ // Missing the body
323
+ ctx.getHttpContext().setBody({ ...tokenInfo, login: userId, password: "a" });
324
+ ctx.reinit();
325
+ await assert.rejects(() => executor.execute(ctx), /400/);
326
+ // @ts-ignore
327
+ this.authentication._passwordVerifier = {
328
+ validate: async (p) => {
329
+ return p === "retesttest";
330
+ }
331
+ };
332
+ ctx.getHttpContext().setBody({ ...tokenInfo, login: userId, password: "anyotherpass" });
333
+ ctx.reinit();
334
+ await assert.rejects(() => executor.execute(ctx), /400/);
335
+ ctx.getHttpContext().setBody({ ...tokenInfo, login: userId, password: "retesttest" });
336
+ ctx.reinit();
337
+ await executor.execute(ctx);
338
+ // Should be update with password retest now
339
+ ctx.newSession();
340
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
341
+ login: "test2@webda.io",
342
+ password: "retesttest"
343
+ });
344
+ await executor.execute(ctx);
345
+ assert.notStrictEqual(ctx.getSession().userId, undefined);
346
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/recover");
347
+ await executor.execute(ctx);
348
+ assert.strictEqual(this.mailer.sent.length, 1);
349
+ assert.strictEqual(this.mailer.sent[0].to, "test2@webda.io");
350
+ assert.notStrictEqual(this.mailer.sent[0].replacements.infos, undefined);
351
+ assert.notStrictEqual(this.mailer.sent[0].replacements.infos.expire, undefined);
352
+ assert.notStrictEqual(this.mailer.sent[0].replacements.infos.token, undefined);
353
+ await assert.rejects(() => executor.execute(ctx), /429/);
354
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test66@webda.io/recover");
355
+ await assert.rejects(() => executor.execute(ctx), /404/);
466
356
  }
467
- redirectEmailRegister() {
468
- return __awaiter(this, void 0, void 0, function* () {
469
- let token = this.authentication.generateEmailValidationToken(undefined, "test@webda.io");
470
- let ctx = yield this.newContext();
471
- let executor = this.getExecutor(ctx, "test.webda.io", "GET", `/auth/email/callback?email=test@webda.io&token=${token}`);
472
- yield executor.execute(ctx);
473
- assert.strictEqual(ctx.statusCode, 302);
474
- assert.strictEqual(ctx.getResponseHeaders().Location, `https://webda.io/register.html?token=${token}&email=test@webda.io`);
357
+ async addEmailToAccount() {
358
+ // Log in as test2
359
+ let ctx = await this.newContext();
360
+ await this.registerTest2(ctx);
361
+ this.mailer.sent = [];
362
+ let executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate", {
363
+ login: "test2@webda.io",
364
+ password: "retesttest"
365
+ });
366
+ await executor.execute(ctx);
367
+ let ident = await this.identStore.get("newtest@webda.io_email");
368
+ assert.notStrictEqual(ident, undefined);
369
+ assert.strictEqual(ident._validation, undefined);
370
+ userId = ctx.getCurrentUserId();
371
+ var match = this.mailer.sent[0].replacements.url.match(validationUrl);
372
+ assert.notStrictEqual(match, undefined);
373
+ assert.strictEqual(match[1], "newtest@webda.io");
374
+ // Send another one on newtest2
375
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest2@webda.io/validate", {
376
+ login: "test2@webda.io",
377
+ password: "retesttest"
378
+ });
379
+ await executor.execute(ctx);
380
+ var match2 = this.mailer.sent[1].replacements.url.match(validationUrl);
381
+ assert.notStrictEqual(match2, undefined);
382
+ assert.strictEqual(match2[1], "newtest2@webda.io");
383
+ // Try to validate with wrong email
384
+ ctx.getSession().userId = "anotheruser";
385
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&user=" + match[4]);
386
+ await assert.rejects(() => executor.execute(ctx), /400/);
387
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
388
+ await executor.execute(ctx);
389
+ assert.strictEqual(ctx.statusCode, 302);
390
+ assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badUser");
391
+ // Right user
392
+ ctx.getSession().userId = userId;
393
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=bouzouf" + "&user=" + match[4]);
394
+ await executor.execute(ctx);
395
+ assert.strictEqual(ctx.statusCode, 302);
396
+ assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badToken");
397
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
398
+ await executor.execute(ctx);
399
+ assert.strictEqual(ctx.statusCode, 302);
400
+ assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
401
+ // Check ident is added to the user
402
+ ident = await this.identStore.get("newtest@webda.io_email");
403
+ assert.notStrictEqual(ident._validation, undefined);
404
+ // Verify exception if same user try to revalidate
405
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
406
+ await assert.rejects(() => executor.execute(ctx), /412/);
407
+ // Verify exception if different user try to validate
408
+ ctx.getSession().userId = "bouzouf";
409
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
410
+ await assert.rejects(() => executor.execute(ctx), /409/);
411
+ // Check register on validated email does not work
412
+ ctx.newSession();
413
+ executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
414
+ login: "newtest@webda.io",
415
+ password: "testtest",
416
+ register: true
475
417
  });
418
+ await assert.rejects(() => executor.execute(ctx), /409/);
419
+ // Validation with no user
420
+ ctx.newSession();
421
+ executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match2[1] + "&token=" + match2[2] + "&user=" + match2[4]);
422
+ await executor.execute(ctx);
423
+ assert.strictEqual(ctx.statusCode, 302);
424
+ assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
425
+ await this.identStore.delete("newtest2@webda.io_email", undefined, undefined, true);
426
+ await executor.execute(ctx);
427
+ assert.ok(await this.identStore.exists("newtest2@webda.io_email"));
428
+ }
429
+ async multipleCreate() {
430
+ await this.authentication.createUserWithIdent("email", "test@test.com");
431
+ await assert.rejects(() => this.authentication.createUserWithIdent("email", "test@test.com"), /Ident is already known/);
432
+ }
433
+ async redirectEmailRegister() {
434
+ let token = await this.authentication.generateEmailValidationToken(undefined, "test@webda.io");
435
+ let ctx = await this.newContext();
436
+ let executor = this.getExecutor(ctx, "test.webda.io", "GET", `/auth/email/callback?email=test@webda.io&token=${token}`);
437
+ await executor.execute(ctx);
438
+ assert.strictEqual(ctx.statusCode, 302);
439
+ assert.strictEqual(ctx.getResponseHeaders().Location, `https://webda.io/register.html?token=${token}&email=test@webda.io`);
476
440
  }
477
441
  };
478
442
  __decorate([
479
- mocha_1.test
443
+ test
480
444
  ], AuthenticationTest.prototype, "cov", null);
481
445
  __decorate([
482
- (0, mocha_1.test)("register")
446
+ test("register")
483
447
  ], AuthenticationTest.prototype, "register", null);
484
448
  __decorate([
485
- (0, mocha_1.test)("register - bad password")
449
+ test("register - bad password")
486
450
  ], AuthenticationTest.prototype, "registerBadPassword", null);
487
451
  __decorate([
488
- (0, mocha_1.test)("/me")
452
+ test("/me")
489
453
  ], AuthenticationTest.prototype, "me", null);
490
454
  __decorate([
491
- (0, mocha_1.test)("login")
455
+ test("login")
492
456
  ], AuthenticationTest.prototype, "login", null);
493
457
  __decorate([
494
- (0, mocha_1.test)("passwordRecovery")
458
+ test("passwordRecovery")
495
459
  ], AuthenticationTest.prototype, "testPasswordRecovery", null);
496
460
  __decorate([
497
- (0, mocha_1.test)("add email to existing account")
461
+ test("add email to existing account")
498
462
  ], AuthenticationTest.prototype, "addEmailToAccount", null);
499
463
  __decorate([
500
- mocha_1.test
464
+ test
501
465
  ], AuthenticationTest.prototype, "multipleCreate", null);
502
466
  __decorate([
503
- mocha_1.test
467
+ test
504
468
  ], AuthenticationTest.prototype, "redirectEmailRegister", null);
505
469
  AuthenticationTest = __decorate([
506
- mocha_1.suite
470
+ suite
507
471
  ], AuthenticationTest);
508
472
  //# sourceMappingURL=authentication.spec.js.map