aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuardTests
diff options
context:
space:
mode:
authorJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-15 22:52:37 +0200
committerJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-15 22:52:37 +0200
commit91daed0c8061f0bd02bc171942933423f26c9fc1 (patch)
treeb1ac389699506b07e04d8be06f32d357f294a4c8 /WireGuardTests
parentAssign correct copyright. (diff)
downloadwireguard-apple-91daed0c8061f0bd02bc171942933423f26c9fc1.tar.xz
wireguard-apple-91daed0c8061f0bd02bc171942933423f26c9fc1.zip
Improve validator for IPv6.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuardTests/ValidatorsTests.swift53
-rw-r--r--WireGuardTests/WireGuardTests.swift36
2 files changed, 31 insertions, 58 deletions
diff --git a/WireGuardTests/ValidatorsTests.swift b/WireGuardTests/ValidatorsTests.swift
index 306c775..df70c89 100644
--- a/WireGuardTests/ValidatorsTests.swift
+++ b/WireGuardTests/ValidatorsTests.swift
@@ -10,47 +10,56 @@ import XCTest
@testable import WireGuard
class ValidatorsTests: XCTestCase {
- func testIPv6Endpoint() throws {
- XCTFail("Still needs implementation")
- }
-
- func testIPv4Endpoint() throws {
+ func testEndpoint() throws {
+ _ = try Endpoint(endpointString: "[2607:f938:3001:4000::aac]:12345")
_ = try Endpoint(endpointString: "192.168.0.1:12345")
}
- func testIPv4Endpoint_invalidIP() throws {
- XCTAssertThrowsError(try Endpoint(endpointString: "12345:12345")) { (error) in
- guard case EndpointValidationError.invalidIP(let value) = error else {
- return XCTFail("Unexpected error")
+ func testEndpoint_invalidIP() throws {
+ func executeTest(endpointString: String, ipString: String, file: StaticString = #file, line: UInt = #line) {
+ XCTAssertThrowsError(try Endpoint(endpointString: endpointString)) { (error) in
+ guard case EndpointValidationError.invalidIP(let value) = error else {
+ return XCTFail("Unexpected error: \(error)", file: file, line: line)
+ }
+ XCTAssertEqual(value, ipString, file: file, line: line)
}
- XCTAssertEqual(value, "12345")
}
+
+ executeTest(endpointString: "12345:12345", ipString: "12345")
+ executeTest(endpointString: ":12345", ipString: "")
}
- func testIPv4Endpoint_invalidPort() throws {
- XCTAssertThrowsError(try Endpoint(endpointString: "192.168.0.1:-12345")) { (error) in
- guard case EndpointValidationError.invalidPort(let value) = error else {
- return XCTFail("Unexpected error")
+ func testEndpoint_invalidPort() throws {
+ func executeTest(endpointString: String, portString: String, file: StaticString = #file, line: UInt = #line) {
+ XCTAssertThrowsError(try Endpoint(endpointString: endpointString)) { (error) in
+ guard case EndpointValidationError.invalidPort(let value) = error else {
+ return XCTFail("Unexpected error: \(error)", file: file, line: line)
+ }
+ XCTAssertEqual(value, portString, file: file, line: line)
}
- XCTAssertEqual(value, "-12345")
}
+
+ executeTest(endpointString: ":", portString: "")
+ executeTest(endpointString: "[2607:f938:3001:4000::aac]:-12345", portString: "-12345")
+ executeTest(endpointString: "[2607:f938:3001:4000::aac]", portString: "aac]")
+ executeTest(endpointString: "[2607:f938:3001:4000::aac]:", portString: "")
+ executeTest(endpointString: "192.168.0.1:-12345", portString: "-12345")
+ executeTest(endpointString: "192.168.0.1:", portString: "")
+
}
- func testIPv4Endpoint_noIpAndPort() throws {
+ func testEndpoint_noIpAndPort() throws {
- func executeTest(endpointString: String) {
+ func executeTest(endpointString: String, file: StaticString = #file, line: UInt = #line) {
XCTAssertThrowsError(try Endpoint(endpointString: endpointString)) { (error) in
guard case EndpointValidationError.noIpAndPort(let value) = error else {
- return XCTFail("Unexpected error")
+ return XCTFail("Unexpected error: \(error)", file: file, line: line)
}
- XCTAssertEqual(value, endpointString, file: #file, line: #line)
+ XCTAssertEqual(value, endpointString, file: file, line: line)
}
}
- executeTest(endpointString: ":")
executeTest(endpointString: "192.168.0.1")
- executeTest(endpointString: "192.168.0.1:")
- executeTest(endpointString: ":12345")
executeTest(endpointString: "12345")
}
}
diff --git a/WireGuardTests/WireGuardTests.swift b/WireGuardTests/WireGuardTests.swift
deleted file mode 100644
index a952cfe..0000000
--- a/WireGuardTests/WireGuardTests.swift
+++ /dev/null
@@ -1,36 +0,0 @@
-//
-// WireGuardTests.swift
-// WireGuardTests
-//
-// Created by Jeroen Leenarts on 23-05-18.
-// Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All rights reserved.
-//
-
-import XCTest
-@testable import WireGuard
-
-class WireGuardTests: XCTestCase {
-
- override func setUp() {
- super.setUp()
- // Put setup code here. This method is called before the invocation of each test method in the class.
- }
-
- override func tearDown() {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
- super.tearDown()
- }
-
- func testExample() {
- // This is an example of a functional test case.
- // Use XCTAssert and related functions to verify your tests produce the correct results.
- }
-
- func testPerformanceExample() {
- // This is an example of a performance test case.
- self.measure {
- // Put the code you want to measure the time of here.
- }
- }
-
-}