summaryrefslogtreecommitdiffhomepage
path: root/ios/PacketTunnelCoreTests/Mocks/SettingsReaderStub.swift
blob: 0f78fa7c51e765248754f4e6d8f7257f6b6423c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
//  SettingsReaderStub.swift
//  PacketTunnelCoreTests
//
//  Created by pronebird on 05/09/2023.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import MullvadTypes
import PacketTunnelCore
import WireGuardKitTypes

@testable import MullvadSettings

/// Settings reader stub that can be configured with a block to provide the desired behavior when testing.
struct SettingsReaderStub: SettingsReaderProtocol {
    let block: () throws -> Settings

    func read() throws -> Settings {
        return try block()
    }
}

extension SettingsReaderStub {
    /// Initialize non-fallible settings reader stub that will always return the same static configuration generated at the time of creation.
    static func staticConfiguration() -> SettingsReaderStub {
        let staticSettings = Settings(
            privateKey: PrivateKey(),
            interfaceAddresses: [IPAddressRange(from: "127.0.0.1/32")!],
            tunnelSettings: LatestTunnelSettings(
                relayConstraints: RelayConstraints(),
                dnsSettings: DNSSettings(),
                wireGuardObfuscation: WireGuardObfuscationSettings(state: .off),
                tunnelQuantumResistance: .automatic,
                tunnelMultihopState: .off,
                daita: DAITASettings()
            )
        )

        return SettingsReaderStub {
            return staticSettings
        }
    }

    static func noPostQuantumConfiguration() -> SettingsReaderStub {
        let staticSettings = Settings(
            privateKey: PrivateKey(),
            interfaceAddresses: [IPAddressRange(from: "127.0.0.1/32")!],
            tunnelSettings: LatestTunnelSettings(
                relayConstraints: RelayConstraints(),
                dnsSettings: DNSSettings(),
                wireGuardObfuscation: WireGuardObfuscationSettings(state: .off),
                tunnelQuantumResistance: .off,
                tunnelMultihopState: .off,
                daita: DAITASettings()
            )
        )
        return SettingsReaderStub {
            return staticSettings
        }
    }
}