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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io' as io;
import 'dart:typed_data';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/doctor_validator.dart';
import 'package:flutter_tools/src/proxy_validator.dart';
import '../../src/common.dart';
void main() {
setUp(() {
setNetworkInterfaceLister(
({
bool includeLoopback = true,
bool includeLinkLocal = true,
InternetAddressType type = InternetAddressType.any,
}) async {
final List<FakeNetworkInterface> interfaces = <FakeNetworkInterface>[
FakeNetworkInterface(<FakeInternetAddress>[
const FakeInternetAddress('127.0.0.1'),
]),
FakeNetworkInterface(<FakeInternetAddress>[
const FakeInternetAddress('::1'),
]),
];
return Future<List<NetworkInterface>>.value(interfaces);
});
});
tearDown(() {
resetNetworkInterfaceLister();
});
testWithoutContext('ProxyValidator does not show if HTTP_PROXY is not set', () {
final Platform platform = FakePlatform(environment: <String, String>{});
expect(ProxyValidator(platform: platform).shouldShow, isFalse);
});
testWithoutContext('ProxyValidator does not show if HTTP_PROXY is only whitespace', () {
final Platform platform = FakePlatform(environment: <String, String>{'HTTP_PROXY': ' '});
expect(ProxyValidator(platform: platform).shouldShow, isFalse);
});
testWithoutContext('ProxyValidator shows when HTTP_PROXY is set', () {
final Platform platform = FakePlatform(environment: <String, String>{'HTTP_PROXY': 'fakeproxy.local'});
expect(ProxyValidator(platform: platform).shouldShow, isTrue);
});
testWithoutContext('ProxyValidator shows when http_proxy is set', () {
final Platform platform = FakePlatform(environment: <String, String>{'http_proxy': 'fakeproxy.local'});
expect(ProxyValidator(platform: platform).shouldShow, isTrue);
});
testWithoutContext('ProxyValidator reports success when NO_PROXY is configured correctly', () async {
final Platform platform = FakePlatform(
environment: <String, String>{
'HTTP_PROXY': 'fakeproxy.local',
'NO_PROXY': 'localhost,127.0.0.1,::1',
},
);
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is localhost,127.0.0.1,::1'),
ValidationMessage('NO_PROXY contains localhost'),
ValidationMessage('NO_PROXY contains 127.0.0.1'),
ValidationMessage('NO_PROXY contains ::1'),
]);
});
testWithoutContext('ProxyValidator reports success when no_proxy is configured correctly', () async {
final Platform platform = FakePlatform(
environment: <String, String>{
'http_proxy': 'fakeproxy.local',
'no_proxy': 'localhost,127.0.0.1,::1',
},
);
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is localhost,127.0.0.1,::1'),
ValidationMessage('NO_PROXY contains localhost'),
ValidationMessage('NO_PROXY contains 127.0.0.1'),
ValidationMessage('NO_PROXY contains ::1'),
]);
});
testWithoutContext('ProxyValidator reports issues when NO_PROXY is missing localhost', () async {
final Platform platform = FakePlatform(
environment: <String, String>{
'HTTP_PROXY': 'fakeproxy.local',
'NO_PROXY': '127.0.0.1,::1',
},
);
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is 127.0.0.1,::1'),
ValidationMessage.hint('NO_PROXY does not contain localhost'),
ValidationMessage('NO_PROXY contains 127.0.0.1'),
ValidationMessage('NO_PROXY contains ::1'),
]);
});
testWithoutContext('ProxyValidator reports issues when NO_PROXY is missing 127.0.0.1', () async {
final Platform platform = FakePlatform(environment: <String, String>{
'HTTP_PROXY': 'fakeproxy.local',
'NO_PROXY': 'localhost,::1',
});
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is localhost,::1'),
ValidationMessage('NO_PROXY contains localhost'),
ValidationMessage.hint('NO_PROXY does not contain 127.0.0.1'),
ValidationMessage('NO_PROXY contains ::1'),
]);
});
testWithoutContext('ProxyValidator reports issues when NO_PROXY is missing ::1', () async {
final Platform platform = FakePlatform(environment: <String, String>{
'HTTP_PROXY': 'fakeproxy.local',
'NO_PROXY': 'localhost,127.0.0.1',
});
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is localhost,127.0.0.1'),
ValidationMessage('NO_PROXY contains localhost'),
ValidationMessage('NO_PROXY contains 127.0.0.1'),
ValidationMessage.hint('NO_PROXY does not contain ::1'),
]);
});
testWithoutContext('ProxyValidator reports issues when NO_PROXY is missing localhost, 127.0.0.1', () async {
final Platform platform = FakePlatform(
environment: <String, String>{
'HTTP_PROXY': 'fakeproxy.local',
'NO_PROXY': '::1',
},
);
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is ::1'),
ValidationMessage.hint('NO_PROXY does not contain localhost'),
ValidationMessage.hint('NO_PROXY does not contain 127.0.0.1'),
ValidationMessage('NO_PROXY contains ::1'),
]);
});
testWithoutContext('ProxyValidator reports issues when NO_PROXY is missing localhost, ::1', () async {
final Platform platform = FakePlatform(
environment: <String, String>{
'HTTP_PROXY': 'fakeproxy.local',
'NO_PROXY': '127.0.0.1',
},
);
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is 127.0.0.1'),
ValidationMessage.hint('NO_PROXY does not contain localhost'),
ValidationMessage('NO_PROXY contains 127.0.0.1'),
ValidationMessage.hint('NO_PROXY does not contain ::1'),
]);
});
testWithoutContext('ProxyValidator reports issues when NO_PROXY is missing 127.0.0.1, ::1', () async {
final Platform platform = FakePlatform(
environment: <String, String>{
'HTTP_PROXY': 'fakeproxy.local',
'NO_PROXY': 'localhost',
},
);
final ValidationResult results = await ProxyValidator(platform: platform).validate();
expect(results.messages, const <ValidationMessage>[
ValidationMessage('HTTP_PROXY is set'),
ValidationMessage('NO_PROXY is localhost'),
ValidationMessage('NO_PROXY contains localhost'),
ValidationMessage.hint('NO_PROXY does not contain 127.0.0.1'),
ValidationMessage.hint('NO_PROXY does not contain ::1'),
]);
});
}
class FakeNetworkInterface extends NetworkInterface {
FakeNetworkInterface(List<FakeInternetAddress> addresses):
super(FakeNetworkInterfaceDelegate(addresses));
@override
String get name => 'FakeNetworkInterface$index';
}
class FakeNetworkInterfaceDelegate implements io.NetworkInterface {
FakeNetworkInterfaceDelegate(this._fakeAddresses);
final List<FakeInternetAddress> _fakeAddresses;
@override
List<io.InternetAddress> get addresses => _fakeAddresses;
@override
int get index => addresses.length;
@override
String get name => 'FakeNetworkInterfaceDelegate$index';
}
class FakeInternetAddress implements io.InternetAddress {
const FakeInternetAddress(this._fakeAddress);
final String _fakeAddress;
@override
String get address => _fakeAddress;
@override
String get host => throw UnimplementedError();
@override
bool get isLinkLocal => throw UnimplementedError();
@override
bool get isLoopback => true;
@override
bool get isMulticast => throw UnimplementedError();
@override
Uint8List get rawAddress => throw UnimplementedError();
@override
Future<io.InternetAddress> reverse() =>
throw UnimplementedError();
@override
io.InternetAddressType get type => throw UnimplementedError();
}