feat(certificates): handle self signed certificates (#1951)
* wip: add page and loading of certificates in folder * wip: add certificate addition and removal * feat: add removal ui for certificates * feat: migrate integrations to fetch or agent with trusted certificates * fix: lock file issues * fix: typecheck issue * fix: inconsistent package versions * chore: address pull request feedback * fix: add missing navigation item and restrict access to page * chore: address pull request feedback * fix: inconsistent undici dependency version * fix: inconsistent undici dependency version
This commit is contained in:
52
packages/validation/src/certificates.ts
Normal file
52
packages/validation/src/certificates.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { createCustomErrorParams } from "./form/i18n";
|
||||
|
||||
const validFileNameSchema = z.string().regex(/^[\w\-. ]+$/);
|
||||
|
||||
export const superRefineCertificateFile = (value: File | null, context: z.RefinementCtx) => {
|
||||
if (!value) {
|
||||
return context.addIssue({
|
||||
code: "invalid_type",
|
||||
expected: "object",
|
||||
received: "null",
|
||||
});
|
||||
}
|
||||
|
||||
const result = validFileNameSchema.safeParse(value.name);
|
||||
if (!result.success) {
|
||||
return context.addIssue({
|
||||
code: "custom",
|
||||
params: createCustomErrorParams({
|
||||
key: "invalidFileName",
|
||||
params: {},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
if (value.type !== "application/x-x509-ca-cert" && value.type !== "application/pkix-cert") {
|
||||
return context.addIssue({
|
||||
code: "custom",
|
||||
params: createCustomErrorParams({
|
||||
key: "invalidFileType",
|
||||
params: { expected: ".crt" },
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
if (value.size > 1024 * 1024) {
|
||||
return context.addIssue({
|
||||
code: "custom",
|
||||
params: createCustomErrorParams({
|
||||
key: "fileTooLarge",
|
||||
params: { maxSize: "1 MB" },
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const certificateSchemas = {
|
||||
validFileNameSchema,
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
import { appSchemas } from "./app";
|
||||
import { boardSchemas } from "./board";
|
||||
import { certificateSchemas } from "./certificates";
|
||||
import { commonSchemas } from "./common";
|
||||
import { groupSchemas } from "./group";
|
||||
import { iconsSchemas } from "./icons";
|
||||
@@ -24,6 +25,7 @@ export const validation = {
|
||||
media: mediaSchemas,
|
||||
settings: settingsSchemas,
|
||||
common: commonSchemas,
|
||||
certificates: certificateSchemas,
|
||||
};
|
||||
|
||||
export {
|
||||
@@ -33,6 +35,7 @@ export {
|
||||
type BoardItemAdvancedOptions,
|
||||
type BoardItemIntegration,
|
||||
} from "./shared";
|
||||
export { superRefineCertificateFile } from "./certificates";
|
||||
export { passwordRequirements } from "./user";
|
||||
export { supportedMediaUploadFormats } from "./media";
|
||||
export { zodEnumFromArray, zodUnionFromArray } from "./enums";
|
||||
|
||||
Reference in New Issue
Block a user