2018-11-10 09:54:50 +00:00
|
|
|
//
|
|
|
|
// ConfigurationParserTests.swift
|
|
|
|
// TunnelKitTests
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 11/10/18.
|
2019-03-09 10:44:18 +00:00
|
|
|
// Copyright (c) 2019 Davide De Rosa. All rights reserved.
|
2018-11-10 09:54:50 +00:00
|
|
|
//
|
|
|
|
// https://github.com/keeshux
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
import TunnelKit
|
|
|
|
|
|
|
|
class ConfigurationParserTests: 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 testPIA() throws {
|
|
|
|
let file = try ConfigurationParser.parsed(fromURL: url(withName: "pia-hungary"))
|
|
|
|
XCTAssertEqual(file.hostname, "hungary.privateinternetaccess.com")
|
|
|
|
XCTAssertEqual(file.configuration.cipher, .aes128cbc)
|
|
|
|
XCTAssertEqual(file.configuration.digest, .sha1)
|
|
|
|
XCTAssertEqual(file.protocols, [
|
|
|
|
EndpointProtocol(.udp, 1198),
|
|
|
|
EndpointProtocol(.tcp, 502)
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStripped() throws {
|
|
|
|
let lines = try ConfigurationParser.parsed(fromURL: url(withName: "pia-hungary"), returnsStripped: true).strippedLines!
|
|
|
|
let stripped = lines.joined(separator: "\n")
|
|
|
|
print(stripped)
|
|
|
|
}
|
|
|
|
|
2019-03-25 14:51:43 +00:00
|
|
|
func testEncryptedCertificateKey() throws {
|
2019-04-01 22:09:18 +00:00
|
|
|
try privateTestEncryptedCertificateKey(pkcs: "1")
|
2019-04-01 22:33:20 +00:00
|
|
|
try privateTestEncryptedCertificateKey(pkcs: "8")
|
2019-04-01 22:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private func privateTestEncryptedCertificateKey(pkcs: String) throws {
|
2019-04-02 16:58:30 +00:00
|
|
|
let cfgURL = url(withName: "tunnelbear.enc.\(pkcs)")
|
|
|
|
XCTAssertThrowsError(try ConfigurationParser.parsed(fromURL: cfgURL))
|
|
|
|
XCTAssertNoThrow(try ConfigurationParser.parsed(fromURL: cfgURL, passphrase: "foobar"))
|
2019-04-01 22:55:44 +00:00
|
|
|
}
|
|
|
|
|
2018-11-10 09:54:50 +00:00
|
|
|
private func url(withName name: String) -> URL {
|
|
|
|
return Bundle(for: ConfigurationParserTests.self).url(forResource: name, withExtension: "ovpn")!
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|