mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-20 22:32:31 +00:00
Compare commits
1 Commits
copilot/pu
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
241610579c |
@@ -48,18 +48,18 @@ export async function applyBlueprint({
|
|||||||
name,
|
name,
|
||||||
source = "API"
|
source = "API"
|
||||||
}: ApplyBlueprintArgs): Promise<Blueprint> {
|
}: ApplyBlueprintArgs): Promise<Blueprint> {
|
||||||
// Validate the input data
|
|
||||||
const validationResult = ConfigSchema.safeParse(configData);
|
|
||||||
if (!validationResult.success) {
|
|
||||||
throw new Error(fromError(validationResult.error).toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
const config: Config = validationResult.data;
|
|
||||||
let blueprintSucceeded: boolean = false;
|
let blueprintSucceeded: boolean = false;
|
||||||
let blueprintMessage: string;
|
let blueprintMessage = "";
|
||||||
let error: any | null = null;
|
let error: any | null = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const validationResult = ConfigSchema.safeParse(configData);
|
||||||
|
if (!validationResult.success) {
|
||||||
|
throw new Error(fromError(validationResult.error).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const config: Config = validationResult.data;
|
||||||
|
|
||||||
let proxyResourcesResults: PublicResourcesResults = [];
|
let proxyResourcesResults: PublicResourcesResults = [];
|
||||||
let clientResourcesResults: ClientResourcesResults = [];
|
let clientResourcesResults: ClientResourcesResults = [];
|
||||||
await db.transaction(async (trx) => {
|
await db.transaction(async (trx) => {
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import {
|
import { isValidUrlGlobPattern } from "./validators";
|
||||||
getResourceRuleValueValidationError,
|
|
||||||
isValidUrlGlobPattern
|
|
||||||
} from "./validators";
|
|
||||||
import { assertEquals } from "@test/assert";
|
import { assertEquals } from "@test/assert";
|
||||||
|
|
||||||
function runTests() {
|
function runTests() {
|
||||||
@@ -239,43 +236,6 @@ function runTests() {
|
|||||||
"Path with isolated percent sign should be invalid"
|
"Path with isolated percent sign should be invalid"
|
||||||
);
|
);
|
||||||
|
|
||||||
// ASN validation tests
|
|
||||||
assertEquals(
|
|
||||||
getResourceRuleValueValidationError("ASN", "AS15169"),
|
|
||||||
null,
|
|
||||||
"Standard ASN should be valid"
|
|
||||||
);
|
|
||||||
assertEquals(
|
|
||||||
getResourceRuleValueValidationError("ASN", " As15169 "),
|
|
||||||
null,
|
|
||||||
"Standard ASN should be valid with mixed case and whitespace"
|
|
||||||
);
|
|
||||||
assertEquals(
|
|
||||||
getResourceRuleValueValidationError("ASN", "ALL"),
|
|
||||||
null,
|
|
||||||
"ALL ASN selector should be valid"
|
|
||||||
);
|
|
||||||
assertEquals(
|
|
||||||
getResourceRuleValueValidationError("ASN", " all "),
|
|
||||||
null,
|
|
||||||
"ALL ASN selector should be valid with mixed case and whitespace"
|
|
||||||
);
|
|
||||||
assertEquals(
|
|
||||||
getResourceRuleValueValidationError("ASN", "AS0"),
|
|
||||||
null,
|
|
||||||
"AS0 alias should be valid"
|
|
||||||
);
|
|
||||||
assertEquals(
|
|
||||||
getResourceRuleValueValidationError("ASN", " as0 "),
|
|
||||||
null,
|
|
||||||
"AS0 alias should be valid with mixed case and whitespace"
|
|
||||||
);
|
|
||||||
assertEquals(
|
|
||||||
getResourceRuleValueValidationError("ASN", "not-an-asn"),
|
|
||||||
"Invalid ASN provided",
|
|
||||||
"Invalid ASN should return an error"
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log("All tests passed!");
|
console.log("All tests passed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,10 +100,7 @@ export function getResourceRuleValueValidationError(
|
|||||||
? null
|
? null
|
||||||
: "Invalid country code provided";
|
: "Invalid country code provided";
|
||||||
case "ASN":
|
case "ASN":
|
||||||
const normalizedValue = value.trim().toUpperCase();
|
return /^AS\d+$/i.test(value.trim())
|
||||||
return /^AS\d+$/.test(normalizedValue) ||
|
|
||||||
normalizedValue === "ALL" ||
|
|
||||||
normalizedValue === "AS0"
|
|
||||||
? null
|
? null
|
||||||
: "Invalid ASN provided";
|
: "Invalid ASN provided";
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -83,19 +83,9 @@ export function createPolicyRuleValueSchema(t: TranslateFn, match: string) {
|
|||||||
{ message: t("rulesErrorInvalidCountryDescription") }
|
{ message: t("rulesErrorInvalidCountryDescription") }
|
||||||
);
|
);
|
||||||
case "ASN":
|
case "ASN":
|
||||||
return required.refine(
|
return required.refine((value) => /^AS\d+$/i.test(value.trim()), {
|
||||||
(value) => {
|
message: t("rulesErrorInvalidAsnDescription")
|
||||||
const normalizedValue = value.trim().toUpperCase();
|
});
|
||||||
return (
|
|
||||||
/^AS\d+$/.test(normalizedValue) ||
|
|
||||||
normalizedValue === "ALL" ||
|
|
||||||
normalizedValue === "AS0"
|
|
||||||
);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: t("rulesErrorInvalidAsnDescription")
|
|
||||||
}
|
|
||||||
);
|
|
||||||
default:
|
default:
|
||||||
return required;
|
return required;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user