test secrets extraction

This commit is contained in:
dswbx
2025-06-25 07:49:39 +02:00
parent 6e78a4c238
commit c161a26ec0
6 changed files with 28 additions and 21 deletions
+1 -1
View File
@@ -1,12 +1,12 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import { Guard } from "../../src/auth";
import { parse } from "../../src/core/utils";
import { DataApi } from "../../src/data/api/DataApi";
import { DataController } from "../../src/data/api/DataController";
import { dataConfigSchema } from "../../src/data/data-schema";
import * as proto from "../../src/data/prototype";
import { schemaToEm } from "../helper";
import { disableConsoleLog, enableConsoleLog } from "core/utils/test";
import { parse } from "core/object/schema";
beforeAll(disableConsoleLog);
afterAll(enableConsoleLog);
+2 -18
View File
@@ -46,20 +46,6 @@ export const guardRoleSchema = s.strictObject({
implicit_allow: s.boolean().optional(),
});
const a = s.record(strategiesSchema, {
// ^?
title: "Strategies",
default: {
password: {
type: "password",
enabled: true,
config: {
hashing: "sha256",
},
},
},
});
export const authConfigSchema = s.strictObject(
{
enabled: s.boolean({ default: false }),
@@ -85,9 +71,7 @@ export const authConfigSchema = s.strictObject(
},
{ title: "Authentication" },
);
const b = authConfigSchema.properties.basepath;
// ^?
const c = authConfigSchema.properties.strategies;
// ^?
export type AppAuthJWTConfig = s.Static<typeof jwtConfig>;
export type AppAuthSchema = s.Static<typeof authConfigSchema>;
+2 -2
View File
@@ -8,7 +8,7 @@ import type { CookieOptions } from "hono/utils/cookie";
import type { ServerEnv } from "modules/Controller";
import { pick } from "lodash-es";
import { InvalidConditionsException } from "auth/errors";
import { s, parse } from "core/object/schema";
import { s, parse, secret } from "core/object/schema";
type Input = any; // workaround
export type JWTPayload = Parameters<typeof sign>[0];
@@ -72,7 +72,7 @@ export const jwtConfig = s
.object(
{
// @todo: autogenerate a secret if not present. But it must be persisted from AppAuth
secret: s.string({ default: "" }),
secret: secret({ default: "" }),
alg: s.string({ enum: ["HS256", "HS384", "HS512"], default: "HS256" }).optional(),
expires: s.number().optional(), // seconds
issuer: s.string().optional(),
+2
View File
@@ -3,6 +3,8 @@ import * as s from "jsonv-ts";
export { validator as jsc, type Options } from "jsonv-ts/hono";
export { describeRoute, schemaToSpec, openAPISpecs } from "jsonv-ts/hono";
export { secret } from "./secret";
export { s };
export const stripMark = <O extends object>(o: O): O => o;
+7
View File
@@ -0,0 +1,7 @@
import { StringSchema, type IStringOptions } from "jsonv-ts";
export class SecretSchema<O extends IStringOptions> extends StringSchema<O> {}
export const secret = <O extends IStringOptions>(o?: O) => {
return new SecretSchema(o);
};
@@ -17,6 +17,7 @@ import {
import * as SystemPermissions from "modules/permissions";
import { jsc, s, describeRoute, InvalidSchemaError } from "core/object/schema";
import { getVersion } from "core/env";
import { SecretSchema } from "core/object/schema/secret";
export type ConfigUpdate<Key extends ModuleKey = ModuleKey> = {
success: true;
@@ -318,6 +319,19 @@ export class SystemController extends Controller {
utc: datetimeStringUTC(),
},
plugins: Array.from(this.app.plugins.keys()),
walk: {
auth: [
...c
.get("app")
.getSchema()
.auth.walk({ data: c.get("app").toJSON(true).auth }),
]
.filter((n) => n.schema instanceof SecretSchema)
.map((n) => ({
...n,
schema: n.schema.constructor.name,
})),
},
}),
);