Compare commits

..

4 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
7c15c428b3 test: add normalized ASN validation coverage 2026-06-16 23:48:28 +00:00
copilot-swe-agent[bot]
f3a52e31d1 refactor: normalize ASN validation value once 2026-06-16 23:46:44 +00:00
copilot-swe-agent[bot]
5e26ceaf02 fix: allow ALL ASN values in policy rule validation 2026-06-16 23:44:35 +00:00
copilot-swe-agent[bot]
d6fe357fcb Initial plan 2026-06-16 23:39:56 +00:00
6 changed files with 70 additions and 24 deletions

View File

@@ -1,4 +1,7 @@
import { isValidUrlGlobPattern } from "./validators";
import {
getResourceRuleValueValidationError,
isValidUrlGlobPattern
} from "./validators";
import { assertEquals } from "@test/assert";
function runTests() {
@@ -236,6 +239,43 @@ function runTests() {
"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!");
}

View File

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

View File

@@ -40,7 +40,6 @@ type TargetRow = {
targetId: number;
resourceId: number;
siteId: number;
siteType: string | null;
siteName?: string;
mode: string | null;
ip: string;
@@ -106,8 +105,7 @@ function RdpServerForm({
const api = createApiClient(useEnvContext());
const router = useRouter();
const targets = targetsResponse.targets.filter((t) => t.mode === "rdp");
const browserGatewayTargets = targets.filter((t) => t.siteType === "newt");
const firstTarget = browserGatewayTargets[0];
const firstTarget = targets[0];
const formSchema = useMemo(
() => createBrowserGatewayTargetFormSchema(t),
@@ -117,7 +115,7 @@ function RdpServerForm({
const form = useForm<BrowserGatewayTargetFormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
selectedSites: browserGatewayTargets.map((target) => ({
selectedSites: targets.map((target) => ({
siteId: target.siteId,
name: target.siteName ?? String(target.siteId),
type: "newt" as const

View File

@@ -62,7 +62,6 @@ type TargetRow = {
targetId: number;
resourceId: number;
siteId: number;
siteType: string | null;
siteName?: string;
mode: string | null;
ip: string;
@@ -131,9 +130,7 @@ function SshServerForm({
const isNativeInitially = resource.authDaemonMode === "native";
const targets = targetsResponse.targets.filter((t) => t.mode === "ssh");
const browserGatewayTargets = targets.filter((t) => t.siteType === "newt");
const firstTarget = targets[0];
const firstBrowserGatewayTarget = browserGatewayTargets[0];
const initialPamMode =
(resource.pamMode as "passthrough" | "push") || "passthrough";
const initialStandardDaemonLocation = isNativeInitially
@@ -166,18 +163,18 @@ function SshServerForm({
selectedSites:
isNativeInitially || useSingleSiteOnLoad
? []
: browserGatewayTargets.map((target) => ({
: targets.map((target) => ({
siteId: target.siteId,
name: target.siteName ?? String(target.siteId),
type: "newt" as const
})),
selectedSite:
useSingleSiteOnLoad && firstBrowserGatewayTarget
useSingleSiteOnLoad && firstTarget
? {
siteId: firstBrowserGatewayTarget.siteId,
siteId: firstTarget.siteId,
name:
firstBrowserGatewayTarget.siteName ??
String(firstBrowserGatewayTarget.siteId),
firstTarget.siteName ??
String(firstTarget.siteId),
type: "newt" as const
}
: null,
@@ -193,11 +190,11 @@ function SshServerForm({
: null,
destination: isNativeInitially
? ""
: (firstBrowserGatewayTarget?.ip ?? ""),
: (firstTarget?.ip ?? ""),
destinationPort: isNativeInitially
? "22"
: firstBrowserGatewayTarget
? String(firstBrowserGatewayTarget.port)
: firstTarget
? String(firstTarget.port)
: "22"
}
});

View File

@@ -40,7 +40,6 @@ type TargetRow = {
targetId: number;
resourceId: number;
siteId: number;
siteType: string | null;
siteName?: string;
mode: string | null;
ip: string;
@@ -106,8 +105,7 @@ function VncServerForm({
const api = createApiClient(useEnvContext());
const router = useRouter();
const targets = targetsResponse.targets.filter((t) => t.mode === "vnc");
const browserGatewayTargets = targets.filter((t) => t.siteType === "newt");
const firstTarget = browserGatewayTargets[0];
const firstTarget = targets[0];
const formSchema = useMemo(
() => createBrowserGatewayTargetFormSchema(t),
@@ -117,7 +115,7 @@ function VncServerForm({
const form = useForm<BrowserGatewayTargetFormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
selectedSites: browserGatewayTargets.map((target) => ({
selectedSites: targets.map((target) => ({
siteId: target.siteId,
name: target.siteName ?? String(target.siteId),
type: "newt" as const

View File

@@ -83,9 +83,19 @@ export function createPolicyRuleValueSchema(t: TranslateFn, match: string) {
{ message: t("rulesErrorInvalidCountryDescription") }
);
case "ASN":
return required.refine((value) => /^AS\d+$/i.test(value.trim()), {
message: t("rulesErrorInvalidAsnDescription")
});
return required.refine(
(value) => {
const normalizedValue = value.trim().toUpperCase();
return (
/^AS\d+$/.test(normalizedValue) ||
normalizedValue === "ALL" ||
normalizedValue === "AS0"
);
},
{
message: t("rulesErrorInvalidAsnDescription")
}
);
default:
return required;
}