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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// @flow
import type { IpcFacade, AccountToken, AccountData, BackendState } from '../../app/lib/ipc-facade';
interface MockIpc {
sendNewState: (BackendState) => void;
killWebSocket: () => void;
-getAccountData: (AccountToken) => Promise<AccountData>;
-connect: () => Promise<void>;
-getAccount: () => Promise<?AccountToken>;
-authenticate: (string) => Promise<void>;
}
export function newMockIpc() {
const stateListeners = [];
const connectionCloseListeners = [];
const mockIpc: IpcFacade & MockIpc = {
setConnectionString: (_str: string) => {},
getAccountData: (accountToken) =>
Promise.resolve({
accountToken: accountToken,
expiry: '',
}),
getRelayLocations: () =>
Promise.resolve({
countries: [],
}),
getAccount: () => Promise.resolve('1111'),
setAccount: () => Promise.resolve(),
updateRelaySettings: () => Promise.resolve(),
getRelaySettings: () =>
Promise.resolve({
custom_tunnel_endpoint: {
host: 'www.example.com',
tunnel: {
openvpn: {
port: 1301,
protocol: 'udp',
},
},
},
}),
setAllowLan: (_allowLan: boolean) => Promise.resolve(),
getAllowLan: () => Promise.resolve(true),
connect: () => Promise.resolve(),
disconnect: () => Promise.resolve(),
shutdown: () => Promise.resolve(),
getLocation: () =>
Promise.resolve({
ip: '',
country: '',
city: '',
latitude: 0.0,
longitude: 0.0,
mullvad_exit_ip: false,
}),
getState: () =>
Promise.resolve({
state: 'unsecured',
target_state: 'unsecured',
}),
registerStateListener: (listener: (BackendState) => void) => {
stateListeners.push(listener);
},
sendNewState: (state: BackendState) => {
for (const l of stateListeners) {
l(state);
}
},
setCloseConnectionHandler: (listener: () => void) => {
connectionCloseListeners.push(listener);
},
authenticate: (_secret: string) => Promise.resolve(),
getAccountHistory: () => Promise.resolve([]),
removeAccountFromHistory: (_accountToken) => Promise.resolve(),
killWebSocket: () => {
for (const l of connectionCloseListeners) {
l();
}
},
};
return mockIpc;
}
|