Fix OpenVPN/WireGuard import error messages (#967)

OpenVPN parser was indirectly swallowing WireGuard errors.
This commit is contained in:
Davide 2024-12-01 21:33:58 +01:00 committed by GitHub
parent 725168b652
commit f87cc1da0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 37 deletions

View File

@ -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

View File

@ -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"
} }
}, },
{ {

View File

@ -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")
], ],

View File

@ -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()

View File

@ -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(

View File

@ -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,18 +123,27 @@ 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
} }
}
}
extension SomeModule.Implementation: ModuleImporter {
func module(fromContents contents: String, object: Any?) throws -> Module {
fatalError()
}
func module(fromURL url: URL, object: Any?) throws -> Module { func module(fromURL url: URL, object: Any?) throws -> Module {
if url.absoluteString.hasSuffix(".encrypted") { if url.absoluteString.hasSuffix(".encrypted") {
@ -150,5 +156,4 @@ private struct SomeModule: Module {
} }
return SomeModule() return SomeModule()
} }
}
} }