mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-02-21 23:32:07 +00:00
Fix OpenVPN/WireGuard import error messages (#967)
OpenVPN parser was indirectly swallowing WireGuard errors.
This commit is contained in:
parent
725168b652
commit
f87cc1da0b
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@ -23,6 +23,7 @@ jobs:
|
|||||||
- uses: passepartoutvpn/action-prepare-xcode-build@master
|
- uses: passepartoutvpn/action-prepare-xcode-build@master
|
||||||
with:
|
with:
|
||||||
access_token: ${{ secrets.ACCESS_TOKEN }}
|
access_token: ${{ secrets.ACCESS_TOKEN }}
|
||||||
- run: |
|
- name: "Run tests"
|
||||||
|
run: |
|
||||||
cd Library
|
cd Library
|
||||||
swift test
|
swift test
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "5211efce28b6d96a38747a6004a4bf03e169b27c"
|
"revision" : "aa85d745f8419def59ef630501d71a491a32829e"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -58,7 +58,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go",
|
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "68fceaa664913988b2d9053405738682a30b87b8"
|
"revision" : "c2bfbf8744e04571a3e858385f49c98863fe9616",
|
||||||
|
"version" : "0.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -51,14 +51,14 @@ let package = Package(
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.11.0"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "5211efce28b6d96a38747a6004a4bf03e169b27c"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "aa85d745f8419def59ef630501d71a491a32829e"),
|
||||||
// .package(path: "../../passepartoutkit-source"),
|
// .package(path: "../../passepartoutkit-source"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"),
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
|
||||||
// .package(path: "../../passepartoutkit-source-openvpn-openssl"),
|
// .package(path: "../../passepartoutkit-source-openvpn-openssl"),
|
||||||
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", from: "0.9.2"),
|
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", from: "0.12.0"),
|
||||||
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", revision: "68fceaa664913988b2d9053405738682a30b87b8"),
|
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", revision: "68fceaa664913988b2d9053405738682a30b87b8"),
|
||||||
// .package(path: "../../passepartoutkit-source-wireguard-go"),
|
// .package(path: "../../passepartoutkit-source-wireguard-go"),
|
||||||
.package(url: "https://github.com/Cocoanetics/Kvitto", from: "1.0.0")
|
.package(url: "https://github.com/Cocoanetics/Kvitto", from: "1.0.0")
|
||||||
],
|
],
|
||||||
|
@ -46,7 +46,7 @@ final class ProfileImporter: ObservableObject {
|
|||||||
func tryImport(
|
func tryImport(
|
||||||
urls: [URL],
|
urls: [URL],
|
||||||
profileManager: ProfileManager,
|
profileManager: ProfileManager,
|
||||||
registry: Registry
|
importer: ModuleImporter
|
||||||
) async throws {
|
) async throws {
|
||||||
var withPassphrase: [URL] = []
|
var withPassphrase: [URL] = []
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ final class ProfileImporter: ObservableObject {
|
|||||||
url,
|
url,
|
||||||
withPassphrase: nil,
|
withPassphrase: nil,
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
registry: registry
|
importer: importer
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
if let error = error as? PassepartoutError, error.code == .OpenVPN.passphraseRequired {
|
if let error = error as? PassepartoutError, error.code == .OpenVPN.passphraseRequired {
|
||||||
@ -74,13 +74,13 @@ final class ProfileImporter: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reImport(url: URL, profileManager: ProfileManager, registry: Registry) async throws {
|
func reImport(url: URL, profileManager: ProfileManager, importer: ModuleImporter) async throws {
|
||||||
do {
|
do {
|
||||||
try await importURL(
|
try await importURL(
|
||||||
url,
|
url,
|
||||||
withPassphrase: currentPassphrase,
|
withPassphrase: currentPassphrase,
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
registry: registry
|
importer: importer
|
||||||
)
|
)
|
||||||
urlsRequiringPassphrase.removeFirst()
|
urlsRequiringPassphrase.removeFirst()
|
||||||
scheduleNextImport()
|
scheduleNextImport()
|
||||||
@ -113,7 +113,7 @@ private extension ProfileImporter {
|
|||||||
_ url: URL,
|
_ url: URL,
|
||||||
withPassphrase passphrase: String?,
|
withPassphrase passphrase: String?,
|
||||||
profileManager: ProfileManager,
|
profileManager: ProfileManager,
|
||||||
registry: Registry
|
importer: ModuleImporter
|
||||||
) async throws {
|
) async throws {
|
||||||
guard url.startAccessingSecurityScopedResource() else {
|
guard url.startAccessingSecurityScopedResource() else {
|
||||||
throw AppError.permissionDenied
|
throw AppError.permissionDenied
|
||||||
@ -122,7 +122,7 @@ private extension ProfileImporter {
|
|||||||
url.stopAccessingSecurityScopedResource()
|
url.stopAccessingSecurityScopedResource()
|
||||||
}
|
}
|
||||||
|
|
||||||
let module = try registry.module(fromURL: url, object: passphrase)
|
let module = try importer.module(fromURL: url, object: passphrase)
|
||||||
let onDemandModule = OnDemandModule.Builder().tryBuild()
|
let onDemandModule = OnDemandModule.Builder().tryBuild()
|
||||||
|
|
||||||
var builder = Profile.Builder()
|
var builder = Profile.Builder()
|
||||||
|
@ -75,7 +75,7 @@ private extension ProfileImporterModifier {
|
|||||||
try await importer.reImport(
|
try await importer.reImport(
|
||||||
url: url,
|
url: url,
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
registry: registry
|
importer: registry
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ private extension ProfileImporterModifier {
|
|||||||
try await importer.tryImport(
|
try await importer.tryImport(
|
||||||
urls: urls,
|
urls: urls,
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
registry: registry
|
importer: registry
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
await errorHandler.handle(
|
await errorHandler.handle(
|
||||||
|
@ -31,10 +31,7 @@ import PassepartoutKit
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
final class ProfileImporterTests: XCTestCase {
|
final class ProfileImporterTests: XCTestCase {
|
||||||
private let registry = Registry(
|
private let moduleImporter = SomeModule.Implementation()
|
||||||
allHandlers: [SomeModule.moduleHandler],
|
|
||||||
allImplementations: [SomeModule.Implementation()]
|
|
||||||
)
|
|
||||||
|
|
||||||
private var subscriptions: Set<AnyCancellable> = []
|
private var subscriptions: Set<AnyCancellable> = []
|
||||||
}
|
}
|
||||||
@ -45,7 +42,7 @@ extension ProfileImporterTests {
|
|||||||
let sut = ProfileImporter()
|
let sut = ProfileImporter()
|
||||||
let profileManager = ProfileManager(profiles: [])
|
let profileManager = ProfileManager(profiles: [])
|
||||||
|
|
||||||
try await sut.tryImport(urls: [], profileManager: profileManager, registry: registry)
|
try await sut.tryImport(urls: [], profileManager: profileManager, importer: moduleImporter)
|
||||||
XCTAssertEqual(sut.nextURL, nil)
|
XCTAssertEqual(sut.nextURL, nil)
|
||||||
XCTAssertTrue(profileManager.previews.isEmpty)
|
XCTAssertTrue(profileManager.previews.isEmpty)
|
||||||
}
|
}
|
||||||
@ -75,7 +72,7 @@ extension ProfileImporterTests {
|
|||||||
try await sut.tryImport(
|
try await sut.tryImport(
|
||||||
urls: [url],
|
urls: [url],
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
registry: registry
|
importer: moduleImporter
|
||||||
)
|
)
|
||||||
XCTAssertEqual(sut.nextURL, nil)
|
XCTAssertEqual(sut.nextURL, nil)
|
||||||
|
|
||||||
@ -107,12 +104,12 @@ extension ProfileImporterTests {
|
|||||||
try await sut.tryImport(
|
try await sut.tryImport(
|
||||||
urls: [url],
|
urls: [url],
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
registry: registry
|
importer: moduleImporter
|
||||||
)
|
)
|
||||||
XCTAssertEqual(sut.nextURL, url)
|
XCTAssertEqual(sut.nextURL, url)
|
||||||
|
|
||||||
sut.currentPassphrase = "passphrase"
|
sut.currentPassphrase = "passphrase"
|
||||||
try await sut.reImport(url: url, profileManager: profileManager, registry: registry)
|
try await sut.reImport(url: url, profileManager: profileManager, importer: moduleImporter)
|
||||||
XCTAssertEqual(sut.nextURL, nil)
|
XCTAssertEqual(sut.nextURL, nil)
|
||||||
|
|
||||||
await fulfillment(of: [exp])
|
await fulfillment(of: [exp])
|
||||||
@ -126,29 +123,37 @@ extension ProfileImporterTests {
|
|||||||
try await sut.tryImport(
|
try await sut.tryImport(
|
||||||
urls: [url, url, url],
|
urls: [url, url, url],
|
||||||
profileManager: profileManager,
|
profileManager: profileManager,
|
||||||
registry: registry
|
importer: moduleImporter
|
||||||
)
|
)
|
||||||
XCTAssertEqual(sut.nextURL, url)
|
XCTAssertEqual(sut.nextURL, url)
|
||||||
XCTAssertEqual(sut.urlsRequiringPassphrase.count, 3)
|
XCTAssertEqual(sut.urlsRequiringPassphrase.count, 3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: -
|
||||||
|
|
||||||
private struct SomeModule: Module {
|
private struct SomeModule: Module {
|
||||||
struct Implementation: ModuleImplementation, ModuleImporter {
|
struct Implementation: ModuleImplementation {
|
||||||
var moduleHandlerId: ModuleHandler.ID {
|
var moduleHandlerId: ModuleHandler.ID {
|
||||||
moduleHandler.id
|
moduleHandler.id
|
||||||
}
|
}
|
||||||
|
}
|
||||||
func module(fromURL url: URL, object: Any?) throws -> Module {
|
}
|
||||||
if url.absoluteString.hasSuffix(".encrypted") {
|
|
||||||
guard let passphrase = object as? String else {
|
extension SomeModule.Implementation: ModuleImporter {
|
||||||
throw PassepartoutError(.OpenVPN.passphraseRequired)
|
func module(fromContents contents: String, object: Any?) throws -> Module {
|
||||||
}
|
fatalError()
|
||||||
guard passphrase == "passphrase" else {
|
}
|
||||||
throw PassepartoutError(.crypto)
|
|
||||||
}
|
func module(fromURL url: URL, object: Any?) throws -> Module {
|
||||||
}
|
if url.absoluteString.hasSuffix(".encrypted") {
|
||||||
return SomeModule()
|
guard let passphrase = object as? String else {
|
||||||
}
|
throw PassepartoutError(.OpenVPN.passphraseRequired)
|
||||||
|
}
|
||||||
|
guard passphrase == "passphrase" else {
|
||||||
|
throw PassepartoutError(.crypto)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SomeModule()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user