Skip to content

Commit

Permalink
Update library and fix importer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keeshux committed Dec 1, 2024
1 parent 2e6aab3 commit b009426
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Library/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"kind" : "remoteSourceControl",
"location" : "git@github.com:passepartoutvpn/passepartoutkit-source",
"state" : {
"revision" : "e8833c9416503026ba933adcb6c5850a9db2f13b",
"version" : "0.12.0"
"revision" : "aa85d745f8419def59ef630501d71a491a32829e"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Library/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ let package = Package(
)
],
dependencies: [
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "e8833c9416503026ba933adcb6c5850a9db2f13b"),
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.12.0"),
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "aa85d745f8419def59ef630501d71a491a32829e"),
// .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", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"),
Expand Down
43 changes: 24 additions & 19 deletions Library/Tests/AppUIMainTests/ProfileImporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ import PassepartoutKit
import XCTest

final class ProfileImporterTests: XCTestCase {
private let registry = Registry(
allHandlers: [SomeModule.moduleHandler],
allImplementations: [SomeModule.Implementation()]
)
private let moduleImporter = SomeModule.Implementation()

private var subscriptions: Set<AnyCancellable> = []
}
Expand All @@ -45,7 +42,7 @@ extension ProfileImporterTests {
let sut = ProfileImporter()
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)
XCTAssertTrue(profileManager.previews.isEmpty)
}
Expand Down Expand Up @@ -75,7 +72,7 @@ extension ProfileImporterTests {
try await sut.tryImport(
urls: [url],
profileManager: profileManager,
registry: registry
importer: moduleImporter
)
XCTAssertEqual(sut.nextURL, nil)

Expand Down Expand Up @@ -107,12 +104,12 @@ extension ProfileImporterTests {
try await sut.tryImport(
urls: [url],
profileManager: profileManager,
registry: registry
importer: moduleImporter
)
XCTAssertEqual(sut.nextURL, url)

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)

await fulfillment(of: [exp])
Expand All @@ -126,29 +123,37 @@ extension ProfileImporterTests {
try await sut.tryImport(
urls: [url, url, url],
profileManager: profileManager,
registry: registry
importer: moduleImporter
)
XCTAssertEqual(sut.nextURL, url)
XCTAssertEqual(sut.urlsRequiringPassphrase.count, 3)
}
}

// MARK: -

private struct SomeModule: Module {
struct Implementation: ModuleImplementation, ModuleImporter {
struct Implementation: ModuleImplementation {
var moduleHandlerId: 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 {
throw PassepartoutError(.OpenVPN.passphraseRequired)
}
guard passphrase == "passphrase" else {
throw PassepartoutError(.crypto)
}
extension SomeModule.Implementation: ModuleImporter {
func module(fromContents contents: String, object: Any?) throws -> Module {
fatalError()
}

func module(fromURL url: URL, object: Any?) throws -> Module {
if url.absoluteString.hasSuffix(".encrypted") {
guard let passphrase = object as? String else {
throw PassepartoutError(.OpenVPN.passphraseRequired)
}
guard passphrase == "passphrase" else {
throw PassepartoutError(.crypto)
}
return SomeModule()
}
return SomeModule()
}
}

0 comments on commit b009426

Please sign in to comment.