@webda/core 2.0.0-beta.3 → 2.1.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 (276) hide show
  1. package/lib/application.d.ts +5 -5
  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 +21 -25
  7. package/lib/core.js +233 -320
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +334 -406
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +49 -48
  12. package/lib/index.js +53 -70
  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 -152
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +33 -14
  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 -168
  34. package/lib/models/ownermodel.spec.js.map +1 -1
  35. package/lib/models/rolemodel.d.ts +1 -1
  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 -63
  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 +3 -3
  62. package/lib/queues/queueservice.js +51 -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 +23 -13
  75. package/lib/services/authentication.js +540 -566
  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 -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 +1 -1
  92. package/lib/services/configuration.js +78 -105
  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 +9 -4
  102. package/lib/services/cryptoservice.js +187 -221
  103. package/lib/services/cryptoservice.js.map +1 -1
  104. package/lib/services/cryptoservice.spec.js +88 -115
  105. package/lib/services/cryptoservice.spec.js.map +1 -1
  106. package/lib/services/debugmailer.d.ts +1 -1
  107. package/lib/services/debugmailer.js +13 -34
  108. package/lib/services/debugmailer.js.map +1 -1
  109. package/lib/services/debugmailer.spec.js +16 -29
  110. package/lib/services/debugmailer.spec.js.map +1 -1
  111. package/lib/services/echo.d.ts +2 -2
  112. package/lib/services/echo.js +15 -31
  113. package/lib/services/echo.js.map +1 -1
  114. package/lib/services/echo.spec.js +27 -40
  115. package/lib/services/echo.spec.js.map +1 -1
  116. package/lib/services/filebinary.d.ts +5 -5
  117. package/lib/services/filebinary.js +165 -210
  118. package/lib/services/filebinary.js.map +1 -1
  119. package/lib/services/filebinary.spec.d.ts +2 -1
  120. package/lib/services/filebinary.spec.js +106 -116
  121. package/lib/services/filebinary.spec.js.map +1 -1
  122. package/lib/services/fileconfiguration.d.ts +1 -1
  123. package/lib/services/fileconfiguration.js +25 -44
  124. package/lib/services/fileconfiguration.js.map +1 -1
  125. package/lib/services/fileconfiguration.spec.js +79 -109
  126. package/lib/services/fileconfiguration.spec.js.map +1 -1
  127. package/lib/services/invitationservice.d.ts +8 -8
  128. package/lib/services/invitationservice.js +274 -314
  129. package/lib/services/invitationservice.js.map +1 -1
  130. package/lib/services/invitationservice.spec.js +443 -449
  131. package/lib/services/invitationservice.spec.js.map +1 -1
  132. package/lib/services/kubernetesconfiguration.d.ts +1 -1
  133. package/lib/services/kubernetesconfiguration.js +41 -60
  134. package/lib/services/kubernetesconfiguration.js.map +1 -1
  135. package/lib/services/kubernetesconfiguration.spec.js +80 -98
  136. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  137. package/lib/services/mailer.d.ts +4 -4
  138. package/lib/services/mailer.js +62 -86
  139. package/lib/services/mailer.js.map +1 -1
  140. package/lib/services/mailer.spec.js +86 -127
  141. package/lib/services/mailer.spec.js.map +1 -1
  142. package/lib/services/notificationservice.d.ts +3 -3
  143. package/lib/services/notificationservice.js +21 -42
  144. package/lib/services/notificationservice.js.map +1 -1
  145. package/lib/services/notificationservice.spec.js +47 -73
  146. package/lib/services/notificationservice.spec.js.map +1 -1
  147. package/lib/services/oauth.d.ts +4 -4
  148. package/lib/services/oauth.js +68 -83
  149. package/lib/services/oauth.js.map +1 -1
  150. package/lib/services/oauth.spec.js +130 -156
  151. package/lib/services/oauth.spec.js.map +1 -1
  152. package/lib/services/proxy.d.ts +2 -6
  153. package/lib/services/proxy.js +45 -58
  154. package/lib/services/proxy.js.map +1 -1
  155. package/lib/services/proxy.spec.js +34 -53
  156. package/lib/services/proxy.spec.js.map +1 -1
  157. package/lib/services/resource.d.ts +2 -2
  158. package/lib/services/resource.js +12 -18
  159. package/lib/services/resource.js.map +1 -1
  160. package/lib/services/resource.spec.js +67 -99
  161. package/lib/services/resource.spec.js.map +1 -1
  162. package/lib/services/service.d.ts +26 -3
  163. package/lib/services/service.js +68 -40
  164. package/lib/services/service.js.map +1 -1
  165. package/lib/services/service.spec.js +62 -67
  166. package/lib/services/service.spec.js.map +1 -1
  167. package/lib/services/version.d.ts +1 -1
  168. package/lib/services/version.js +3 -8
  169. package/lib/services/version.js.map +1 -1
  170. package/lib/services/version.spec.js +11 -24
  171. package/lib/services/version.spec.js.map +1 -1
  172. package/lib/stores/aggregator.d.ts +2 -2
  173. package/lib/stores/aggregator.js +37 -58
  174. package/lib/stores/aggregator.js.map +1 -1
  175. package/lib/stores/file.d.ts +3 -3
  176. package/lib/stores/file.js +93 -131
  177. package/lib/stores/file.js.map +1 -1
  178. package/lib/stores/file.spec.d.ts +2 -2
  179. package/lib/stores/file.spec.js +262 -289
  180. package/lib/stores/file.spec.js.map +1 -1
  181. package/lib/stores/mapper.d.ts +3 -3
  182. package/lib/stores/mapper.js +110 -137
  183. package/lib/stores/mapper.js.map +1 -1
  184. package/lib/stores/mapper.spec.js +133 -150
  185. package/lib/stores/mapper.spec.js.map +1 -1
  186. package/lib/stores/memory.d.ts +3 -3
  187. package/lib/stores/memory.js +98 -144
  188. package/lib/stores/memory.js.map +1 -1
  189. package/lib/stores/memory.spec.d.ts +2 -2
  190. package/lib/stores/memory.spec.js +124 -145
  191. package/lib/stores/memory.spec.js.map +1 -1
  192. package/lib/stores/store.d.ts +27 -17
  193. package/lib/stores/store.js +833 -849
  194. package/lib/stores/store.js.map +1 -1
  195. package/lib/stores/store.spec.d.ts +5 -4
  196. package/lib/stores/store.spec.js +625 -669
  197. package/lib/stores/store.spec.js.map +1 -1
  198. package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
  199. package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
  200. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  201. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
  202. package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
  203. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  204. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
  205. package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
  206. package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
  207. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
  208. package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
  209. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  210. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
  211. package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
  212. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
  213. package/lib/stores/webdaql/query.d.ts +4 -5
  214. package/lib/stores/webdaql/query.js +16 -19
  215. package/lib/stores/webdaql/query.js.map +1 -1
  216. package/lib/stores/webdaql/query.spec.js +30 -32
  217. package/lib/stores/webdaql/query.spec.js.map +1 -1
  218. package/lib/test.d.ts +3 -3
  219. package/lib/test.js +73 -100
  220. package/lib/test.js.map +1 -1
  221. package/lib/unpackedapplication.d.ts +1 -1
  222. package/lib/unpackedapplication.js +49 -39
  223. package/lib/unpackedapplication.js.map +1 -1
  224. package/lib/utils/abstractdeployer.js +1 -5
  225. package/lib/utils/abstractdeployer.js.map +1 -1
  226. package/lib/utils/abstractdeployer.spec.js +6 -8
  227. package/lib/utils/abstractdeployer.spec.js.map +1 -1
  228. package/lib/utils/context.d.ts +7 -5
  229. package/lib/utils/context.js +95 -103
  230. package/lib/utils/context.js.map +1 -1
  231. package/lib/utils/context.spec.js +139 -163
  232. package/lib/utils/context.spec.js.map +1 -1
  233. package/lib/utils/cookie.d.ts +3 -3
  234. package/lib/utils/cookie.js +42 -61
  235. package/lib/utils/cookie.js.map +1 -1
  236. package/lib/utils/cookie.spec.js +42 -64
  237. package/lib/utils/cookie.spec.js.map +1 -1
  238. package/lib/utils/esm.d.ts +4 -0
  239. package/lib/utils/esm.js +10 -0
  240. package/lib/utils/esm.js.map +1 -0
  241. package/lib/utils/httpcontext.d.ts +3 -0
  242. package/lib/utils/httpcontext.js +48 -65
  243. package/lib/utils/httpcontext.js.map +1 -1
  244. package/lib/utils/httpcontext.spec.js +37 -56
  245. package/lib/utils/httpcontext.spec.js.map +1 -1
  246. package/lib/utils/logger.d.ts +2 -2
  247. package/lib/utils/logger.js +15 -28
  248. package/lib/utils/logger.js.map +1 -1
  249. package/lib/utils/logger.spec.js +9 -11
  250. package/lib/utils/logger.spec.js.map +1 -1
  251. package/lib/utils/serializers.js +17 -20
  252. package/lib/utils/serializers.js.map +1 -1
  253. package/lib/utils/serializers.spec.js +43 -44
  254. package/lib/utils/serializers.spec.js.map +1 -1
  255. package/lib/utils/session.d.ts +6 -6
  256. package/lib/utils/session.js +37 -59
  257. package/lib/utils/session.js.map +1 -1
  258. package/lib/utils/session.spec.js +38 -51
  259. package/lib/utils/session.spec.js.map +1 -1
  260. package/lib/utils/waiter.d.ts +1 -1
  261. package/lib/utils/waiter.js +32 -52
  262. package/lib/utils/waiter.js.map +1 -1
  263. package/lib/utils/waiter.spec.js +75 -92
  264. package/lib/utils/waiter.spec.js.map +1 -1
  265. package/package.json +18 -13
  266. package/test/config-invitation.json +1 -3
  267. package/test/config.json +1 -2
  268. package/test/config.old.json +1 -2
  269. package/test/moddas/annotatedservice.js +5 -5
  270. package/test/moddas/debugmailer.js +2 -3
  271. package/test/moddas/fakeservice.js +2 -3
  272. package/test/moddas/voidstore.js +6 -4
  273. package/test/models/ident.js +2 -6
  274. package/test/models/task.js +3 -7
  275. package/test/package.json +2 -1
  276. package/webda.module.json +895 -190
package/lib/core.spec.js CHANGED
@@ -1,317 +1,277 @@
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
  }
310
- registry() {
311
- return __awaiter(this, void 0, void 0, function* () {
312
- yield this.webda.getRegistry().put("test", { anyData: "plop" });
313
- assert.strictEqual((yield this.webda.getRegistry().get("test")).anyData, "plop");
314
- });
272
+ async registry() {
273
+ await this.webda.getRegistry().put("test", { anyData: "plop" });
274
+ assert.strictEqual((await this.webda.getRegistry().get("test")).anyData, "plop");
315
275
  }
316
276
  getServicesImplementations() {
317
277
  let moddas = this.webda.getServicesOfType();
@@ -319,17 +279,19 @@ let CoreTest = class CoreTest extends test_1.WebdaTest {
319
279
  }
320
280
  getStores() {
321
281
  let moddas = this.webda.getStores();
322
- assert.strictEqual(Object.keys(moddas).length, 8);
282
+ assert.strictEqual(Object.keys(moddas).length, 7);
323
283
  }
324
284
  getServicesImplementationsWithType() {
325
- let stores = this.webda.getServicesOfType(store_1.Store);
326
- assert.strictEqual(Object.keys(stores).length, 8);
285
+ let stores = this.webda.getServicesOfType(Store);
286
+ assert.strictEqual(Object.keys(stores).length, 7);
327
287
  }
328
288
  getVersion() {
329
- assert.strictEqual(this.webda.getVersion(), require("../package.json").version);
289
+ assert.strictEqual(this.webda.getVersion(), JSONUtils.loadFile("package.json").version);
330
290
  }
331
291
  knownPage() {
332
292
  let executor = this.getExecutor(this.ctx, "test.webda.io", "GET", "/");
293
+ // @ts-ignore
294
+ console.log(Object.keys(this.webda.getRouter().routes));
333
295
  assert.notStrictEqual(executor, undefined);
334
296
  assert.strictEqual(this.ctx.getParameters()["TEST_ADD"], undefined);
335
297
  let service = this.ctx.getExecutor();
@@ -378,6 +340,8 @@ let CoreTest = class CoreTest extends test_1.WebdaTest {
378
340
  }
379
341
  covValidateSchema() {
380
342
  assert.strictEqual(this.webda.validateSchema("test", {}), null);
343
+ assert.strictEqual(this.webda.validateSchema("test", {}, true), null);
344
+ assert.strictEqual(this.webda.validateSchema("webda/fileconfiguration", {}, true), true);
381
345
  }
382
346
  covGetModules() {
383
347
  this.webda.getModules();
@@ -395,95 +359,85 @@ let CoreTest = class CoreTest extends test_1.WebdaTest {
395
359
  this.webda.isDebug(); // Just for CodeCoverage
396
360
  assert.strictEqual(JSON.parse(this.webda.toPublicJSON(obj))._title, undefined);
397
361
  }
398
- updateConfiguration() {
399
- return __awaiter(this, void 0, void 0, function* () {
400
- let service = this.webda.getService("Authentication");
401
- assert.strictEqual(service.getParameters().password.regexp, ".{8,}");
402
- assert.strictEqual(service.getParameters().email.mailer, "DefinedMailer");
403
- yield this.webda.reinit({
404
- "Authentication.password.regexp": ".{12,}"
405
- });
406
- let newService = this.webda.getService("Authentication");
407
- assert.strictEqual(newService.getParameters().password.regexp, ".{12,}");
408
- assert.strictEqual(newService.getParameters().email.mailer, "DefinedMailer");
409
- yield assert.rejects(() => this.webda.reinit({
410
- "Bouzouf.plop": "Testor"
411
- }), Error);
412
- yield assert.rejects(() => this.webda.reinit({
413
- "$.Bouzouf": {
414
- Testor: "plop"
415
- }
416
- }), /Configuration is not designed to add dynamically services/);
362
+ async updateConfiguration() {
363
+ let service = this.webda.getService("Authentication");
364
+ assert.strictEqual(service.getParameters().password.regexp, ".{8,}");
365
+ assert.strictEqual(service.getParameters().email.mailer, "DefinedMailer");
366
+ await this.webda.reinit({
367
+ "Authentication.password.regexp": ".{12,}"
417
368
  });
369
+ let newService = this.webda.getService("Authentication");
370
+ assert.strictEqual(newService.getParameters().password.regexp, ".{12,}");
371
+ assert.strictEqual(newService.getParameters().email.mailer, "DefinedMailer");
372
+ await assert.rejects(() => this.webda.reinit({
373
+ "Bouzouf.plop": "Testor"
374
+ }), Error);
375
+ await assert.rejects(() => this.webda.reinit({
376
+ "$.Bouzouf": {
377
+ Testor: "plop"
378
+ }
379
+ }), /Configuration is not designed to add dynamically services/);
418
380
  }
419
381
  assertInitError(service, msg) {
420
382
  let serviceBean = this.webda.getService(service);
421
383
  assert.notStrictEqual(serviceBean._initException, undefined, `${service} should have failed init with ${msg}`);
422
384
  assert.strictEqual(serviceBean._initException.message.indexOf(msg) >= 0, true);
423
385
  }
424
- errorChecks() {
425
- return __awaiter(this, void 0, void 0, function* () {
426
- assert.throws(this.webda.getModel.bind(this.webda), "test");
427
- assert.throws(this.webda.getModel.bind(this.webda, "Ghost"), Error);
428
- assert.strictEqual(this.webda.getService("Ghost"), undefined);
429
- assert.strictEqual(this.webda.getService(), undefined);
430
- // @ts-ignore
431
- this.webda._currentExecutor = {
432
- session: "test"
433
- };
434
- let local = this.webda.getConfiguration().parameters.locales;
435
- this.webda.getConfiguration().parameters.locales = undefined;
436
- assert.strictEqual(this.webda.getLocales().indexOf("en-GB"), 0);
437
- this.webda.getConfiguration().parameters.locales = local;
438
- assert.strictEqual(this.webda.getService("plop"), undefined);
439
- assert.strictEqual(JSON.stringify(this.webda.getModels()), "{}");
440
- process.env.WEBDA_CONFIG = __dirname + "/../test/config.broken.json";
441
- // assertInitError("ConfigurationService", "Need a source for");
442
- // assertInitError("ConfigurationServiceBadSource", "Need a valid service");
443
- // assertInitError("ConfigurationServiceBadSourceNoId", "Need a valid source");
444
- // assertInitError("ConfigurationServiceBadSourceWithId", "is not implementing ConfigurationProvider interface");
445
- let err = new core_1.WebdaError("CODE", "");
446
- assert.strictEqual(err.getCode(), "CODE");
447
- });
448
- }
449
- autoConnectFailure() {
450
- return __awaiter(this, void 0, void 0, function* () {
451
- let app = new test_1.TestApplication(__dirname + "/../test/config.broken.json");
452
- yield app.load();
453
- let core = new core_1.Core(app);
454
- yield core.init();
455
- core.getServices()["implicitbean"].resolve = () => {
456
- throw new Error();
457
- };
458
- // @ts-ignore
459
- core.autoConnectServices();
460
- core.getServices()["implicitbean"].resolve = undefined;
461
- // @ts-ignore
462
- core.autoConnectServices();
463
- });
464
- }
465
- cov() {
466
- return __awaiter(this, void 0, void 0, function* () {
467
- //assert.deepStrictEqual(this.webda.getDeployers(), {});
468
- this.webda.getUuid();
469
- this.webda.getInstanceId();
470
- // a8b7f4a4-62aa-4b2a-b6a8-0ffdc0d82c96
471
- assert.ok(/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.exec(this.webda.getUuid()) !== null);
472
- assert.ok(/[0-9a-f]{32}/.exec(this.webda.getUuid("hex")) !== null);
473
- assert.ok(/[0-9a-zA-Z\-_]{22}/.exec(this.webda.getUuid("base64")) !== null);
474
- });
475
- }
476
- listenersTest() {
477
- return __awaiter(this, void 0, void 0, function* () {
478
- let stub = sinon.stub();
479
- let stub2 = sinon.stub().callsFake(() => __awaiter(this, void 0, void 0, function* () { }));
480
- this.webda.on("Test", stub);
481
- this.webda.on("Test", stub2);
482
- // @ts-ignore
483
- yield this.webda.emitSync("Test");
484
- assert.strictEqual(stub.callCount, 1);
485
- assert.strictEqual(stub2.callCount, 1);
486
- });
386
+ async errorChecks() {
387
+ assert.throws(this.webda.getModel.bind(this.webda), "test");
388
+ assert.throws(this.webda.getModel.bind(this.webda, "Ghost"), Error);
389
+ assert.strictEqual(this.webda.getService("Ghost"), undefined);
390
+ assert.strictEqual(this.webda.getService(), undefined);
391
+ // @ts-ignore
392
+ this.webda._currentExecutor = {
393
+ session: "test"
394
+ };
395
+ let local = this.webda.getConfiguration().parameters.locales;
396
+ this.webda.getConfiguration().parameters.locales = undefined;
397
+ assert.strictEqual(this.webda.getLocales().indexOf("en-GB"), 0);
398
+ this.webda.getConfiguration().parameters.locales = local;
399
+ assert.strictEqual(this.webda.getService("plop"), undefined);
400
+ assert.strictEqual(JSON.stringify(this.webda.getModels()), "{}");
401
+ process.env.WEBDA_CONFIG = __dirname + "/../test/config.broken.json";
402
+ // assertInitError("ConfigurationService", "Need a source for");
403
+ // assertInitError("ConfigurationServiceBadSource", "Need a valid service");
404
+ // assertInitError("ConfigurationServiceBadSourceNoId", "Need a valid source");
405
+ // assertInitError("ConfigurationServiceBadSourceWithId", "is not implementing ConfigurationProvider interface");
406
+ let err = new WebdaError("CODE", "");
407
+ assert.strictEqual(err.getCode(), "CODE");
408
+ }
409
+ async autoConnectFailure() {
410
+ let app = new TestApplication(__dirname + "/../test/config.broken.json");
411
+ await app.load();
412
+ let core = new Core(app);
413
+ await core.init();
414
+ core.getServices()["implicitbean"].resolve = () => {
415
+ throw new Error();
416
+ };
417
+ // @ts-ignore
418
+ core.autoConnectServices();
419
+ core.getServices()["implicitbean"].resolve = undefined;
420
+ // @ts-ignore
421
+ core.autoConnectServices();
422
+ }
423
+ async cov() {
424
+ //assert.deepStrictEqual(this.webda.getDeployers(), {});
425
+ this.webda.getUuid();
426
+ this.webda.getInstanceId();
427
+ // a8b7f4a4-62aa-4b2a-b6a8-0ffdc0d82c96
428
+ assert.ok(/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.exec(this.webda.getUuid()) !== null);
429
+ assert.ok(/[0-9a-f]{32}/.exec(this.webda.getUuid("hex")) !== null);
430
+ assert.ok(/[0-9a-zA-Z\-_]{22}/.exec(this.webda.getUuid("base64")) !== null);
431
+ }
432
+ async listenersTest() {
433
+ let stub = sinon.stub();
434
+ let stub2 = sinon.stub().callsFake(async () => { });
435
+ this.webda.on("Test", stub);
436
+ this.webda.on("Test", stub2);
437
+ // @ts-ignore
438
+ await this.webda.emitSync("Test");
439
+ assert.strictEqual(stub.callCount, 1);
440
+ assert.strictEqual(stub2.callCount, 1);
487
441
  }
488
442
  createServices() {
489
443
  this.webda.getApplication();
@@ -501,132 +455,106 @@ let CoreTest = class CoreTest extends test_1.WebdaTest {
501
455
  };
502
456
  method();
503
457
  }
504
- badInit() {
505
- return __awaiter(this, void 0, void 0, function* () {
506
- let service = this.webda.getService("definedmailer");
507
- service.init = () => __awaiter(this, void 0, void 0, function* () {
508
- throw new Error("Not happy");
509
- });
510
- service.reinit = () => __awaiter(this, void 0, void 0, function* () {
511
- throw new Error("Not happy");
512
- });
513
- // @ts-ignore
514
- yield this.webda.initService("definedmailer");
515
- assert.notStrictEqual(service._initException, undefined);
516
- // @ts-ignore
517
- yield this.webda.reinitService("definedmailer");
518
- });
519
- }
520
- sandbox() {
521
- const code = `let protected = false;
522
- let json = require('jsonpath');
523
- try {
524
- require('net');
525
- } catch (err) {
526
- protected = err.message === "not allowed"
527
- }
528
- module.exports = function() { return protected }`;
529
- assert.strictEqual(this.webda.sandbox(code, {
530
- require: function (mod) {
531
- // We need to add more control here
532
- if (mod === "net") {
533
- throw Error("not allowed");
534
- }
535
- // if the module is okay to load, load it:
536
- return require.apply(this, arguments);
537
- }
538
- }), true);
539
- assert.throws(() => this.webda.sandbox(code), /not allowed/);
458
+ async badInit() {
459
+ let service = this.webda.getService("definedmailer");
460
+ service.init = async () => {
461
+ throw new Error("Not happy");
462
+ };
463
+ service.reinit = async () => {
464
+ throw new Error("Not happy");
465
+ };
466
+ // @ts-ignore
467
+ await this.webda.initService("definedmailer");
468
+ assert.notStrictEqual(service._initException, undefined);
469
+ // @ts-ignore
470
+ await this.webda.reinitService("definedmailer");
540
471
  }
541
472
  };
542
473
  __decorate([
543
- mocha_1.test
474
+ test
544
475
  ], CoreTest.prototype, "exportOpenAPI", null);
545
476
  __decorate([
546
- mocha_1.test
477
+ test
547
478
  ], CoreTest.prototype, "getStringRoute", null);
548
479
  __decorate([
549
- mocha_1.test
480
+ test
550
481
  ], CoreTest.prototype, "getStringPostRoute", null);
551
482
  __decorate([
552
- mocha_1.test
483
+ test
553
484
  ], CoreTest.prototype, "getServiceSample", null);
554
485
  __decorate([
555
- mocha_1.test
486
+ test
556
487
  ], CoreTest.prototype, "registry", null);
557
488
  __decorate([
558
- mocha_1.test
489
+ test
559
490
  ], CoreTest.prototype, "getServicesImplementations", null);
560
491
  __decorate([
561
- mocha_1.test
492
+ test
562
493
  ], CoreTest.prototype, "getStores", null);
563
494
  __decorate([
564
- mocha_1.test
495
+ test
565
496
  ], CoreTest.prototype, "getServicesImplementationsWithType", null);
566
497
  __decorate([
567
- mocha_1.test
498
+ test
568
499
  ], CoreTest.prototype, "getVersion", null);
569
500
  __decorate([
570
- mocha_1.test
501
+ test
571
502
  ], CoreTest.prototype, "knownPage", null);
572
503
  __decorate([
573
- mocha_1.test
504
+ test
574
505
  ], CoreTest.prototype, "knownPageMultipleMethod", null);
575
506
  __decorate([
576
- mocha_1.test
507
+ test
577
508
  ], CoreTest.prototype, "knownPageUnknownMethod", null);
578
509
  __decorate([
579
- mocha_1.test
510
+ test
580
511
  ], CoreTest.prototype, "unknownPage", null);
581
512
  __decorate([
582
- mocha_1.test
513
+ test
583
514
  ], CoreTest.prototype, "knownTemplatePage", null);
584
515
  __decorate([
585
- mocha_1.test
516
+ test
586
517
  ], CoreTest.prototype, "slashInQueryString", null);
587
518
  __decorate([
588
- mocha_1.test
519
+ test
589
520
  ], CoreTest.prototype, "slashInPath", null);
590
521
  __decorate([
591
- mocha_1.test
522
+ test
592
523
  ], CoreTest.prototype, "me", null);
593
524
  __decorate([
594
- mocha_1.test
525
+ test
595
526
  ], CoreTest.prototype, "covValidateSchema", null);
596
527
  __decorate([
597
- mocha_1.test
528
+ test
598
529
  ], CoreTest.prototype, "covGetModules", null);
599
530
  __decorate([
600
- mocha_1.test
531
+ test
601
532
  ], CoreTest.prototype, "covRemoveRoute", null);
602
533
  __decorate([
603
- mocha_1.test
534
+ test
604
535
  ], CoreTest.prototype, "toPublicJson", null);
605
536
  __decorate([
606
- mocha_1.test
537
+ test
607
538
  ], CoreTest.prototype, "updateConfiguration", null);
608
539
  __decorate([
609
- mocha_1.test
540
+ test
610
541
  ], CoreTest.prototype, "errorChecks", null);
611
542
  __decorate([
612
- mocha_1.test
543
+ test
613
544
  ], CoreTest.prototype, "autoConnectFailure", null);
614
545
  __decorate([
615
- mocha_1.test
546
+ test
616
547
  ], CoreTest.prototype, "cov", null);
617
548
  __decorate([
618
- mocha_1.test
549
+ test
619
550
  ], CoreTest.prototype, "listenersTest", null);
620
551
  __decorate([
621
- mocha_1.test
552
+ test
622
553
  ], CoreTest.prototype, "createServices", null);
623
554
  __decorate([
624
- mocha_1.test
555
+ test
625
556
  ], CoreTest.prototype, "badInit", null);
626
- __decorate([
627
- mocha_1.test
628
- ], CoreTest.prototype, "sandbox", null);
629
557
  CoreTest = __decorate([
630
- mocha_1.suite
558
+ suite
631
559
  ], CoreTest);
632
560
  //# sourceMappingURL=core.spec.js.map