aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuardTests/ValidatorsTests.swift
diff options
context:
space:
mode:
authorJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-15 20:35:21 +0200
committerJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-15 20:35:21 +0200
commit9037b90747ccd153b57dfb223a6400456dcddcf5 (patch)
tree36dc813e5dc07c0699b6907536001bd37bd4d0ae /WireGuardTests/ValidatorsTests.swift
parentRemove old import. (diff)
downloadwireguard-apple-9037b90747ccd153b57dfb223a6400456dcddcf5.tar.xz
wireguard-apple-9037b90747ccd153b57dfb223a6400456dcddcf5.zip
Add Validator for Endpoints.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuardTests/ValidatorsTests.swift56
1 files changed, 56 insertions, 0 deletions
diff --git a/WireGuardTests/ValidatorsTests.swift b/WireGuardTests/ValidatorsTests.swift
new file mode 100644
index 0000000..1efae8d
--- /dev/null
+++ b/WireGuardTests/ValidatorsTests.swift
@@ -0,0 +1,56 @@
+//
+// ValidatorsTests.swift
+// WireGuardTests
+//
+// Created by Jeroen Leenarts on 15-08-18.
+// Copyright © 2018 WireGuard. All rights reserved.
+//
+
+import XCTest
+@testable import WireGuard
+
+class ValidatorsTests: XCTestCase {
+ func testIPv6Endpoint() throws {
+ XCTFail("Still needs implementation")
+ }
+
+ func testIPv4Endpoint() throws {
+ _ = 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")
+ }
+ XCTAssertEqual(value, "12345")
+ }
+ }
+
+ 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")
+ }
+ XCTAssertEqual(value, "-12345")
+ }
+ }
+
+ func testIPv4Endpoint_noIpAndPort() throws {
+
+ func executeTest(endpointString: String) {
+ XCTAssertThrowsError(try Endpoint(endpointString: endpointString)) { (error) in
+ guard case EndpointValidationError.noIpAndPort(let value) = error else {
+ return XCTFail("Unexpected error")
+ }
+ 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")
+ }
+}