@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
|
@@ -1,44 +1,29 @@
|
|
|
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
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const mocha_1 = require("@testdeck/mocha");
|
|
19
|
-
const assert = require("assert");
|
|
20
|
-
const __1 = require("../");
|
|
21
|
-
const test_1 = require("../test");
|
|
22
|
-
const oauth_1 = require("./oauth");
|
|
23
|
-
class FakeOAuthService extends oauth_1.OAuthService {
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import { HttpContext } from "../.js";
|
|
10
|
+
import { WebdaTest } from "../test.js";
|
|
11
|
+
import { OAuthService } from "./oauth.js";
|
|
12
|
+
class FakeOAuthService extends OAuthService {
|
|
24
13
|
getDefaultUrl() {
|
|
25
14
|
return "/fake";
|
|
26
15
|
}
|
|
27
16
|
generateAuthUrl() {
|
|
28
17
|
return "/fakeredirect";
|
|
29
18
|
}
|
|
30
|
-
handleToken() {
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
});
|
|
19
|
+
async handleToken() {
|
|
20
|
+
return {
|
|
21
|
+
identId: "i1",
|
|
22
|
+
profile: {}
|
|
23
|
+
};
|
|
37
24
|
}
|
|
38
|
-
handleCallback() {
|
|
39
|
-
return
|
|
40
|
-
return this.handleToken();
|
|
41
|
-
});
|
|
25
|
+
async handleCallback() {
|
|
26
|
+
return this.handleToken();
|
|
42
27
|
}
|
|
43
28
|
getName() {
|
|
44
29
|
return "fake";
|
|
@@ -47,147 +32,136 @@ class FakeOAuthService extends oauth_1.OAuthService {
|
|
|
47
32
|
return [/bouzouf\d?\.com$/];
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
|
-
let OAuthServiceTest = class OAuthServiceTest extends
|
|
51
|
-
before() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
yield _super.before.call(this);
|
|
57
|
-
this.service = new FakeOAuthService(this.webda, "fake", {
|
|
58
|
-
authorized_uris: ["https://redirect.me/plop"]
|
|
59
|
-
});
|
|
60
|
-
this.registerService(this.service);
|
|
35
|
+
let OAuthServiceTest = class OAuthServiceTest extends WebdaTest {
|
|
36
|
+
async before() {
|
|
37
|
+
await super.before();
|
|
38
|
+
this.service = new FakeOAuthService(this.webda, "fake", {
|
|
39
|
+
authorized_uris: ["https://redirect.me/plop"]
|
|
61
40
|
});
|
|
41
|
+
this.registerService(this.service);
|
|
62
42
|
}
|
|
63
|
-
testCheckRequest() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
assert.strictEqual(yield this.service.checkRequest(ctx), true, "should allow without referer");
|
|
79
|
-
});
|
|
43
|
+
async testCheckRequest() {
|
|
44
|
+
let ctx = await this.newContext();
|
|
45
|
+
ctx.setHttpContext(new HttpContext("bouzouf.com", "GET", "/fake", "https", 80, { referer: "bouzouf.com" }));
|
|
46
|
+
assert.strictEqual(await this.service.checkRequest(ctx), true, "should allow bouzouf.com referer");
|
|
47
|
+
ctx.setHttpContext(new HttpContext("bouzouf.com", "GET", "/fake", "https", 80, { referer: "bouzouf2.com" }));
|
|
48
|
+
assert.strictEqual(await this.service.checkRequest(ctx), true, "should allow bouzouf2.com referer");
|
|
49
|
+
ctx.setHttpContext(new HttpContext("bouzouf.com", "GET", "/fake", "https", 80, { referer: "bouzouf12.com" }));
|
|
50
|
+
assert.strictEqual(await this.service.checkRequest(ctx), false, "should not allow bouzouf12.com referer");
|
|
51
|
+
ctx.setHttpContext(new HttpContext("bouzouf.com", "GET", "/plop", "https", 80, { referer: "bouzouf.com" }));
|
|
52
|
+
assert.strictEqual(await this.service.checkRequest(ctx), false, "should allow bouzouf.com only on its own url");
|
|
53
|
+
ctx.setHttpContext(new HttpContext("bouzouf.com", "GET", "/fake", "https", 80, {}));
|
|
54
|
+
assert.strictEqual(await this.service.checkRequest(ctx), false, "should not allow without referer");
|
|
55
|
+
this.service.getParameters().no_referer = true;
|
|
56
|
+
ctx.setHttpContext(new HttpContext("bouzouf.com", "GET", "/fake", "https", 80, {}));
|
|
57
|
+
assert.strictEqual(await this.service.checkRequest(ctx), true, "should allow without referer");
|
|
80
58
|
}
|
|
81
|
-
misc() {
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
authorized_uris: ["google.com"]
|
|
116
|
-
});
|
|
117
|
-
this.service.hasToken = () => true;
|
|
118
|
-
this.service.resolve();
|
|
119
|
-
this.registerService(this.service);
|
|
120
|
-
assert.strictEqual(this.service._authenticationService, undefined, "Should not get any Authentication service");
|
|
121
|
-
yield this.execute(ctx, "webda.io", "GET", "/bouzouf/scope");
|
|
122
|
-
assert.deepStrictEqual(JSON.parse(ctx.getResponseBody()), ["email", "image"]);
|
|
123
|
-
let event = 0;
|
|
124
|
-
this.service.on("OAuth.Callback", evt => {
|
|
125
|
-
if (evt.type === "token") {
|
|
126
|
-
event++;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
yield this.execute(ctx, "webda.io", "POST", "/bouzouf/token");
|
|
130
|
-
assert.strictEqual(event, 1);
|
|
131
|
-
this.service.removeAllListeners();
|
|
132
|
-
this.service.on("OAuth.Callback", evt => {
|
|
133
|
-
if (evt.type === "callback") {
|
|
134
|
-
event++;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
ctx.getSession().oauth.redirect = "bouzouf.com";
|
|
138
|
-
yield this.getExecutor(ctx, "webda.io", "GET", "/bouzouf/callback").execute(ctx);
|
|
139
|
-
assert.strictEqual(event, 2);
|
|
140
|
-
assert.strictEqual(ctx.getResponseHeaders()["Location"], "bouzouf.com");
|
|
141
|
-
assert.strictEqual(ctx.getSession().oauth.redirect, undefined);
|
|
142
|
-
assert.strictEqual(ctx.getSession().oauth.state, undefined);
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
this.service.parameters = this.service.loadParameters({
|
|
145
|
-
authenticationService: "Authentication2",
|
|
146
|
-
exposeScope: true,
|
|
147
|
-
scope: ["email", "image"],
|
|
148
|
-
url: "/bouzouf"
|
|
149
|
-
});
|
|
150
|
-
// @ts-ignore readonly
|
|
151
|
-
ctx.getHttpContext().getHeaders().referer = "http://myownwebsite.com";
|
|
152
|
-
this.service._redirect(ctx);
|
|
153
|
-
assert.strictEqual(ctx.getSession().oauth.redirect, "http://myownwebsite.com");
|
|
59
|
+
async misc() {
|
|
60
|
+
this.service.resolve();
|
|
61
|
+
assert.notStrictEqual(this.service._authenticationService, undefined, "Should get default Authentication service");
|
|
62
|
+
// Test the 403 on handleReturn
|
|
63
|
+
assert.rejects(() => this.service.handleReturn(undefined, undefined, undefined), /403/);
|
|
64
|
+
let ctx = await this.newContext();
|
|
65
|
+
await this.webda.getService("Idents").__clean();
|
|
66
|
+
// Register with oauth
|
|
67
|
+
await this.service.handleReturn(ctx, "plop", { email: "rcattiau@gmail.com" }, undefined);
|
|
68
|
+
// We should have two idents existing now
|
|
69
|
+
assert.strictEqual(await this.webda.getService("Idents").exists("plop_fake"), true);
|
|
70
|
+
assert.strictEqual(await this.webda.getService("Idents").exists("rcattiau@gmail.com_email"), true);
|
|
71
|
+
ctx.newSession();
|
|
72
|
+
// Log with known ident / email
|
|
73
|
+
assert.strictEqual(ctx.getSession().identUsed, undefined);
|
|
74
|
+
await this.service.handleReturn(ctx, "plop", { email: "rcattiau@gmail.com" }, undefined);
|
|
75
|
+
assert.strictEqual(ctx.getSession().identUsed, "plop_fake");
|
|
76
|
+
let userId = ctx.getCurrentUserId();
|
|
77
|
+
ctx.newSession();
|
|
78
|
+
// Log with new ident / known email
|
|
79
|
+
await this.service.handleReturn(ctx, "plop2", { email: "rcattiau@gmail.com" }, undefined);
|
|
80
|
+
assert.strictEqual(ctx.getSession().identUsed, "plop2_fake");
|
|
81
|
+
assert.strictEqual(ctx.getCurrentUserId(), userId);
|
|
82
|
+
await this.service.handleReturn(ctx, "plop3", { email: "rcattiau@gmail.com" }, undefined);
|
|
83
|
+
// Default to false for token
|
|
84
|
+
assert.rejects(() => this.execute(ctx, "webda.io", "GET", "/fake/scope"), /404/);
|
|
85
|
+
assert.rejects(() => this.execute(ctx, "webda.io", "POST", "/fake/token"), /404/);
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
this.service.parameters = this.service.loadParameters({
|
|
88
|
+
authenticationService: "Authentication2",
|
|
89
|
+
exposeScope: true,
|
|
90
|
+
scope: ["email", "image"],
|
|
91
|
+
url: "/bouzouf",
|
|
92
|
+
authorized_uris: ["google.com"]
|
|
154
93
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.service.getParameters().no_referer = true;
|
|
175
|
-
this.service._redirect(ctx);
|
|
176
|
-
assert.strictEqual(ctx.getSession().oauth.redirect, undefined);
|
|
177
|
-
assert.strictEqual(ctx.getResponseHeaders().Location, "/fakeredirect");
|
|
94
|
+
this.service.hasToken = () => true;
|
|
95
|
+
this.service.resolve();
|
|
96
|
+
this.registerService(this.service);
|
|
97
|
+
assert.strictEqual(this.service._authenticationService, undefined, "Should not get any Authentication service");
|
|
98
|
+
await this.execute(ctx, "webda.io", "GET", "/bouzouf/scope");
|
|
99
|
+
assert.deepStrictEqual(JSON.parse(ctx.getResponseBody()), ["email", "image"]);
|
|
100
|
+
let event = 0;
|
|
101
|
+
this.service.on("OAuth.Callback", evt => {
|
|
102
|
+
if (evt.type === "token") {
|
|
103
|
+
event++;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
await this.execute(ctx, "webda.io", "POST", "/bouzouf/token");
|
|
107
|
+
assert.strictEqual(event, 1);
|
|
108
|
+
this.service.removeAllListeners();
|
|
109
|
+
this.service.on("OAuth.Callback", evt => {
|
|
110
|
+
if (evt.type === "callback") {
|
|
111
|
+
event++;
|
|
112
|
+
}
|
|
178
113
|
});
|
|
114
|
+
ctx.getSession().oauth.redirect = "bouzouf.com";
|
|
115
|
+
await this.getExecutor(ctx, "webda.io", "GET", "/bouzouf/callback").execute(ctx);
|
|
116
|
+
assert.strictEqual(event, 2);
|
|
117
|
+
assert.strictEqual(ctx.getResponseHeaders()["Location"], "bouzouf.com");
|
|
118
|
+
assert.strictEqual(ctx.getSession().oauth.redirect, undefined);
|
|
119
|
+
assert.strictEqual(ctx.getSession().oauth.state, undefined);
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
this.service.parameters = this.service.loadParameters({
|
|
122
|
+
authenticationService: "Authentication2",
|
|
123
|
+
exposeScope: true,
|
|
124
|
+
scope: ["email", "image"],
|
|
125
|
+
url: "/bouzouf"
|
|
126
|
+
});
|
|
127
|
+
// @ts-ignore readonly
|
|
128
|
+
ctx.getHttpContext().getHeaders().referer = "http://myownwebsite.com";
|
|
129
|
+
this.service._redirect(ctx);
|
|
130
|
+
assert.strictEqual(ctx.getSession().oauth.redirect, "http://myownwebsite.com");
|
|
131
|
+
}
|
|
132
|
+
async redirect() {
|
|
133
|
+
let ctx = await this.newContext();
|
|
134
|
+
ctx.setHttpContext(new HttpContext("test.webda.io", "GET", "/fake", "https", 443, {
|
|
135
|
+
referer: "https://redirect.me/plop"
|
|
136
|
+
}));
|
|
137
|
+
await this.service._redirect(ctx);
|
|
138
|
+
assert.notStrictEqual(ctx.getSession().oauth.state, undefined);
|
|
139
|
+
assert.strictEqual(ctx.getSession().oauth.redirect, "https://redirect.me/plop");
|
|
140
|
+
assert.strictEqual(ctx.getResponseHeaders().Location, "/fakeredirect");
|
|
141
|
+
ctx.setHttpContext(new HttpContext("test.webda.io", "GET", "/fake", "https", 443, {
|
|
142
|
+
referer: "https://redirect.me/plop2"
|
|
143
|
+
}));
|
|
144
|
+
assert.throws(() => this.service._redirect(ctx), /401/);
|
|
145
|
+
// Test w/o referer
|
|
146
|
+
ctx.setHttpContext(new HttpContext("test.webda.io", "GET", "/fake"));
|
|
147
|
+
assert.throws(() => this.service._redirect(ctx), /401/);
|
|
148
|
+
// Enable the no_referer
|
|
149
|
+
this.service.getParameters().no_referer = true;
|
|
150
|
+
this.service._redirect(ctx);
|
|
151
|
+
assert.strictEqual(ctx.getSession().oauth.redirect, undefined);
|
|
152
|
+
assert.strictEqual(ctx.getResponseHeaders().Location, "/fakeredirect");
|
|
179
153
|
}
|
|
180
154
|
};
|
|
181
155
|
__decorate([
|
|
182
|
-
|
|
156
|
+
test
|
|
183
157
|
], OAuthServiceTest.prototype, "testCheckRequest", null);
|
|
184
158
|
__decorate([
|
|
185
|
-
|
|
159
|
+
test
|
|
186
160
|
], OAuthServiceTest.prototype, "misc", null);
|
|
187
161
|
__decorate([
|
|
188
|
-
|
|
162
|
+
test
|
|
189
163
|
], OAuthServiceTest.prototype, "redirect", null);
|
|
190
164
|
OAuthServiceTest = __decorate([
|
|
191
|
-
|
|
165
|
+
suite
|
|
192
166
|
], OAuthServiceTest);
|
|
193
167
|
//# sourceMappingURL=oauth.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.spec.js","sourceRoot":"","sources":["../../src/services/oauth.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"oauth.spec.js","sourceRoot":"","sources":["../../src/services/oauth.spec.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,WAAW,EAAgB,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,YAAY,EAAgB,MAAM,SAAS,CAAC;AAErD,MAAM,gBAAiB,SAAQ,YAAY;IACzC,aAAa;QAC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IAAI;4CA0EJ;AAGD;IADC,IAAI;gDA0BJ;AAxIG,gBAAgB;IADrB,KAAK;GACA,gBAAgB,CAyIrB"}
|
package/lib/services/proxy.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as http from "http";
|
|
3
|
-
import { Context } from "../utils/context";
|
|
4
|
-
import { Service, ServiceParameters } from "./service";
|
|
3
|
+
import { Context } from "../utils/context.js";
|
|
4
|
+
import { Service, ServiceParameters } from "./service.js";
|
|
5
5
|
/**
|
|
6
6
|
* Proxy to a backend service
|
|
7
7
|
*/
|
|
@@ -29,10 +29,6 @@ export declare class ProxyService<T extends ProxyParameters = ProxyParameters> e
|
|
|
29
29
|
* @override
|
|
30
30
|
*/
|
|
31
31
|
loadParameters(params: any): ProxyParameters;
|
|
32
|
-
/**
|
|
33
|
-
* @override
|
|
34
|
-
*/
|
|
35
|
-
resolve(): this;
|
|
36
32
|
/**
|
|
37
33
|
* Create the request to the backend
|
|
38
34
|
* @param url
|
package/lib/services/proxy.js
CHANGED
|
@@ -1,47 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
6
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const http = require("http");
|
|
14
|
-
const service_1 = require("./service");
|
|
7
|
+
import * as http from "http";
|
|
8
|
+
import { Route, Service, ServiceParameters } from "./service.js";
|
|
15
9
|
/**
|
|
16
10
|
* Proxy to a backend service
|
|
17
11
|
*/
|
|
18
|
-
class ProxyParameters extends
|
|
12
|
+
export class ProxyParameters extends ServiceParameters {
|
|
19
13
|
}
|
|
20
|
-
exports.ProxyParameters = ProxyParameters;
|
|
21
14
|
/**
|
|
22
15
|
* Proxy to starling computation api
|
|
23
16
|
*
|
|
24
17
|
* @WebdaModda
|
|
25
18
|
*/
|
|
26
|
-
class ProxyService extends
|
|
19
|
+
export class ProxyService extends Service {
|
|
27
20
|
/**
|
|
28
21
|
* @override
|
|
29
22
|
*/
|
|
30
23
|
loadParameters(params) {
|
|
31
24
|
return new ProxyParameters(params);
|
|
32
25
|
}
|
|
33
|
-
/**
|
|
34
|
-
* @override
|
|
35
|
-
*/
|
|
36
|
-
resolve() {
|
|
37
|
-
super.resolve();
|
|
38
|
-
// Can be used to reuse proxy system without exposing it directly
|
|
39
|
-
if (this.parameters.url) {
|
|
40
|
-
this.addRoute(this.parameters.url, ["GET", "POST", "DELETE", "PUT", "PATCH"], this.proxyRoute);
|
|
41
|
-
this.addRoute(`${this.parameters.url}/{path}`, ["GET", "POST", "DELETE", "PUT", "PATCH"], this.proxyRoute, undefined, true);
|
|
42
|
-
}
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
26
|
/**
|
|
46
27
|
* Create the request to the backend
|
|
47
28
|
* @param url
|
|
@@ -97,43 +78,49 @@ class ProxyService extends service_1.Service {
|
|
|
97
78
|
* @param host
|
|
98
79
|
* @param url
|
|
99
80
|
*/
|
|
100
|
-
proxy(ctx, host, url) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
81
|
+
async proxy(ctx, host, url) {
|
|
82
|
+
const subUrl = ctx.getHttpContext().getRelativeUri().substring(url.length);
|
|
83
|
+
this.log("DEBUG", "Proxying to", `${ctx.getHttpContext().getMethod()} ${host}${subUrl}`);
|
|
84
|
+
await new Promise((resolve, reject) => {
|
|
85
|
+
let xff = ctx.getHttpContext().getHeader("x-forwarded-for");
|
|
86
|
+
if (!xff) {
|
|
87
|
+
xff += `, ${ctx.getHttpContext().getClientIp()}`;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
xff = ctx.getHttpContext().getClientIp();
|
|
91
|
+
}
|
|
92
|
+
const protocol = ctx.getHttpContext().getProtocol();
|
|
93
|
+
let req = this.createRequest(`${host}${subUrl}`, ctx.getHttpContext().getMethod(), {
|
|
94
|
+
...this.getRequestHeaders(ctx),
|
|
95
|
+
"X-Rewrite-URL": ctx.getHttpContext().getRelativeUri(),
|
|
96
|
+
"X-Forwarded-Host": ctx.getHttpContext().getHeader("x-forwarded-host", `${ctx.getHttpContext().getHost()}`),
|
|
97
|
+
"X-Forwarded-Proto": ctx
|
|
98
|
+
.getHttpContext()
|
|
99
|
+
.getHeader("x-forwarded-proto", protocol.substring(0, protocol.length - 1)),
|
|
100
|
+
"X-Forwarded-For": xff
|
|
101
|
+
}, res => {
|
|
102
|
+
res.on("end", resolve);
|
|
103
|
+
res.on("error", reject);
|
|
104
|
+
this.forwardResponse(res, ctx);
|
|
121
105
|
});
|
|
106
|
+
req.on("error", reject);
|
|
107
|
+
ctx.getHttpContext().getRawStream().pipe(req);
|
|
122
108
|
});
|
|
123
109
|
}
|
|
124
110
|
/**
|
|
125
111
|
* Proxy to starling
|
|
126
112
|
* @param ctx
|
|
127
113
|
*/
|
|
128
|
-
proxyRoute(ctx) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
yield this.proxy(ctx, this.parameters.backend, this.parameters.url);
|
|
135
|
-
});
|
|
114
|
+
async proxyRoute(ctx) {
|
|
115
|
+
if (this.parameters.requireAuthentication && !ctx.getCurrentUserId()) {
|
|
116
|
+
throw 401;
|
|
117
|
+
}
|
|
118
|
+
// Add any additional controls here
|
|
119
|
+
await this.proxy(ctx, this.parameters.backend, this.parameters.url);
|
|
136
120
|
}
|
|
137
121
|
}
|
|
138
|
-
|
|
122
|
+
__decorate([
|
|
123
|
+
Route("./{path}", ["GET", "POST", "DELETE", "PUT", "PATCH"], true),
|
|
124
|
+
Route(".", ["GET", "POST", "DELETE", "PUT", "PATCH"])
|
|
125
|
+
], ProxyService.prototype, "proxyRoute", null);
|
|
139
126
|
//# sourceMappingURL=proxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/services/proxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/services/proxy.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,iBAAiB;CAarD;AAED;;;;GAIG;AACH,MAAM,OAAO,YAA0D,SAAQ,OAAU;IACvF;;OAEG;IACH,cAAc,CAAC,MAAW;QACxB,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,GAAW,EAAE,MAAc,EAAE,OAAY,EAAE,QAAkD;QACzG,OAAO,IAAI,CAAC,OAAO,CACjB,G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