@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.
- package/lib/application.d.ts +5 -5
- 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 +21 -25
- package/lib/core.js +233 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +334 -406
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -48
- package/lib/index.js +53 -70
- 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 +128 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +33 -14
- package/lib/models/coremodel.js +160 -117
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +143 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -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 +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -168
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +1 -1
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -63
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +9 -9
- 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 +3 -3
- package/lib/queues/queueservice.js +51 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- 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 +23 -13
- package/lib/services/authentication.js +540 -566
- 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 -245
- 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 +45 -70
- 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 +1 -1
- package/lib/services/configuration.js +78 -105
- 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 +9 -4
- package/lib/services/cryptoservice.js +187 -221
- package/lib/services/cryptoservice.js.map +1 -1
- package/lib/services/cryptoservice.spec.js +88 -115
- package/lib/services/cryptoservice.spec.js.map +1 -1
- 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 +5 -5
- package/lib/services/filebinary.js +165 -210
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -116
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -1
- package/lib/services/fileconfiguration.js +25 -44
- 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 +8 -8
- package/lib/services/invitationservice.js +274 -314
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +443 -449
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +1 -1
- package/lib/services/kubernetesconfiguration.js +41 -60
- 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 +3 -3
- package/lib/services/notificationservice.js +21 -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 +4 -4
- package/lib/services/oauth.js +68 -83
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +130 -156
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +2 -6
- package/lib/services/proxy.js +45 -58
- package/lib/services/proxy.js.map +1 -1
- package/lib/services/proxy.spec.js +34 -53
- package/lib/services/proxy.spec.js.map +1 -1
- 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 +26 -3
- package/lib/services/service.js +68 -40
- 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 +2 -2
- package/lib/stores/aggregator.js +37 -58
- 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 +262 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +3 -3
- package/lib/stores/mapper.js +110 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +133 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +3 -3
- package/lib/stores/memory.js +98 -144
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +2 -2
- package/lib/stores/memory.spec.js +124 -145
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +27 -17
- package/lib/stores/store.js +833 -849
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +625 -669
- 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 +73 -100
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +49 -39
- 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 +7 -5
- package/lib/utils/context.js +95 -103
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +139 -163
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +3 -3
- package/lib/utils/cookie.js +42 -61
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -64
- 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 +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- 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 +6 -6
- package/lib/utils/session.js +37 -59
- package/lib/utils/session.js.map +1 -1
- package/lib/utils/session.spec.js +38 -51
- package/lib/utils/session.spec.js.map +1 -1
- 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 +18 -13
- package/test/config-invitation.json +1 -3
- package/test/config.json +1 -2
- 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 +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
|
-
|
|
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
|
}
|
|
310
|
-
registry() {
|
|
311
|
-
|
|
312
|
-
|
|
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,
|
|
282
|
+
assert.strictEqual(Object.keys(moddas).length, 7);
|
|
323
283
|
}
|
|
324
284
|
getServicesImplementationsWithType() {
|
|
325
|
-
let stores = this.webda.getServicesOfType(
|
|
326
|
-
assert.strictEqual(Object.keys(stores).length,
|
|
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(),
|
|
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
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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
|
-
|
|
474
|
+
test
|
|
544
475
|
], CoreTest.prototype, "exportOpenAPI", null);
|
|
545
476
|
__decorate([
|
|
546
|
-
|
|
477
|
+
test
|
|
547
478
|
], CoreTest.prototype, "getStringRoute", null);
|
|
548
479
|
__decorate([
|
|
549
|
-
|
|
480
|
+
test
|
|
550
481
|
], CoreTest.prototype, "getStringPostRoute", null);
|
|
551
482
|
__decorate([
|
|
552
|
-
|
|
483
|
+
test
|
|
553
484
|
], CoreTest.prototype, "getServiceSample", null);
|
|
554
485
|
__decorate([
|
|
555
|
-
|
|
486
|
+
test
|
|
556
487
|
], CoreTest.prototype, "registry", null);
|
|
557
488
|
__decorate([
|
|
558
|
-
|
|
489
|
+
test
|
|
559
490
|
], CoreTest.prototype, "getServicesImplementations", null);
|
|
560
491
|
__decorate([
|
|
561
|
-
|
|
492
|
+
test
|
|
562
493
|
], CoreTest.prototype, "getStores", null);
|
|
563
494
|
__decorate([
|
|
564
|
-
|
|
495
|
+
test
|
|
565
496
|
], CoreTest.prototype, "getServicesImplementationsWithType", null);
|
|
566
497
|
__decorate([
|
|
567
|
-
|
|
498
|
+
test
|
|
568
499
|
], CoreTest.prototype, "getVersion", null);
|
|
569
500
|
__decorate([
|
|
570
|
-
|
|
501
|
+
test
|
|
571
502
|
], CoreTest.prototype, "knownPage", null);
|
|
572
503
|
__decorate([
|
|
573
|
-
|
|
504
|
+
test
|
|
574
505
|
], CoreTest.prototype, "knownPageMultipleMethod", null);
|
|
575
506
|
__decorate([
|
|
576
|
-
|
|
507
|
+
test
|
|
577
508
|
], CoreTest.prototype, "knownPageUnknownMethod", null);
|
|
578
509
|
__decorate([
|
|
579
|
-
|
|
510
|
+
test
|
|
580
511
|
], CoreTest.prototype, "unknownPage", null);
|
|
581
512
|
__decorate([
|
|
582
|
-
|
|
513
|
+
test
|
|
583
514
|
], CoreTest.prototype, "knownTemplatePage", null);
|
|
584
515
|
__decorate([
|
|
585
|
-
|
|
516
|
+
test
|
|
586
517
|
], CoreTest.prototype, "slashInQueryString", null);
|
|
587
518
|
__decorate([
|
|
588
|
-
|
|
519
|
+
test
|
|
589
520
|
], CoreTest.prototype, "slashInPath", null);
|
|
590
521
|
__decorate([
|
|
591
|
-
|
|
522
|
+
test
|
|
592
523
|
], CoreTest.prototype, "me", null);
|
|
593
524
|
__decorate([
|
|
594
|
-
|
|
525
|
+
test
|
|
595
526
|
], CoreTest.prototype, "covValidateSchema", null);
|
|
596
527
|
__decorate([
|
|
597
|
-
|
|
528
|
+
test
|
|
598
529
|
], CoreTest.prototype, "covGetModules", null);
|
|
599
530
|
__decorate([
|
|
600
|
-
|
|
531
|
+
test
|
|
601
532
|
], CoreTest.prototype, "covRemoveRoute", null);
|
|
602
533
|
__decorate([
|
|
603
|
-
|
|
534
|
+
test
|
|
604
535
|
], CoreTest.prototype, "toPublicJson", null);
|
|
605
536
|
__decorate([
|
|
606
|
-
|
|
537
|
+
test
|
|
607
538
|
], CoreTest.prototype, "updateConfiguration", null);
|
|
608
539
|
__decorate([
|
|
609
|
-
|
|
540
|
+
test
|
|
610
541
|
], CoreTest.prototype, "errorChecks", null);
|
|
611
542
|
__decorate([
|
|
612
|
-
|
|
543
|
+
test
|
|
613
544
|
], CoreTest.prototype, "autoConnectFailure", null);
|
|
614
545
|
__decorate([
|
|
615
|
-
|
|
546
|
+
test
|
|
616
547
|
], CoreTest.prototype, "cov", null);
|
|
617
548
|
__decorate([
|
|
618
|
-
|
|
549
|
+
test
|
|
619
550
|
], CoreTest.prototype, "listenersTest", null);
|
|
620
551
|
__decorate([
|
|
621
|
-
|
|
552
|
+
test
|
|
622
553
|
], CoreTest.prototype, "createServices", null);
|
|
623
554
|
__decorate([
|
|
624
|
-
|
|
555
|
+
test
|
|
625
556
|
], CoreTest.prototype, "badInit", null);
|
|
626
|
-
__decorate([
|
|
627
|
-
mocha_1.test
|
|
628
|
-
], CoreTest.prototype, "sandbox", null);
|
|
629
557
|
CoreTest = __decorate([
|
|
630
|
-
|
|
558
|
+
suite
|
|
631
559
|
], CoreTest);
|
|
632
560
|
//# sourceMappingURL=core.spec.js.map
|