@jskit-ai/auth-provider-local-db-core 0.1.7 → 0.1.8

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.
@@ -1,7 +1,7 @@
1
1
  export default Object.freeze({
2
2
  packageVersion: 1,
3
3
  packageId: "@jskit-ai/auth-provider-local-db-core",
4
- version: "0.1.7",
4
+ version: "0.1.8",
5
5
  kind: "runtime",
6
6
  description: "Database-backed local auth storage backend for JSKIT local auth.",
7
7
  dependsOn: [
@@ -73,9 +73,9 @@ export default Object.freeze({
73
73
  mutations: {
74
74
  dependencies: {
75
75
  runtime: {
76
- "@jskit-ai/auth-provider-local-core": "0.1.15",
77
- "@jskit-ai/database-runtime": "0.1.115",
78
- "@jskit-ai/kernel": "0.1.116"
76
+ "@jskit-ai/auth-provider-local-core": "0.1.16",
77
+ "@jskit-ai/database-runtime": "0.1.116",
78
+ "@jskit-ai/kernel": "0.1.117"
79
79
  },
80
80
  dev: {}
81
81
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-provider-local-db-core",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test"
@@ -10,8 +10,8 @@
10
10
  "./server/lib/index": "./src/server/lib/index.js"
11
11
  },
12
12
  "dependencies": {
13
- "@jskit-ai/auth-provider-local-core": "0.1.15",
14
- "@jskit-ai/database-runtime": "0.1.115",
15
- "@jskit-ai/kernel": "0.1.116"
13
+ "@jskit-ai/auth-provider-local-core": "0.1.16",
14
+ "@jskit-ai/database-runtime": "0.1.116",
15
+ "@jskit-ai/kernel": "0.1.117"
16
16
  }
17
17
  }
@@ -9,6 +9,9 @@ import { createLocalDbBackend, LOCAL_AUTH_DB_TABLES } from "../src/server/lib/in
9
9
  import { AuthLocalDbBackendServiceProvider } from "../src/server/providers/AuthLocalDbBackendServiceProvider.js";
10
10
  import descriptor from "../package.descriptor.mjs";
11
11
 
12
+ const DEV_AUTH_SECRET_HEADER = "x-jskit-dev-auth-secret";
13
+ const DEV_AUTH_SECRET = "local-db-preview-exchange-secret";
14
+
12
15
  function clone(value) {
13
16
  return value == null ? value : JSON.parse(JSON.stringify(value));
14
17
  }
@@ -142,6 +145,10 @@ function createDbBackendFixture() {
142
145
  }
143
146
 
144
147
  function createService(backend, options = {}) {
148
+ const {
149
+ config = {},
150
+ ...serviceOptions
151
+ } = options;
145
152
  return createLocalAuthService({
146
153
  backend,
147
154
  config: {
@@ -149,12 +156,26 @@ function createService(backend, options = {}) {
149
156
  sessionSecret: "test-secret",
150
157
  appPublicUrl: "http://localhost:5173",
151
158
  smtpConfigured: false,
152
- recoveryDevOutput: "response"
159
+ recoveryDevOutput: "response",
160
+ ...config
153
161
  },
154
- ...options
162
+ ...serviceOptions
155
163
  });
156
164
  }
157
165
 
166
+ function createLocalRequest({ cookies = {}, exchange = false } = {}) {
167
+ return {
168
+ cookies,
169
+ headers: {
170
+ host: "localhost:4100",
171
+ ...(exchange ? { [DEV_AUTH_SECRET_HEADER]: DEV_AUTH_SECRET } : {})
172
+ },
173
+ socket: {
174
+ remoteAddress: "127.0.0.1"
175
+ }
176
+ };
177
+ }
178
+
158
179
  test("DB local auth backend implements the storage repository contract", async () => {
159
180
  const { backend, transactionManager } = createDbBackendFixture();
160
181
  const password = await hashPassword("stored password value");
@@ -328,6 +349,43 @@ test("local auth service works end to end with DB backend", async () => {
328
349
  );
329
350
  });
330
351
 
352
+ test("local database auth uses the shared native login-as session contract", async () => {
353
+ const { backend } = createDbBackendFixture();
354
+ const password = await hashPassword("stored password value");
355
+ await backend.withTransaction((tx) => tx.users.create({
356
+ displayName: "Database Preview User",
357
+ email: "preview-db@example.com",
358
+ id: "usr_preview_db",
359
+ password
360
+ }));
361
+ const authService = createService(backend, {
362
+ config: {
363
+ devAuth: {
364
+ enabled: true,
365
+ isProduction: false,
366
+ secret: DEV_AUTH_SECRET
367
+ }
368
+ }
369
+ });
370
+
371
+ const impersonated = await authService.devLoginAs(createLocalRequest({
372
+ exchange: true
373
+ }), {
374
+ email: "PREVIEW-DB@EXAMPLE.COM"
375
+ });
376
+ assert.equal(impersonated.profile.id, "usr_preview_db");
377
+ assert.equal(impersonated.session.purpose, "dev-auth");
378
+
379
+ const reply = createReplyFixture();
380
+ authService.writeSessionCookies(reply, impersonated.session);
381
+ const authenticated = await authService.authenticateRequest(createLocalRequest({
382
+ cookies: reply.cookies
383
+ }));
384
+ assert.equal(authenticated.authenticated, true);
385
+ assert.equal(authenticated.profile.email, "preview-db@example.com");
386
+ assert.equal(authenticated.sessionPurpose, "dev-auth");
387
+ });
388
+
331
389
  test("local auth DB backend works with custom password strategy", async () => {
332
390
  const { backend } = createDbBackendFixture();
333
391
  const authService = createService(backend, {