@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.
- package/lib/application.d.ts +9 -21
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +86 -46
- package/lib/core.js +254 -316
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +326 -391
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -45
- package/lib/index.js +54 -67
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +127 -151
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +84 -11
- package/lib/models/coremodel.js +104 -103
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +91 -91
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +5 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +12 -2
- package/lib/models/ownermodel.js +54 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +129 -152
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +2 -2
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -61
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +5 -5
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +4 -4
- package/lib/queues/queueservice.js +52 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +7 -3
- package/lib/router.js +49 -48
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +28 -19
- package/lib/services/authentication.js +539 -571
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +8 -6
- package/lib/services/binary.js +212 -244
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +46 -71
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +6 -3
- package/lib/services/configuration.js +78 -103
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +258 -0
- package/lib/services/cryptoservice.js +312 -0
- package/lib/services/cryptoservice.js.map +1 -0
- package/lib/services/cryptoservice.spec.d.ts +1 -0
- package/lib/services/cryptoservice.spec.js +137 -0
- package/lib/services/cryptoservice.spec.js.map +1 -0
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +15 -5
- package/lib/services/filebinary.js +171 -200
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -117
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +2 -2
- package/lib/services/fileconfiguration.js +25 -43
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +9 -9
- package/lib/services/invitationservice.js +275 -313
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +442 -448
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +2 -2
- package/lib/services/kubernetesconfiguration.js +41 -59
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +4 -4
- package/lib/services/notificationservice.js +23 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +32 -6
- package/lib/services/oauth.js +73 -78
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +128 -147
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +74 -0
- package/lib/services/proxy.js +126 -0
- package/lib/services/proxy.js.map +1 -0
- package/lib/services/proxy.spec.d.ts +1 -0
- package/lib/services/proxy.spec.js +59 -0
- package/lib/services/proxy.spec.js.map +1 -0
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +33 -7
- package/lib/services/service.js +74 -42
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +3 -3
- package/lib/stores/aggregator.js +37 -57
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +261 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +4 -4
- package/lib/stores/mapper.js +112 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +131 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +67 -6
- package/lib/stores/memory.js +155 -117
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +3 -2
- package/lib/stores/memory.spec.js +127 -105
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +35 -15
- package/lib/stores/store.js +839 -821
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +6 -4
- package/lib/stores/store.spec.js +627 -647
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +74 -94
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +25 -31
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +61 -29
- package/lib/utils/context.js +133 -127
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +147 -153
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +66 -45
- package/lib/utils/cookie.js +69 -158
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +220 -238
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +37 -9
- package/lib/utils/httpcontext.js +86 -57
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -48
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +120 -0
- package/lib/utils/session.js +155 -0
- package/lib/utils/session.js.map +1 -0
- package/lib/utils/session.spec.d.ts +1 -0
- package/lib/utils/session.spec.js +66 -0
- package/lib/utils/session.spec.js.map +1 -0
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +22 -14
- package/test/config-invitation.json +1 -3
- package/test/config.json +3 -3
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- 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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
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
|
|
34
|
-
_brokenRoute(ctx) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
ctx.write("CodeCoverage");
|
|
47
|
-
});
|
|
34
|
+
async onString(ctx) {
|
|
35
|
+
ctx.write("CodeCoverage");
|
|
48
36
|
}
|
|
49
|
-
onPostString(ctx) {
|
|
50
|
-
|
|
51
|
-
ctx.write("CodeCoveragePOST");
|
|
52
|
-
});
|
|
37
|
+
async onPostString(ctx) {
|
|
38
|
+
ctx.write("CodeCoveragePOST");
|
|
53
39
|
}
|
|
54
40
|
};
|
|
55
41
|
__decorate([
|
|
56
|
-
|
|
42
|
+
Route("/route/broken/{type}")
|
|
57
43
|
], ExceptionExecutor.prototype, "_brokenRoute", null);
|
|
58
44
|
__decorate([
|
|
59
|
-
|
|
45
|
+
Route("/route/string")
|
|
60
46
|
], ExceptionExecutor.prototype, "onString", null);
|
|
61
47
|
__decorate([
|
|
62
|
-
|
|
48
|
+
Route("/route/string", ["POST"])
|
|
63
49
|
], ExceptionExecutor.prototype, "onPostString", null);
|
|
64
50
|
ExceptionExecutor = __decorate([
|
|
65
|
-
|
|
51
|
+
Bean
|
|
66
52
|
], ExceptionExecutor);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
60
|
+
Route("/whynot")
|
|
74
61
|
], ImplicitBean.prototype, "whynot", null);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
175
|
+
test
|
|
207
176
|
], CSRFTest.prototype, "csrfRegExp", null);
|
|
208
177
|
__decorate([
|
|
209
|
-
|
|
178
|
+
test
|
|
210
179
|
], CSRFTest.prototype, "checkWebdaRequest", null);
|
|
211
180
|
__decorate([
|
|
212
|
-
|
|
181
|
+
test
|
|
213
182
|
], CSRFTest.prototype, "getApiUrl", null);
|
|
214
183
|
__decorate([
|
|
215
|
-
|
|
184
|
+
test
|
|
216
185
|
], CSRFTest.prototype, "websiteString", null);
|
|
217
186
|
__decorate([
|
|
218
|
-
|
|
187
|
+
test
|
|
219
188
|
], CSRFTest.prototype, "websiteArray", null);
|
|
220
189
|
__decorate([
|
|
221
|
-
|
|
190
|
+
test
|
|
222
191
|
], CSRFTest.prototype, "originFilter", null);
|
|
223
192
|
__decorate([
|
|
224
|
-
|
|
193
|
+
test
|
|
225
194
|
], CSRFTest.prototype, "websiteObject", null);
|
|
226
195
|
__decorate([
|
|
227
|
-
|
|
196
|
+
test
|
|
228
197
|
], CSRFTest.prototype, "csrfConditionalFilter", null);
|
|
229
198
|
CSRFTest = __decorate([
|
|
230
|
-
|
|
199
|
+
suite
|
|
231
200
|
], CSRFTest);
|
|
232
|
-
let CoreTest = class CoreTest extends
|
|
233
|
-
before() {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
259
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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,
|
|
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(
|
|
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(),
|
|
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
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
|
|
472
|
+
test
|
|
538
473
|
], CoreTest.prototype, "exportOpenAPI", null);
|
|
539
474
|
__decorate([
|
|
540
|
-
|
|
475
|
+
test
|
|
541
476
|
], CoreTest.prototype, "getStringRoute", null);
|
|
542
477
|
__decorate([
|
|
543
|
-
|
|
478
|
+
test
|
|
544
479
|
], CoreTest.prototype, "getStringPostRoute", null);
|
|
545
480
|
__decorate([
|
|
546
|
-
|
|
481
|
+
test
|
|
547
482
|
], CoreTest.prototype, "getServiceSample", null);
|
|
548
483
|
__decorate([
|
|
549
|
-
|
|
484
|
+
test
|
|
485
|
+
], CoreTest.prototype, "registry", null);
|
|
486
|
+
__decorate([
|
|
487
|
+
test
|
|
550
488
|
], CoreTest.prototype, "getServicesImplementations", null);
|
|
551
489
|
__decorate([
|
|
552
|
-
|
|
490
|
+
test
|
|
553
491
|
], CoreTest.prototype, "getStores", null);
|
|
554
492
|
__decorate([
|
|
555
|
-
|
|
493
|
+
test
|
|
556
494
|
], CoreTest.prototype, "getServicesImplementationsWithType", null);
|
|
557
495
|
__decorate([
|
|
558
|
-
|
|
496
|
+
test
|
|
559
497
|
], CoreTest.prototype, "getVersion", null);
|
|
560
498
|
__decorate([
|
|
561
|
-
|
|
499
|
+
test
|
|
562
500
|
], CoreTest.prototype, "knownPage", null);
|
|
563
501
|
__decorate([
|
|
564
|
-
|
|
502
|
+
test
|
|
565
503
|
], CoreTest.prototype, "knownPageMultipleMethod", null);
|
|
566
504
|
__decorate([
|
|
567
|
-
|
|
505
|
+
test
|
|
568
506
|
], CoreTest.prototype, "knownPageUnknownMethod", null);
|
|
569
507
|
__decorate([
|
|
570
|
-
|
|
508
|
+
test
|
|
571
509
|
], CoreTest.prototype, "unknownPage", null);
|
|
572
510
|
__decorate([
|
|
573
|
-
|
|
511
|
+
test
|
|
574
512
|
], CoreTest.prototype, "knownTemplatePage", null);
|
|
575
513
|
__decorate([
|
|
576
|
-
|
|
514
|
+
test
|
|
577
515
|
], CoreTest.prototype, "slashInQueryString", null);
|
|
578
516
|
__decorate([
|
|
579
|
-
|
|
517
|
+
test
|
|
580
518
|
], CoreTest.prototype, "slashInPath", null);
|
|
581
519
|
__decorate([
|
|
582
|
-
|
|
520
|
+
test
|
|
583
521
|
], CoreTest.prototype, "me", null);
|
|
584
522
|
__decorate([
|
|
585
|
-
|
|
523
|
+
test
|
|
586
524
|
], CoreTest.prototype, "covValidateSchema", null);
|
|
587
525
|
__decorate([
|
|
588
|
-
|
|
526
|
+
test
|
|
589
527
|
], CoreTest.prototype, "covGetModules", null);
|
|
590
528
|
__decorate([
|
|
591
|
-
|
|
529
|
+
test
|
|
592
530
|
], CoreTest.prototype, "covRemoveRoute", null);
|
|
593
531
|
__decorate([
|
|
594
|
-
|
|
532
|
+
test
|
|
595
533
|
], CoreTest.prototype, "toPublicJson", null);
|
|
596
534
|
__decorate([
|
|
597
|
-
|
|
535
|
+
test
|
|
598
536
|
], CoreTest.prototype, "updateConfiguration", null);
|
|
599
537
|
__decorate([
|
|
600
|
-
|
|
538
|
+
test
|
|
601
539
|
], CoreTest.prototype, "errorChecks", null);
|
|
602
540
|
__decorate([
|
|
603
|
-
|
|
541
|
+
test
|
|
604
542
|
], CoreTest.prototype, "autoConnectFailure", null);
|
|
605
543
|
__decorate([
|
|
606
|
-
|
|
544
|
+
test
|
|
607
545
|
], CoreTest.prototype, "cov", null);
|
|
608
546
|
__decorate([
|
|
609
|
-
|
|
547
|
+
test
|
|
610
548
|
], CoreTest.prototype, "listenersTest", null);
|
|
611
549
|
__decorate([
|
|
612
|
-
|
|
550
|
+
test
|
|
613
551
|
], CoreTest.prototype, "createServices", null);
|
|
614
552
|
__decorate([
|
|
615
|
-
|
|
553
|
+
test
|
|
616
554
|
], CoreTest.prototype, "badInit", null);
|
|
617
|
-
__decorate([
|
|
618
|
-
mocha_1.test
|
|
619
|
-
], CoreTest.prototype, "sandbox", null);
|
|
620
555
|
CoreTest = __decorate([
|
|
621
|
-
|
|
556
|
+
suite
|
|
622
557
|
], CoreTest);
|
|
623
558
|
//# sourceMappingURL=core.spec.js.map
|