Added validation before saving any tunnels
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
This commit is contained in:
@@ -62,4 +62,62 @@ class ValidatorsTests: XCTestCase {
|
||||
executeTest(endpointString: "192.168.0.1")
|
||||
executeTest(endpointString: "12345")
|
||||
}
|
||||
|
||||
func testCIDRAddress() throws {
|
||||
_ = try CIDRAddress(stringRepresentation: "2607:f938:3001:4000::aac/24")
|
||||
_ = try CIDRAddress(stringRepresentation: "192.168.0.1/24")
|
||||
}
|
||||
|
||||
func testIPv4CIDRAddress() throws {
|
||||
_ = try CIDRAddress(stringRepresentation: "192.168.0.1/24")
|
||||
}
|
||||
|
||||
func testCIDRAddress_invalidIP() throws {
|
||||
func executeTest(stringRepresentation: String, ipString: String, file: StaticString = #file, line: UInt = #line) {
|
||||
XCTAssertThrowsError(try CIDRAddress(stringRepresentation: stringRepresentation)) { (error) in
|
||||
guard case CIDRAddressValidationError.invalidIP(let value) = error else {
|
||||
return XCTFail("Unexpected error: \(error)", file: file, line: line)
|
||||
}
|
||||
XCTAssertEqual(value, ipString, file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
executeTest(stringRepresentation: "12345/12345", ipString: "12345")
|
||||
executeTest(stringRepresentation: "/12345", ipString: "")
|
||||
}
|
||||
|
||||
func testCIDRAddress_invalidSubnet() throws {
|
||||
func executeTest(stringRepresentation: String, subnetString: String, file: StaticString = #file, line: UInt = #line) {
|
||||
XCTAssertThrowsError(try CIDRAddress(stringRepresentation: stringRepresentation)) { (error) in
|
||||
guard case CIDRAddressValidationError.invalidSubnet(let value) = error else {
|
||||
return XCTFail("Unexpected error: \(error)", file: file, line: line)
|
||||
}
|
||||
XCTAssertEqual(value, subnetString, file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
executeTest(stringRepresentation: "/", subnetString: "")
|
||||
executeTest(stringRepresentation: "2607:f938:3001:4000::aac/a", subnetString: "a")
|
||||
executeTest(stringRepresentation: "2607:f938:3001:4000:/aac", subnetString: "aac")
|
||||
executeTest(stringRepresentation: "2607:f938:3001:4000::aac/", subnetString: "")
|
||||
executeTest(stringRepresentation: "192.168.0.1/a", subnetString: "a")
|
||||
executeTest(stringRepresentation: "192.168.0.1/", subnetString: "")
|
||||
|
||||
}
|
||||
|
||||
func testCIDRAddress_noIpAndSubnet() throws {
|
||||
|
||||
func executeTest(stringRepresentation: String, file: StaticString = #file, line: UInt = #line) {
|
||||
XCTAssertThrowsError(try CIDRAddress(stringRepresentation: stringRepresentation)) { (error) in
|
||||
guard case CIDRAddressValidationError.noIpAndSubnet(let value) = error else {
|
||||
return XCTFail("Unexpected error: \(error)", file: file, line: line)
|
||||
}
|
||||
XCTAssertEqual(value, stringRepresentation, file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
executeTest(stringRepresentation: "192.168.0.1")
|
||||
executeTest(stringRepresentation: "12345")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user