@webda/core 2.0.0-beta.3 → 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 +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 +20 -24
- package/lib/core.js +222 -315
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +332 -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 +127 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +7 -6
- package/lib/models/coremodel.js +65 -113
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +88 -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 +3 -3
- 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 +537 -563
- 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 +7 -5
- package/lib/services/binary.js +211 -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 +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 +7 -7
- package/lib/services/invitationservice.js +274 -314
- 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 +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 +261 -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 +131 -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 +17 -13
- package/lib/stores/store.js +819 -847
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +624 -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 +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 +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 +17 -12
- 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 +956 -189
|
@@ -1,28 +1,17 @@
|
|
|
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
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const mocha_1 = require("@testdeck/mocha");
|
|
19
|
-
const assert = require("assert");
|
|
20
|
-
const __1 = require("..");
|
|
21
|
-
const test_1 = require("../test");
|
|
22
|
-
const authentication_1 = require("./authentication");
|
|
7
|
+
import { suite, test } from "@testdeck/mocha";
|
|
8
|
+
import * as assert from "assert";
|
|
9
|
+
import { Authentication } from "...js";
|
|
10
|
+
import { WebdaTest } from "../test.js";
|
|
11
|
+
import { AuthenticationParameters } from "./authentication.js";
|
|
23
12
|
const validationUrl = /.*\/auth\/email\/callback\?email=([^&]+)&token=([^& ]+)(&user=([^ &]+))?/;
|
|
24
13
|
var userId;
|
|
25
|
-
let AuthenticationTest = class AuthenticationTest extends
|
|
14
|
+
let AuthenticationTest = class AuthenticationTest extends WebdaTest {
|
|
26
15
|
constructor() {
|
|
27
16
|
super(...arguments);
|
|
28
17
|
this.events = 0;
|
|
@@ -33,476 +22,451 @@ let AuthenticationTest = class AuthenticationTest extends test_1.WebdaTest {
|
|
|
33
22
|
getIdentStore() {
|
|
34
23
|
return this.getService("Idents");
|
|
35
24
|
}
|
|
36
|
-
before() {
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
async before() {
|
|
26
|
+
await super.before();
|
|
27
|
+
this.userStore = this.getUserStore();
|
|
28
|
+
this.identStore = this.getIdentStore();
|
|
29
|
+
assert.notStrictEqual(this.userStore, undefined);
|
|
30
|
+
assert.notStrictEqual(this.identStore, undefined);
|
|
31
|
+
await this.userStore.__clean();
|
|
32
|
+
await this.identStore.__clean();
|
|
33
|
+
this.authentication = this.getService("Authentication");
|
|
34
|
+
this.mailer = this.getService("DefinedMailer");
|
|
35
|
+
this.authentication.on("Authentication.Login", () => {
|
|
36
|
+
this.events++;
|
|
39
37
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
assert.notStrictEqual(this.userStore, undefined);
|
|
45
|
-
assert.notStrictEqual(this.identStore, undefined);
|
|
46
|
-
yield this.userStore.__clean();
|
|
47
|
-
yield this.identStore.__clean();
|
|
48
|
-
this.authentication = this.getService("Authentication");
|
|
49
|
-
this.mailer = this.getService("DefinedMailer");
|
|
50
|
-
this.authentication.on("Authentication.Login", () => {
|
|
51
|
-
this.events++;
|
|
52
|
-
});
|
|
53
|
-
this.authentication.on("Authentication.Register", evt => {
|
|
54
|
-
this.events++;
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
evt.user.test = "TESTOR";
|
|
57
|
-
});
|
|
58
|
-
this.mailer.sent = [];
|
|
38
|
+
this.authentication.on("Authentication.Register", evt => {
|
|
39
|
+
this.events++;
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
evt.user.test = "TESTOR";
|
|
59
42
|
});
|
|
43
|
+
this.mailer.sent = [];
|
|
60
44
|
}
|
|
61
|
-
registerTest2(ctx) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
69
|
-
});
|
|
70
|
-
ctx.newSession();
|
|
71
|
-
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
72
|
-
yield executor.execute(ctx);
|
|
45
|
+
async registerTest2(ctx) {
|
|
46
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
47
|
+
login: "Test2@Webda.io",
|
|
48
|
+
password: "testtest",
|
|
49
|
+
register: true
|
|
50
|
+
}, {
|
|
51
|
+
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
73
52
|
});
|
|
53
|
+
ctx.newSession();
|
|
54
|
+
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
55
|
+
await executor.execute(ctx);
|
|
74
56
|
}
|
|
75
|
-
cov() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
identStore: "id",
|
|
96
|
-
userStore: "us",
|
|
97
|
-
url: "/aaa"
|
|
98
|
-
});
|
|
99
|
-
assert.strictEqual(params.identStore, "id");
|
|
100
|
-
assert.strictEqual(params.userStore, "us");
|
|
101
|
-
assert.strictEqual(params.url, "/aaa");
|
|
102
|
-
let auth = new __1.Authentication(this.webda, "auth", { email: { mailer: "plop" } });
|
|
103
|
-
assert.throws(() => auth.resolve(), /email authentication requires a Mailer service/);
|
|
57
|
+
async cov() {
|
|
58
|
+
this.authentication.addProvider("plop");
|
|
59
|
+
this.authentication.addProvider("plop");
|
|
60
|
+
this.authentication.addProvider("plop2");
|
|
61
|
+
let ctx = await this.newContext();
|
|
62
|
+
this.authentication._listAuthentications(ctx);
|
|
63
|
+
assert.strictEqual(ctx.getResponseBody(), JSON.stringify(["email", "plop", "plop2"]));
|
|
64
|
+
ctx.setPathParameters({ provider: "plop" });
|
|
65
|
+
this.authentication.getParameters().password.verifier = "VersionService";
|
|
66
|
+
this.authentication.computeParameters();
|
|
67
|
+
assert.strictEqual(await this.authentication.getPasswordRecoveryInfos("bouzouf"), undefined);
|
|
68
|
+
assert.strictEqual(this.authentication._passwordVerifier, this.getService("VersionService"));
|
|
69
|
+
let params = new AuthenticationParameters({});
|
|
70
|
+
assert.strictEqual(params.identStore, "idents");
|
|
71
|
+
assert.strictEqual(params.userStore, "users");
|
|
72
|
+
assert.strictEqual(params.url, "/auth");
|
|
73
|
+
params = new AuthenticationParameters({
|
|
74
|
+
identStore: "id",
|
|
75
|
+
userStore: "us",
|
|
76
|
+
url: "/aaa"
|
|
104
77
|
});
|
|
78
|
+
assert.strictEqual(params.identStore, "id");
|
|
79
|
+
assert.strictEqual(params.userStore, "us");
|
|
80
|
+
assert.strictEqual(params.url, "/aaa");
|
|
81
|
+
this.authentication.getParameters().email = undefined;
|
|
82
|
+
assert.strictEqual(this.authentication.getUrl("./emails", ["POST"]), undefined);
|
|
83
|
+
let auth = new Authentication(this.webda, "auth", { email: { mailer: "plop" } });
|
|
84
|
+
assert.throws(() => auth.resolve(), /email authentication requires a Mailer service/);
|
|
105
85
|
}
|
|
106
|
-
register() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
115
|
-
});
|
|
116
|
-
this.events = 0;
|
|
117
|
-
// Should reject because it is login and not email
|
|
118
|
-
yield assert.rejects(() => executor.execute(ctx), res => res == 400);
|
|
119
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
120
|
-
login: "test@Webda.io",
|
|
121
|
-
password: "testtest"
|
|
122
|
-
}, {
|
|
123
|
-
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
124
|
-
});
|
|
125
|
-
// User unknown without register parameter
|
|
126
|
-
yield assert.rejects(() => executor.execute(ctx), res => res == 404);
|
|
127
|
-
// Set register to true
|
|
128
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
129
|
-
login: "test@Webda.io",
|
|
130
|
-
password: "testtest",
|
|
131
|
-
register: true
|
|
132
|
-
}, {
|
|
133
|
-
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
134
|
-
});
|
|
135
|
-
ctx.newSession();
|
|
136
|
-
yield executor.execute(ctx);
|
|
137
|
-
// Should not authentified as we need to check email
|
|
138
|
-
assert.strictEqual(ctx.getSession().identUsed, undefined);
|
|
139
|
-
// Email is sent
|
|
140
|
-
assert.strictEqual(this.mailer.sent.length, 1);
|
|
141
|
-
// Ident is created pending validation
|
|
142
|
-
let ident = yield this.identStore.get("test@webda.io_email");
|
|
143
|
-
assert.strictEqual(ident, undefined);
|
|
144
|
-
// Not registered as postValidation is not set
|
|
145
|
-
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
146
|
-
// With postValidation on the user will be create on first request
|
|
147
|
-
yield this.registerTest2(ctx);
|
|
148
|
-
assert.strictEqual(this.events, 2); // Register + Login
|
|
149
|
-
userId = ctx.getSession().userId;
|
|
150
|
-
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
151
|
-
assert.strictEqual(this.mailer.sent.length, 2);
|
|
152
|
-
let user = yield this.userStore.get(ctx.getSession().userId);
|
|
153
|
-
assert.notStrictEqual(user, undefined);
|
|
154
|
-
assert.notStrictEqual(user.getPassword(), undefined);
|
|
155
|
-
assert.strictEqual(user.locale, "en");
|
|
156
|
-
assert.strictEqual(user.test, "TESTOR"); // Verify that the listener on Register has done something
|
|
157
|
-
// Now logout
|
|
158
|
-
executor = this.getExecutor(ctx, "test.webda.io", "DELETE", "/auth");
|
|
159
|
-
yield executor.execute(ctx);
|
|
160
|
-
// Now validate first user
|
|
161
|
-
ctx.getExecutor().getParameters().email.postValidation = false;
|
|
162
|
-
assert.strictEqual(ctx.getSession().userId, undefined);
|
|
163
|
-
var match = this.mailer.sent[0].replacements.url.match(validationUrl);
|
|
164
|
-
assert.notStrictEqual(match, undefined);
|
|
165
|
-
assert.strictEqual(match[1], "test@webda.io");
|
|
166
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
167
|
-
token: match[2],
|
|
168
|
-
password: "testtest",
|
|
169
|
-
login: match[1],
|
|
170
|
-
register: true,
|
|
171
|
-
add: "plop"
|
|
172
|
-
});
|
|
173
|
-
yield executor.execute(ctx);
|
|
174
|
-
// Should create it with the dat provided
|
|
175
|
-
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
176
|
-
ident = yield this.identStore.get(ctx.getSession().identUsed);
|
|
177
|
-
// Email should be already validate
|
|
178
|
-
assert.notStrictEqual(ident._validation, undefined);
|
|
179
|
-
assert.strictEqual(this.mailer.sent.length, 2);
|
|
180
|
-
// Resend email
|
|
181
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/validate");
|
|
182
|
-
ctx.getSession().login(userId, "fake");
|
|
183
|
-
// Should be to soon to resend an email
|
|
184
|
-
yield assert.rejects(() => executor.execute(ctx), res => res == 429);
|
|
185
|
-
ident = yield this.identStore.get("test2@webda.io_email");
|
|
186
|
-
ident._lastValidationEmail = 10;
|
|
187
|
-
yield ident.save();
|
|
188
|
-
// Should be ok now to send an email
|
|
189
|
-
yield executor.execute(ctx);
|
|
190
|
-
assert.strictEqual(this.mailer.sent.length, 3);
|
|
191
|
-
// Validate email for test2 now
|
|
192
|
-
match = this.mailer.sent[1].replacements.url.match(validationUrl);
|
|
193
|
-
assert.notStrictEqual(match, undefined);
|
|
194
|
-
assert.strictEqual(match[1], "test2@webda.io");
|
|
195
|
-
ctx.newSession();
|
|
196
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2]);
|
|
197
|
-
yield executor.execute(ctx);
|
|
198
|
-
assert.strictEqual(ctx.statusCode, 302);
|
|
199
|
-
// Verify the skipEmailValidation parameter
|
|
200
|
-
this.events = 0;
|
|
201
|
-
ctx.newSession();
|
|
202
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
203
|
-
login: "test4@webda.io",
|
|
204
|
-
password: "testtest",
|
|
205
|
-
register: true
|
|
206
|
-
});
|
|
207
|
-
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
208
|
-
ctx.getExecutor().getParameters().email.skipEmailValidation = true;
|
|
209
|
-
yield executor.execute(ctx);
|
|
210
|
-
// No new email has been sent
|
|
211
|
-
assert.strictEqual(this.mailer.sent.length, 3);
|
|
212
|
-
assert.strictEqual(this.events, 2); // Register + Login
|
|
213
|
-
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
214
|
-
// Register while logged-in should fail with 410
|
|
215
|
-
yield assert.rejects(() => executor.execute(ctx), /410/);
|
|
86
|
+
async register() {
|
|
87
|
+
// By default service does not have postValidation enable
|
|
88
|
+
let ctx = await this.newContext();
|
|
89
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
90
|
+
email: "test@Webda.io",
|
|
91
|
+
password: "testtest"
|
|
92
|
+
}, {
|
|
93
|
+
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
216
94
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
};
|
|
226
|
-
let ctx = yield this.newContext(params);
|
|
227
|
-
let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {}, {
|
|
228
|
-
"Accept-Language": "en-GB"
|
|
229
|
-
});
|
|
230
|
-
// Activate post validation
|
|
231
|
-
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
232
|
-
yield assert.rejects(() => executor.execute(ctx), /400/);
|
|
233
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
234
|
-
login: "testBad@Webda.io",
|
|
235
|
-
register: true
|
|
236
|
-
}, {
|
|
237
|
-
"Accept-Language": "en-GB"
|
|
238
|
-
});
|
|
239
|
-
yield assert.rejects(() => executor.execute(ctx), /400/);
|
|
95
|
+
this.events = 0;
|
|
96
|
+
// Should reject because it is login and not email
|
|
97
|
+
await assert.rejects(() => executor.execute(ctx), res => res == 400);
|
|
98
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
99
|
+
login: "test@Webda.io",
|
|
100
|
+
password: "testtest"
|
|
101
|
+
}, {
|
|
102
|
+
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
240
103
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
104
|
+
// User unknown without register parameter
|
|
105
|
+
await assert.rejects(() => executor.execute(ctx), res => res == 404);
|
|
106
|
+
// Set register to true
|
|
107
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
108
|
+
login: "test@Webda.io",
|
|
109
|
+
password: "testtest",
|
|
110
|
+
register: true
|
|
111
|
+
}, {
|
|
112
|
+
"Accept-Language": "en-GB,en;q=0.9,fr;q=0.8"
|
|
113
|
+
});
|
|
114
|
+
ctx.newSession();
|
|
115
|
+
await executor.execute(ctx);
|
|
116
|
+
// Should not authentified as we need to check email
|
|
117
|
+
assert.strictEqual(ctx.getSession().identUsed, undefined);
|
|
118
|
+
// Email is sent
|
|
119
|
+
assert.strictEqual(this.mailer.sent.length, 1);
|
|
120
|
+
// Ident is created pending validation
|
|
121
|
+
let ident = await this.identStore.get("test@webda.io_email");
|
|
122
|
+
assert.strictEqual(ident, undefined);
|
|
123
|
+
// Not registered as postValidation is not set
|
|
124
|
+
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
125
|
+
// With postValidation on the user will be create on first request
|
|
126
|
+
await this.registerTest2(ctx);
|
|
127
|
+
assert.strictEqual(this.events, 2); // Register + Login
|
|
128
|
+
userId = ctx.getSession().userId;
|
|
129
|
+
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
130
|
+
assert.strictEqual(this.mailer.sent.length, 2);
|
|
131
|
+
let user = await this.userStore.get(ctx.getSession().userId);
|
|
132
|
+
assert.notStrictEqual(user, undefined);
|
|
133
|
+
assert.notStrictEqual(user.getPassword(), undefined);
|
|
134
|
+
assert.strictEqual(user.locale, "en");
|
|
135
|
+
assert.strictEqual(user.test, "TESTOR"); // Verify that the listener on Register has done something
|
|
136
|
+
// Now logout
|
|
137
|
+
executor = this.getExecutor(ctx, "test.webda.io", "DELETE", "/auth");
|
|
138
|
+
await executor.execute(ctx);
|
|
139
|
+
// Now validate first user
|
|
140
|
+
ctx.getExecutor().getParameters().email.postValidation = false;
|
|
141
|
+
assert.strictEqual(ctx.getSession().userId, undefined);
|
|
142
|
+
var match = this.mailer.sent[0].replacements.url.match(validationUrl);
|
|
143
|
+
assert.notStrictEqual(match, undefined);
|
|
144
|
+
assert.strictEqual(match[1], "test@webda.io");
|
|
145
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
146
|
+
token: match[2],
|
|
147
|
+
password: "testtest",
|
|
148
|
+
login: match[1],
|
|
149
|
+
register: true,
|
|
150
|
+
add: "plop"
|
|
263
151
|
});
|
|
152
|
+
await executor.execute(ctx);
|
|
153
|
+
// Should create it with the dat provided
|
|
154
|
+
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
155
|
+
ident = await this.identStore.get(ctx.getSession().identUsed);
|
|
156
|
+
// Email should be already validate
|
|
157
|
+
assert.notStrictEqual(ident._validation, undefined);
|
|
158
|
+
assert.strictEqual(this.mailer.sent.length, 2);
|
|
159
|
+
// Resend email
|
|
160
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/validate");
|
|
161
|
+
ctx.getSession().login(userId, "fake");
|
|
162
|
+
// Should be to soon to resend an email
|
|
163
|
+
await assert.rejects(() => executor.execute(ctx), res => res == 429);
|
|
164
|
+
ident = await this.identStore.get("test2@webda.io_email");
|
|
165
|
+
ident._lastValidationEmail = 10;
|
|
166
|
+
await ident.save();
|
|
167
|
+
// Should be ok now to send an email
|
|
168
|
+
await executor.execute(ctx);
|
|
169
|
+
assert.strictEqual(this.mailer.sent.length, 3);
|
|
170
|
+
// Validate email for test2 now
|
|
171
|
+
match = this.mailer.sent[1].replacements.url.match(validationUrl);
|
|
172
|
+
assert.notStrictEqual(match, undefined);
|
|
173
|
+
assert.strictEqual(match[1], "test2@webda.io");
|
|
174
|
+
ctx.newSession();
|
|
175
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2]);
|
|
176
|
+
await executor.execute(ctx);
|
|
177
|
+
assert.strictEqual(ctx.statusCode, 302);
|
|
178
|
+
// Verify the skipEmailValidation parameter
|
|
179
|
+
this.events = 0;
|
|
180
|
+
ctx.newSession();
|
|
181
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
182
|
+
login: "test4@webda.io",
|
|
183
|
+
password: "testtest",
|
|
184
|
+
register: true
|
|
185
|
+
});
|
|
186
|
+
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
187
|
+
ctx.getExecutor().getParameters().email.skipEmailValidation = true;
|
|
188
|
+
await executor.execute(ctx);
|
|
189
|
+
// No new email has been sent
|
|
190
|
+
assert.strictEqual(this.mailer.sent.length, 3);
|
|
191
|
+
assert.strictEqual(this.events, 2); // Register + Login
|
|
192
|
+
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
193
|
+
// Register while logged-in should fail with 410
|
|
194
|
+
await assert.rejects(() => executor.execute(ctx), /410/);
|
|
264
195
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
yield executor.execute(ctx);
|
|
285
|
-
assert.strictEqual(this.events, 1); // Login
|
|
286
|
-
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
287
|
-
// Verify ident type
|
|
288
|
-
let ident = yield this.identStore.get(ctx.getSession().identUsed);
|
|
289
|
-
assert.strictEqual(ident._type, "email");
|
|
290
|
-
ctx.getHttpContext().setBody({
|
|
291
|
-
login: "test2@webda.io",
|
|
292
|
-
password: "bouzouf"
|
|
293
|
-
});
|
|
294
|
-
ctx.reinit();
|
|
295
|
-
ctx.newSession();
|
|
296
|
-
yield assert.rejects(() => executor.execute(ctx), res => res == 403);
|
|
297
|
-
assert.strictEqual(ctx.getSession().userId, undefined);
|
|
298
|
-
assert.strictEqual(this.events, 1);
|
|
299
|
-
assert.strictEqual(yield (yield this.identStore.get("test2@webda.io_email"))._failedLogin, 1);
|
|
300
|
-
// Re log to reinit failedLogin
|
|
301
|
-
ctx.getHttpContext().setBody({
|
|
302
|
-
login: "test2@webda.io",
|
|
303
|
-
password: "testtest"
|
|
304
|
-
});
|
|
305
|
-
ctx.reinit();
|
|
306
|
-
ctx.newSession();
|
|
307
|
-
yield executor.execute(ctx);
|
|
308
|
-
assert.strictEqual(yield (yield this.identStore.get("test2@webda.io_email"))._failedLogin, 0);
|
|
196
|
+
async registerBadPassword() {
|
|
197
|
+
// By default a password of 8 is needed
|
|
198
|
+
var params = {
|
|
199
|
+
login: "testBad@Webda.io",
|
|
200
|
+
password: "test",
|
|
201
|
+
register: true
|
|
202
|
+
};
|
|
203
|
+
let ctx = await this.newContext(params);
|
|
204
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {}, {
|
|
205
|
+
"Accept-Language": "en-GB"
|
|
206
|
+
});
|
|
207
|
+
// Activate post validation
|
|
208
|
+
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
209
|
+
await assert.rejects(() => executor.execute(ctx), /400/);
|
|
210
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
211
|
+
login: "testBad@Webda.io",
|
|
212
|
+
register: true
|
|
213
|
+
}, {
|
|
214
|
+
"Accept-Language": "en-GB"
|
|
309
215
|
});
|
|
216
|
+
await assert.rejects(() => executor.execute(ctx), /400/);
|
|
310
217
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
|
|
321
|
-
login: userId,
|
|
322
|
-
password: "retesttest"
|
|
323
|
-
});
|
|
324
|
-
tokenInfo = yield this.authentication.getPasswordRecoveryInfos(userId, -10);
|
|
325
|
-
yield assert.rejects(() => executor.execute(ctx), /400/);
|
|
326
|
-
// Missing the body
|
|
327
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
|
|
328
|
-
token: tokenInfo.token,
|
|
329
|
-
expire: 123,
|
|
330
|
-
password: "retesttest",
|
|
331
|
-
login: userId
|
|
332
|
-
});
|
|
333
|
-
yield assert.rejects(() => executor.execute(ctx), /403/);
|
|
334
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
|
|
335
|
-
token: tokenInfo.token,
|
|
336
|
-
expire: tokenInfo.expire,
|
|
337
|
-
password: "retesttest",
|
|
338
|
-
login: "unknown"
|
|
339
|
-
});
|
|
340
|
-
yield assert.rejects(() => executor.execute(ctx), /403/);
|
|
341
|
-
// Missing the body
|
|
342
|
-
ctx.getHttpContext().setBody({
|
|
343
|
-
token: tokenInfo.token,
|
|
344
|
-
expire: tokenInfo.expire,
|
|
345
|
-
password: "retesttest",
|
|
346
|
-
login: userId
|
|
347
|
-
});
|
|
348
|
-
ctx.reinit();
|
|
349
|
-
yield assert.rejects(() => executor.execute(ctx), /410/);
|
|
350
|
-
tokenInfo = yield this.authentication.getPasswordRecoveryInfos(userId);
|
|
351
|
-
// Missing the body
|
|
352
|
-
ctx.getHttpContext().setBody(Object.assign(Object.assign({}, tokenInfo), { login: userId, password: "a" }));
|
|
353
|
-
ctx.reinit();
|
|
354
|
-
yield assert.rejects(() => executor.execute(ctx), /400/);
|
|
355
|
-
// @ts-ignore
|
|
356
|
-
this.authentication._passwordVerifier = {
|
|
357
|
-
validate: (p) => __awaiter(this, void 0, void 0, function* () {
|
|
358
|
-
return p === "retesttest";
|
|
359
|
-
})
|
|
360
|
-
};
|
|
361
|
-
ctx.getHttpContext().setBody(Object.assign(Object.assign({}, tokenInfo), { login: userId, password: "anyotherpass" }));
|
|
362
|
-
ctx.reinit();
|
|
363
|
-
yield assert.rejects(() => executor.execute(ctx), /400/);
|
|
364
|
-
ctx.getHttpContext().setBody(Object.assign(Object.assign({}, tokenInfo), { login: userId, password: "retesttest" }));
|
|
365
|
-
ctx.reinit();
|
|
366
|
-
yield executor.execute(ctx);
|
|
367
|
-
// Should be update with password retest now
|
|
368
|
-
ctx.newSession();
|
|
369
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
370
|
-
login: "test2@webda.io",
|
|
371
|
-
password: "retesttest"
|
|
372
|
-
});
|
|
373
|
-
yield executor.execute(ctx);
|
|
374
|
-
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
375
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/recover");
|
|
376
|
-
yield executor.execute(ctx);
|
|
377
|
-
assert.strictEqual(this.mailer.sent.length, 1);
|
|
378
|
-
assert.strictEqual(this.mailer.sent[0].to, "test2@webda.io");
|
|
379
|
-
assert.notStrictEqual(this.mailer.sent[0].replacements.infos, undefined);
|
|
380
|
-
assert.notStrictEqual(this.mailer.sent[0].replacements.infos.expire, undefined);
|
|
381
|
-
assert.notStrictEqual(this.mailer.sent[0].replacements.infos.token, undefined);
|
|
382
|
-
yield assert.rejects(() => executor.execute(ctx), /429/);
|
|
383
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test66@webda.io/recover");
|
|
384
|
-
yield assert.rejects(() => executor.execute(ctx), /404/);
|
|
218
|
+
async me() {
|
|
219
|
+
let ctx = await this.newContext();
|
|
220
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/me");
|
|
221
|
+
await assert.rejects(() => executor.execute(ctx), res => res == 404);
|
|
222
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
223
|
+
login: "test5@webda.io",
|
|
224
|
+
password: "testtest",
|
|
225
|
+
register: true,
|
|
226
|
+
plop: "yep"
|
|
385
227
|
});
|
|
228
|
+
ctx.getExecutor().getParameters().email.postValidation = true;
|
|
229
|
+
await executor.execute(ctx);
|
|
230
|
+
// Get me on known user
|
|
231
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/me");
|
|
232
|
+
await executor.execute(ctx);
|
|
233
|
+
let user = JSON.parse(ctx.getResponseBody());
|
|
234
|
+
assert.strictEqual(user.plop, "yep");
|
|
235
|
+
assert.strictEqual(user.register, undefined);
|
|
236
|
+
assert.strictEqual(user.locale, "es-ES");
|
|
237
|
+
assert.notStrictEqual(user, undefined);
|
|
386
238
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
var match = this.mailer.sent[0].replacements.url.match(validationUrl);
|
|
403
|
-
assert.notStrictEqual(match, undefined);
|
|
404
|
-
assert.strictEqual(match[1], "newtest@webda.io");
|
|
405
|
-
// Send another one on newtest2
|
|
406
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest2@webda.io/validate", {
|
|
407
|
-
login: "test2@webda.io",
|
|
408
|
-
password: "retesttest"
|
|
409
|
-
});
|
|
410
|
-
yield executor.execute(ctx);
|
|
411
|
-
var match2 = this.mailer.sent[1].replacements.url.match(validationUrl);
|
|
412
|
-
assert.notStrictEqual(match2, undefined);
|
|
413
|
-
assert.strictEqual(match2[1], "newtest2@webda.io");
|
|
414
|
-
// Try to validate with wrong email
|
|
415
|
-
ctx.getSession().userId = "anotheruser";
|
|
416
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&user=" + match[4]);
|
|
417
|
-
yield assert.rejects(() => executor.execute(ctx), /400/);
|
|
418
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
|
|
419
|
-
yield executor.execute(ctx);
|
|
420
|
-
assert.strictEqual(ctx.statusCode, 302);
|
|
421
|
-
assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badUser");
|
|
422
|
-
// Right user
|
|
423
|
-
ctx.getSession().userId = userId;
|
|
424
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=bouzouf" + "&user=" + match[4]);
|
|
425
|
-
yield executor.execute(ctx);
|
|
426
|
-
assert.strictEqual(ctx.statusCode, 302);
|
|
427
|
-
assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badToken");
|
|
428
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
|
|
429
|
-
yield executor.execute(ctx);
|
|
430
|
-
assert.strictEqual(ctx.statusCode, 302);
|
|
431
|
-
assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
|
|
432
|
-
// Check ident is added to the user
|
|
433
|
-
ident = yield this.identStore.get("newtest@webda.io_email");
|
|
434
|
-
assert.notStrictEqual(ident._validation, undefined);
|
|
435
|
-
// Verify exception if same user try to revalidate
|
|
436
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
|
|
437
|
-
yield assert.rejects(() => executor.execute(ctx), /412/);
|
|
438
|
-
// Verify exception if different user try to validate
|
|
439
|
-
ctx.getSession().userId = "bouzouf";
|
|
440
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
|
|
441
|
-
yield assert.rejects(() => executor.execute(ctx), /409/);
|
|
442
|
-
// Check register on validated email does not work
|
|
443
|
-
ctx.newSession();
|
|
444
|
-
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
445
|
-
login: "newtest@webda.io",
|
|
446
|
-
password: "testtest",
|
|
447
|
-
register: true
|
|
448
|
-
});
|
|
449
|
-
yield assert.rejects(() => executor.execute(ctx), /409/);
|
|
450
|
-
// Validation with no user
|
|
451
|
-
ctx.newSession();
|
|
452
|
-
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match2[1] + "&token=" + match2[2] + "&user=" + match2[4]);
|
|
453
|
-
yield executor.execute(ctx);
|
|
454
|
-
assert.strictEqual(ctx.statusCode, 302);
|
|
455
|
-
assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
|
|
456
|
-
yield this.identStore.delete("newtest2@webda.io_email", undefined, undefined, true);
|
|
457
|
-
yield executor.execute(ctx);
|
|
458
|
-
assert.ok(yield this.identStore.exists("newtest2@webda.io_email"));
|
|
239
|
+
async login() {
|
|
240
|
+
let ctx = await this.newContext();
|
|
241
|
+
await this.registerTest2(ctx);
|
|
242
|
+
ctx.newSession();
|
|
243
|
+
this.events = 0;
|
|
244
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
245
|
+
login: "test3@webda.io",
|
|
246
|
+
password: "testtest"
|
|
247
|
+
});
|
|
248
|
+
await assert.rejects(() => executor.execute(ctx), res => res == 404);
|
|
249
|
+
assert.strictEqual(ctx.getSession().userId, undefined);
|
|
250
|
+
// As it has not been validate
|
|
251
|
+
ctx.getHttpContext().setBody({
|
|
252
|
+
login: "test2@webda.io",
|
|
253
|
+
password: "testtest"
|
|
459
254
|
});
|
|
255
|
+
ctx.reinit();
|
|
256
|
+
ctx.newSession();
|
|
257
|
+
await executor.execute(ctx);
|
|
258
|
+
assert.strictEqual(this.events, 1); // Login
|
|
259
|
+
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
260
|
+
// Verify ident type
|
|
261
|
+
let ident = await this.identStore.get(ctx.getSession().identUsed);
|
|
262
|
+
assert.strictEqual(ident._type, "email");
|
|
263
|
+
ctx.getHttpContext().setBody({
|
|
264
|
+
login: "test2@webda.io",
|
|
265
|
+
password: "bouzouf"
|
|
266
|
+
});
|
|
267
|
+
ctx.reinit();
|
|
268
|
+
ctx.newSession();
|
|
269
|
+
await assert.rejects(() => executor.execute(ctx), res => res == 403);
|
|
270
|
+
assert.strictEqual(ctx.getSession().userId, undefined);
|
|
271
|
+
assert.strictEqual(this.events, 1);
|
|
272
|
+
assert.strictEqual(await (await this.identStore.get("test2@webda.io_email"))._failedLogin, 1);
|
|
273
|
+
// Re log to reinit failedLogin
|
|
274
|
+
ctx.getHttpContext().setBody({
|
|
275
|
+
login: "test2@webda.io",
|
|
276
|
+
password: "testtest"
|
|
277
|
+
});
|
|
278
|
+
ctx.reinit();
|
|
279
|
+
ctx.newSession();
|
|
280
|
+
await executor.execute(ctx);
|
|
281
|
+
assert.strictEqual(await (await this.identStore.get("test2@webda.io_email"))._failedLogin, 0);
|
|
460
282
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
283
|
+
async testPasswordRecovery() {
|
|
284
|
+
let tokenInfo;
|
|
285
|
+
let ctx = await this.newContext();
|
|
286
|
+
await this.registerTest2(ctx);
|
|
287
|
+
this.mailer.sent = [];
|
|
288
|
+
this.events = 0;
|
|
289
|
+
userId = ctx.getSession().userId;
|
|
290
|
+
ctx.newSession();
|
|
291
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
|
|
292
|
+
login: userId,
|
|
293
|
+
password: "retesttest"
|
|
294
|
+
});
|
|
295
|
+
tokenInfo = await this.authentication.getPasswordRecoveryInfos(userId, -10);
|
|
296
|
+
await assert.rejects(() => executor.execute(ctx), /400/);
|
|
297
|
+
// Missing the body
|
|
298
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
|
|
299
|
+
token: tokenInfo.token,
|
|
300
|
+
expire: 123,
|
|
301
|
+
password: "retesttest",
|
|
302
|
+
login: userId
|
|
303
|
+
});
|
|
304
|
+
await assert.rejects(() => executor.execute(ctx), /403/);
|
|
305
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email/passwordRecovery", {
|
|
306
|
+
token: tokenInfo.token,
|
|
307
|
+
expire: tokenInfo.expire,
|
|
308
|
+
password: "retesttest",
|
|
309
|
+
login: "unknown"
|
|
310
|
+
});
|
|
311
|
+
await assert.rejects(() => executor.execute(ctx), /403/);
|
|
312
|
+
// Missing the body
|
|
313
|
+
ctx.getHttpContext().setBody({
|
|
314
|
+
token: tokenInfo.token,
|
|
315
|
+
expire: tokenInfo.expire,
|
|
316
|
+
password: "retesttest",
|
|
317
|
+
login: userId
|
|
465
318
|
});
|
|
319
|
+
ctx.reinit();
|
|
320
|
+
await assert.rejects(() => executor.execute(ctx), /410/);
|
|
321
|
+
tokenInfo = await this.authentication.getPasswordRecoveryInfos(userId);
|
|
322
|
+
// Missing the body
|
|
323
|
+
ctx.getHttpContext().setBody({ ...tokenInfo, login: userId, password: "a" });
|
|
324
|
+
ctx.reinit();
|
|
325
|
+
await assert.rejects(() => executor.execute(ctx), /400/);
|
|
326
|
+
// @ts-ignore
|
|
327
|
+
this.authentication._passwordVerifier = {
|
|
328
|
+
validate: async (p) => {
|
|
329
|
+
return p === "retesttest";
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
ctx.getHttpContext().setBody({ ...tokenInfo, login: userId, password: "anyotherpass" });
|
|
333
|
+
ctx.reinit();
|
|
334
|
+
await assert.rejects(() => executor.execute(ctx), /400/);
|
|
335
|
+
ctx.getHttpContext().setBody({ ...tokenInfo, login: userId, password: "retesttest" });
|
|
336
|
+
ctx.reinit();
|
|
337
|
+
await executor.execute(ctx);
|
|
338
|
+
// Should be update with password retest now
|
|
339
|
+
ctx.newSession();
|
|
340
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
341
|
+
login: "test2@webda.io",
|
|
342
|
+
password: "retesttest"
|
|
343
|
+
});
|
|
344
|
+
await executor.execute(ctx);
|
|
345
|
+
assert.notStrictEqual(ctx.getSession().userId, undefined);
|
|
346
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test2@webda.io/recover");
|
|
347
|
+
await executor.execute(ctx);
|
|
348
|
+
assert.strictEqual(this.mailer.sent.length, 1);
|
|
349
|
+
assert.strictEqual(this.mailer.sent[0].to, "test2@webda.io");
|
|
350
|
+
assert.notStrictEqual(this.mailer.sent[0].replacements.infos, undefined);
|
|
351
|
+
assert.notStrictEqual(this.mailer.sent[0].replacements.infos.expire, undefined);
|
|
352
|
+
assert.notStrictEqual(this.mailer.sent[0].replacements.infos.token, undefined);
|
|
353
|
+
await assert.rejects(() => executor.execute(ctx), /429/);
|
|
354
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/test66@webda.io/recover");
|
|
355
|
+
await assert.rejects(() => executor.execute(ctx), /404/);
|
|
466
356
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
357
|
+
async addEmailToAccount() {
|
|
358
|
+
// Log in as test2
|
|
359
|
+
let ctx = await this.newContext();
|
|
360
|
+
await this.registerTest2(ctx);
|
|
361
|
+
this.mailer.sent = [];
|
|
362
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate", {
|
|
363
|
+
login: "test2@webda.io",
|
|
364
|
+
password: "retesttest"
|
|
365
|
+
});
|
|
366
|
+
await executor.execute(ctx);
|
|
367
|
+
let ident = await this.identStore.get("newtest@webda.io_email");
|
|
368
|
+
assert.notStrictEqual(ident, undefined);
|
|
369
|
+
assert.strictEqual(ident._validation, undefined);
|
|
370
|
+
userId = ctx.getCurrentUserId();
|
|
371
|
+
var match = this.mailer.sent[0].replacements.url.match(validationUrl);
|
|
372
|
+
assert.notStrictEqual(match, undefined);
|
|
373
|
+
assert.strictEqual(match[1], "newtest@webda.io");
|
|
374
|
+
// Send another one on newtest2
|
|
375
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest2@webda.io/validate", {
|
|
376
|
+
login: "test2@webda.io",
|
|
377
|
+
password: "retesttest"
|
|
378
|
+
});
|
|
379
|
+
await executor.execute(ctx);
|
|
380
|
+
var match2 = this.mailer.sent[1].replacements.url.match(validationUrl);
|
|
381
|
+
assert.notStrictEqual(match2, undefined);
|
|
382
|
+
assert.strictEqual(match2[1], "newtest2@webda.io");
|
|
383
|
+
// Try to validate with wrong email
|
|
384
|
+
ctx.getSession().userId = "anotheruser";
|
|
385
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&user=" + match[4]);
|
|
386
|
+
await assert.rejects(() => executor.execute(ctx), /400/);
|
|
387
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
|
|
388
|
+
await executor.execute(ctx);
|
|
389
|
+
assert.strictEqual(ctx.statusCode, 302);
|
|
390
|
+
assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badUser");
|
|
391
|
+
// Right user
|
|
392
|
+
ctx.getSession().userId = userId;
|
|
393
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=bouzouf" + "&user=" + match[4]);
|
|
394
|
+
await executor.execute(ctx);
|
|
395
|
+
assert.strictEqual(ctx.statusCode, 302);
|
|
396
|
+
assert.strictEqual(ctx.getResponseHeaders().Location, "/login-error?reason=badToken");
|
|
397
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match[1] + "&token=" + match[2] + "&user=" + match[4]);
|
|
398
|
+
await executor.execute(ctx);
|
|
399
|
+
assert.strictEqual(ctx.statusCode, 302);
|
|
400
|
+
assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
|
|
401
|
+
// Check ident is added to the user
|
|
402
|
+
ident = await this.identStore.get("newtest@webda.io_email");
|
|
403
|
+
assert.notStrictEqual(ident._validation, undefined);
|
|
404
|
+
// Verify exception if same user try to revalidate
|
|
405
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
|
|
406
|
+
await assert.rejects(() => executor.execute(ctx), /412/);
|
|
407
|
+
// Verify exception if different user try to validate
|
|
408
|
+
ctx.getSession().userId = "bouzouf";
|
|
409
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/newtest@webda.io/validate");
|
|
410
|
+
await assert.rejects(() => executor.execute(ctx), /409/);
|
|
411
|
+
// Check register on validated email does not work
|
|
412
|
+
ctx.newSession();
|
|
413
|
+
executor = this.getExecutor(ctx, "test.webda.io", "POST", "/auth/email", {
|
|
414
|
+
login: "newtest@webda.io",
|
|
415
|
+
password: "testtest",
|
|
416
|
+
register: true
|
|
475
417
|
});
|
|
418
|
+
await assert.rejects(() => executor.execute(ctx), /409/);
|
|
419
|
+
// Validation with no user
|
|
420
|
+
ctx.newSession();
|
|
421
|
+
executor = this.getExecutor(ctx, "test.webda.io", "GET", "/auth/email/callback?email=" + match2[1] + "&token=" + match2[2] + "&user=" + match2[4]);
|
|
422
|
+
await executor.execute(ctx);
|
|
423
|
+
assert.strictEqual(ctx.statusCode, 302);
|
|
424
|
+
assert.strictEqual(ctx.getResponseHeaders().Location, "https://webda.io/user.html?validation=email");
|
|
425
|
+
await this.identStore.delete("newtest2@webda.io_email", undefined, undefined, true);
|
|
426
|
+
await executor.execute(ctx);
|
|
427
|
+
assert.ok(await this.identStore.exists("newtest2@webda.io_email"));
|
|
428
|
+
}
|
|
429
|
+
async multipleCreate() {
|
|
430
|
+
await this.authentication.createUserWithIdent("email", "test@test.com");
|
|
431
|
+
await assert.rejects(() => this.authentication.createUserWithIdent("email", "test@test.com"), /Ident is already known/);
|
|
432
|
+
}
|
|
433
|
+
async redirectEmailRegister() {
|
|
434
|
+
let token = await this.authentication.generateEmailValidationToken(undefined, "test@webda.io");
|
|
435
|
+
let ctx = await this.newContext();
|
|
436
|
+
let executor = this.getExecutor(ctx, "test.webda.io", "GET", `/auth/email/callback?email=test@webda.io&token=${token}`);
|
|
437
|
+
await executor.execute(ctx);
|
|
438
|
+
assert.strictEqual(ctx.statusCode, 302);
|
|
439
|
+
assert.strictEqual(ctx.getResponseHeaders().Location, `https://webda.io/register.html?token=${token}&email=test@webda.io`);
|
|
476
440
|
}
|
|
477
441
|
};
|
|
478
442
|
__decorate([
|
|
479
|
-
|
|
443
|
+
test
|
|
480
444
|
], AuthenticationTest.prototype, "cov", null);
|
|
481
445
|
__decorate([
|
|
482
|
-
|
|
446
|
+
test("register")
|
|
483
447
|
], AuthenticationTest.prototype, "register", null);
|
|
484
448
|
__decorate([
|
|
485
|
-
|
|
449
|
+
test("register - bad password")
|
|
486
450
|
], AuthenticationTest.prototype, "registerBadPassword", null);
|
|
487
451
|
__decorate([
|
|
488
|
-
|
|
452
|
+
test("/me")
|
|
489
453
|
], AuthenticationTest.prototype, "me", null);
|
|
490
454
|
__decorate([
|
|
491
|
-
|
|
455
|
+
test("login")
|
|
492
456
|
], AuthenticationTest.prototype, "login", null);
|
|
493
457
|
__decorate([
|
|
494
|
-
|
|
458
|
+
test("passwordRecovery")
|
|
495
459
|
], AuthenticationTest.prototype, "testPasswordRecovery", null);
|
|
496
460
|
__decorate([
|
|
497
|
-
|
|
461
|
+
test("add email to existing account")
|
|
498
462
|
], AuthenticationTest.prototype, "addEmailToAccount", null);
|
|
499
463
|
__decorate([
|
|
500
|
-
|
|
464
|
+
test
|
|
501
465
|
], AuthenticationTest.prototype, "multipleCreate", null);
|
|
502
466
|
__decorate([
|
|
503
|
-
|
|
467
|
+
test
|
|
504
468
|
], AuthenticationTest.prototype, "redirectEmailRegister", null);
|
|
505
469
|
AuthenticationTest = __decorate([
|
|
506
|
-
|
|
470
|
+
suite
|
|
507
471
|
], AuthenticationTest);
|
|
508
472
|
//# sourceMappingURL=authentication.spec.js.map
|