test: add normalized ASN validation coverage

This commit is contained in:
copilot-swe-agent[bot]
2026-06-16 23:48:28 +00:00
committed by GitHub
parent f3a52e31d1
commit 7c15c428b3
3 changed files with 17 additions and 2 deletions

View File

@@ -245,16 +245,31 @@ function runTests() {
null, null,
"Standard ASN should be valid" "Standard ASN should be valid"
); );
assertEquals(
getResourceRuleValueValidationError("ASN", " As15169 "),
null,
"Standard ASN should be valid with mixed case and whitespace"
);
assertEquals( assertEquals(
getResourceRuleValueValidationError("ASN", "ALL"), getResourceRuleValueValidationError("ASN", "ALL"),
null, null,
"ALL ASN selector should be valid" "ALL ASN selector should be valid"
); );
assertEquals(
getResourceRuleValueValidationError("ASN", " all "),
null,
"ALL ASN selector should be valid with mixed case and whitespace"
);
assertEquals( assertEquals(
getResourceRuleValueValidationError("ASN", "AS0"), getResourceRuleValueValidationError("ASN", "AS0"),
null, null,
"AS0 alias should be valid" "AS0 alias should be valid"
); );
assertEquals(
getResourceRuleValueValidationError("ASN", " as0 "),
null,
"AS0 alias should be valid with mixed case and whitespace"
);
assertEquals( assertEquals(
getResourceRuleValueValidationError("ASN", "not-an-asn"), getResourceRuleValueValidationError("ASN", "not-an-asn"),
"Invalid ASN provided", "Invalid ASN provided",

View File

@@ -101,7 +101,7 @@ export function getResourceRuleValueValidationError(
: "Invalid country code provided"; : "Invalid country code provided";
case "ASN": case "ASN":
const normalizedValue = value.trim().toUpperCase(); const normalizedValue = value.trim().toUpperCase();
return /^AS\d+$/i.test(normalizedValue) || return /^AS\d+$/.test(normalizedValue) ||
normalizedValue === "ALL" || normalizedValue === "ALL" ||
normalizedValue === "AS0" normalizedValue === "AS0"
? null ? null

View File

@@ -87,7 +87,7 @@ export function createPolicyRuleValueSchema(t: TranslateFn, match: string) {
(value) => { (value) => {
const normalizedValue = value.trim().toUpperCase(); const normalizedValue = value.trim().toUpperCase();
return ( return (
/^AS\d+$/i.test(normalizedValue) || /^AS\d+$/.test(normalizedValue) ||
normalizedValue === "ALL" || normalizedValue === "ALL" ||
normalizedValue === "AS0" normalizedValue === "AS0"
); );