2018-08-23 08:19:25 +00:00
|
|
|
//
|
|
|
|
// AppExtensionTests.swift
|
2018-08-23 10:07:55 +00:00
|
|
|
// TunnelKitTests
|
2018-08-23 08:19:25 +00:00
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 10/23/17.
|
|
|
|
// Copyright © 2018 London Trust Media. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
2018-08-23 10:09:44 +00:00
|
|
|
@testable import TunnelKit
|
2018-08-23 08:19:25 +00:00
|
|
|
import NetworkExtension
|
|
|
|
|
|
|
|
class AppExtensionTests: 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 testConfiguration() {
|
2018-08-23 10:07:55 +00:00
|
|
|
var builder: TunnelKitProvider.ConfigurationBuilder!
|
|
|
|
var cfg: TunnelKitProvider.Configuration!
|
2018-08-23 08:19:25 +00:00
|
|
|
|
|
|
|
let identifier = "com.example.Provider"
|
2018-08-23 10:09:44 +00:00
|
|
|
let appGroup = "group.com.algoritmico.TunnelKit"
|
2018-08-23 10:07:55 +00:00
|
|
|
let endpoint = TunnelKitProvider.AuthenticatedEndpoint(
|
2018-08-23 08:19:25 +00:00
|
|
|
hostname: "example.com",
|
|
|
|
username: "foo",
|
|
|
|
password: "bar"
|
|
|
|
)
|
|
|
|
|
2018-08-23 10:07:55 +00:00
|
|
|
builder = TunnelKitProvider.ConfigurationBuilder(appGroup: appGroup)
|
2018-08-23 08:19:25 +00:00
|
|
|
XCTAssertNotNil(builder)
|
|
|
|
|
|
|
|
builder.cipher = .aes128cbc
|
|
|
|
builder.digest = .sha256
|
|
|
|
builder.handshake = .rsa3072
|
|
|
|
cfg = builder.build()
|
|
|
|
|
|
|
|
let proto = try? cfg.generatedTunnelProtocol(withBundleIdentifier: identifier, endpoint: endpoint)
|
|
|
|
XCTAssertNotNil(proto)
|
|
|
|
|
|
|
|
XCTAssertEqual(proto?.providerBundleIdentifier, identifier)
|
|
|
|
XCTAssertEqual(proto?.serverAddress, endpoint.hostname)
|
|
|
|
XCTAssertEqual(proto?.username, endpoint.username)
|
|
|
|
XCTAssertEqual(proto?.passwordReference, try? Keychain(group: appGroup).passwordReference(for: endpoint.username))
|
|
|
|
|
|
|
|
if let pc = proto?.providerConfiguration {
|
|
|
|
print("\(pc)")
|
|
|
|
}
|
|
|
|
|
2018-08-23 10:07:55 +00:00
|
|
|
let K = TunnelKitProvider.Configuration.Keys.self
|
2018-08-23 08:19:25 +00:00
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.appGroup] as? String, cfg.appGroup)
|
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.cipherAlgorithm] as? String, cfg.cipher.rawValue)
|
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.digestAlgorithm] as? String, cfg.digest.rawValue)
|
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.handshakeCertificate] as? String, cfg.handshake.rawValue)
|
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.mtu] as? NSNumber, cfg.mtu)
|
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.renegotiatesAfter] as? Int, cfg.renegotiatesAfterSeconds)
|
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.debug] as? Bool, cfg.shouldDebug)
|
|
|
|
XCTAssertEqual(proto?.providerConfiguration?[K.debugLogKey] as? String, cfg.debugLogKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testDNSResolver() {
|
|
|
|
let exp = expectation(description: "DNS")
|
|
|
|
DNSResolver.resolve("djsbjhcbjzhbxjnvsd.com", timeout: 1000, queue: DispatchQueue.main) { (addrs, error) in
|
|
|
|
defer {
|
|
|
|
exp.fulfill()
|
|
|
|
}
|
|
|
|
guard let addrs = addrs else {
|
|
|
|
print("Can't resolve")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
print("\(addrs)")
|
|
|
|
}
|
|
|
|
waitForExpectations(timeout: 5.0, handler: nil)
|
|
|
|
}
|
|
|
|
}
|