6
6
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
7
7
//
8
8
9
+ import MullvadREST
10
+ @testable import MullvadSettings
9
11
import XCTest
10
12
11
13
final class TunnelManagerTests : XCTestCase {
14
+ static let store = InMemorySettingsStore < SettingNotFound > ( )
15
+
16
+ override class func setUp( ) {
17
+ SettingsManager . unitTestStore = store
18
+ }
19
+
20
+ override class func tearDown( ) {
21
+ SettingsManager . unitTestStore = nil
22
+ }
23
+
12
24
func testTunnelManager( ) {
13
25
let application = UIApplicationStub ( )
14
26
let tunnelStore = TunnelStoreStub ( )
@@ -17,7 +29,27 @@ final class TunnelManagerTests: XCTestCase {
17
29
let devicesProxy = DevicesProxyStub ( )
18
30
let apiProxy = APIProxyStub ( )
19
31
let accessTokenManager = AccessTokenManagerStub ( )
32
+ let tunnelManager = TunnelManager (
33
+ application: application,
34
+ tunnelStore: tunnelStore,
35
+ relayCacheTracker: relayCacheTracker,
36
+ accountsProxy: accountProxy,
37
+ devicesProxy: devicesProxy,
38
+ apiProxy: apiProxy,
39
+ accessTokenManager: accessTokenManager
40
+ )
41
+ XCTAssertNotNil ( tunnelManager)
42
+ }
20
43
44
+ func testLogInStartsKeyRotations( ) async throws {
45
+ let application = UIApplicationStub ( )
46
+ let tunnelStore = TunnelStoreStub ( )
47
+ let relayCacheTracker = RelayCacheTrackerStub ( )
48
+ var accountProxy = AccountsProxyStub ( )
49
+ let devicesProxy = DevicesProxyStub ( )
50
+ let apiProxy = APIProxyStub ( )
51
+ let accessTokenManager = AccessTokenManagerStub ( )
52
+ accountProxy. createAccountResult = . success( REST . NewAccountData. mockValue ( ) )
21
53
let tunnelManager = TunnelManager (
22
54
application: application,
23
55
tunnelStore: tunnelStore,
@@ -27,7 +59,30 @@ final class TunnelManagerTests: XCTestCase {
27
59
apiProxy: apiProxy,
28
60
accessTokenManager: accessTokenManager
29
61
)
62
+ _ = try await tunnelManager. setNewAccount ( )
63
+ XCTAssertEqual ( tunnelManager. isRunningPeriodicPrivateKeyRotation, true )
64
+ }
30
65
31
- XCTAssertNotNil ( tunnelManager)
66
+ func testLogOutStopsKeyRotations( ) async throws {
67
+ let application = UIApplicationStub ( )
68
+ let tunnelStore = TunnelStoreStub ( )
69
+ let relayCacheTracker = RelayCacheTrackerStub ( )
70
+ var accountProxy = AccountsProxyStub ( )
71
+ let devicesProxy = DevicesProxyStub ( )
72
+ let apiProxy = APIProxyStub ( )
73
+ let accessTokenManager = AccessTokenManagerStub ( )
74
+ accountProxy. createAccountResult = . success( REST . NewAccountData. mockValue ( ) )
75
+ let tunnelManager = TunnelManager (
76
+ application: application,
77
+ tunnelStore: tunnelStore,
78
+ relayCacheTracker: relayCacheTracker,
79
+ accountsProxy: accountProxy,
80
+ devicesProxy: devicesProxy,
81
+ apiProxy: apiProxy,
82
+ accessTokenManager: accessTokenManager
83
+ )
84
+ _ = try await tunnelManager. setNewAccount ( )
85
+ await tunnelManager. unsetAccount ( )
86
+ XCTAssertEqual ( tunnelManager. isRunningPeriodicPrivateKeyRotation, false )
32
87
}
33
88
}
0 commit comments