From 22c7f098f94dca26f87840994b1897502dfd19bd Mon Sep 17 00:00:00 2001 From: Ryan Newington Date: Mon, 15 Sep 2025 14:40:24 +1000 Subject: [PATCH 1/4] Improve CIDR validation logic for IPv4 addresses --- DPCLibrary/Utils/Validate.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DPCLibrary/Utils/Validate.cs b/DPCLibrary/Utils/Validate.cs index 8bf3396..86e16f2 100644 --- a/DPCLibrary/Utils/Validate.cs +++ b/DPCLibrary/Utils/Validate.cs @@ -190,9 +190,9 @@ public static bool IPv4CIDR(string address) return false; } - if (!IPv4(SplitCIDR[0])) + if (!(SplitCIDR[0] == "0.0.0.0" || IPv4(SplitCIDR[0]))) { - //Front part isn't a valid address + //Front part isn't 0.0.0.0 or a valid address return false; } @@ -461,4 +461,4 @@ public static bool PackageId(string id) } } } -} \ No newline at end of file +} From 375cba1f225a4b1212376ecd528b1bdd7d83fe1f Mon Sep 17 00:00:00 2001 From: Ryan Newington Date: Mon, 15 Sep 2025 14:52:13 +1000 Subject: [PATCH 2/4] Add test cases for 0.0.0.0/1 CIDR notation This commit introduces new test cases in the `ValidateTests.cs` file for the following methods: - `ValidIpv4ORCIDR` - `ValidIpv4ORIpv6ORCIDR` - `ValidIpv4CIDR` Each test case includes the data row `0.0.0.0/1` to ensure proper validation of this CIDR notation. --- DPCLibraryTests/ValidateTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DPCLibraryTests/ValidateTests.cs b/DPCLibraryTests/ValidateTests.cs index 076de47..a817ea6 100644 --- a/DPCLibraryTests/ValidateTests.cs +++ b/DPCLibraryTests/ValidateTests.cs @@ -50,6 +50,7 @@ public void InvalidIpv4ORCIDR(string IPv4Address) [DataRow("192.168.0.0/16")] [DataRow("192.168.1.1/32")] [DataRow("20.1.2.3/32")] + [DataRow("0.0.0.0/1")] public void ValidIpv4ORCIDR(string IPv4Address) { bool result = Validate.IPv4OrCIDR(IPv4Address); @@ -203,6 +204,7 @@ public void ValidIpv6ORCIDR(string IPv4Address) [DataRow("192.168.0.0/16")] [DataRow("192.168.1.1/32")] [DataRow("20.1.2.3/32")] + [DataRow("0.0.0.0/1")] public void ValidIpv4ORIpv6ORCIDR(string IPv4Address) { bool result = Validate.IPv4OrIPv6OrCIDR(IPv4Address); @@ -424,6 +426,7 @@ public void InvalidIpv4CIDR(string IPv4Address) [DataRow("192.168.0.0/16")] [DataRow("192.168.1.1/32")] [DataRow("20.1.2.3/32")] + [DataRow("0.0.0.0/1")] public void ValidIpv4CIDR(string IPv4Address) { bool result = Validate.IPv4CIDR(IPv4Address); From 6ca9cc03d93bd49082b72d20e74c81e9e2ed2d17 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Mon, 15 Sep 2025 22:03:52 +0100 Subject: [PATCH 3/4] Update development pipeline to run for all branches other than main --- .github/workflows/DevelopmentDPC.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/DevelopmentDPC.yml b/.github/workflows/DevelopmentDPC.yml index 26190ec..3f70424 100644 --- a/.github/workflows/DevelopmentDPC.yml +++ b/.github/workflows/DevelopmentDPC.yml @@ -7,9 +7,11 @@ name: Development DPC on: push: - branches: [ "Development" ] + branches-ignore: + - main pull_request: - branches: [ "Development" ] + branches-ignore: + - main jobs: build: From 2c0e27c0f3c1221ab5d2dc15820890f1d8228ab6 Mon Sep 17 00:00:00 2001 From: Ryan Newington Date: Tue, 16 Sep 2025 08:13:48 +1000 Subject: [PATCH 4/4] Adds support for validating CIDR 0.0.0.0/0 Updates test cases in to cover new scenarios for both invalid and valid IPv4 and CIDR inputs. Removed some duplicate DataRow test cases. --- DPCLibrary/Utils/Validate.cs | 18 ++++++++++++------ DPCLibraryTests/ValidateTests.cs | 13 +++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/DPCLibrary/Utils/Validate.cs b/DPCLibrary/Utils/Validate.cs index 86e16f2..7ab08cf 100644 --- a/DPCLibrary/Utils/Validate.cs +++ b/DPCLibrary/Utils/Validate.cs @@ -105,7 +105,7 @@ public static bool IPv6(string address) { return false; //reject simple IPv6 Zero } - + //Find and reject other ways of making IPv6 Zero Match zeroResult = Regex.Match(address, "^s*(((0{1,4}:){7}(0{1,4}|:))|((0{1,4}:){6}|(:))|((0{1,4}:){5}(((:0]{1,4}){1,2})|:))|((0{1,4}:){4}(((:0{1,4}){1,3})|((:0{1,4})?:)|:))|((0{1,4}:){3}(((:0{1,4}){1,4})|((:0{1,4}){0,2}:)|:))|((0{1,4}:){2}(((:0{1,4}){1,5})|((:0{1,4}){0,3}:)|:))|((0{1,4}:){1}(((:0{1,4}){1,6})|((:0{1,4}){0,4}:)|:))|(:(((:0{1,4}){1,7})|((:0{1,4}){0,5}:)|:)))(%.+)?s*"); if (zeroResult.Value == address) @@ -190,15 +190,16 @@ public static bool IPv4CIDR(string address) return false; } - if (!(SplitCIDR[0] == "0.0.0.0" || IPv4(SplitCIDR[0]))) + string AddressVal = SplitCIDR[0]; + if (!int.TryParse(SplitCIDR[1], out int CIDRVal)) { - //Front part isn't 0.0.0.0 or a valid address + //Unable to turn second part into int return false; } - if (!int.TryParse(SplitCIDR[1], out int CIDRVal)) + if (!(AddressVal == "0.0.0.0" || IPv4(AddressVal))) { - //Unable to turn second part into int + //Front part isn't 0.0.0.0 or a valid address return false; } @@ -207,7 +208,12 @@ public static bool IPv4CIDR(string address) return false; } - if (CIDRVal <= 0) + if (CIDRVal < 0) + { + return false; + } + + if (CIDRVal == 0 && AddressVal != "0.0.0.0") { return false; } diff --git a/DPCLibraryTests/ValidateTests.cs b/DPCLibraryTests/ValidateTests.cs index a817ea6..d09f6d9 100644 --- a/DPCLibraryTests/ValidateTests.cs +++ b/DPCLibraryTests/ValidateTests.cs @@ -29,9 +29,9 @@ public class ValidateTests [DataRow("1.1.1.1/-1")] [DataRow("1.1.1.1/33")] [DataRow("1.1.1.1/bob")] - [DataRow("2001:0db9::1/64")] - [DataRow("2001:0db9::1")] [DataRow("192.168..1/32")] + [DataRow("192.168.1.1/0")] + [DataRow("0.0.0.0")] public void InvalidIpv4ORCIDR(string IPv4Address) { bool result = Validate.IPv4OrCIDR(IPv4Address); @@ -51,6 +51,7 @@ public void InvalidIpv4ORCIDR(string IPv4Address) [DataRow("192.168.1.1/32")] [DataRow("20.1.2.3/32")] [DataRow("0.0.0.0/1")] + [DataRow("0.0.0.0/0")] public void ValidIpv4ORCIDR(string IPv4Address) { bool result = Validate.IPv4OrCIDR(IPv4Address); @@ -151,13 +152,7 @@ public void InvalidIpv6CIDR(string IPv6Address) [DataRow("255.255.255.255")] [DataRow("20.1.2.3")] [DataRow("0.0.0.0")] - [DataRow("10.0.0.0")] - [DataRow("172.16.35.3")] - [DataRow("192.168.5.4")] - [DataRow("255.255.255.255")] - [DataRow("20.1.2.3")] [DataRow("172.16.0.0/12")] - [DataRow("10.32.99.0/24")] [DataRow("192.168.0.0/16")] [DataRow("192.168.1.1/32")] [DataRow("20.1.2.3/32")] @@ -205,6 +200,7 @@ public void ValidIpv6ORCIDR(string IPv4Address) [DataRow("192.168.1.1/32")] [DataRow("20.1.2.3/32")] [DataRow("0.0.0.0/1")] + [DataRow("0.0.0.0/0")] public void ValidIpv4ORIpv6ORCIDR(string IPv4Address) { bool result = Validate.IPv4OrIPv6OrCIDR(IPv4Address); @@ -427,6 +423,7 @@ public void InvalidIpv4CIDR(string IPv4Address) [DataRow("192.168.1.1/32")] [DataRow("20.1.2.3/32")] [DataRow("0.0.0.0/1")] + [DataRow("0.0.0.0/0")] public void ValidIpv4CIDR(string IPv4Address) { bool result = Validate.IPv4CIDR(IPv4Address);