mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-17 12:57:17 +00:00
fix: allow ALL ASN values in policy rule validation
This commit is contained in:
committed by
GitHub
parent
d6fe357fcb
commit
5e26ceaf02
@@ -1,4 +1,7 @@
|
|||||||
import { isValidUrlGlobPattern } from "./validators";
|
import {
|
||||||
|
getResourceRuleValueValidationError,
|
||||||
|
isValidUrlGlobPattern
|
||||||
|
} from "./validators";
|
||||||
import { assertEquals } from "@test/assert";
|
import { assertEquals } from "@test/assert";
|
||||||
|
|
||||||
function runTests() {
|
function runTests() {
|
||||||
@@ -236,6 +239,28 @@ 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", "ALL"),
|
||||||
|
null,
|
||||||
|
"ALL ASN selector should be valid"
|
||||||
|
);
|
||||||
|
assertEquals(
|
||||||
|
getResourceRuleValueValidationError("ASN", "AS0"),
|
||||||
|
null,
|
||||||
|
"AS0 alias should be valid"
|
||||||
|
);
|
||||||
|
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,7 +100,9 @@ export function getResourceRuleValueValidationError(
|
|||||||
? null
|
? null
|
||||||
: "Invalid country code provided";
|
: "Invalid country code provided";
|
||||||
case "ASN":
|
case "ASN":
|
||||||
return /^AS\d+$/i.test(value.trim())
|
return /^AS\d+$/i.test(value.trim()) ||
|
||||||
|
value.trim().toUpperCase() === "ALL" ||
|
||||||
|
value.trim().toUpperCase() === "AS0"
|
||||||
? null
|
? null
|
||||||
: "Invalid ASN provided";
|
: "Invalid ASN provided";
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -83,9 +83,19 @@ export function createPolicyRuleValueSchema(t: TranslateFn, match: string) {
|
|||||||
{ message: t("rulesErrorInvalidCountryDescription") }
|
{ message: t("rulesErrorInvalidCountryDescription") }
|
||||||
);
|
);
|
||||||
case "ASN":
|
case "ASN":
|
||||||
return required.refine((value) => /^AS\d+$/i.test(value.trim()), {
|
return required.refine(
|
||||||
message: t("rulesErrorInvalidAsnDescription")
|
(value) => {
|
||||||
});
|
const normalizedValue = value.trim().toUpperCase();
|
||||||
|
return (
|
||||||
|
/^AS\d+$/i.test(normalizedValue) ||
|
||||||
|
normalizedValue === "ALL" ||
|
||||||
|
normalizedValue === "AS0"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: t("rulesErrorInvalidAsnDescription")
|
||||||
|
}
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return required;
|
return required;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user