-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data-driven TunnelSettingsUpdate type and method for atomically a…
…pplying them, modify Preferences{Interactor,ViewController} to use these.
- Loading branch information
1 parent
2105a49
commit e329328
Showing
9 changed files
with
155 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// TunnelSettingsUpdate.swift | ||
// MullvadSettings | ||
// | ||
// Created by Andrew Bulhak on 2024-02-13. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import MullvadTypes | ||
|
||
public enum TunnelSettingsUpdate { | ||
case dnsSettings(DNSSettings) | ||
case obfuscation(WireGuardObfuscationSettings) | ||
case relayConstraints(RelayConstraints) | ||
case quantumResistance(TunnelQuantumResistance) | ||
} | ||
|
||
extension TunnelSettingsUpdate { | ||
public func apply(to settings: inout LatestTunnelSettings) { | ||
switch self { | ||
case let .dnsSettings(newDNSSettings): | ||
settings.dnsSettings = newDNSSettings | ||
case let .obfuscation(newObfuscationSettings): | ||
settings.wireGuardObfuscation = newObfuscationSettings | ||
case let .relayConstraints(newRelayConstraints): | ||
settings.relayConstraints = newRelayConstraints | ||
case let .quantumResistance(newQuantumResistance): | ||
settings.tunnelQuantumResistance = newQuantumResistance | ||
} | ||
} | ||
|
||
public var subjectName: String { | ||
switch self { | ||
case .dnsSettings: "DNS settings" | ||
case .obfuscation: "obfuscation settings" | ||
case .relayConstraints: "relay constraints" | ||
case .quantumResistance: "quantum resistance" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
ios/MullvadVPNTests/MullvadSettings/TunnelSettingsUpdateTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// TunnelSettingsUpdateTests.swift | ||
// MullvadVPNTests | ||
// | ||
// Created by Andrew Bulhak on 2024-02-14. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
@testable import MullvadSettings | ||
import MullvadTypes | ||
import Network | ||
import XCTest | ||
|
||
final class TunnelSettingsUpdateTests: XCTestCase { | ||
func testApplyDNSSettings() { | ||
// Given: | ||
var settings = LatestTunnelSettings() | ||
|
||
// When: | ||
var dnsSettings = DNSSettings() | ||
dnsSettings.blockingOptions = [.blockAdvertising, .blockTracking] | ||
dnsSettings.enableCustomDNS = true | ||
dnsSettings.customDNSDomains = [.ipv4(IPv4Address("1.2.3.4")!)] | ||
let update = TunnelSettingsUpdate.dnsSettings(dnsSettings) | ||
update.apply(to: &settings) | ||
|
||
// Then: | ||
XCTAssertEqual(settings.dnsSettings.blockingOptions, [.blockAdvertising, .blockTracking]) | ||
XCTAssertEqual(settings.dnsSettings.enableCustomDNS, true) | ||
XCTAssertEqual(settings.dnsSettings.customDNSDomains, [.ipv4(IPv4Address("1.2.3.4")!)]) | ||
} | ||
|
||
func testApplyObfuscation() { | ||
// Given: | ||
var settings = LatestTunnelSettings() | ||
|
||
// When: | ||
let update = TunnelSettingsUpdate.obfuscation(.init(state: .on, port: .port5001)) | ||
update.apply(to: &settings) | ||
|
||
// Then: | ||
XCTAssertEqual(settings.wireGuardObfuscation, WireGuardObfuscationSettings(state: .on, port: .port5001)) | ||
} | ||
|
||
func testApplyRelayConstraints() { | ||
// Given: | ||
var settings = LatestTunnelSettings() | ||
|
||
// When: | ||
let relayConstraints = RelayConstraints( | ||
location: .only(.country("zz")), | ||
port: .only(9999), | ||
filter: .only(.init(ownership: .rented, providers: .only(["foo", "bar"]))) | ||
) | ||
let update = TunnelSettingsUpdate.relayConstraints(relayConstraints) | ||
update.apply(to: &settings) | ||
|
||
// Then: | ||
XCTAssertEqual(settings.relayConstraints, relayConstraints) | ||
} | ||
|
||
func testApplyQuantumResistance() { | ||
// Given: | ||
var settings = LatestTunnelSettings() | ||
|
||
// When: | ||
let update = TunnelSettingsUpdate.quantumResistance(.on) | ||
update.apply(to: &settings) | ||
|
||
// Then: | ||
XCTAssertEqual(settings.tunnelQuantumResistance, .on) | ||
} | ||
} |