@jskit-ai/auth-provider-local-core 0.2.50 → 0.2.52
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/package.json +4 -4
- package/test/providerRuntime.test.js +30 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-provider-local-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"./locales/en.json": "./locales/en.json"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@jskit-ai/auth-pass": "0.1.
|
|
15
|
+
"@jskit-ai/auth-pass": "0.1.12",
|
|
16
16
|
"openid-client": "6.8.8"
|
|
17
17
|
},
|
|
18
18
|
"description": "Local auth provider with a file backend default, no database requirement, and optional Google, Microsoft and GitHub sign-in.",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@jskit-ai/auth-core": "0.2.
|
|
77
|
-
"@jskit-ai/kernel": "0.2.
|
|
76
|
+
"@jskit-ai/auth-core": "0.2.43",
|
|
77
|
+
"@jskit-ai/kernel": "0.2.38"
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -34,6 +34,10 @@ const PRODUCTION = Object.freeze({
|
|
|
34
34
|
});
|
|
35
35
|
const STAGING = Object.freeze({ ...PRODUCTION, APP_ENV: "staging" });
|
|
36
36
|
const temporaryStoreDirs = [];
|
|
37
|
+
// Every runtime a test started. Local auth sends emails and sign-in events after answering, and each one's store
|
|
38
|
+
// transaction creates store.lock in the store directory, so a directory is removed only once its app has stopped,
|
|
39
|
+
// which waits for them.
|
|
40
|
+
const startedRuntimes = [];
|
|
37
41
|
|
|
38
42
|
async function temporaryStoreDir(prefix) {
|
|
39
43
|
const storeDir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
|
@@ -41,7 +45,16 @@ async function temporaryStoreDir(prefix) {
|
|
|
41
45
|
return storeDir;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
/** Stops a started app, then removes its store directory. */
|
|
49
|
+
async function removeStartedApp(app) {
|
|
50
|
+
await app.runtime.shutdown();
|
|
51
|
+
await fs.rm(app.storeDir, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test.after(async () => {
|
|
55
|
+
for (const runtime of startedRuntimes) await runtime.shutdown();
|
|
56
|
+
await Promise.all(temporaryStoreDirs.map((storeDir) => fs.rm(storeDir, { recursive: true, force: true })));
|
|
57
|
+
});
|
|
45
58
|
|
|
46
59
|
// The setup code a production server without accounts asks its first registration for.
|
|
47
60
|
async function firstAccountSetupCode(storeDir) {
|
|
@@ -186,6 +199,7 @@ async function createStartedApp({
|
|
|
186
199
|
]
|
|
187
200
|
});
|
|
188
201
|
await runtime.start();
|
|
202
|
+
startedRuntimes.push(runtime);
|
|
189
203
|
return {
|
|
190
204
|
actionExecutor,
|
|
191
205
|
authService,
|
|
@@ -1428,7 +1442,7 @@ test("production sessions use host-only __Host- cookies and ignore the old names
|
|
|
1428
1442
|
const app = await createStartedApp({
|
|
1429
1443
|
env: { APP_ENV: "production", NODE_ENV: "production", AUTH_LOCAL_SESSION_SECRET: "fixture-session-secret", AUTH_LOCAL_RECOVERY_DEV_OUTPUT: "" }
|
|
1430
1444
|
});
|
|
1431
|
-
t.after(() =>
|
|
1445
|
+
t.after(() => removeStartedApp(app));
|
|
1432
1446
|
const registered = await app.authService.register({
|
|
1433
1447
|
email: "host@example.com",
|
|
1434
1448
|
password: "correct horse battery staple",
|
|
@@ -1454,7 +1468,7 @@ test("an installed auth.local.sign-in-events is given each sign-in event, and wi
|
|
|
1454
1468
|
const PASSWORD = "correct horse battery staple";
|
|
1455
1469
|
const events = [];
|
|
1456
1470
|
const app = await createStartedApp({ signInEvents: async (event) => { events.push(event); } });
|
|
1457
|
-
t.after(() =>
|
|
1471
|
+
t.after(() => removeStartedApp(app));
|
|
1458
1472
|
const ada = (await app.authService.register({ email: "ada@example.com", password: PASSWORD })).actor.providerUserId;
|
|
1459
1473
|
await assert.rejects(app.authService.login({ email: "ada@example.com", password: "a wrong password" }), { status: 401 });
|
|
1460
1474
|
// Stopping waits for the events still being handed over.
|
|
@@ -1468,7 +1482,7 @@ test("an installed auth.local.sign-in-events is given each sign-in event, and wi
|
|
|
1468
1482
|
const logged = await createStartedApp({
|
|
1469
1483
|
logger: { info: (fields, message) => logs.push([message, fields?.signInEvent?.method]), warn() {}, error() {}, debug() {} }
|
|
1470
1484
|
});
|
|
1471
|
-
t.after(() =>
|
|
1485
|
+
t.after(() => removeStartedApp(logged));
|
|
1472
1486
|
await logged.authService.register({ email: "ada@example.com", password: PASSWORD });
|
|
1473
1487
|
await logged.runtime.shutdown();
|
|
1474
1488
|
assert.deepEqual(logs.filter(([message]) => String(message).startsWith("Local auth sign-in")),
|
|
@@ -1487,7 +1501,7 @@ test("an installed auth.local.email-change-sender sends as APP_ENV says; without
|
|
|
1487
1501
|
// Production sends each link to its address.
|
|
1488
1502
|
const sent = [];
|
|
1489
1503
|
const production = await createStartedApp({ env: { ...PRODUCTION, ...stagingOrProduction }, emailChangeSender: async (delivery) => { sent.push(delivery); } });
|
|
1490
|
-
t.after(() =>
|
|
1504
|
+
t.after(() => removeStartedApp(production));
|
|
1491
1505
|
assert.equal(production.authService.getCapabilities().features.emailChange, true);
|
|
1492
1506
|
await production.authService.requestEmailChangeForUser({ userId: await account(production, "usr_ada", "ada@example.com"), email: "ada.new@example.com" });
|
|
1493
1507
|
// Stopping waits for the links still being sent.
|
|
@@ -1500,7 +1514,7 @@ test("an installed auth.local.email-change-sender sends as APP_ENV says; without
|
|
|
1500
1514
|
const logs = [];
|
|
1501
1515
|
const logger = { info: (details, message) => logs.push({ details, message }), warn() {}, error() {}, debug() {} };
|
|
1502
1516
|
const copy = await createStartedApp({ emailChangeSender: async (delivery) => { sent.push(delivery); }, logger });
|
|
1503
|
-
t.after(() =>
|
|
1517
|
+
t.after(() => removeStartedApp(copy));
|
|
1504
1518
|
await copy.authService.requestEmailChangeForUser({ userId: await account(copy, "usr_bob", "bob@example.com"), email: "bob.new@example.com" });
|
|
1505
1519
|
await copy.runtime.shutdown();
|
|
1506
1520
|
assert.equal(sent.length, 1, "nothing more sent");
|
|
@@ -1511,7 +1525,7 @@ test("an installed auth.local.email-change-sender sends as APP_ENV says; without
|
|
|
1511
1525
|
// Without one, development and test log each link.
|
|
1512
1526
|
logs.length = 0;
|
|
1513
1527
|
const logged = await createStartedApp({ logger });
|
|
1514
|
-
t.after(() =>
|
|
1528
|
+
t.after(() => removeStartedApp(logged));
|
|
1515
1529
|
await logged.authService.requestEmailChangeForUser({ userId: await account(logged, "usr_eve", "eve@example.com"), email: "eve.new@example.com" });
|
|
1516
1530
|
await logged.runtime.shutdown();
|
|
1517
1531
|
assert.deepEqual(logs.filter(({ message }) => String(message).startsWith("Local auth email change")).map(({ details, message }) => [message, details.email]),
|
|
@@ -1520,7 +1534,7 @@ test("an installed auth.local.email-change-sender sends as APP_ENV says; without
|
|
|
1520
1534
|
// Staging and production without one offer no email change, and a sender needs the public URL its links name.
|
|
1521
1535
|
for (const env of [STAGING, PRODUCTION]) {
|
|
1522
1536
|
const without = await createStartedApp({ env: { ...env, ...stagingOrProduction } });
|
|
1523
|
-
t.after(() =>
|
|
1537
|
+
t.after(() => removeStartedApp(without));
|
|
1524
1538
|
assert.equal(without.authService.getCapabilities().features.emailChange, false, env.APP_ENV);
|
|
1525
1539
|
for (const asked of [
|
|
1526
1540
|
without.authService.requestEmailChange({ cookies: {} }, { email: "x@example.com", password: PASSWORD }),
|
|
@@ -1545,7 +1559,7 @@ test("local recovery uses the application sender without returning or logging it
|
|
|
1545
1559
|
recoverySender: async (message) => { messages.push(message); },
|
|
1546
1560
|
logger: { info: (...args) => logs.push(args), warn() {}, error() {}, debug() {} }
|
|
1547
1561
|
});
|
|
1548
|
-
t.after(() =>
|
|
1562
|
+
t.after(() => removeStartedApp(app));
|
|
1549
1563
|
await app.authService.register({
|
|
1550
1564
|
email: "sender@example.com",
|
|
1551
1565
|
password: "correct horse battery staple",
|
|
@@ -1578,7 +1592,7 @@ test("staging sends an installed sender's emails only to STAGING_EMAIL_TO, namin
|
|
|
1578
1592
|
confirmationSender: async (message) => { sent.push(message); },
|
|
1579
1593
|
logger: { info: (details, message) => logs.push({ details, message }), warn() {}, error() {}, debug() {} }
|
|
1580
1594
|
});
|
|
1581
|
-
t.after(() =>
|
|
1595
|
+
t.after(() => removeStartedApp(app));
|
|
1582
1596
|
await app.authService.register({
|
|
1583
1597
|
email: "owner@example.com",
|
|
1584
1598
|
password: "correct horse battery staple",
|
|
@@ -1657,7 +1671,7 @@ test("a failing recovery sender is logged, never answered", async (t) => {
|
|
|
1657
1671
|
recoverySender: async () => { throw failure; },
|
|
1658
1672
|
logger: { info: (...args) => logs.push(args), warn() {}, error: (...args) => errors.push(args), debug() {} }
|
|
1659
1673
|
});
|
|
1660
|
-
t.after(() =>
|
|
1674
|
+
t.after(() => removeStartedApp(app));
|
|
1661
1675
|
await app.authService.register({
|
|
1662
1676
|
email: "failure@example.com",
|
|
1663
1677
|
password: "correct horse battery staple",
|
|
@@ -1685,7 +1699,7 @@ test("stopping the server waits for a password reset email still being sent", as
|
|
|
1685
1699
|
sent.push(email);
|
|
1686
1700
|
}
|
|
1687
1701
|
});
|
|
1688
|
-
t.after(() =>
|
|
1702
|
+
t.after(() => removeStartedApp(app));
|
|
1689
1703
|
await app.authService.register({
|
|
1690
1704
|
email: "late@example.com",
|
|
1691
1705
|
password: "correct horse battery staple",
|
|
@@ -1744,7 +1758,7 @@ test("with AUTH_LOCAL_SELF_REGISTRATION=false, production starts without a confi
|
|
|
1744
1758
|
}
|
|
1745
1759
|
}
|
|
1746
1760
|
});
|
|
1747
|
-
t.after(() =>
|
|
1761
|
+
t.after(() => removeStartedApp(app));
|
|
1748
1762
|
assert.equal(app.authService.getCapabilities().features.emailConfirmation, false);
|
|
1749
1763
|
// Until the first account exists, its registration is offered; then only an invited person's.
|
|
1750
1764
|
const password = () => app.authService.getCapabilities().features.password;
|
|
@@ -1775,7 +1789,7 @@ test("with AUTH_LOCAL_SELF_REGISTRATION=false, production starts without a confi
|
|
|
1775
1789
|
|
|
1776
1790
|
test("in development with AUTH_LOCAL_SELF_REGISTRATION=false, the first account's registration is offered until it exists", async (t) => {
|
|
1777
1791
|
const app = await createStartedApp({ env: { AUTH_LOCAL_SELF_REGISTRATION: "false", AUTH_LOCAL_EMAIL_CONFIRMATION: "false" } });
|
|
1778
|
-
t.after(() =>
|
|
1792
|
+
t.after(() => removeStartedApp(app));
|
|
1779
1793
|
const password = () => app.authService.getCapabilities().features.password;
|
|
1780
1794
|
assert.equal(password().selfRegister, true);
|
|
1781
1795
|
assert.equal(app.authService.getCapabilities().features.firstAccountSetupCode, false, "development needs no setup code");
|
|
@@ -1787,7 +1801,7 @@ test("in development with AUTH_LOCAL_SELF_REGISTRATION=false, the first account'
|
|
|
1787
1801
|
);
|
|
1788
1802
|
// With self-registration on (the default), anyone may register.
|
|
1789
1803
|
const open = await createStartedApp({ env: { AUTH_LOCAL_EMAIL_CONFIRMATION: "false" } });
|
|
1790
|
-
t.after(() =>
|
|
1804
|
+
t.after(() => removeStartedApp(open));
|
|
1791
1805
|
assert.equal(open.authService.getCapabilities().features.password.selfRegister, true);
|
|
1792
1806
|
});
|
|
1793
1807
|
|
|
@@ -1813,7 +1827,7 @@ test("the confirmation sender emails the link, which is never returned or logged
|
|
|
1813
1827
|
}));
|
|
1814
1828
|
}
|
|
1815
1829
|
});
|
|
1816
|
-
t.after(() =>
|
|
1830
|
+
t.after(() => removeStartedApp(app));
|
|
1817
1831
|
const features = app.authService.getCapabilities().features;
|
|
1818
1832
|
assert.deepEqual([features.emailConfirmation, features.emailConfirmationCode], [true, true]);
|
|
1819
1833
|
|