mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
fix: finish 2.9.0 plugin moves and get every check green
This commit is contained in:
1 parent
8c1e02af89
commit
6489b62ece
335 files changed
+29878
-17749
No files matched your search
@@ -6,7 +6,7 @@
|
||||
"scripts": {
|
||||
"build": "termix-plugin build",
|
||||
"test": "termix-plugin test",
|
||||
"typecheck": "tsc -p tsconfig.json",
|
||||
"typecheck": "tsc -b ../../tsconfig.plugins.json ../../tsconfig.plugins.frontend.json",
|
||||
"validate": "termix-plugin validate"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -396,3 +396,22 @@ export function parseSshCertificate(line: string): SshCertificateInfo {
|
||||
validBefore: toDate(validBefore),
|
||||
};
|
||||
}
|
||||
|
||||
/** Save-time checks for the admin page: a bad URL or fingerprint says so there. */
|
||||
export function validateCaSettings(
|
||||
values: Record<string, unknown>,
|
||||
): Record<string, string> {
|
||||
const errors: Record<string, string> = {};
|
||||
const check = (key: string, normalize: (raw: string) => string) => {
|
||||
const value = values[key];
|
||||
if (typeof value !== "string" || value.trim() === "") return;
|
||||
try {
|
||||
normalize(value);
|
||||
} catch (error) {
|
||||
errors[key] = error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
};
|
||||
check("caUrl", normalizeCaUrl);
|
||||
check("fingerprint", normalizeFingerprint);
|
||||
return errors;
|
||||
}
|
||||
@@ -6,8 +6,10 @@ import { createRuntime } from "./runtime.js";
|
||||
import { createAuthSessions } from "./auth-session.js";
|
||||
import { createStepCaProvider } from "./provider.js";
|
||||
import { PUBLIC_PATHS, registerRoutes } from "./routes.js";
|
||||
import { validateCaSettings } from "./client.js";
|
||||
|
||||
export async function activate(ctx: PluginContext) {
|
||||
ctx.settings.onValidate("admin", validateCaSettings);
|
||||
const table = await ctx.db.define(certsTable);
|
||||
const certs = createCertStore(ctx, table);
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { validateCaSettings } from "../../src/backend/client.js";
|
||||
|
||||
describe("validateCaSettings", () => {
|
||||
it("accepts an https URL and a SHA-256 fingerprint", () => {
|
||||
expect(
|
||||
validateCaSettings({
|
||||
caUrl: "https://ca.example.com:9000/",
|
||||
fingerprint: "ab".repeat(32),
|
||||
}),
|
||||
).toEqual({});
|
||||
});
|
||||
|
||||
it("rejects a plain http URL and a short fingerprint at save time", () => {
|
||||
const errors = validateCaSettings({
|
||||
caUrl: "http://ca.example.com",
|
||||
fingerprint: "abcd",
|
||||
});
|
||||
expect(Object.keys(errors).sort()).toEqual(["caUrl", "fingerprint"]);
|
||||
});
|
||||
|
||||
it("leaves empty fields to the not-configured message", () => {
|
||||
expect(validateCaSettings({ caUrl: "", fingerprint: " " })).toEqual({});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user