feat(auth): support schema-qualified SQL stores
This commit is contained in:
1 parent
a85cbf240d
commit
681679483a
5 files changed
+48
-4
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import type { Db } from "@wrnexus/db";
|
||||
import { SqlAuthStore } from "../src/stores/sql.ts";
|
||||
|
||||
test("auth store qualifies tables without changing parameter values", async () => {
|
||||
let query = "";
|
||||
let values: unknown[] = [];
|
||||
const db = {
|
||||
driver: { dialect: "postgres" },
|
||||
one: async (sql: string, params: unknown[]) => {
|
||||
query = sql;
|
||||
values = params;
|
||||
return undefined;
|
||||
},
|
||||
} as unknown as Db;
|
||||
const store = new SqlAuthStore(db, { schema: "sso", tablePrefix: "" });
|
||||
await store.findUserById("wrn_auth_users");
|
||||
expect(query).toContain('FROM "sso"."users"');
|
||||
expect(query).toContain("$1");
|
||||
expect(values).toEqual(["wrn_auth_users"]);
|
||||
expect(() => new SqlAuthStore(db, { schema: 'sso";DROP TABLE users' })).toThrow();
|
||||
});
|
||||
Reference in new issue
Block a user