@proteinjs/user-server 1.22.4 → 1.23.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/CHANGELOG.md +18 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/routes/executePasswordReset.js +3 -1
- package/dist/src/routes/executePasswordReset.js.map +1 -1
- package/dist/src/routes/initiatePasswordReset.d.ts.map +1 -1
- package/dist/src/routes/initiatePasswordReset.js +14 -12
- package/dist/src/routes/initiatePasswordReset.js.map +1 -1
- package/dist/src/routes/login.js +18 -14
- package/dist/src/routes/login.js.map +1 -1
- package/dist/src/throttle/MemoryThrottleWindowStore.d.ts +28 -0
- package/dist/src/throttle/MemoryThrottleWindowStore.d.ts.map +1 -0
- package/dist/src/throttle/MemoryThrottleWindowStore.js +108 -0
- package/dist/src/throttle/MemoryThrottleWindowStore.js.map +1 -0
- package/dist/src/throttle/PasswordResetThrottle.d.ts +9 -8
- package/dist/src/throttle/PasswordResetThrottle.d.ts.map +1 -1
- package/dist/src/throttle/PasswordResetThrottle.js +63 -15
- package/dist/src/throttle/PasswordResetThrottle.js.map +1 -1
- package/dist/src/throttle/SignInThrottle.d.ts +21 -15
- package/dist/src/throttle/SignInThrottle.d.ts.map +1 -1
- package/dist/src/throttle/SignInThrottle.js +94 -25
- package/dist/src/throttle/SignInThrottle.js.map +1 -1
- package/dist/src/throttle/SlidingWindow.d.ts +6 -4
- package/dist/src/throttle/SlidingWindow.d.ts.map +1 -1
- package/dist/src/throttle/SlidingWindow.js +6 -4
- package/dist/src/throttle/SlidingWindow.js.map +1 -1
- package/dist/src/throttle/StoredWindow.d.ts +59 -0
- package/dist/src/throttle/StoredWindow.d.ts.map +1 -0
- package/dist/src/throttle/StoredWindow.js +209 -0
- package/dist/src/throttle/StoredWindow.js.map +1 -0
- package/dist/src/throttle/ThrottleWindowStore.d.ts +38 -0
- package/dist/src/throttle/ThrottleWindowStore.d.ts.map +1 -0
- package/dist/src/throttle/ThrottleWindowStore.js +3 -0
- package/dist/src/throttle/ThrottleWindowStore.js.map +1 -0
- package/dist/test/MemoryThrottleWindowStore.test.d.ts +2 -0
- package/dist/test/MemoryThrottleWindowStore.test.d.ts.map +1 -0
- package/dist/test/MemoryThrottleWindowStore.test.js +210 -0
- package/dist/test/MemoryThrottleWindowStore.test.js.map +1 -0
- package/dist/test/SharedThrottleWindows.integration.test.d.ts +2 -0
- package/dist/test/SharedThrottleWindows.integration.test.d.ts.map +1 -0
- package/dist/test/SharedThrottleWindows.integration.test.js +756 -0
- package/dist/test/SharedThrottleWindows.integration.test.js.map +1 -0
- package/dist/test/UserServerTestEnvironment.d.ts.map +1 -1
- package/dist/test/UserServerTestEnvironment.js +3 -0
- package/dist/test/UserServerTestEnvironment.js.map +1 -1
- package/generated/index.ts +1 -1
- package/index.ts +4 -0
- package/package.json +5 -5
- package/src/routes/executePasswordReset.ts +1 -1
- package/src/routes/initiatePasswordReset.ts +2 -1
- package/src/routes/login.ts +2 -2
- package/src/throttle/MemoryThrottleWindowStore.ts +60 -0
- package/src/throttle/PasswordResetThrottle.ts +14 -11
- package/src/throttle/SignInThrottle.ts +27 -19
- package/src/throttle/SlidingWindow.ts +6 -4
- package/src/throttle/StoredWindow.ts +132 -0
- package/src/throttle/ThrottleWindowStore.ts +41 -0
- package/test/MemoryThrottleWindowStore.test.ts +74 -0
- package/test/SharedThrottleWindows.integration.test.ts +407 -0
- package/test/UserServerTestEnvironment.ts +3 -0
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
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
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
var db_1 = require("@proteinjs/db");
|
|
49
|
+
var email_server_1 = require("@proteinjs/email-server");
|
|
50
|
+
var reflection_1 = require("@proteinjs/reflection");
|
|
51
|
+
var user_1 = require("@proteinjs/user");
|
|
52
|
+
var util_node_1 = require("@proteinjs/util-node");
|
|
53
|
+
var login_1 = require("../src/routes/login");
|
|
54
|
+
var initiatePasswordReset_1 = require("../src/routes/initiatePasswordReset");
|
|
55
|
+
var PasswordHasher_1 = require("../src/authentication/PasswordHasher");
|
|
56
|
+
var PasswordResetToken_1 = require("../src/authentication/PasswordResetToken");
|
|
57
|
+
var RequestDigests_1 = require("../src/throttle/RequestDigests");
|
|
58
|
+
var SignInThrottle_1 = require("../src/throttle/SignInThrottle");
|
|
59
|
+
var PasswordResetThrottle_1 = require("../src/throttle/PasswordResetThrottle");
|
|
60
|
+
var passportSessionHarness_1 = require("./passportSessionHarness");
|
|
61
|
+
var UserServerTestEnvironment_1 = require("./UserServerTestEnvironment");
|
|
62
|
+
var LogCapture_1 = require("./LogCapture");
|
|
63
|
+
var testEnv = new UserServerTestEnvironment_1.UserServerTestEnvironment();
|
|
64
|
+
/**
|
|
65
|
+
* The windows keyed on something other than the device — the sign-in door's per-account window
|
|
66
|
+
* and the reset door's per-address window — counted in ONE store that every server process shares
|
|
67
|
+
* (a store registered through `@proteinjs/user-server/DefaultThrottleWindowStoreFactory`), so the
|
|
68
|
+
* count is one across replicas and survives a deploy. Against the Spanner emulator, outcomes only:
|
|
69
|
+
* - two "pods" (the door in this process, and a second process's throttle) count as one: ten wrong
|
|
70
|
+
* passwords through the door, and the second pod refuses the eleventh;
|
|
71
|
+
* - a deploy (a new process with a new store instance over the same backing store) sees the old
|
|
72
|
+
* count, and the window's expiry (its TTL — equal to the window: 15 minutes per account, an hour
|
|
73
|
+
* per reset address) clears it;
|
|
74
|
+
* - a success on one pod clears the account's window for every pod;
|
|
75
|
+
* - the reset door's per-address window is one count across pods;
|
|
76
|
+
* - the store failing or stalling is the NAMED FALLBACK: the door counts in this process's memory
|
|
77
|
+
* window until the store answers again — ten wrong passwords are judged wrong and the eleventh is
|
|
78
|
+
* refused, the right password signs in, a stalled store is judged within its deadline, the reset
|
|
79
|
+
* door still mints and mails — and the outage is one WARN line per window saying so, once however
|
|
80
|
+
* many tries meet it, and one INFO line when the store answers again;
|
|
81
|
+
* - an outage's boundary continues from this process's own count (every try the store answered was
|
|
82
|
+
* counted in memory too): nine wrong in the store, then the store fails, and the eleventh is
|
|
83
|
+
* refused; on recovery the store counts from what it holds (the outage's tries were this
|
|
84
|
+
* process's own and never reach it).
|
|
85
|
+
*
|
|
86
|
+
* The backing store here is a stand-in for the shared one (a map every instance reads and writes,
|
|
87
|
+
* the way every process reads and writes one Redis), with its own clock for the TTL.
|
|
88
|
+
*/
|
|
89
|
+
var WRONG = 'User name or password incorrect';
|
|
90
|
+
var THROTTLED = 'Too many attempts. Try again in a few minutes.';
|
|
91
|
+
var RIGHT_PASSWORD = 'the right horse battery';
|
|
92
|
+
var MINUTE = 60 * 1000;
|
|
93
|
+
var FACTORY = '@proteinjs/user-server/DefaultThrottleWindowStoreFactory';
|
|
94
|
+
/** Every instance reads and writes one backing map: a new instance is a new process on the same store. */
|
|
95
|
+
var SharedBackingStore = /** @class */ (function () {
|
|
96
|
+
function SharedBackingStore() {
|
|
97
|
+
}
|
|
98
|
+
SharedBackingStore.prototype.increment = function (key, windowMs) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
+
var live, entry;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
live = this.live(key);
|
|
103
|
+
entry = live !== null && live !== void 0 ? live : { count: 0, expiresAt: SharedBackingStore.now() + windowMs };
|
|
104
|
+
if (!live) {
|
|
105
|
+
SharedBackingStore.windows.set(key, windowMs);
|
|
106
|
+
}
|
|
107
|
+
entry.count++;
|
|
108
|
+
SharedBackingStore.backing.set(key, entry);
|
|
109
|
+
return [2 /*return*/, entry.count];
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
SharedBackingStore.prototype.read = function (key) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
return __generator(this, function (_c) {
|
|
117
|
+
return [2 /*return*/, (_b = (_a = this.live(key)) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0];
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
SharedBackingStore.prototype.clear = function (key) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
return __generator(this, function (_a) {
|
|
124
|
+
SharedBackingStore.backing.delete(key);
|
|
125
|
+
return [2 /*return*/];
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
SharedBackingStore.prototype.live = function (key) {
|
|
130
|
+
var entry = SharedBackingStore.backing.get(key);
|
|
131
|
+
if (entry && entry.expiresAt <= SharedBackingStore.now()) {
|
|
132
|
+
SharedBackingStore.backing.delete(key);
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
return entry;
|
|
136
|
+
};
|
|
137
|
+
SharedBackingStore.backing = new Map();
|
|
138
|
+
/** key → the window (TTL) its first count was given. */
|
|
139
|
+
SharedBackingStore.windows = new Map();
|
|
140
|
+
SharedBackingStore.now = function () { return Date.now(); };
|
|
141
|
+
return SharedBackingStore;
|
|
142
|
+
}());
|
|
143
|
+
/** A store that is down: every call fails the way a lost connection does. */
|
|
144
|
+
var DownStore = /** @class */ (function () {
|
|
145
|
+
function DownStore() {
|
|
146
|
+
}
|
|
147
|
+
DownStore.prototype.increment = function () {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
throw new Error('Connection is closed.');
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
DownStore.prototype.read = function () {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
throw new Error('Connection is closed.');
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
DownStore.prototype.clear = function () {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
+
return __generator(this, function (_a) {
|
|
164
|
+
throw new Error('Connection is closed.');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
return DownStore;
|
|
169
|
+
}());
|
|
170
|
+
/** A store that never answers (a client queueing commands while it reconnects). */
|
|
171
|
+
var StalledStore = /** @class */ (function () {
|
|
172
|
+
function StalledStore() {
|
|
173
|
+
}
|
|
174
|
+
StalledStore.prototype.increment = function () {
|
|
175
|
+
return new Promise(function () { return undefined; });
|
|
176
|
+
};
|
|
177
|
+
StalledStore.prototype.read = function () {
|
|
178
|
+
return new Promise(function () { return undefined; });
|
|
179
|
+
};
|
|
180
|
+
StalledStore.prototype.clear = function () {
|
|
181
|
+
return new Promise(function () { return undefined; });
|
|
182
|
+
};
|
|
183
|
+
return StalledStore;
|
|
184
|
+
}());
|
|
185
|
+
var register = function (store) {
|
|
186
|
+
reflection_1.SourceRepository.get().objectCache[FACTORY] = [{ getStore: store }];
|
|
187
|
+
};
|
|
188
|
+
var run = 0;
|
|
189
|
+
/** A fresh address per test, so the counts of one test never meet another's. */
|
|
190
|
+
var address = function (label) { return "shared-".concat(label, "-").concat(Date.now(), "-").concat(++run, "@test.local"); };
|
|
191
|
+
var ipSeed = 0;
|
|
192
|
+
/** A fresh client address per try, so the per-device window (per pod, by design) never decides. */
|
|
193
|
+
var freshIp = function () {
|
|
194
|
+
ipSeed++;
|
|
195
|
+
return "10.".concat((ipSeed >> 16) & 255, ".").concat((ipSeed >> 8) & 255, ".").concat(ipSeed & 255);
|
|
196
|
+
};
|
|
197
|
+
/** One sign-in try through pod A's door (this process's `POST /user/login`). */
|
|
198
|
+
var signIn = function (email, password, ip) {
|
|
199
|
+
if (ip === void 0) { ip = freshIp(); }
|
|
200
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
201
|
+
var sent, response, request;
|
|
202
|
+
var _a;
|
|
203
|
+
return __generator(this, function (_b) {
|
|
204
|
+
switch (_b.label) {
|
|
205
|
+
case 0:
|
|
206
|
+
response = {
|
|
207
|
+
send: function (body) {
|
|
208
|
+
sent = body;
|
|
209
|
+
},
|
|
210
|
+
status: function () { return response; },
|
|
211
|
+
};
|
|
212
|
+
return [4 /*yield*/, (0, passportSessionHarness_1.createPassportRequest)({
|
|
213
|
+
body: { email: email, password: password },
|
|
214
|
+
headers: {},
|
|
215
|
+
socket: { remoteAddress: ip },
|
|
216
|
+
app: { get: function () { return false; } },
|
|
217
|
+
})];
|
|
218
|
+
case 1:
|
|
219
|
+
request = (_b.sent()).request;
|
|
220
|
+
return [4 /*yield*/, login_1.login.onRequest(request, response)];
|
|
221
|
+
case 2:
|
|
222
|
+
_b.sent();
|
|
223
|
+
return [2 /*return*/, { sent: sent, signedInAs: (_a = request.session.passport) === null || _a === void 0 ? void 0 : _a.user }];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
var wrongTries = function (count, email) { return __awaiter(void 0, void 0, void 0, function () {
|
|
229
|
+
var answers, i, _a, _b;
|
|
230
|
+
var _c;
|
|
231
|
+
return __generator(this, function (_d) {
|
|
232
|
+
switch (_d.label) {
|
|
233
|
+
case 0:
|
|
234
|
+
answers = [];
|
|
235
|
+
i = 0;
|
|
236
|
+
_d.label = 1;
|
|
237
|
+
case 1:
|
|
238
|
+
if (!(i < count)) return [3 /*break*/, 4];
|
|
239
|
+
_b = (_a = answers).push;
|
|
240
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
241
|
+
case 2:
|
|
242
|
+
_b.apply(_a, [(_c = (_d.sent()).sent) === null || _c === void 0 ? void 0 : _c.error]);
|
|
243
|
+
_d.label = 3;
|
|
244
|
+
case 3:
|
|
245
|
+
i++;
|
|
246
|
+
return [3 /*break*/, 1];
|
|
247
|
+
case 4: return [2 /*return*/, answers];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}); };
|
|
251
|
+
/** One reset request through pod A's door (`POST /user/initiate-password-reset`). */
|
|
252
|
+
var requestReset = function (email, ip) {
|
|
253
|
+
if (ip === void 0) { ip = freshIp(); }
|
|
254
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
255
|
+
var sent, response;
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
switch (_a.label) {
|
|
258
|
+
case 0:
|
|
259
|
+
response = {
|
|
260
|
+
send: function (body) {
|
|
261
|
+
sent = body;
|
|
262
|
+
},
|
|
263
|
+
status: function () { return response; },
|
|
264
|
+
};
|
|
265
|
+
return [4 /*yield*/, initiatePasswordReset_1.initiatePasswordReset.onRequest({ body: { email: email }, headers: {}, socket: { remoteAddress: ip }, app: { get: function () { return false; } } }, response)];
|
|
266
|
+
case 1:
|
|
267
|
+
_a.sent();
|
|
268
|
+
// The door answers first and works after; let the work settle before reading the row.
|
|
269
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 300); })];
|
|
270
|
+
case 2:
|
|
271
|
+
// The door answers first and works after; let the work settle before reading the row.
|
|
272
|
+
_a.sent();
|
|
273
|
+
return [2 /*return*/, sent];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
var createAccount = function (email) { return __awaiter(void 0, void 0, void 0, function () {
|
|
279
|
+
var user, _a, _b, _c;
|
|
280
|
+
var _d;
|
|
281
|
+
return __generator(this, function (_e) {
|
|
282
|
+
switch (_e.label) {
|
|
283
|
+
case 0: return [4 /*yield*/, testEnv.createUser({ name: 'Shared Window User', email: email })];
|
|
284
|
+
case 1:
|
|
285
|
+
user = _e.sent();
|
|
286
|
+
_b = (_a = (0, db_1.getDbAsSystem)()).update;
|
|
287
|
+
_c = [user_1.tables.User];
|
|
288
|
+
_d = { id: user.id };
|
|
289
|
+
return [4 /*yield*/, new PasswordHasher_1.PasswordHasher().hash(RIGHT_PASSWORD)];
|
|
290
|
+
case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.password = _e.sent(), _d)]))];
|
|
291
|
+
case 3:
|
|
292
|
+
_e.sent();
|
|
293
|
+
return [2 /*return*/, user];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}); };
|
|
297
|
+
var coarseIp = function () { return new RequestDigests_1.RequestDigests().coarseIp(freshIp()); };
|
|
298
|
+
describe('the account and reset-address windows, one count across server processes', function () {
|
|
299
|
+
var originalTransport = process.env.EMAIL_TRANSPORT;
|
|
300
|
+
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
301
|
+
var objectCache;
|
|
302
|
+
return __generator(this, function (_a) {
|
|
303
|
+
switch (_a.label) {
|
|
304
|
+
case 0: return [4 /*yield*/, testEnv.beforeAll()];
|
|
305
|
+
case 1:
|
|
306
|
+
_a.sent();
|
|
307
|
+
objectCache = reflection_1.SourceRepository.get().objectCache;
|
|
308
|
+
objectCache['@proteinjs/email-server/DefaultEmailConfigFactory'] = [
|
|
309
|
+
{
|
|
310
|
+
getEmailConfig: function () { return ({
|
|
311
|
+
host: 'smtp.test.local',
|
|
312
|
+
port: 465,
|
|
313
|
+
secure: true,
|
|
314
|
+
from: '"Example" <hi@example.com>',
|
|
315
|
+
}); },
|
|
316
|
+
},
|
|
317
|
+
];
|
|
318
|
+
objectCache['@proteinjs/email-server/DefaultPasswordResetEmailConfigFactory'] = [
|
|
319
|
+
{ getConfig: function () { return ({ getEmailContent: function (path) { return ({ text: "Reset: https://app.test.local/".concat(path) }); } }); } },
|
|
320
|
+
];
|
|
321
|
+
process.env.EMAIL_TRANSPORT = 'sink';
|
|
322
|
+
return [2 /*return*/];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}); }, 120000);
|
|
326
|
+
beforeEach(function () {
|
|
327
|
+
SharedBackingStore.now = function () { return Date.now(); };
|
|
328
|
+
register(function () { return new SharedBackingStore(); });
|
|
329
|
+
});
|
|
330
|
+
afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
331
|
+
return __generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0:
|
|
334
|
+
delete reflection_1.SourceRepository.get().objectCache[FACTORY];
|
|
335
|
+
if (originalTransport === undefined) {
|
|
336
|
+
delete process.env.EMAIL_TRANSPORT;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
process.env.EMAIL_TRANSPORT = originalTransport;
|
|
340
|
+
}
|
|
341
|
+
return [4 /*yield*/, testEnv.afterAll()];
|
|
342
|
+
case 1:
|
|
343
|
+
_a.sent();
|
|
344
|
+
return [2 /*return*/];
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}); });
|
|
348
|
+
it('two pods count as one: ten wrong passwords through the door, and the second pod refuses the eleventh', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
349
|
+
var email, podB, _a, _b, right;
|
|
350
|
+
return __generator(this, function (_c) {
|
|
351
|
+
switch (_c.label) {
|
|
352
|
+
case 0:
|
|
353
|
+
email = address('two-pods');
|
|
354
|
+
return [4 /*yield*/, createAccount(email)];
|
|
355
|
+
case 1:
|
|
356
|
+
_c.sent();
|
|
357
|
+
podB = new SignInThrottle_1.SignInThrottle();
|
|
358
|
+
_a = expect;
|
|
359
|
+
return [4 /*yield*/, wrongTries(10, email)];
|
|
360
|
+
case 2:
|
|
361
|
+
_a.apply(void 0, [_c.sent()]).toEqual(Array(10).fill(WRONG));
|
|
362
|
+
_b = expect;
|
|
363
|
+
return [4 /*yield*/, podB.admit(coarseIp(), new RequestDigests_1.RequestDigests().account(email))];
|
|
364
|
+
case 3:
|
|
365
|
+
_b.apply(void 0, [_c.sent()]).toBe('account');
|
|
366
|
+
return [4 /*yield*/, signIn(email, RIGHT_PASSWORD)];
|
|
367
|
+
case 4:
|
|
368
|
+
right = _c.sent();
|
|
369
|
+
expect(right.sent).toEqual({ error: THROTTLED });
|
|
370
|
+
expect(right.signedInAs).toBeUndefined();
|
|
371
|
+
return [2 /*return*/];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}); });
|
|
375
|
+
it('interleaved across two pods, the eleventh wrong password is refused wherever it lands', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
376
|
+
var email, account, podB, i, _a, _b, _c;
|
|
377
|
+
return __generator(this, function (_d) {
|
|
378
|
+
switch (_d.label) {
|
|
379
|
+
case 0:
|
|
380
|
+
email = address('interleaved');
|
|
381
|
+
account = new RequestDigests_1.RequestDigests().account(email);
|
|
382
|
+
podB = new SignInThrottle_1.SignInThrottle();
|
|
383
|
+
i = 0;
|
|
384
|
+
_d.label = 1;
|
|
385
|
+
case 1:
|
|
386
|
+
if (!(i < 5)) return [3 /*break*/, 5];
|
|
387
|
+
_a = expect;
|
|
388
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
389
|
+
case 2:
|
|
390
|
+
_a.apply(void 0, [(_d.sent()).sent]).toEqual({ error: WRONG });
|
|
391
|
+
_b = expect;
|
|
392
|
+
return [4 /*yield*/, podB.admit(coarseIp(), account)];
|
|
393
|
+
case 3:
|
|
394
|
+
_b.apply(void 0, [_d.sent()]).toBeUndefined();
|
|
395
|
+
_d.label = 4;
|
|
396
|
+
case 4:
|
|
397
|
+
i++;
|
|
398
|
+
return [3 /*break*/, 1];
|
|
399
|
+
case 5:
|
|
400
|
+
_c = expect;
|
|
401
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
402
|
+
case 6:
|
|
403
|
+
_c.apply(void 0, [(_d.sent()).sent]).toEqual({ error: THROTTLED });
|
|
404
|
+
return [2 /*return*/];
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}); });
|
|
408
|
+
it('a deploy sees the old count (a new process, a new store instance, the same store) — and the window’s expiry clears it', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
409
|
+
var email, account, _a, afterDeploy, _b, counted, start, _c;
|
|
410
|
+
return __generator(this, function (_d) {
|
|
411
|
+
switch (_d.label) {
|
|
412
|
+
case 0:
|
|
413
|
+
email = address('deploy');
|
|
414
|
+
account = new RequestDigests_1.RequestDigests().account(email);
|
|
415
|
+
_a = expect;
|
|
416
|
+
return [4 /*yield*/, wrongTries(10, email)];
|
|
417
|
+
case 1:
|
|
418
|
+
_a.apply(void 0, [_d.sent()]).toEqual(Array(10).fill(WRONG));
|
|
419
|
+
afterDeploy = new SignInThrottle_1.SignInThrottle();
|
|
420
|
+
_b = expect;
|
|
421
|
+
return [4 /*yield*/, afterDeploy.admit(coarseIp(), account)];
|
|
422
|
+
case 2:
|
|
423
|
+
_b.apply(void 0, [_d.sent()]).toBe('account');
|
|
424
|
+
counted = Array.from(SharedBackingStore.windows.entries()).filter(function (_a) {
|
|
425
|
+
var key = _a[0];
|
|
426
|
+
return key.includes(account);
|
|
427
|
+
});
|
|
428
|
+
expect(counted.map(function (_a) {
|
|
429
|
+
var windowMs = _a[1];
|
|
430
|
+
return windowMs;
|
|
431
|
+
})).toEqual([15 * MINUTE]);
|
|
432
|
+
start = Date.now();
|
|
433
|
+
SharedBackingStore.now = function () { return start + 15 * MINUTE + 1; };
|
|
434
|
+
_c = expect;
|
|
435
|
+
return [4 /*yield*/, afterDeploy.admit(coarseIp(), account)];
|
|
436
|
+
case 3:
|
|
437
|
+
_c.apply(void 0, [_d.sent()]).toBeUndefined();
|
|
438
|
+
return [2 /*return*/];
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}); });
|
|
442
|
+
it("a success on one pod clears the account's window for every pod", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
443
|
+
var email, account, podB, _a, _b, _c;
|
|
444
|
+
return __generator(this, function (_d) {
|
|
445
|
+
switch (_d.label) {
|
|
446
|
+
case 0:
|
|
447
|
+
email = address('cleared');
|
|
448
|
+
return [4 /*yield*/, createAccount(email)];
|
|
449
|
+
case 1:
|
|
450
|
+
_d.sent();
|
|
451
|
+
account = new RequestDigests_1.RequestDigests().account(email);
|
|
452
|
+
podB = new SignInThrottle_1.SignInThrottle();
|
|
453
|
+
_a = expect;
|
|
454
|
+
return [4 /*yield*/, wrongTries(9, email)];
|
|
455
|
+
case 2:
|
|
456
|
+
_a.apply(void 0, [_d.sent()]).toEqual(Array(9).fill(WRONG));
|
|
457
|
+
// Pod B sees the account prove itself (a sign-in there, or a reset link redeemed there).
|
|
458
|
+
return [4 /*yield*/, podB.recordSuccess(account)];
|
|
459
|
+
case 3:
|
|
460
|
+
// Pod B sees the account prove itself (a sign-in there, or a reset link redeemed there).
|
|
461
|
+
_d.sent();
|
|
462
|
+
_b = expect;
|
|
463
|
+
return [4 /*yield*/, wrongTries(10, email)];
|
|
464
|
+
case 4:
|
|
465
|
+
_b.apply(void 0, [_d.sent()]).toEqual(Array(10).fill(WRONG));
|
|
466
|
+
_c = expect;
|
|
467
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
468
|
+
case 5:
|
|
469
|
+
_c.apply(void 0, [(_d.sent()).sent]).toEqual({ error: THROTTLED });
|
|
470
|
+
return [2 /*return*/];
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}); });
|
|
474
|
+
it("the reset door's per-address window is one count across pods, with the hour as its TTL", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
475
|
+
var email, account, podB, i, _a, counted;
|
|
476
|
+
return __generator(this, function (_b) {
|
|
477
|
+
switch (_b.label) {
|
|
478
|
+
case 0:
|
|
479
|
+
email = address('reset');
|
|
480
|
+
return [4 /*yield*/, createAccount(email)];
|
|
481
|
+
case 1:
|
|
482
|
+
_b.sent();
|
|
483
|
+
account = new util_node_1.RequestDigests().account(email);
|
|
484
|
+
podB = new PasswordResetThrottle_1.PasswordResetThrottle();
|
|
485
|
+
i = 0;
|
|
486
|
+
_b.label = 2;
|
|
487
|
+
case 2:
|
|
488
|
+
if (!(i < 3)) return [3 /*break*/, 5];
|
|
489
|
+
return [4 /*yield*/, requestReset(email)];
|
|
490
|
+
case 3:
|
|
491
|
+
_b.sent();
|
|
492
|
+
_b.label = 4;
|
|
493
|
+
case 4:
|
|
494
|
+
i++;
|
|
495
|
+
return [3 /*break*/, 2];
|
|
496
|
+
case 5:
|
|
497
|
+
_a = expect;
|
|
498
|
+
return [4 /*yield*/, podB.admit(new util_node_1.RequestDigests().coarseIp(freshIp()), account)];
|
|
499
|
+
case 6:
|
|
500
|
+
_a.apply(void 0, [_b.sent()]).toBe('account');
|
|
501
|
+
counted = Array.from(SharedBackingStore.windows.entries()).filter(function (_a) {
|
|
502
|
+
var key = _a[0];
|
|
503
|
+
return key.includes(account);
|
|
504
|
+
});
|
|
505
|
+
expect(counted.map(function (_a) {
|
|
506
|
+
var windowMs = _a[1];
|
|
507
|
+
return windowMs;
|
|
508
|
+
})).toEqual([60 * MINUTE]);
|
|
509
|
+
return [2 /*return*/];
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}); });
|
|
513
|
+
it('windows sharing one store never meet: three reset requests for an address leave its ten sign-in tries whole', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
514
|
+
var email, i, _a, _b;
|
|
515
|
+
return __generator(this, function (_c) {
|
|
516
|
+
switch (_c.label) {
|
|
517
|
+
case 0:
|
|
518
|
+
email = address('never-meet');
|
|
519
|
+
return [4 /*yield*/, createAccount(email)];
|
|
520
|
+
case 1:
|
|
521
|
+
_c.sent();
|
|
522
|
+
i = 0;
|
|
523
|
+
_c.label = 2;
|
|
524
|
+
case 2:
|
|
525
|
+
if (!(i < 3)) return [3 /*break*/, 5];
|
|
526
|
+
return [4 /*yield*/, requestReset(email)];
|
|
527
|
+
case 3:
|
|
528
|
+
_c.sent();
|
|
529
|
+
_c.label = 4;
|
|
530
|
+
case 4:
|
|
531
|
+
i++;
|
|
532
|
+
return [3 /*break*/, 2];
|
|
533
|
+
case 5:
|
|
534
|
+
_a = expect;
|
|
535
|
+
return [4 /*yield*/, wrongTries(10, email)];
|
|
536
|
+
case 6:
|
|
537
|
+
_a.apply(void 0, [_c.sent()]).toEqual(Array(10).fill(WRONG));
|
|
538
|
+
_b = expect;
|
|
539
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
540
|
+
case 7:
|
|
541
|
+
_b.apply(void 0, [(_c.sent()).sent]).toEqual({ error: THROTTLED });
|
|
542
|
+
return [2 /*return*/];
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}); });
|
|
546
|
+
describe("when the store fails, the counted doors count in this process's memory until it answers", function () {
|
|
547
|
+
it('a store that is down: the right password signs in, ten wrong passwords are judged wrong, the eleventh is refused (the right password too, no session) — one WARN saying so until the store answers again', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
548
|
+
var email, log, unavailable, recovered, again;
|
|
549
|
+
return __generator(this, function (_a) {
|
|
550
|
+
switch (_a.label) {
|
|
551
|
+
case 0:
|
|
552
|
+
email = address('down');
|
|
553
|
+
return [4 /*yield*/, createAccount(email)];
|
|
554
|
+
case 1:
|
|
555
|
+
_a.sent();
|
|
556
|
+
register(function () { return new DownStore(); });
|
|
557
|
+
return [4 /*yield*/, LogCapture_1.LogCapture.during(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
558
|
+
var first, _a, eleventh;
|
|
559
|
+
return __generator(this, function (_b) {
|
|
560
|
+
switch (_b.label) {
|
|
561
|
+
case 0: return [4 /*yield*/, signIn(email, RIGHT_PASSWORD)];
|
|
562
|
+
case 1:
|
|
563
|
+
first = _b.sent();
|
|
564
|
+
expect(first.sent).toEqual({});
|
|
565
|
+
expect(first.signedInAs).toBe(email);
|
|
566
|
+
_a = expect;
|
|
567
|
+
return [4 /*yield*/, wrongTries(10, email)];
|
|
568
|
+
case 2:
|
|
569
|
+
_a.apply(void 0, [_b.sent()]).toEqual(Array(10).fill(WRONG));
|
|
570
|
+
return [4 /*yield*/, signIn(email, RIGHT_PASSWORD)];
|
|
571
|
+
case 3:
|
|
572
|
+
eleventh = _b.sent();
|
|
573
|
+
expect(eleventh.sent).toEqual({ error: THROTTLED });
|
|
574
|
+
expect(eleventh.signedInAs).toBeUndefined();
|
|
575
|
+
return [2 /*return*/];
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}); })];
|
|
579
|
+
case 2:
|
|
580
|
+
log = _a.sent();
|
|
581
|
+
unavailable = log.linesContaining('Throttle window store unavailable');
|
|
582
|
+
expect(unavailable.lines).toHaveLength(1);
|
|
583
|
+
expect(unavailable.text).toContain("counting in this process's memory until it answers");
|
|
584
|
+
expect(unavailable.text).toContain('sign-in-account');
|
|
585
|
+
expect(log.addresses).toEqual([]);
|
|
586
|
+
// The store answers again: the door counts there again (the outage's tries were this process's
|
|
587
|
+
// own), the right password signs in — and its success clears the memory window too.
|
|
588
|
+
register(function () { return new SharedBackingStore(); });
|
|
589
|
+
return [4 /*yield*/, LogCapture_1.LogCapture.during(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
590
|
+
var right;
|
|
591
|
+
return __generator(this, function (_a) {
|
|
592
|
+
switch (_a.label) {
|
|
593
|
+
case 0: return [4 /*yield*/, signIn(email, RIGHT_PASSWORD)];
|
|
594
|
+
case 1:
|
|
595
|
+
right = _a.sent();
|
|
596
|
+
expect(right.sent).toEqual({});
|
|
597
|
+
expect(right.signedInAs).toBe(email);
|
|
598
|
+
return [2 /*return*/];
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
}); })];
|
|
602
|
+
case 3:
|
|
603
|
+
recovered = _a.sent();
|
|
604
|
+
expect(recovered.linesContaining('Throttle window store answering again').lines).toHaveLength(1);
|
|
605
|
+
// The next outage is its own line, and the memory window starts clean.
|
|
606
|
+
register(function () { return new DownStore(); });
|
|
607
|
+
return [4 /*yield*/, LogCapture_1.LogCapture.during(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
608
|
+
var _a;
|
|
609
|
+
return __generator(this, function (_b) {
|
|
610
|
+
switch (_b.label) {
|
|
611
|
+
case 0:
|
|
612
|
+
_a = expect;
|
|
613
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
614
|
+
case 1:
|
|
615
|
+
_a.apply(void 0, [(_b.sent()).sent]).toEqual({ error: WRONG });
|
|
616
|
+
return [2 /*return*/];
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}); })];
|
|
620
|
+
case 4:
|
|
621
|
+
again = _a.sent();
|
|
622
|
+
expect(again.linesContaining('Throttle window store unavailable').lines).toHaveLength(1);
|
|
623
|
+
return [2 /*return*/];
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}); });
|
|
627
|
+
it("the store fails after nine wrong tries: the memory window continues from this process's own nine — the tenth is judged wrong, the eleventh refused; one WARN", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
628
|
+
var email, _a, log;
|
|
629
|
+
return __generator(this, function (_b) {
|
|
630
|
+
switch (_b.label) {
|
|
631
|
+
case 0:
|
|
632
|
+
email = address('boundary');
|
|
633
|
+
return [4 /*yield*/, createAccount(email)];
|
|
634
|
+
case 1:
|
|
635
|
+
_b.sent();
|
|
636
|
+
_a = expect;
|
|
637
|
+
return [4 /*yield*/, wrongTries(9, email)];
|
|
638
|
+
case 2:
|
|
639
|
+
_a.apply(void 0, [_b.sent()]).toEqual(Array(9).fill(WRONG));
|
|
640
|
+
register(function () { return new DownStore(); });
|
|
641
|
+
return [4 /*yield*/, LogCapture_1.LogCapture.during(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
642
|
+
var _a, right;
|
|
643
|
+
return __generator(this, function (_b) {
|
|
644
|
+
switch (_b.label) {
|
|
645
|
+
case 0:
|
|
646
|
+
_a = expect;
|
|
647
|
+
return [4 /*yield*/, wrongTries(2, email)];
|
|
648
|
+
case 1:
|
|
649
|
+
_a.apply(void 0, [_b.sent()]).toEqual([WRONG, THROTTLED]);
|
|
650
|
+
return [4 /*yield*/, signIn(email, RIGHT_PASSWORD)];
|
|
651
|
+
case 2:
|
|
652
|
+
right = _b.sent();
|
|
653
|
+
expect(right.sent).toEqual({ error: THROTTLED });
|
|
654
|
+
expect(right.signedInAs).toBeUndefined();
|
|
655
|
+
return [2 /*return*/];
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
}); })];
|
|
659
|
+
case 3:
|
|
660
|
+
log = _b.sent();
|
|
661
|
+
expect(log.linesContaining('Throttle window store unavailable').lines).toHaveLength(1);
|
|
662
|
+
expect(log.addresses).toEqual([]);
|
|
663
|
+
return [2 /*return*/];
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
}); });
|
|
667
|
+
it("on recovery the store counts from what it holds: the outage's five wrong tries never reach the shared count (ten fresh before the refusal, one INFO) — and this process's own count, kept all along, refuses at once in the next outage", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
668
|
+
var email, _a, recovered, _b;
|
|
669
|
+
return __generator(this, function (_c) {
|
|
670
|
+
switch (_c.label) {
|
|
671
|
+
case 0:
|
|
672
|
+
email = address('recovery');
|
|
673
|
+
return [4 /*yield*/, createAccount(email)];
|
|
674
|
+
case 1:
|
|
675
|
+
_c.sent();
|
|
676
|
+
register(function () { return new DownStore(); });
|
|
677
|
+
_a = expect;
|
|
678
|
+
return [4 /*yield*/, wrongTries(5, email)];
|
|
679
|
+
case 2:
|
|
680
|
+
_a.apply(void 0, [_c.sent()]).toEqual(Array(5).fill(WRONG));
|
|
681
|
+
register(function () { return new SharedBackingStore(); });
|
|
682
|
+
return [4 /*yield*/, LogCapture_1.LogCapture.during(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
683
|
+
var _a;
|
|
684
|
+
return __generator(this, function (_b) {
|
|
685
|
+
switch (_b.label) {
|
|
686
|
+
case 0:
|
|
687
|
+
_a = expect;
|
|
688
|
+
return [4 /*yield*/, wrongTries(11, email)];
|
|
689
|
+
case 1:
|
|
690
|
+
_a.apply(void 0, [_b.sent()]).toEqual(__spreadArray(__spreadArray([], Array(10).fill(WRONG), true), [THROTTLED], false));
|
|
691
|
+
return [2 /*return*/];
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
}); })];
|
|
695
|
+
case 3:
|
|
696
|
+
recovered = _c.sent();
|
|
697
|
+
expect(recovered.linesContaining('Throttle window store answering again').lines).toHaveLength(1);
|
|
698
|
+
// Sixteen tries met this process within the window (five in the outage, eleven while the store
|
|
699
|
+
// answered): when the store fails again, memory judges from all sixteen.
|
|
700
|
+
register(function () { return new DownStore(); });
|
|
701
|
+
_b = expect;
|
|
702
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
703
|
+
case 4:
|
|
704
|
+
_b.apply(void 0, [(_c.sent()).sent]).toEqual({ error: THROTTLED });
|
|
705
|
+
return [2 /*return*/];
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
}); });
|
|
709
|
+
it('a store that never answers: the door judges the try within the store deadline — not never, and not a refusal', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
710
|
+
var email, started, answer;
|
|
711
|
+
return __generator(this, function (_a) {
|
|
712
|
+
switch (_a.label) {
|
|
713
|
+
case 0:
|
|
714
|
+
email = address('stalled');
|
|
715
|
+
register(function () { return new StalledStore(); });
|
|
716
|
+
started = Date.now();
|
|
717
|
+
return [4 /*yield*/, signIn(email, 'wrong guess')];
|
|
718
|
+
case 1:
|
|
719
|
+
answer = _a.sent();
|
|
720
|
+
expect(answer.sent).toEqual({ error: WRONG });
|
|
721
|
+
expect(Date.now() - started).toBeLessThan(5000);
|
|
722
|
+
return [2 /*return*/];
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
}); });
|
|
726
|
+
it('the reset door with the store down: the one answer as always, AND the link minted and mailed', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
727
|
+
var email, user, _a, row;
|
|
728
|
+
return __generator(this, function (_b) {
|
|
729
|
+
switch (_b.label) {
|
|
730
|
+
case 0:
|
|
731
|
+
email = address('reset-down');
|
|
732
|
+
return [4 /*yield*/, createAccount(email)];
|
|
733
|
+
case 1:
|
|
734
|
+
user = _b.sent();
|
|
735
|
+
register(function () { return new DownStore(); });
|
|
736
|
+
email_server_1.MailSink.get().clear();
|
|
737
|
+
_a = expect;
|
|
738
|
+
return [4 /*yield*/, requestReset(email)];
|
|
739
|
+
case 2:
|
|
740
|
+
_a.apply(void 0, [_b.sent()]).toEqual({
|
|
741
|
+
message: 'If that address has an account, a reset link is on its way.',
|
|
742
|
+
});
|
|
743
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().get(user_1.tables.User, { id: user.id })];
|
|
744
|
+
case 3:
|
|
745
|
+
row = _b.sent();
|
|
746
|
+
expect(new PasswordResetToken_1.PasswordResetToken().mintedAt(row)).toBeDefined();
|
|
747
|
+
expect(email_server_1.MailSink.get()
|
|
748
|
+
.list()
|
|
749
|
+
.map(function (mail) { return mail.to; })).toEqual([[email]]);
|
|
750
|
+
return [2 /*return*/];
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}); });
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
//# sourceMappingURL=SharedThrottleWindows.integration.test.js.map
|