@webda/core 2.0.0-beta.1 → 2.0.0

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 +9 -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 +86 -46
  7. package/lib/core.js +254 -316
  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 +127 -151
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +84 -11
  20. package/lib/models/coremodel.js +104 -103
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +91 -91
  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 +5 -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 +12 -2
  31. package/lib/models/ownermodel.js +54 -62
  32. package/lib/models/ownermodel.js.map +1 -1
  33. package/lib/models/ownermodel.spec.js +129 -152
  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 +5 -5
  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 +7 -3
  65. package/lib/router.js +49 -48
  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 +539 -571
  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 +8 -6
  80. package/lib/services/binary.js +212 -244
  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 +46 -71
  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 +15 -5
  118. package/lib/services/filebinary.js +171 -200
  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 +9 -9
  129. package/lib/services/invitationservice.js +275 -313
  130. package/lib/services/invitationservice.js.map +1 -1
  131. package/lib/services/invitationservice.spec.js +442 -448
  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 -147
  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 +33 -7
  165. package/lib/services/service.js +74 -42
  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 +261 -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 +112 -137
  185. package/lib/stores/mapper.js.map +1 -1
  186. package/lib/stores/mapper.spec.js +131 -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 +35 -15
  195. package/lib/stores/store.js +839 -821
  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 +627 -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 +25 -31
  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 +147 -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 +37 -9
  244. package/lib/utils/httpcontext.js +86 -57
  245. package/lib/utils/httpcontext.js.map +1 -1
  246. package/lib/utils/httpcontext.spec.js +37 -48
  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 +956 -188
package/lib/core.spec.js CHANGED
@@ -1,329 +1,297 @@
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 assert = require("assert");
19
- const mocha_1 = require("@testdeck/mocha");
20
- const path = require("path");
21
- const core_1 = require("./core");
22
- const index_1 = require("./index");
23
- const store_1 = require("./stores/store");
24
- const test_1 = require("./test");
25
- const context_1 = require("./utils/context");
26
- const httpcontext_1 = require("./utils/httpcontext");
27
- const sinon = require("sinon");
7
+ import { suite, test } from "@testdeck/mocha";
8
+ import * as assert from "assert";
9
+ import * as path from "path";
10
+ import * as sinon from "sinon";
11
+ import { Core, OriginFilter, WebdaError, WebsiteOriginFilter } from "./core.js";
12
+ import { Bean, ConsoleLoggerService, Route, Service } from "./index.js";
13
+ import { Store } from "./stores/store.js";
14
+ import { TestApplication, WebdaTest } from "./test.js";
15
+ import { Context } from "./utils/context.js";
16
+ import { getCommonJS } from "./utils/esm.js";
17
+ import { HttpContext } from "./utils/httpcontext.js";
18
+ import { JSONUtils } from "./utils/serializers.js";
19
+ const { __dirname } = getCommonJS(import.meta.url);
28
20
  class BadService {
29
21
  constructor() {
30
22
  throw new Error();
31
23
  }
32
24
  }
33
- let ExceptionExecutor = class ExceptionExecutor extends index_1.Service {
34
- _brokenRoute(ctx) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- if (ctx.parameters.type === "401") {
37
- throw 401;
38
- }
39
- else if (ctx.parameters.type === "Error") {
40
- throw new Error();
41
- }
42
- });
25
+ let ExceptionExecutor = class ExceptionExecutor extends Service {
26
+ async _brokenRoute(ctx) {
27
+ if (ctx.parameters.type === "401") {
28
+ throw 401;
29
+ }
30
+ else if (ctx.parameters.type === "Error") {
31
+ throw new Error();
32
+ }
43
33
  }
44
- onString(ctx) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- ctx.write("CodeCoverage");
47
- });
34
+ async onString(ctx) {
35
+ ctx.write("CodeCoverage");
48
36
  }
49
- onPostString(ctx) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- ctx.write("CodeCoveragePOST");
52
- });
37
+ async onPostString(ctx) {
38
+ ctx.write("CodeCoveragePOST");
53
39
  }
54
40
  };
55
41
  __decorate([
56
- (0, index_1.Route)("/route/broken/{type}")
42
+ Route("/route/broken/{type}")
57
43
  ], ExceptionExecutor.prototype, "_brokenRoute", null);
58
44
  __decorate([
59
- (0, index_1.Route)("/route/string")
45
+ Route("/route/string")
60
46
  ], ExceptionExecutor.prototype, "onString", null);
61
47
  __decorate([
62
- (0, index_1.Route)("/route/string", ["POST"])
48
+ Route("/route/string", ["POST"])
63
49
  ], ExceptionExecutor.prototype, "onPostString", null);
64
50
  ExceptionExecutor = __decorate([
65
- index_1.Bean
51
+ Bean
66
52
  ], ExceptionExecutor);
67
- class ImplicitBean extends index_1.Service {
68
- whynot() {
69
- return __awaiter(this, void 0, void 0, function* () { });
70
- }
71
- }
53
+ /**
54
+ * ImplicitBean are not permitted anymore so just adding the @Bean
55
+ */
56
+ let ImplicitBean = class ImplicitBean extends Service {
57
+ async whynot() { }
58
+ };
72
59
  __decorate([
73
- (0, index_1.Route)("/whynot")
60
+ Route("/whynot")
74
61
  ], ImplicitBean.prototype, "whynot", null);
75
- let CSRFTest = class CSRFTest extends test_1.WebdaTest {
76
- checkRequest(ctx) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- // @ts-ignore
79
- return this.webda.checkCORSRequest(ctx);
80
- });
81
- }
82
- before() {
83
- const _super = Object.create(null, {
84
- before: { get: () => super.before }
85
- });
86
- return __awaiter(this, void 0, void 0, function* () {
87
- yield _super.before.call(this);
88
- this.ctx = yield this.newContext();
89
- });
90
- }
91
- csrfRegExp() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- this.webda.getConfiguration().parameters.website = "http://localhost:18181";
94
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("accounts.google.fr", "GET", "/", "https", 443));
95
- assert.strictEqual(yield this.checkRequest(this.ctx), true);
96
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("accounts.google.com", "GET", "/", "https", 443));
97
- assert.strictEqual(yield this.checkRequest(this.ctx), true);
98
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("accounts.google.fr.loopingz.com", "GET", "/", "https", 443));
99
- assert.strictEqual(yield this.checkRequest(this.ctx), false);
100
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("www.facebook.com", "GET", "/", "https", 443));
101
- assert.strictEqual(yield this.checkRequest(this.ctx), true);
102
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("www.facebook.com.eu", "GET", "/", "https", 443));
103
- assert.strictEqual(yield this.checkRequest(this.ctx), false);
104
- });
105
- }
106
- checkWebdaRequest() {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- let calls = 0;
109
- this.webda.registerRequestFilter({
110
- checkRequest: () => __awaiter(this, void 0, void 0, function* () {
111
- calls++;
112
- return true;
113
- })
114
- });
115
- // @ts-ignore
116
- yield this.webda.checkRequest(this.ctx);
117
- this.ctx.getHttpContext().method = "OPTIONS";
118
- // @ts-ignore
119
- yield this.webda.checkRequest(this.ctx);
120
- assert.strictEqual(calls, 1);
62
+ ImplicitBean = __decorate([
63
+ Bean
64
+ ], ImplicitBean);
65
+ let CSRFTest = class CSRFTest extends WebdaTest {
66
+ async checkRequest(ctx) {
67
+ // @ts-ignore
68
+ return this.webda.checkCORSRequest(ctx);
69
+ }
70
+ async before() {
71
+ await super.before();
72
+ this.ctx = await this.newContext();
73
+ }
74
+ async csrfRegExp() {
75
+ this.webda.getConfiguration().parameters.website = "http://localhost:18181";
76
+ this.ctx.setHttpContext(new HttpContext("accounts.google.fr", "GET", "/", "https", 443));
77
+ assert.strictEqual(await this.checkRequest(this.ctx), true);
78
+ this.ctx.setHttpContext(new HttpContext("accounts.google.com", "GET", "/", "https", 443));
79
+ assert.strictEqual(await this.checkRequest(this.ctx), true);
80
+ this.ctx.setHttpContext(new HttpContext("accounts.google.fr.loopingz.com", "GET", "/", "https", 443));
81
+ assert.strictEqual(await this.checkRequest(this.ctx), false);
82
+ this.ctx.setHttpContext(new HttpContext("www.facebook.com", "GET", "/", "https", 443));
83
+ assert.strictEqual(await this.checkRequest(this.ctx), true);
84
+ this.ctx.setHttpContext(new HttpContext("www.facebook.com.eu", "GET", "/", "https", 443));
85
+ assert.strictEqual(await this.checkRequest(this.ctx), false);
86
+ }
87
+ async checkWebdaRequest() {
88
+ let calls = 0;
89
+ this.webda.registerRequestFilter({
90
+ checkRequest: async () => {
91
+ calls++;
92
+ return true;
93
+ }
121
94
  });
95
+ // @ts-ignore
96
+ await this.webda.checkRequest(this.ctx);
97
+ this.ctx.getHttpContext().method = "OPTIONS";
98
+ // @ts-ignore
99
+ await this.webda.checkRequest(this.ctx);
100
+ assert.strictEqual(calls, 1);
122
101
  }
123
102
  getApiUrl() {
124
103
  assert.strictEqual(this.webda.getApiUrl("/plop"), "http://localhost:18080/plop");
125
104
  assert.strictEqual(this.webda.getApiUrl("plop"), "http://localhost:18080/plop");
126
105
  }
127
- websiteString() {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- this.filter = new core_1.WebsiteOriginFilter("http://localhost:18181");
130
- // Exact match
131
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost:18181", "GET", "/", "http", 80));
132
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), true);
133
- // Bad protocol
134
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost:18181", "GET", "/", "https", 443));
135
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), false);
136
- // Bad port
137
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost:18181", "GET", "/", "http", 18182));
138
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), false);
139
- // Bad host
140
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost2:18181", "GET", "/", "http", 18181));
141
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), false);
142
- });
143
- }
144
- websiteArray() {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- this.filter = new core_1.WebsiteOriginFilter(["http://localhost:18181", "http://localhost2:18181"]);
147
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost", "GET", "/", "http", 18181));
148
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), true);
149
- // Just host headers
150
- this.webda.getConfiguration().parameters.website = ["http://localhost:18181", "http://localhost2:18181"];
151
- // First host
152
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost", "GET", "/", "http", 18181));
153
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), true);
154
- // Second host
155
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost2", "GET", "/", "http", 18181));
156
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), true);
157
- // Bad port
158
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost", "GET", "/", "http", 18182));
159
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), false);
160
- // Bad host
161
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost3", "GET", "/", "http", 18181));
162
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), false);
163
- });
164
- }
165
- originFilter() {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- let filter = new core_1.OriginFilter(["https://localhost3"]);
168
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost3", "GET", "/", "https", 443));
169
- assert.strictEqual(yield filter.checkRequest(this.ctx), true);
170
- });
171
- }
172
- websiteObject() {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- // Use object
175
- this.filter = new core_1.WebsiteOriginFilter({
176
- url: "localhost:18181"
177
- });
178
- // Good host
179
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost", "GET", "/", "http", 18181));
180
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), true);
181
- // Bad host
182
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost2", "GET", "/", "http", 18181));
183
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), false);
184
- // Bad port
185
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("localhost", "GET", "/", "http", 18182));
186
- assert.strictEqual(yield this.filter.checkRequest(this.ctx), false);
187
- });
188
- }
189
- csrfConditionalFilter() {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- /*
192
- , "http://localhost:18182", {
193
- url: "localhost:18181"
194
- }
195
- */
196
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("csrf.com", "GET", "/bouzouf/route", "https", 443));
197
- assert.strictEqual(yield this.checkRequest(this.ctx), true);
198
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("csrf.com", "GET", "/bouzouf2/route", "https", 443));
199
- assert.strictEqual(yield this.checkRequest(this.ctx), false);
200
- this.ctx.setHttpContext(new httpcontext_1.HttpContext("csrfs.com", "GET", "/bouzouf/route", "https", 443));
201
- assert.strictEqual(yield this.checkRequest(this.ctx), false);
106
+ async websiteString() {
107
+ this.filter = new WebsiteOriginFilter("http://localhost:18181");
108
+ // Exact match
109
+ this.ctx.setHttpContext(new HttpContext("localhost:18181", "GET", "/", "http", 80));
110
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), true);
111
+ // Bad protocol
112
+ this.ctx.setHttpContext(new HttpContext("localhost:18181", "GET", "/", "https", 443));
113
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), false);
114
+ // Bad port
115
+ this.ctx.setHttpContext(new HttpContext("localhost:18181", "GET", "/", "http", 18182));
116
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), false);
117
+ // Bad host
118
+ this.ctx.setHttpContext(new HttpContext("localhost2:18181", "GET", "/", "http", 18181));
119
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), false);
120
+ }
121
+ async websiteArray() {
122
+ this.filter = new WebsiteOriginFilter(["http://localhost:18181", "http://localhost2:18181"]);
123
+ this.ctx.setHttpContext(new HttpContext("localhost", "GET", "/", "http", 18181));
124
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), true);
125
+ // Just host headers
126
+ this.webda.getConfiguration().parameters.website = ["http://localhost:18181", "http://localhost2:18181"];
127
+ // First host
128
+ this.ctx.setHttpContext(new HttpContext("localhost", "GET", "/", "http", 18181));
129
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), true);
130
+ // Second host
131
+ this.ctx.setHttpContext(new HttpContext("localhost2", "GET", "/", "http", 18181));
132
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), true);
133
+ // Bad port
134
+ this.ctx.setHttpContext(new HttpContext("localhost", "GET", "/", "http", 18182));
135
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), false);
136
+ // Bad host
137
+ this.ctx.setHttpContext(new HttpContext("localhost3", "GET", "/", "http", 18181));
138
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), false);
139
+ }
140
+ async originFilter() {
141
+ let filter = new OriginFilter(["https://localhost3"]);
142
+ this.ctx.setHttpContext(new HttpContext("localhost3", "GET", "/", "https", 443));
143
+ assert.strictEqual(await filter.checkRequest(this.ctx), true);
144
+ }
145
+ async websiteObject() {
146
+ // Use object
147
+ this.filter = new WebsiteOriginFilter({
148
+ url: "localhost:18181"
202
149
  });
150
+ // Good host
151
+ this.ctx.setHttpContext(new HttpContext("localhost", "GET", "/", "http", 18181));
152
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), true);
153
+ // Bad host
154
+ this.ctx.setHttpContext(new HttpContext("localhost2", "GET", "/", "http", 18181));
155
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), false);
156
+ // Bad port
157
+ this.ctx.setHttpContext(new HttpContext("localhost", "GET", "/", "http", 18182));
158
+ assert.strictEqual(await this.filter.checkRequest(this.ctx), false);
159
+ }
160
+ async csrfConditionalFilter() {
161
+ /*
162
+ , "http://localhost:18182", {
163
+ url: "localhost:18181"
164
+ }
165
+ */
166
+ this.ctx.setHttpContext(new HttpContext("csrf.com", "GET", "/bouzouf/route", "https", 443));
167
+ assert.strictEqual(await this.checkRequest(this.ctx), true);
168
+ this.ctx.setHttpContext(new HttpContext("csrf.com", "GET", "/bouzouf2/route", "https", 443));
169
+ assert.strictEqual(await this.checkRequest(this.ctx), false);
170
+ this.ctx.setHttpContext(new HttpContext("csrfs.com", "GET", "/bouzouf/route", "https", 443));
171
+ assert.strictEqual(await this.checkRequest(this.ctx), false);
203
172
  }
204
173
  };
205
174
  __decorate([
206
- mocha_1.test
175
+ test
207
176
  ], CSRFTest.prototype, "csrfRegExp", null);
208
177
  __decorate([
209
- mocha_1.test
178
+ test
210
179
  ], CSRFTest.prototype, "checkWebdaRequest", null);
211
180
  __decorate([
212
- mocha_1.test
181
+ test
213
182
  ], CSRFTest.prototype, "getApiUrl", null);
214
183
  __decorate([
215
- mocha_1.test
184
+ test
216
185
  ], CSRFTest.prototype, "websiteString", null);
217
186
  __decorate([
218
- mocha_1.test
187
+ test
219
188
  ], CSRFTest.prototype, "websiteArray", null);
220
189
  __decorate([
221
- mocha_1.test
190
+ test
222
191
  ], CSRFTest.prototype, "originFilter", null);
223
192
  __decorate([
224
- mocha_1.test
193
+ test
225
194
  ], CSRFTest.prototype, "websiteObject", null);
226
195
  __decorate([
227
- mocha_1.test
196
+ test
228
197
  ], CSRFTest.prototype, "csrfConditionalFilter", null);
229
198
  CSRFTest = __decorate([
230
- mocha_1.suite
199
+ suite
231
200
  ], CSRFTest);
232
- let CoreTest = class CoreTest extends test_1.WebdaTest {
233
- before() {
234
- const _super = Object.create(null, {
235
- before: { get: () => super.before }
236
- });
237
- return __awaiter(this, void 0, void 0, function* () {
238
- yield _super.before.call(this);
239
- this.ctx = yield this.newContext({});
201
+ let CoreTest = class CoreTest extends WebdaTest {
202
+ async before() {
203
+ await super.before();
204
+ this.ctx = await this.newContext({});
205
+ }
206
+ async exportOpenAPI() {
207
+ let app = new TestApplication(path.join(__dirname, "..", "..", "..", "sample-app"));
208
+ await app.load();
209
+ let webda = new Core(app);
210
+ // @ts-ignore
211
+ webda.services["ConsoleLogger"] = new ConsoleLoggerService(webda, "ConsoleLogger", {});
212
+ await webda.init();
213
+ let openapi = webda.exportOpenAPI();
214
+ assert.notStrictEqual(openapi.paths["/contacts"], undefined);
215
+ assert.notStrictEqual(openapi.paths["/contacts/{uuid}"], undefined);
216
+ app.addModel("webda/anotherContext", Context);
217
+ app.getConfiguration().openapi = {
218
+ tags: [{ name: "Zzzz" }, { name: "Aaaaa" }]
219
+ };
220
+ app.getPackageDescription = () => ({
221
+ license: "GPL",
222
+ author: {
223
+ name: "Test"
224
+ }
240
225
  });
241
- }
242
- exportOpenAPI() {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- let app = new test_1.TestApplication(path.join(__dirname, "..", "..", "..", "sample-app"));
245
- yield app.load();
246
- let webda = new core_1.Core(app);
247
- // @ts-ignore
248
- webda.services["ConsoleLogger"] = new index_1.ConsoleLoggerService(webda, "ConsoleLogger", {});
249
- yield webda.init();
250
- webda.reinitResolvedRoutes();
251
- let openapi = webda.exportOpenAPI();
252
- assert.notStrictEqual(openapi.paths["/contacts"], undefined);
253
- assert.notStrictEqual(openapi.paths["/contacts/{uuid}"], undefined);
254
- app.addModel("webda/anotherContext", context_1.Context);
255
- app.getConfiguration().openapi = {
256
- tags: [{ name: "Zzzz" }, { name: "Aaaaa" }]
226
+ app.getSchema = type => {
227
+ let res = {
228
+ definitions: {},
229
+ properties: {},
230
+ title: type
257
231
  };
258
- app.getPackageDescription = () => ({
259
- license: "GPL",
260
- author: {
261
- name: "Test"
262
- }
263
- });
264
- app.getSchema = type => {
265
- let res = {
266
- definitions: {},
267
- properties: {},
268
- title: type
269
- };
270
- res.definitions[`other$${type}`] = {
271
- description: `Fake ${type}`
272
- };
273
- return res;
232
+ res.definitions[`other$${type}`] = {
233
+ description: `Fake ${type}`
274
234
  };
275
- openapi = webda.exportOpenAPI();
276
- assert.strictEqual(openapi.info.contact.name, "Test");
277
- assert.strictEqual(openapi.info.license.name, "GPL");
278
- assert.deepStrictEqual(openapi.tags, [{ name: "Aaaaa" }, { name: "contacts" }, { name: "Zzzz" }]);
279
- // @ts-ignore
280
- assert.ok(Object.keys(openapi.definitions).length > 10);
281
- app.getPackageDescription = () => ({
282
- license: {
283
- name: "GPL"
284
- },
285
- author: "Test"
286
- });
287
- openapi = webda.exportOpenAPI();
288
- assert.strictEqual(openapi.info.contact.name, "Test");
235
+ return res;
236
+ };
237
+ openapi = webda.exportOpenAPI();
238
+ assert.strictEqual(openapi.info.contact.name, "Test");
239
+ assert.strictEqual(openapi.info.license.name, "GPL");
240
+ assert.deepStrictEqual(openapi.tags, [
241
+ { name: "Aaaaa" },
242
+ { name: "contacts" },
243
+ { name: "ExceptionExecutor" },
244
+ { name: "ImplicitBean" },
245
+ { name: "Zzzz" }
246
+ ]);
247
+ assert.ok(Object.keys(openapi.components.schemas).length > 10);
248
+ app.getPackageDescription = () => ({
249
+ license: {
250
+ name: "GPL"
251
+ },
252
+ author: "Test"
289
253
  });
254
+ openapi = webda.exportOpenAPI();
255
+ assert.strictEqual(openapi.info.contact.name, "Test");
290
256
  }
291
- getStringRoute() {
292
- return __awaiter(this, void 0, void 0, function* () {
293
- let ctx = yield this.newContext();
294
- let exec = this.getExecutor(ctx, "test.webda.io", "GET", "/route/string");
295
- exec.execute(ctx);
296
- assert.strictEqual(ctx.getResponseBody(), "CodeCoverage");
297
- });
257
+ async getStringRoute() {
258
+ let ctx = await this.newContext();
259
+ let exec = this.getExecutor(ctx, "test.webda.io", "GET", "/route/string");
260
+ exec.execute(ctx);
261
+ assert.strictEqual(ctx.getResponseBody(), "CodeCoverage");
298
262
  }
299
- getStringPostRoute() {
300
- return __awaiter(this, void 0, void 0, function* () {
301
- let ctx = yield this.newContext();
302
- let exec = this.getExecutor(ctx, "test.webda.io", "POST", "/route/string");
303
- exec.execute(ctx);
304
- assert.strictEqual(ctx.getResponseBody(), "CodeCoveragePOST");
305
- });
263
+ async getStringPostRoute() {
264
+ let ctx = await this.newContext();
265
+ let exec = this.getExecutor(ctx, "test.webda.io", "POST", "/route/string");
266
+ exec.execute(ctx);
267
+ assert.strictEqual(ctx.getResponseBody(), "CodeCoveragePOST");
306
268
  }
307
269
  getServiceSample() {
308
270
  assert.notStrictEqual(null, this.webda.getService("Authentication"));
309
271
  }
272
+ async registry() {
273
+ await this.webda.getRegistry().put("test", { anyData: "plop" });
274
+ assert.strictEqual((await this.webda.getRegistry().get("test")).anyData, "plop");
275
+ }
310
276
  getServicesImplementations() {
311
277
  let moddas = this.webda.getServicesOfType();
312
- assert.strictEqual(Object.keys(moddas).length, 26);
278
+ assert.strictEqual(Object.keys(moddas).length, 29);
313
279
  }
314
280
  getStores() {
315
281
  let moddas = this.webda.getStores();
316
282
  assert.strictEqual(Object.keys(moddas).length, 7);
317
283
  }
318
284
  getServicesImplementationsWithType() {
319
- let stores = this.webda.getServicesOfType(store_1.Store);
285
+ let stores = this.webda.getServicesOfType(Store);
320
286
  assert.strictEqual(Object.keys(stores).length, 7);
321
287
  }
322
288
  getVersion() {
323
- assert.strictEqual(this.webda.getVersion(), require("../package.json").version);
289
+ assert.strictEqual(this.webda.getVersion(), JSONUtils.loadFile("package.json").version);
324
290
  }
325
291
  knownPage() {
326
292
  let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/");
293
+ // @ts-ignore
294
+ console.log(Object.keys(this.webda.getRouter().routes));
327
295
  assert.notStrictEqual(executor, undefined);
328
296
  assert.strictEqual(this.ctx.getParameters()["TEST_ADD"], undefined);
329
297
  let service = this.ctx.getExecutor();
@@ -389,95 +357,85 @@ let CoreTest = class CoreTest extends test_1.WebdaTest {
389
357
  this.webda.isDebug(); // Just for CodeCoverage
390
358
  assert.strictEqual(JSON.parse(this.webda.toPublicJSON(obj))._title, undefined);
391
359
  }
392
- updateConfiguration() {
393
- return __awaiter(this, void 0, void 0, function* () {
394
- let service = this.webda.getService("Authentication");
395
- assert.strictEqual(service.getParameters().password.regexp, ".{8,}");
396
- assert.strictEqual(service.getParameters().email.mailer, "DefinedMailer");
397
- yield this.webda.reinit({
398
- "Authentication.password.regexp": ".{12,}"
399
- });
400
- let newService = this.webda.getService("Authentication");
401
- assert.strictEqual(newService.getParameters().password.regexp, ".{12,}");
402
- assert.strictEqual(newService.getParameters().email.mailer, "DefinedMailer");
403
- yield assert.rejects(() => this.webda.reinit({
404
- "Bouzouf.plop": "Testor"
405
- }), Error);
406
- yield assert.rejects(() => this.webda.reinit({
407
- "$.Bouzouf": {
408
- Testor: "plop"
409
- }
410
- }), /Configuration is not designed to add dynamically services/);
360
+ async updateConfiguration() {
361
+ let service = this.webda.getService("Authentication");
362
+ assert.strictEqual(service.getParameters().password.regexp, ".{8,}");
363
+ assert.strictEqual(service.getParameters().email.mailer, "DefinedMailer");
364
+ await this.webda.reinit({
365
+ "Authentication.password.regexp": ".{12,}"
411
366
  });
367
+ let newService = this.webda.getService("Authentication");
368
+ assert.strictEqual(newService.getParameters().password.regexp, ".{12,}");
369
+ assert.strictEqual(newService.getParameters().email.mailer, "DefinedMailer");
370
+ await assert.rejects(() => this.webda.reinit({
371
+ "Bouzouf.plop": "Testor"
372
+ }), Error);
373
+ await assert.rejects(() => this.webda.reinit({
374
+ "$.Bouzouf": {
375
+ Testor: "plop"
376
+ }
377
+ }), /Configuration is not designed to add dynamically services/);
412
378
  }
413
379
  assertInitError(service, msg) {
414
380
  let serviceBean = this.webda.getService(service);
415
381
  assert.notStrictEqual(serviceBean._initException, undefined, `${service} should have failed init with ${msg}`);
416
382
  assert.strictEqual(serviceBean._initException.message.indexOf(msg) >= 0, true);
417
383
  }
418
- errorChecks() {
419
- return __awaiter(this, void 0, void 0, function* () {
420
- assert.throws(this.webda.getModel.bind(this.webda), "test");
421
- assert.throws(this.webda.getModel.bind(this.webda, "Ghost"), Error);
422
- assert.strictEqual(this.webda.getService("Ghost"), undefined);
423
- assert.strictEqual(this.webda.getService(), undefined);
424
- // @ts-ignore
425
- this.webda._currentExecutor = {
426
- session: "test"
427
- };
428
- let local = this.webda.getConfiguration().parameters.locales;
429
- this.webda.getConfiguration().parameters.locales = undefined;
430
- assert.strictEqual(this.webda.getLocales().indexOf("en-GB"), 0);
431
- this.webda.getConfiguration().parameters.locales = local;
432
- assert.strictEqual(this.webda.getService("plop"), undefined);
433
- assert.strictEqual(JSON.stringify(this.webda.getModels()), "{}");
434
- process.env.WEBDA_CONFIG = __dirname + "/../test/config.broken.json";
435
- // assertInitError("ConfigurationService", "Need a source for");
436
- // assertInitError("ConfigurationServiceBadSource", "Need a valid service");
437
- // assertInitError("ConfigurationServiceBadSourceNoId", "Need a valid source");
438
- // assertInitError("ConfigurationServiceBadSourceWithId", "is not implementing ConfigurationProvider interface");
439
- let err = new core_1.WebdaError("CODE", "");
440
- assert.strictEqual(err.getCode(), "CODE");
441
- });
442
- }
443
- autoConnectFailure() {
444
- return __awaiter(this, void 0, void 0, function* () {
445
- let app = new test_1.TestApplication(__dirname + "/../test/config.broken.json");
446
- yield app.load();
447
- let core = new core_1.Core(app);
448
- yield core.init();
449
- core.getServices()["implicitbean"].resolve = () => {
450
- throw new Error();
451
- };
452
- // @ts-ignore
453
- core.autoConnectServices();
454
- core.getServices()["implicitbean"].resolve = undefined;
455
- // @ts-ignore
456
- core.autoConnectServices();
457
- });
384
+ async errorChecks() {
385
+ assert.throws(this.webda.getModel.bind(this.webda), "test");
386
+ assert.throws(this.webda.getModel.bind(this.webda, "Ghost"), Error);
387
+ assert.strictEqual(this.webda.getService("Ghost"), undefined);
388
+ assert.strictEqual(this.webda.getService(), undefined);
389
+ // @ts-ignore
390
+ this.webda._currentExecutor = {
391
+ session: "test"
392
+ };
393
+ let local = this.webda.getConfiguration().parameters.locales;
394
+ this.webda.getConfiguration().parameters.locales = undefined;
395
+ assert.strictEqual(this.webda.getLocales().indexOf("en-GB"), 0);
396
+ this.webda.getConfiguration().parameters.locales = local;
397
+ assert.strictEqual(this.webda.getService("plop"), undefined);
398
+ assert.strictEqual(JSON.stringify(this.webda.getModels()), "{}");
399
+ process.env.WEBDA_CONFIG = __dirname + "/../test/config.broken.json";
400
+ // assertInitError("ConfigurationService", "Need a source for");
401
+ // assertInitError("ConfigurationServiceBadSource", "Need a valid service");
402
+ // assertInitError("ConfigurationServiceBadSourceNoId", "Need a valid source");
403
+ // assertInitError("ConfigurationServiceBadSourceWithId", "is not implementing ConfigurationProvider interface");
404
+ let err = new WebdaError("CODE", "");
405
+ assert.strictEqual(err.getCode(), "CODE");
406
+ }
407
+ async autoConnectFailure() {
408
+ let app = new TestApplication(__dirname + "/../test/config.broken.json");
409
+ await app.load();
410
+ let core = new Core(app);
411
+ await core.init();
412
+ core.getServices()["implicitbean"].resolve = () => {
413
+ throw new Error();
414
+ };
415
+ // @ts-ignore
416
+ core.autoConnectServices();
417
+ core.getServices()["implicitbean"].resolve = undefined;
418
+ // @ts-ignore
419
+ core.autoConnectServices();
458
420
  }
459
- cov() {
421
+ async cov() {
460
422
  //assert.deepStrictEqual(this.webda.getDeployers(), {});
461
423
  this.webda.getUuid();
462
424
  this.webda.getInstanceId();
463
- this.webda.getHmac(this.webda.getInstanceId());
464
425
  // a8b7f4a4-62aa-4b2a-b6a8-0ffdc0d82c96
465
426
  assert.ok(/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.exec(this.webda.getUuid()) !== null);
466
427
  assert.ok(/[0-9a-f]{32}/.exec(this.webda.getUuid("hex")) !== null);
467
428
  assert.ok(/[0-9a-zA-Z\-_]{22}/.exec(this.webda.getUuid("base64")) !== null);
468
- assert.strictEqual(this.webda.getSalt(), this.webda.getConfiguration().parameters.salt);
469
- }
470
- listenersTest() {
471
- return __awaiter(this, void 0, void 0, function* () {
472
- let stub = sinon.stub();
473
- let stub2 = sinon.stub().callsFake(() => __awaiter(this, void 0, void 0, function* () { }));
474
- this.webda.on("Test", stub);
475
- this.webda.on("Test", stub2);
476
- // @ts-ignore
477
- yield this.webda.emitSync("Test");
478
- assert.strictEqual(stub.callCount, 1);
479
- assert.strictEqual(stub2.callCount, 1);
480
- });
429
+ }
430
+ async listenersTest() {
431
+ let stub = sinon.stub();
432
+ let stub2 = sinon.stub().callsFake(async () => { });
433
+ this.webda.on("Test", stub);
434
+ this.webda.on("Test", stub2);
435
+ // @ts-ignore
436
+ await this.webda.emitSync("Test");
437
+ assert.strictEqual(stub.callCount, 1);
438
+ assert.strictEqual(stub2.callCount, 1);
481
439
  }
482
440
  createServices() {
483
441
  this.webda.getApplication();
@@ -495,129 +453,106 @@ let CoreTest = class CoreTest extends test_1.WebdaTest {
495
453
  };
496
454
  method();
497
455
  }
498
- badInit() {
499
- return __awaiter(this, void 0, void 0, function* () {
500
- let service = this.webda.getService("definedmailer");
501
- service.init = () => __awaiter(this, void 0, void 0, function* () {
502
- throw new Error("Not happy");
503
- });
504
- service.reinit = () => __awaiter(this, void 0, void 0, function* () {
505
- throw new Error("Not happy");
506
- });
507
- // @ts-ignore
508
- yield this.webda.initService("definedmailer");
509
- assert.notStrictEqual(service._initException, undefined);
510
- // @ts-ignore
511
- yield this.webda.reinitService("definedmailer");
512
- });
513
- }
514
- sandbox() {
515
- const code = `let protected = false;
516
- let json = require('jsonpath');
517
- try {
518
- require('net');
519
- } catch (err) {
520
- protected = err.message === "not allowed"
521
- }
522
- module.exports = function() { return protected }`;
523
- assert.strictEqual(this.webda.sandbox(code, {
524
- require: function (mod) {
525
- // We need to add more control here
526
- if (mod === "net") {
527
- throw Error("not allowed");
528
- }
529
- // if the module is okay to load, load it:
530
- return require.apply(this, arguments);
531
- }
532
- }), true);
533
- assert.throws(() => this.webda.sandbox(code), /not allowed/);
456
+ async badInit() {
457
+ let service = this.webda.getService("definedmailer");
458
+ service.init = async () => {
459
+ throw new Error("Not happy");
460
+ };
461
+ service.reinit = async () => {
462
+ throw new Error("Not happy");
463
+ };
464
+ // @ts-ignore
465
+ await this.webda.initService("definedmailer");
466
+ assert.notStrictEqual(service._initException, undefined);
467
+ // @ts-ignore
468
+ await this.webda.reinitService("definedmailer");
534
469
  }
535
470
  };
536
471
  __decorate([
537
- mocha_1.test
472
+ test
538
473
  ], CoreTest.prototype, "exportOpenAPI", null);
539
474
  __decorate([
540
- mocha_1.test
475
+ test
541
476
  ], CoreTest.prototype, "getStringRoute", null);
542
477
  __decorate([
543
- mocha_1.test
478
+ test
544
479
  ], CoreTest.prototype, "getStringPostRoute", null);
545
480
  __decorate([
546
- mocha_1.test
481
+ test
547
482
  ], CoreTest.prototype, "getServiceSample", null);
548
483
  __decorate([
549
- mocha_1.test
484
+ test
485
+ ], CoreTest.prototype, "registry", null);
486
+ __decorate([
487
+ test
550
488
  ], CoreTest.prototype, "getServicesImplementations", null);
551
489
  __decorate([
552
- mocha_1.test
490
+ test
553
491
  ], CoreTest.prototype, "getStores", null);
554
492
  __decorate([
555
- mocha_1.test
493
+ test
556
494
  ], CoreTest.prototype, "getServicesImplementationsWithType", null);
557
495
  __decorate([
558
- mocha_1.test
496
+ test
559
497
  ], CoreTest.prototype, "getVersion", null);
560
498
  __decorate([
561
- mocha_1.test
499
+ test
562
500
  ], CoreTest.prototype, "knownPage", null);
563
501
  __decorate([
564
- mocha_1.test
502
+ test
565
503
  ], CoreTest.prototype, "knownPageMultipleMethod", null);
566
504
  __decorate([
567
- mocha_1.test
505
+ test
568
506
  ], CoreTest.prototype, "knownPageUnknownMethod", null);
569
507
  __decorate([
570
- mocha_1.test
508
+ test
571
509
  ], CoreTest.prototype, "unknownPage", null);
572
510
  __decorate([
573
- mocha_1.test
511
+ test
574
512
  ], CoreTest.prototype, "knownTemplatePage", null);
575
513
  __decorate([
576
- mocha_1.test
514
+ test
577
515
  ], CoreTest.prototype, "slashInQueryString", null);
578
516
  __decorate([
579
- mocha_1.test
517
+ test
580
518
  ], CoreTest.prototype, "slashInPath", null);
581
519
  __decorate([
582
- mocha_1.test
520
+ test
583
521
  ], CoreTest.prototype, "me", null);
584
522
  __decorate([
585
- mocha_1.test
523
+ test
586
524
  ], CoreTest.prototype, "covValidateSchema", null);
587
525
  __decorate([
588
- mocha_1.test
526
+ test
589
527
  ], CoreTest.prototype, "covGetModules", null);
590
528
  __decorate([
591
- mocha_1.test
529
+ test
592
530
  ], CoreTest.prototype, "covRemoveRoute", null);
593
531
  __decorate([
594
- mocha_1.test
532
+ test
595
533
  ], CoreTest.prototype, "toPublicJson", null);
596
534
  __decorate([
597
- mocha_1.test
535
+ test
598
536
  ], CoreTest.prototype, "updateConfiguration", null);
599
537
  __decorate([
600
- mocha_1.test
538
+ test
601
539
  ], CoreTest.prototype, "errorChecks", null);
602
540
  __decorate([
603
- mocha_1.test
541
+ test
604
542
  ], CoreTest.prototype, "autoConnectFailure", null);
605
543
  __decorate([
606
- mocha_1.test
544
+ test
607
545
  ], CoreTest.prototype, "cov", null);
608
546
  __decorate([
609
- mocha_1.test
547
+ test
610
548
  ], CoreTest.prototype, "listenersTest", null);
611
549
  __decorate([
612
- mocha_1.test
550
+ test
613
551
  ], CoreTest.prototype, "createServices", null);
614
552
  __decorate([
615
- mocha_1.test
553
+ test
616
554
  ], CoreTest.prototype, "badInit", null);
617
- __decorate([
618
- mocha_1.test
619
- ], CoreTest.prototype, "sandbox", null);
620
555
  CoreTest = __decorate([
621
- mocha_1.suite
556
+ suite
622
557
  ], CoreTest);
623
558
  //# sourceMappingURL=core.spec.js.map