Skip to content

Commit

Permalink
removing network operation from settings migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii committed Dec 20, 2023
1 parent ce7f4f7 commit 9e8c155
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 30 deletions.
4 changes: 0 additions & 4 deletions ios/MullvadSettings/MigrationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import MullvadLogging
import MullvadREST
import MullvadTypes

public enum SettingsMigrationResult {
Expand Down Expand Up @@ -37,7 +36,6 @@ public struct MigrationManager {
/// - migrationCompleted: Completion handler called with a migration result.
public func migrateSettings(
store: SettingsStore,
proxyFactory: REST.ProxyFactory,
migrationCompleted: @escaping (SettingsMigrationResult) -> Void
) {
let resetStoreHandler = { (result: SettingsMigrationResult) in
Expand All @@ -51,7 +49,6 @@ public struct MigrationManager {
do {
try upgradeSettingsToLatestVersion(
store: store,
proxyFactory: proxyFactory,
migrationCompleted: migrationCompleted
)
} catch .itemNotFound as KeychainError {
Expand All @@ -63,7 +60,6 @@ public struct MigrationManager {

private func upgradeSettingsToLatestVersion(
store: SettingsStore,
proxyFactory: REST.ProxyFactory,
migrationCompleted: @escaping (SettingsMigrationResult) -> Void
) throws {
let parser = SettingsParser(decoder: JSONDecoder(), encoder: JSONEncoder())
Expand Down
1 change: 0 additions & 1 deletion ios/MullvadSettings/SettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import MullvadLogging
import MullvadREST
import MullvadTypes

private let keychainServiceName = "Mullvad VPN"
Expand Down
1 change: 0 additions & 1 deletion ios/MullvadSettings/TunnelSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import MullvadREST

/// Alias to the latest version of the `TunnelSettings`.
public typealias LatestTunnelSettings = TunnelSettingsV3
Expand Down
1 change: 0 additions & 1 deletion ios/MullvadSettings/TunnelSettingsV1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import MullvadREST
import MullvadTypes
import Network
import WireGuardKitTypes
Expand Down
1 change: 0 additions & 1 deletion ios/MullvadSettings/TunnelSettingsV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import MullvadREST
import MullvadTypes

public struct TunnelSettingsV2: Codable, Equatable, TunnelSettings {
Expand Down
1 change: 0 additions & 1 deletion ios/MullvadSettings/TunnelSettingsV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import MullvadREST
import MullvadTypes

public struct TunnelSettingsV3: Codable, Equatable, TunnelSettings {
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
private func getMigrateSettingsOperation(application: UIApplication) -> AsyncBlockOperation {
AsyncBlockOperation(dispatchQueue: .main) { [self] finish in
migrationManager
.migrateSettings(store: SettingsManager.store, proxyFactory: proxyFactory) { [self] migrationResult in
.migrateSettings(store: SettingsManager.store) { [self] migrationResult in
switch migrationResult {
case .success:
// Tell the tunnel to re-read tunnel configuration after migration.
Expand Down
27 changes: 7 additions & 20 deletions ios/MullvadVPNTests/MigrationManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class MigrationManagerTests: XCTestCase {
static let store = InMemorySettingsStore<SettingNotFound>()

var manager: MigrationManager!
var proxyFactory: REST.ProxyFactory!
override class func setUp() {
SettingsManager.unitTestStore = store
}
Expand All @@ -25,18 +24,6 @@ final class MigrationManagerTests: XCTestCase {
}

override func setUpWithError() throws {
let transportProvider = REST.AnyTransportProvider { nil }
let addressCache = REST.AddressCache(canWriteToCache: false, fileCache: MemoryCache())
let proxyConfiguration = REST.ProxyConfiguration(
transportProvider: transportProvider,
addressCacheStore: addressCache
)
let authProxy = REST.AuthProxyConfiguration(
proxyConfiguration: proxyConfiguration,
accessTokenManager: AccessTokenManagerStub()
)

proxyFactory = REST.ProxyFactory(configuration: authProxy)
manager = MigrationManager()
}

Expand All @@ -46,7 +33,7 @@ final class MigrationManagerTests: XCTestCase {
try SettingsManager.writeSettings(settings)

let nothingToMigrateExpectation = expectation(description: "No migration")
manager.migrateSettings(store: store, proxyFactory: proxyFactory) { result in
manager.migrateSettings(store: store) { result in
if case .nothing = result {
nothingToMigrateExpectation.fulfill()
}
Expand All @@ -59,7 +46,7 @@ final class MigrationManagerTests: XCTestCase {
SettingsManager.unitTestStore = store

let nothingToMigrateExpectation = expectation(description: "No migration")
manager.migrateSettings(store: store, proxyFactory: proxyFactory) { result in
manager.migrateSettings(store: store) { result in
if case .nothing = result {
nothingToMigrateExpectation.fulfill()
}
Expand All @@ -74,7 +61,7 @@ final class MigrationManagerTests: XCTestCase {
func testFailedMigration() throws {
let store = Self.store
let failedMigrationExpectation = expectation(description: "Failed migration")
manager.migrateSettings(store: store, proxyFactory: proxyFactory) { result in
manager.migrateSettings(store: store) { result in
if case .failure = result {
failedMigrationExpectation.fulfill()
}
Expand All @@ -89,7 +76,7 @@ final class MigrationManagerTests: XCTestCase {
try store.write(data, for: .deviceState)

// Failed migration should reset settings and device state keys
manager.migrateSettings(store: store, proxyFactory: proxyFactory) { _ in }
manager.migrateSettings(store: store) { _ in }

let assertDeletionFor: (SettingsKey) throws -> Void = { key in
try XCTAssertThrowsError(store.read(key: key)) { thrownError in
Expand All @@ -106,7 +93,7 @@ final class MigrationManagerTests: XCTestCase {
let settings = FutureVersionSettings()
try write(settings: settings, version: Int.max - 1, in: store)

manager.migrateSettings(store: store, proxyFactory: proxyFactory) { _ in }
manager.migrateSettings(store: store) { _ in }

let assertDeletionFor: (SettingsKey) throws -> Void = { key in
try XCTAssertThrowsError(store.read(key: key)) { thrownError in
Expand All @@ -124,7 +111,7 @@ final class MigrationManagerTests: XCTestCase {
try write(settings: settings, version: -42, in: store)

let failedMigrationExpectation = expectation(description: "Failed migration")
manager.migrateSettings(store: store, proxyFactory: proxyFactory) { result in
manager.migrateSettings(store: store) { result in
if case .failure = result {
failedMigrationExpectation.fulfill()
}
Expand Down Expand Up @@ -161,7 +148,7 @@ final class MigrationManagerTests: XCTestCase {
try write(settings: settings, version: version.rawValue, in: store)

let successfulMigrationExpectation = expectation(description: "Successful migration")
manager.migrateSettings(store: store, proxyFactory: proxyFactory) { result in
manager.migrateSettings(store: store) { result in
if case .success = result {
successfulMigrationExpectation.fulfill()
}
Expand Down

0 comments on commit 9e8c155

Please sign in to comment.