2018-08-28 14:43:54 +00:00
|
|
|
//
|
|
|
|
// PushTests.swift
|
|
|
|
// TunnelKitTests
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 8/24/18.
|
2020-01-11 08:26:41 +00:00
|
|
|
// Copyright (c) 2020 Davide De Rosa. All rights reserved.
|
2018-08-28 14:43:54 +00:00
|
|
|
//
|
2019-05-14 08:58:47 +00:00
|
|
|
// https://github.com/passepartoutvpn
|
2018-08-28 14:43:54 +00:00
|
|
|
//
|
|
|
|
// This file is part of TunnelKit.
|
|
|
|
//
|
|
|
|
// TunnelKit is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// TunnelKit is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with TunnelKit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
@testable import TunnelKit
|
|
|
|
|
2019-05-19 13:50:30 +00:00
|
|
|
private extension OpenVPN.PushReply {
|
2018-08-28 14:43:54 +00:00
|
|
|
func debug() {
|
2019-04-04 11:01:32 +00:00
|
|
|
print("Compression framing: \(options.compressionFraming?.description ?? "disabled")")
|
|
|
|
print("Compression algorithm: \(options.compressionAlgorithm?.description ?? "disabled")")
|
2019-04-03 08:48:25 +00:00
|
|
|
print("IPv4: \(options.ipv4?.description ?? "none")")
|
|
|
|
print("IPv6: \(options.ipv6?.description ?? "none")")
|
2019-04-04 10:40:28 +00:00
|
|
|
print("DNS: \(options.dnsServers?.description ?? "none")")
|
2018-08-28 14:43:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PushTests: XCTestCase {
|
|
|
|
|
|
|
|
override func 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.
|
|
|
|
}
|
|
|
|
|
|
|
|
func testNet30() {
|
|
|
|
let msg = "PUSH_REPLY,redirect-gateway def1,dhcp-option DNS 209.222.18.222,dhcp-option DNS 209.222.18.218,ping 10,comp-lzo no,route 10.5.10.1,topology net30,ifconfig 10.5.10.6 10.5.10.5,auth-token AUkQf/b3nj3L+CH4RJPP0Vuq8/gpntr7uPqzjQhncig="
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-08-28 14:43:54 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.ipv4?.address, "10.5.10.6")
|
|
|
|
XCTAssertEqual(reply.options.ipv4?.addressMask, "255.255.255.255")
|
|
|
|
XCTAssertEqual(reply.options.ipv4?.defaultGateway, "10.5.10.5")
|
|
|
|
XCTAssertEqual(reply.options.dnsServers, ["209.222.18.222", "209.222.18.218"])
|
2018-08-28 14:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testSubnet() {
|
|
|
|
let msg = "PUSH_REPLY,dhcp-option DNS 8.8.8.8,dhcp-option DNS 4.4.4.4,route-gateway 10.8.0.1,topology subnet,ping 10,ping-restart 120,ifconfig 10.8.0.2 255.255.255.0,peer-id 0"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-08-28 14:43:54 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.ipv4?.address, "10.8.0.2")
|
|
|
|
XCTAssertEqual(reply.options.ipv4?.addressMask, "255.255.255.0")
|
|
|
|
XCTAssertEqual(reply.options.ipv4?.defaultGateway, "10.8.0.1")
|
|
|
|
XCTAssertEqual(reply.options.dnsServers, ["8.8.8.8", "4.4.4.4"])
|
2018-08-28 14:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testRoute() {
|
|
|
|
let msg = "PUSH_REPLY,dhcp-option DNS 8.8.8.8,dhcp-option DNS 4.4.4.4,route-gateway 10.8.0.1,route 192.168.0.0 255.255.255.0 10.8.0.12,topology subnet,ping 10,ping-restart 120,ifconfig 10.8.0.2 255.255.255.0,peer-id 0"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-08-28 14:43:54 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-03 08:48:25 +00:00
|
|
|
let route = reply.options.ipv4!.routes.first!
|
2018-08-28 14:43:54 +00:00
|
|
|
|
|
|
|
XCTAssertEqual(route.destination, "192.168.0.0")
|
|
|
|
XCTAssertEqual(route.mask, "255.255.255.0")
|
|
|
|
XCTAssertEqual(route.gateway, "10.8.0.12")
|
|
|
|
}
|
2018-08-24 13:00:10 +00:00
|
|
|
|
|
|
|
func testIPv6() {
|
|
|
|
let msg = "PUSH_REPLY,dhcp-option DNS6 2001:4860:4860::8888,dhcp-option DNS6 2001:4860:4860::8844,tun-ipv6,route-gateway 10.8.0.1,topology subnet,ping 10,ping-restart 120,ifconfig-ipv6 fe80::601:30ff:feb7:ec01/64 fe80::601:30ff:feb7:dc02,ifconfig 10.8.0.2 255.255.255.0,peer-id 0"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-08-24 13:00:10 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.ipv4?.address, "10.8.0.2")
|
|
|
|
XCTAssertEqual(reply.options.ipv4?.addressMask, "255.255.255.0")
|
|
|
|
XCTAssertEqual(reply.options.ipv4?.defaultGateway, "10.8.0.1")
|
|
|
|
XCTAssertEqual(reply.options.ipv6?.address, "fe80::601:30ff:feb7:ec01")
|
|
|
|
XCTAssertEqual(reply.options.ipv6?.addressPrefixLength, 64)
|
|
|
|
XCTAssertEqual(reply.options.ipv6?.defaultGateway, "fe80::601:30ff:feb7:dc02")
|
|
|
|
XCTAssertEqual(reply.options.dnsServers, ["2001:4860:4860::8888", "2001:4860:4860::8844"])
|
2018-08-24 13:00:10 +00:00
|
|
|
}
|
2018-09-01 23:25:27 +00:00
|
|
|
|
2018-09-07 13:13:58 +00:00
|
|
|
func testCompressionFraming() {
|
|
|
|
let msg = "PUSH_REPLY,dhcp-option DNS 8.8.8.8,dhcp-option DNS 4.4.4.4,comp-lzo no,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-CBC"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-09-07 13:13:58 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.compressionFraming, .compLZO)
|
2018-09-07 13:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 18:54:38 +00:00
|
|
|
func testCompression() {
|
|
|
|
let msg = "PUSH_REPLY,dhcp-option DNS 8.8.8.8,dhcp-option DNS 4.4.4.4,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-CBC"
|
2019-05-19 13:50:30 +00:00
|
|
|
var reply: OpenVPN.PushReply
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2019-05-19 13:50:30 +00:00
|
|
|
reply = try! OpenVPN.PushReply(message: msg.appending(",comp-lzo no"))!
|
2019-02-23 18:54:38 +00:00
|
|
|
reply.debug()
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.compressionFraming, .compLZO)
|
|
|
|
XCTAssertEqual(reply.options.compressionAlgorithm, .disabled)
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2019-05-19 13:50:30 +00:00
|
|
|
reply = try! OpenVPN.PushReply(message: msg.appending(",comp-lzo"))!
|
2019-02-23 18:54:38 +00:00
|
|
|
reply.debug()
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.compressionFraming, .compLZO)
|
|
|
|
XCTAssertEqual(reply.options.compressionAlgorithm, .LZO)
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2019-05-19 13:50:30 +00:00
|
|
|
reply = try! OpenVPN.PushReply(message: msg.appending(",comp-lzo yes"))!
|
2019-02-23 18:54:38 +00:00
|
|
|
reply.debug()
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.compressionFraming, .compLZO)
|
|
|
|
XCTAssertEqual(reply.options.compressionAlgorithm, .LZO)
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2019-05-19 13:50:30 +00:00
|
|
|
reply = try! OpenVPN.PushReply(message: msg.appending(",compress"))!
|
2019-02-23 18:54:38 +00:00
|
|
|
reply.debug()
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.compressionFraming, .compress)
|
|
|
|
XCTAssertEqual(reply.options.compressionAlgorithm, .disabled)
|
2019-02-23 18:54:38 +00:00
|
|
|
|
2019-05-19 13:50:30 +00:00
|
|
|
reply = try! OpenVPN.PushReply(message: msg.appending(",compress lz4"))!
|
2019-02-23 18:54:38 +00:00
|
|
|
reply.debug()
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.compressionFraming, .compress)
|
|
|
|
XCTAssertEqual(reply.options.compressionAlgorithm, .other)
|
2019-02-23 18:54:38 +00:00
|
|
|
}
|
|
|
|
|
2018-09-01 23:25:27 +00:00
|
|
|
func testNCP() {
|
2018-09-07 13:25:00 +00:00
|
|
|
let msg = "PUSH_REPLY,dhcp-option DNS 8.8.8.8,dhcp-option DNS 4.4.4.4,comp-lzo no,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-GCM"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-09-01 23:25:27 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.cipher, .aes256gcm)
|
2018-09-05 01:53:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func testNCPTrailing() {
|
|
|
|
let msg = "PUSH_REPLY,dhcp-option DNS 8.8.8.8,dhcp-option DNS 4.4.4.4,comp-lzo no,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.18 10.8.0.17,peer-id 3,cipher AES-256-GCM,auth-token"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-09-05 01:53:16 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-03 08:48:25 +00:00
|
|
|
XCTAssertEqual(reply.options.cipher, .aes256gcm)
|
2018-09-01 23:25:27 +00:00
|
|
|
}
|
2018-09-08 18:28:53 +00:00
|
|
|
|
|
|
|
func testPing() {
|
|
|
|
let msg = "PUSH_REPLY,route 192.168.1.0 255.255.255.0,route 10.0.2.0 255.255.255.0,dhcp-option DNS 192.168.1.99,dhcp-option DNS 176.103.130.130,route 10.0.2.1,topology net30,ping 10,ping-restart 60,ifconfig 10.0.2.14 10.0.2.13"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
2018-09-08 18:28:53 +00:00
|
|
|
reply.debug()
|
|
|
|
|
2019-04-04 10:40:28 +00:00
|
|
|
XCTAssertEqual(reply.options.keepAliveInterval, 10)
|
2018-09-08 18:28:53 +00:00
|
|
|
}
|
2019-04-16 21:55:50 +00:00
|
|
|
|
2019-09-30 18:54:29 +00:00
|
|
|
func testPingRestart() {
|
|
|
|
let msg = "PUSH_REPLY,route 192.168.1.0 255.255.255.0,route 10.0.2.0 255.255.255.0,dhcp-option DNS 192.168.1.99,dhcp-option DNS 176.103.130.130,route 10.0.2.1,topology net30,ping 10,ping-restart 60,ifconfig 10.0.2.14 10.0.2.13"
|
|
|
|
let reply = try! OpenVPN.PushReply(message: msg)!
|
|
|
|
reply.debug()
|
|
|
|
|
|
|
|
XCTAssertEqual(reply.options.keepAliveTimeout, 60)
|
|
|
|
}
|
|
|
|
|
2019-04-16 21:55:50 +00:00
|
|
|
func testProvost() {
|
|
|
|
let msg = "PUSH_REPLY,route 87.233.192.218,route 87.233.192.219,route 87.233.192.220,route 87.248.186.252,route 92.241.171.245,route 103.246.200.0 255.255.252.0,route 109.239.140.0 255.255.255.0,route 128.199.0.0 255.255.0.0,route 13.125.0.0 255.255.0.0,route 13.230.0.0 255.254.0.0,route 13.56.0.0 255.252.0.0,route 149.154.160.0 255.255.252.0,route 149.154.164.0 255.255.252.0,route 149.154.168.0 255.255.252.0,route 149.154.172.0 255.255.252.0,route 159.122.128.0 255.255.192.0,route 159.203.0.0 255.255.0.0,route 159.65.0.0 255.255.0.0,route 159.89.0.0 255.255.0.0,route 165.227.0.0 255.255.0.0,route 167.99.0.0 255.255.0.0,route 174.138.0.0 255.255.128.0,route 176.67.169.0 255.255.255.0,route 178.239.88.0 255.255.248.0,route 178.63.0.0 255.255.0.0,route 18.130.0.0 255.255.0.0,route 18.144.0.0 255.255.0.0,route 18.184.0.0 255.254.0.0,route 18.194.0.0 255.254.0.0,route 18.196.0.0 255.254.0.0,route 18.204.0.0 255.252.0.0,push-continuation 2"
|
2019-05-19 13:50:30 +00:00
|
|
|
let reply = try? OpenVPN.PushReply(message: msg)!
|
2019-05-19 00:08:49 +00:00
|
|
|
reply?.debug()
|
2019-04-16 21:55:50 +00:00
|
|
|
}
|
2018-08-28 14:43:54 +00:00
|
|
|
}
|