@proteinjs/user-server 1.24.3 → 1.24.5
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 +19 -0
- package/dist/src/routes/devLogin.d.ts +9 -5
- package/dist/src/routes/devLogin.d.ts.map +1 -1
- package/dist/src/routes/devLogin.js +30 -22
- package/dist/src/routes/devLogin.js.map +1 -1
- package/dist/test/DevLogin.test.js +75 -0
- package/dist/test/DevLogin.test.js.map +1 -1
- package/package.json +3 -3
- package/src/routes/devLogin.ts +34 -20
- package/test/DevLogin.test.ts +40 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.24.5](https://github.com/proteinjs/user/compare/@proteinjs/user-server@1.24.4...@proteinjs/user-server@1.24.5) (2026-10-15)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @proteinjs/user-server
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.24.4](https://github.com/proteinjs/user/compare/@proteinjs/user-server@1.24.3...@proteinjs/user-server@1.24.4) (2026-10-09)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **dev-login:** an existing account signs in as it stands; the door creates only a missing one ([fbdd545](https://github.com/proteinjs/user/commit/fbdd545aaddc89d23aaf2a31cdcc3a916b6a3d74))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [1.24.3](https://github.com/proteinjs/user/compare/@proteinjs/user-server@1.24.2...@proteinjs/user-server@1.24.3) (2026-10-03)
|
|
7
26
|
|
|
8
27
|
|
|
@@ -18,11 +18,15 @@ import { Route } from '@proteinjs/server-api';
|
|
|
18
18
|
* decodes to a SPACE, so the route minted a stray `brent lane-a@…` account. The 400 names the
|
|
19
19
|
* remedy (`%2B`) because plus-addressing is the fan-out convention this door exists for.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
21
|
+
* An existing account signs in as it stands — a person's row, or a machine account's row the boot
|
|
22
|
+
* sync made from its declaration (the machine's roles ride the session; its credential is never
|
|
23
|
+
* involved). A missing account is created through the normal signup creation path
|
|
24
|
+
* (`Signup.createAccount`) as a normal test user — password `test`, matching the seeded
|
|
25
|
+
* test-account convention, so interactive login works for the same identity — and never under an
|
|
26
|
+
* address a machine-account declaration owns (the creation path refuses it in words; the door
|
|
27
|
+
* answers 400 with them). Composes with userCache's missing-account→guest seam: that covers
|
|
28
|
+
* sessions whose account was deleted AFTER minting; this ensures dev-minted sessions reference a
|
|
29
|
+
* real account from the start.
|
|
26
30
|
*
|
|
27
31
|
* First-admin door (`DEV_BOOTSTRAP_ADMIN_EMAIL`): a dev server on a FRESH real database has no
|
|
28
32
|
* privileged account and no sanctioned raw write to make one. Behind the same two gates, when
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devLogin.d.ts","sourceRoot":"","sources":["../../../src/routes/devLogin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"devLogin.d.ts","sourceRoot":"","sources":["../../../src/routes/devLogin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAiB9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,QAAQ,EAAE,KA+EtB,CAAC"}
|
|
@@ -37,7 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.devLogin = void 0;
|
|
40
|
+
var db_1 = require("@proteinjs/db");
|
|
40
41
|
var logger_1 = require("@proteinjs/logger");
|
|
42
|
+
var user_1 = require("@proteinjs/user");
|
|
41
43
|
var util_node_1 = require("@proteinjs/util-node");
|
|
42
44
|
var util_1 = require("@proteinjs/util");
|
|
43
45
|
var establishSession_1 = require("../authentication/establishSession");
|
|
@@ -67,11 +69,15 @@ var emailDomain = function (address) { return address.slice(address.lastIndexOf(
|
|
|
67
69
|
* decodes to a SPACE, so the route minted a stray `brent lane-a@…` account. The 400 names the
|
|
68
70
|
* remedy (`%2B`) because plus-addressing is the fan-out convention this door exists for.
|
|
69
71
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
* An existing account signs in as it stands — a person's row, or a machine account's row the boot
|
|
73
|
+
* sync made from its declaration (the machine's roles ride the session; its credential is never
|
|
74
|
+
* involved). A missing account is created through the normal signup creation path
|
|
75
|
+
* (`Signup.createAccount`) as a normal test user — password `test`, matching the seeded
|
|
76
|
+
* test-account convention, so interactive login works for the same identity — and never under an
|
|
77
|
+
* address a machine-account declaration owns (the creation path refuses it in words; the door
|
|
78
|
+
* answers 400 with them). Composes with userCache's missing-account→guest seam: that covers
|
|
79
|
+
* sessions whose account was deleted AFTER minting; this ensures dev-minted sessions reference a
|
|
80
|
+
* real account from the start.
|
|
75
81
|
*
|
|
76
82
|
* First-admin door (`DEV_BOOTSTRAP_ADMIN_EMAIL`): a dev server on a FRESH real database has no
|
|
77
83
|
* privileged account and no sanctioned raw write to make one. Behind the same two gates, when
|
|
@@ -127,9 +133,13 @@ exports.devLogin = {
|
|
|
127
133
|
}
|
|
128
134
|
email = email.toLowerCase();
|
|
129
135
|
digests = new util_node_1.RequestDigests();
|
|
130
|
-
|
|
136
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().get(user_1.tables.User, { email: email })];
|
|
131
137
|
case 1:
|
|
132
|
-
_d.
|
|
138
|
+
if (!_d.sent()) return [3 /*break*/, 2];
|
|
139
|
+
creation = 'exists';
|
|
140
|
+
return [3 /*break*/, 5];
|
|
141
|
+
case 2:
|
|
142
|
+
_d.trys.push([2, 4, , 5]);
|
|
133
143
|
return [4 /*yield*/, new Signup_1.Signup().createAccount({
|
|
134
144
|
name: email.slice(0, email.indexOf('@')),
|
|
135
145
|
email: email,
|
|
@@ -137,41 +147,39 @@ exports.devLogin = {
|
|
|
137
147
|
emailVerified: false,
|
|
138
148
|
invitedBy: null,
|
|
139
149
|
})];
|
|
140
|
-
case 2:
|
|
141
|
-
creation = _d.sent();
|
|
142
|
-
return [3 /*break*/, 4];
|
|
143
150
|
case 3:
|
|
151
|
+
creation = _d.sent();
|
|
152
|
+
return [3 /*break*/, 5];
|
|
153
|
+
case 4:
|
|
144
154
|
error_1 = _d.sent();
|
|
145
|
-
// createAccount refuses in plain words (an address a machine-account declaration owns); the
|
|
146
|
-
// dev door answers the way its other refusals do — the words, no session, no row.
|
|
147
155
|
response
|
|
148
156
|
.status(400)
|
|
149
157
|
.send("/dev/login: ".concat(error_1 instanceof Error ? error_1.message : 'the account could not be created'));
|
|
150
158
|
return [2 /*return*/];
|
|
151
|
-
case
|
|
159
|
+
case 5:
|
|
152
160
|
if (creation === 'created') {
|
|
153
161
|
logger.info({ message: 'Dev auto-login created missing test account', obj: { account: digests.account(email) } });
|
|
154
162
|
}
|
|
155
163
|
bootstrapEmail = ((_c = process.env.DEV_BOOTSTRAP_ADMIN_EMAIL) !== null && _c !== void 0 ? _c : '').trim().toLowerCase();
|
|
156
|
-
if (!(bootstrapEmail && email === bootstrapEmail)) return [3 /*break*/,
|
|
164
|
+
if (!(bootstrapEmail && email === bootstrapEmail)) return [3 /*break*/, 7];
|
|
157
165
|
return [4 /*yield*/, new Roles_1.Roles().bootstrapAdmin(email)];
|
|
158
|
-
case
|
|
166
|
+
case 6:
|
|
159
167
|
outcome = _d.sent();
|
|
160
168
|
logger.info({ message: "Dev bootstrap admin door: ".concat(outcome), obj: { account: digests.account(email) } });
|
|
161
|
-
_d.label =
|
|
162
|
-
case
|
|
169
|
+
_d.label = 7;
|
|
170
|
+
case 7:
|
|
163
171
|
bootstrapRoles = DevBootstrapRoles_1.DevBootstrapRoles.rolesFor(email);
|
|
164
|
-
if (!(bootstrapRoles.length > 0)) return [3 /*break*/,
|
|
172
|
+
if (!(bootstrapRoles.length > 0)) return [3 /*break*/, 9];
|
|
165
173
|
return [4 /*yield*/, new Roles_1.Roles().bootstrapRoles(email, bootstrapRoles)];
|
|
166
|
-
case
|
|
174
|
+
case 8:
|
|
167
175
|
outcome = _d.sent();
|
|
168
176
|
logger.info({ message: DevBootstrapRoles_1.DevBootstrapRoles.markerLine(email, outcome) });
|
|
169
|
-
_d.label =
|
|
170
|
-
case
|
|
177
|
+
_d.label = 9;
|
|
178
|
+
case 9:
|
|
171
179
|
// establishSession commits the session row before the redirect — the redirected GET / must
|
|
172
180
|
// never read the store ahead of the write (observed: first /dev/login load landed on /login).
|
|
173
181
|
return [4 /*yield*/, (0, establishSession_1.establishSession)(request, email)];
|
|
174
|
-
case
|
|
182
|
+
case 10:
|
|
175
183
|
// establishSession commits the session row before the redirect — the redirected GET / must
|
|
176
184
|
// never read the store ahead of the write (observed: first /dev/login load landed on /login).
|
|
177
185
|
_d.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devLogin.js","sourceRoot":"","sources":["../../../src/routes/devLogin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAA2C;AAC3C,kDAAsD;AACtD,wCAA6C;AAC7C,uEAAsE;AACtE,2CAA0C;AAC1C,6CAA4C;AAC5C,yDAAwD;AAExD,IAAM,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;AAEhD;kFACkF;AAClF,IAAM,WAAW,GAAG,UAAC,OAAe,I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OAAO,EAAE,KAAK,CAAC,EAAA;;oBAFtC,2FAA2F;oBAC3F,8FAA8F;oBAC9F,SAAsC,CAAC;oBACvC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,oCAAoC,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;oBACzG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;;;;SACxB;CACF,CAAC"}
|
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -258,6 +269,70 @@ describe('devLogin route', function () {
|
|
|
258
269
|
}
|
|
259
270
|
});
|
|
260
271
|
}); });
|
|
272
|
+
it('establishes a session for a declared machine account whose row the boot sync made — the door creates nothing, the account signs in as it stands', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
273
|
+
var SyncedMachineAccount, declaration, repo, outcome, row;
|
|
274
|
+
var _a;
|
|
275
|
+
return __generator(this, function (_b) {
|
|
276
|
+
switch (_b.label) {
|
|
277
|
+
case 0:
|
|
278
|
+
SyncedMachineAccount = /** @class */ (function (_super) {
|
|
279
|
+
__extends(SyncedMachineAccount, _super);
|
|
280
|
+
// The dev door exists so automated dev-loop testing can self-serve a session for any account of
|
|
281
|
+
// the build — a declared machine account's included, once the boot sync has created its row. The
|
|
282
|
+
// door never CREATES one (the case above); an existing row is signed in like any other account's.
|
|
283
|
+
function SyncedMachineAccount() {
|
|
284
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
285
|
+
_this.id = 'synced-machine';
|
|
286
|
+
_this.email = 'synced.machine@test.local';
|
|
287
|
+
_this.accountName = 'Synced machine';
|
|
288
|
+
_this.roles = [];
|
|
289
|
+
_this.secretName = 'synced-machine-secret';
|
|
290
|
+
return _this;
|
|
291
|
+
}
|
|
292
|
+
return SyncedMachineAccount;
|
|
293
|
+
}(user_1.MachineAccount));
|
|
294
|
+
declaration = new SyncedMachineAccount();
|
|
295
|
+
repo = reflection_1.SourceRepository.get();
|
|
296
|
+
repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'] = [
|
|
297
|
+
{
|
|
298
|
+
qualifiedName: '@proteinjs/user-server-test/SyncedMachineAccount',
|
|
299
|
+
packageName: '@test/declarer',
|
|
300
|
+
object: declaration,
|
|
301
|
+
},
|
|
302
|
+
];
|
|
303
|
+
// The row as the boot sync writes it from the declaration: sync-owned, the machine marker set, no password.
|
|
304
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().insert(user_1.tables.User, __assign(__assign({}, declaration.record), { isLoadedFromSource: true }))];
|
|
305
|
+
case 1:
|
|
306
|
+
// The row as the boot sync writes it from the declaration: sync-owned, the machine marker set, no password.
|
|
307
|
+
_b.sent();
|
|
308
|
+
_b.label = 2;
|
|
309
|
+
case 2:
|
|
310
|
+
_b.trys.push([2, , 5, 7]);
|
|
311
|
+
return [4 /*yield*/, (0, devLoginHarness_1.invokeDevLogin)({ email: declaration.email })];
|
|
312
|
+
case 3:
|
|
313
|
+
outcome = _b.sent();
|
|
314
|
+
expect(outcome.status).toBeUndefined();
|
|
315
|
+
expect(outcome.redirect).toBe('/');
|
|
316
|
+
expect(outcome.loggedInAs).toBe(declaration.email);
|
|
317
|
+
expect(outcome.sessionRegenerated).toBe(true);
|
|
318
|
+
expect(outcome.sessionSaved).toBe(true);
|
|
319
|
+
return [4 /*yield*/, getUserRow(declaration.email)];
|
|
320
|
+
case 4:
|
|
321
|
+
row = _b.sent();
|
|
322
|
+
expect(row === null || row === void 0 ? void 0 : row.machine).toBe(true);
|
|
323
|
+
expect(row === null || row === void 0 ? void 0 : row.isLoadedFromSource).toBe(true);
|
|
324
|
+
expect((_a = row === null || row === void 0 ? void 0 : row.password) !== null && _a !== void 0 ? _a : null).toBeNull();
|
|
325
|
+
return [3 /*break*/, 7];
|
|
326
|
+
case 5:
|
|
327
|
+
delete repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'];
|
|
328
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().delete(user_1.tables.User, { email: declaration.email })];
|
|
329
|
+
case 6:
|
|
330
|
+
_b.sent();
|
|
331
|
+
return [7 /*endfinally*/];
|
|
332
|
+
case 7: return [2 /*return*/];
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}); });
|
|
261
336
|
it('rejects a malformed same-domain ?email with 400 — no session, no stray account', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
262
337
|
var malformed, outcome, _a;
|
|
263
338
|
return __generator(this, function (_b) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DevLogin.test.js","sourceRoot":"","sources":["../../test/DevLogin.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DevLogin.test.js","sourceRoot":"","sources":["../../test/DevLogin.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA8C;AAC9C,oDAAyD;AACzD,wCAAyD;AACzD,uEAAsE;AACtE,qDAAmD;AACnD,yE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CAAC,aAAa,EAAE,CAAC;oBAC3C,KAAA,MAAM,CAAA;oBAAC,qBAAM,UAAU,CAAC,mBAAmB,CAAC,EAAA;;oBAA5C,kBAAO,SAAqC,EAAC,CAAC,aAAa,EAAE,CAAC;;;;SAC/D,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user-server",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.5",
|
|
4
4
|
"description": "User server components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@proteinjs/server": "^3.8.5",
|
|
31
31
|
"@proteinjs/server-api": "^3.0.11",
|
|
32
32
|
"@proteinjs/service": "^1.5.1",
|
|
33
|
-
"@proteinjs/user": "^1.23.
|
|
33
|
+
"@proteinjs/user": "^1.23.2",
|
|
34
34
|
"@proteinjs/util": "^1.6.1",
|
|
35
35
|
"@proteinjs/util-node": "^1.11.1",
|
|
36
36
|
"@types/express-session": "1.17.0",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
},
|
|
62
62
|
"main": "./dist/generated/index.js",
|
|
63
63
|
"types": "./dist/generated/index.d.ts",
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "76c27675ce2764251028af8c7795404f75021883"
|
|
65
65
|
}
|
package/src/routes/devLogin.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Route } from '@proteinjs/server-api';
|
|
2
|
+
import { getDbAsSystem } from '@proteinjs/db';
|
|
2
3
|
import { Logger } from '@proteinjs/logger';
|
|
4
|
+
import { tables } from '@proteinjs/user';
|
|
3
5
|
import { RequestDigests } from '@proteinjs/util-node';
|
|
4
6
|
import { emailRegex } from '@proteinjs/util';
|
|
5
7
|
import { establishSession } from '../authentication/establishSession';
|
|
@@ -32,11 +34,15 @@ const emailDomain = (address: string) => address.slice(address.lastIndexOf('@')
|
|
|
32
34
|
* decodes to a SPACE, so the route minted a stray `brent lane-a@…` account. The 400 names the
|
|
33
35
|
* remedy (`%2B`) because plus-addressing is the fan-out convention this door exists for.
|
|
34
36
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* An existing account signs in as it stands — a person's row, or a machine account's row the boot
|
|
38
|
+
* sync made from its declaration (the machine's roles ride the session; its credential is never
|
|
39
|
+
* involved). A missing account is created through the normal signup creation path
|
|
40
|
+
* (`Signup.createAccount`) as a normal test user — password `test`, matching the seeded
|
|
41
|
+
* test-account convention, so interactive login works for the same identity — and never under an
|
|
42
|
+
* address a machine-account declaration owns (the creation path refuses it in words; the door
|
|
43
|
+
* answers 400 with them). Composes with userCache's missing-account→guest seam: that covers
|
|
44
|
+
* sessions whose account was deleted AFTER minting; this ensures dev-minted sessions reference a
|
|
45
|
+
* real account from the start.
|
|
40
46
|
*
|
|
41
47
|
* First-admin door (`DEV_BOOTSTRAP_ADMIN_EMAIL`): a dev server on a FRESH real database has no
|
|
42
48
|
* privileged account and no sanctioned raw write to make one. Behind the same two gates, when
|
|
@@ -91,22 +97,30 @@ export const devLogin: Route = {
|
|
|
91
97
|
email = email.toLowerCase();
|
|
92
98
|
const digests = new RequestDigests();
|
|
93
99
|
|
|
100
|
+
// An EXISTING account signs in as it stands — a person's row, or a machine account's row the boot
|
|
101
|
+
// sync made from its declaration (this door exists so automated dev-loop testing can self-serve a
|
|
102
|
+
// session for any account of the build). The door CREATES only a missing account, and never one
|
|
103
|
+
// under an address a declaration owns: createAccount refuses that in words (a row the sync does
|
|
104
|
+
// not own would make it refuse the declaration), and the door answers the way its other refusals
|
|
105
|
+
// do — the words, no session, no row.
|
|
94
106
|
let creation: 'created' | 'exists';
|
|
95
|
-
|
|
96
|
-
creation =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
if (await getDbAsSystem().get(tables.User, { email })) {
|
|
108
|
+
creation = 'exists';
|
|
109
|
+
} else {
|
|
110
|
+
try {
|
|
111
|
+
creation = await new Signup().createAccount({
|
|
112
|
+
name: email.slice(0, email.indexOf('@')),
|
|
113
|
+
email,
|
|
114
|
+
password: 'test',
|
|
115
|
+
emailVerified: false, // same shape an inviteless signup produces
|
|
116
|
+
invitedBy: null,
|
|
117
|
+
});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
response
|
|
120
|
+
.status(400)
|
|
121
|
+
.send(`/dev/login: ${error instanceof Error ? error.message : 'the account could not be created'}`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
110
124
|
}
|
|
111
125
|
if (creation === 'created') {
|
|
112
126
|
logger.info({ message: 'Dev auto-login created missing test account', obj: { account: digests.account(email) } });
|
package/test/DevLogin.test.ts
CHANGED
|
@@ -141,6 +141,46 @@ describe('devLogin route', () => {
|
|
|
141
141
|
}
|
|
142
142
|
});
|
|
143
143
|
|
|
144
|
+
it('establishes a session for a declared machine account whose row the boot sync made — the door creates nothing, the account signs in as it stands', async () => {
|
|
145
|
+
// The dev door exists so automated dev-loop testing can self-serve a session for any account of
|
|
146
|
+
// the build — a declared machine account's included, once the boot sync has created its row. The
|
|
147
|
+
// door never CREATES one (the case above); an existing row is signed in like any other account's.
|
|
148
|
+
class SyncedMachineAccount extends MachineAccount {
|
|
149
|
+
id = 'synced-machine';
|
|
150
|
+
email = 'synced.machine@test.local';
|
|
151
|
+
accountName = 'Synced machine';
|
|
152
|
+
roles = [];
|
|
153
|
+
secretName = 'synced-machine-secret';
|
|
154
|
+
}
|
|
155
|
+
const declaration = new SyncedMachineAccount();
|
|
156
|
+
const repo = SourceRepository.get() as unknown as { namedObjectCache: Record<string, unknown[]> };
|
|
157
|
+
repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'] = [
|
|
158
|
+
{
|
|
159
|
+
qualifiedName: '@proteinjs/user-server-test/SyncedMachineAccount',
|
|
160
|
+
packageName: '@test/declarer',
|
|
161
|
+
object: declaration,
|
|
162
|
+
},
|
|
163
|
+
];
|
|
164
|
+
// The row as the boot sync writes it from the declaration: sync-owned, the machine marker set, no password.
|
|
165
|
+
await getDbAsSystem().insert(tables.User, { ...declaration.record, isLoadedFromSource: true } as never);
|
|
166
|
+
try {
|
|
167
|
+
const outcome = await invokeDevLogin({ email: declaration.email });
|
|
168
|
+
|
|
169
|
+
expect(outcome.status).toBeUndefined();
|
|
170
|
+
expect(outcome.redirect).toBe('/');
|
|
171
|
+
expect(outcome.loggedInAs).toBe(declaration.email);
|
|
172
|
+
expect(outcome.sessionRegenerated).toBe(true);
|
|
173
|
+
expect(outcome.sessionSaved).toBe(true);
|
|
174
|
+
const row = await getUserRow(declaration.email);
|
|
175
|
+
expect(row?.machine).toBe(true);
|
|
176
|
+
expect(row?.isLoadedFromSource).toBe(true);
|
|
177
|
+
expect(row?.password ?? null).toBeNull();
|
|
178
|
+
} finally {
|
|
179
|
+
delete repo.namedObjectCache['@proteinjs/db/SourceRecordLoader'];
|
|
180
|
+
await getDbAsSystem().delete(tables.User, { email: declaration.email });
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
144
184
|
it('rejects a malformed same-domain ?email with 400 — no session, no stray account', async () => {
|
|
145
185
|
// The observed shape: an unencoded `+` in the query decodes to a space, so
|
|
146
186
|
// `?email=brent+shareproof-a@...` arrived as `brent shareproof-a@...` and minted a stray
|