网络质量探测 1.1.3:自更新、HTTP/3 与中心节点
版本名 1.1.3,构建号 6。应用标识和签名未改。包含自动更新、覆盖安装、目标历史、IPv4/IPv6 开关、HTTP(含 HTTP/3)以及中心服务端一键添加节点。
This commit is contained in:
1 parent
943259774f
commit
8cdc0f436f
66 files changed
+5489
-78
No files matched your search
@@ -84,10 +84,14 @@ void main() {
|
||||
});
|
||||
|
||||
test('history only lists the real tag and this version', () {
|
||||
expect(appVersion, '1.1.2');
|
||||
expect(appBuild, 5);
|
||||
expect(appVersion, '1.1.3');
|
||||
expect(appBuild, 6);
|
||||
expect(appAttribution, '言灸');
|
||||
expect(releaseHistory.map((entry) => entry.version), ['1.1.2', '1.1.1']);
|
||||
expect(releaseHistory.map((entry) => entry.version), [
|
||||
'1.1.3',
|
||||
'1.1.2',
|
||||
'1.1.1',
|
||||
]);
|
||||
expect(releaseHistory.last.published, '2026-11-09');
|
||||
expect(releaseHistory.last.source, contains('v1.1.1'));
|
||||
expect(releaseHistoryNote, contains('不写成另一个版本'));
|
||||
|
||||
@@ -321,6 +321,74 @@ void main() {
|
||||
everyElement('127.0.0.1'),
|
||||
);
|
||||
});
|
||||
|
||||
test('a closed address family is not used after lookup', () async {
|
||||
final echo = await RawDatagramSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
addTearDown(echo.close);
|
||||
echo.listen((event) {
|
||||
if (event != RawSocketEvent.read) {
|
||||
return;
|
||||
}
|
||||
final datagram = echo.receive();
|
||||
if (datagram == null) {
|
||||
return;
|
||||
}
|
||||
echo.send(datagram.data, datagram.address, datagram.port);
|
||||
});
|
||||
final samples = await _collect(
|
||||
ProbeRequest(
|
||||
host: 'example.test',
|
||||
port: echo.port,
|
||||
profileId: 'udp-generic',
|
||||
interval: const Duration(milliseconds: 40),
|
||||
timeout: const Duration(milliseconds: 300),
|
||||
packetSize: 16,
|
||||
echoToken: '',
|
||||
dnsName: '',
|
||||
payloadHex: '',
|
||||
expectHex: '',
|
||||
allowIPv6: false,
|
||||
),
|
||||
count: 1,
|
||||
loop: ProbeLoop(
|
||||
lookup: (_) async => [
|
||||
InternetAddress('2001:db8::1'),
|
||||
InternetAddress('127.0.0.1'),
|
||||
],
|
||||
),
|
||||
);
|
||||
expect(samples.single.status, Outcome.ok);
|
||||
expect(samples.single.detail['address'], '127.0.0.1');
|
||||
});
|
||||
|
||||
test('local http uses the same go engine as the node', () async {
|
||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
||||
addTearDown(server.close);
|
||||
server.listen((request) {
|
||||
request.response.statusCode = 204;
|
||||
request.response.close();
|
||||
});
|
||||
final samples = await _collect(
|
||||
ProbeRequest(
|
||||
host: 'http://127.0.0.1:${server.port}/health',
|
||||
port: server.port,
|
||||
profileId: 'http',
|
||||
interval: const Duration(milliseconds: 200),
|
||||
timeout: const Duration(seconds: 3),
|
||||
packetSize: 64,
|
||||
echoToken: '',
|
||||
dnsName: '',
|
||||
payloadHex: '',
|
||||
expectHex: '',
|
||||
),
|
||||
count: 1,
|
||||
loop: ProbeLoop(helperPath: binary),
|
||||
);
|
||||
expect(samples.single.status, Outcome.ok);
|
||||
expect(samples.single.detail['statusCode'], '204');
|
||||
expect(samples.single.detail['httpVersion'], '1.1');
|
||||
expect(samples.single.summary.failurePct, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<ProbeSample>> _collect(
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:netquality/center/catalog.dart';
|
||||
import 'package:netquality/models/ip_family.dart';
|
||||
import 'package:netquality/models/session_config.dart';
|
||||
import 'package:netquality/models/target_history.dart';
|
||||
import 'package:netquality/update/installer.dart';
|
||||
import 'package:netquality/update/update_check.dart';
|
||||
|
||||
void main() {
|
||||
test('version comparison ignores a leading v and a build suffix', () {
|
||||
final current = SemVer.parse('1.1.3');
|
||||
expect(SemVer.parse('v1.1.4')!.isNewerThan(current!), isTrue);
|
||||
expect(SemVer.parse('1.1.3+6')!.isNewerThan(current), isFalse);
|
||||
expect(SemVer.parse('1.1.2')!.isNewerThan(current), isFalse);
|
||||
expect(SemVer.parse('1.2.0-rc.1')!.isNewerThan(current), isTrue);
|
||||
});
|
||||
|
||||
test('the matching client archive is chosen and checksum files are recognized', () {
|
||||
const assets = [
|
||||
ReleaseFile(name: 'netquality-server-1.1.4-linux-amd64.tar.gz', url: 's'),
|
||||
ReleaseFile(name: 'netquality-client-1.1.4-linux-amd64.tar.gz', url: 'c'),
|
||||
ReleaseFile(name: 'SHA256SUMS', url: 'sum'),
|
||||
];
|
||||
expect(
|
||||
pickClientAsset(assets, os: 'linux', arch: 'amd64'),
|
||||
'netquality-client-1.1.4-linux-amd64.tar.gz',
|
||||
);
|
||||
expect(looksLikeChecksum('SHA256SUMS'), isTrue);
|
||||
final check = interpretRelease(
|
||||
current: '1.1.3',
|
||||
os: 'linux',
|
||||
arch: 'amd64',
|
||||
body: '''
|
||||
{
|
||||
"tag_name": "v1.1.4",
|
||||
"assets": [
|
||||
{"name": "netquality-client-1.1.4-linux-amd64.tar.gz", "browser_download_url": "https://example.test/client.tar.gz"},
|
||||
{"name": "SHA256SUMS", "browser_download_url": "https://example.test/SHA256SUMS"}
|
||||
]
|
||||
}
|
||||
''',
|
||||
);
|
||||
expect(check.offer?.assetName, contains('linux-amd64'));
|
||||
expect(check.offer?.checksumName, 'SHA256SUMS');
|
||||
});
|
||||
|
||||
test('github failure falls through to the spare source', () async {
|
||||
final check = await findUpdate(
|
||||
current: '1.1.3',
|
||||
endpoints: const UpdateEndpoints(
|
||||
github: 'https://github.invalid/latest',
|
||||
gitea: 'https://git.invalid/latest',
|
||||
),
|
||||
os: 'linux',
|
||||
arch: 'amd64',
|
||||
fetch: (url) async {
|
||||
if (url.host.contains('github')) {
|
||||
return null;
|
||||
}
|
||||
return '''
|
||||
{"tag_name":"v1.1.9","assets":[
|
||||
{"name":"netquality-client-1.1.9-linux-amd64.tar.gz","browser_download_url":"https://example.test/a.tar.gz"}
|
||||
]}
|
||||
''';
|
||||
},
|
||||
);
|
||||
expect(check.offer?.version, '1.1.9');
|
||||
});
|
||||
|
||||
test('history keeps the newest identical target and can delete or clear', () {
|
||||
const older = TargetEntry(
|
||||
host: '203.0.113.8',
|
||||
port: 443,
|
||||
profileId: 'http',
|
||||
httpUrl: 'https://203.0.113.8/a',
|
||||
method: 'GET',
|
||||
savedAtMs: 1,
|
||||
);
|
||||
const newer = TargetEntry(
|
||||
host: '203.0.113.8',
|
||||
port: 443,
|
||||
profileId: 'http',
|
||||
httpUrl: 'https://203.0.113.8/a',
|
||||
method: 'get',
|
||||
savedAtMs: 2,
|
||||
);
|
||||
final history = TargetHistory.empty
|
||||
.add(older)
|
||||
.add(
|
||||
const TargetEntry(
|
||||
host: 'example.com',
|
||||
port: 19090,
|
||||
profileId: 'nq-tcp',
|
||||
savedAtMs: 3,
|
||||
),
|
||||
)
|
||||
.add(newer);
|
||||
expect(history.entries, hasLength(2));
|
||||
expect(history.entries.first.savedAtMs, 2);
|
||||
expect(history.entries.first.toJson().containsKey('token'), isFalse);
|
||||
final removed = history.removeAt(0);
|
||||
expect(removed.entries.single.host, 'example.com');
|
||||
expect(removed.clear().entries, isEmpty);
|
||||
|
||||
var capped = TargetHistory.empty;
|
||||
for (var i = 0; i < 45; i++) {
|
||||
capped = capped.add(
|
||||
TargetEntry(
|
||||
host: 'h$i',
|
||||
port: i + 1,
|
||||
profileId: 'tcp-connect',
|
||||
savedAtMs: i,
|
||||
),
|
||||
);
|
||||
}
|
||||
expect(capped.entries, hasLength(TargetHistory.maxEntries));
|
||||
expect(capped.entries.first.host, 'h44');
|
||||
final again = TargetHistory.decode(capped.encode());
|
||||
expect(again.entries.first.host, 'h44');
|
||||
});
|
||||
|
||||
test('disabled families are filtered and a literal of that family is refused', () {
|
||||
final kept = filterAddresses(
|
||||
[
|
||||
InternetAddress('203.0.113.5'),
|
||||
InternetAddress('2001:db8::1'),
|
||||
],
|
||||
v4: true,
|
||||
v6: false,
|
||||
);
|
||||
expect(kept.map((address) => address.address), ['203.0.113.5']);
|
||||
expect(familyRefusal('2001:db8::1', v4: true, v6: false), contains('IPv6'));
|
||||
expect(familyRefusal('203.0.113.5', v4: false, v6: true), contains('IPv4'));
|
||||
expect(familyRefusal('example.com', v4: false, v6: false), contains('都已关闭'));
|
||||
expect(
|
||||
familyRefusal('https://203.0.113.9/path', v4: false, v6: true),
|
||||
contains('IPv4'),
|
||||
);
|
||||
});
|
||||
|
||||
test('a confidential catalog entry cannot keep an address that was sent by mistake', () {
|
||||
const secret = 'https://secret-node.internal:8443';
|
||||
final catalog = Catalog.parse('''
|
||||
{
|
||||
"account": "lab",
|
||||
"group": "lab",
|
||||
"servers": [
|
||||
{
|
||||
"id": "secret-node",
|
||||
"name": "保密节点",
|
||||
"confidential": true,
|
||||
"controlUrl": "$secret",
|
||||
"credential": "node-token-should-not-leak"
|
||||
},
|
||||
{
|
||||
"id": "lab-node",
|
||||
"name": "实验室节点",
|
||||
"confidential": false,
|
||||
"controlUrl": "https://127.0.0.1:8443",
|
||||
"credential": "short-lived"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
final secretServer = catalog.servers.first;
|
||||
expect(secretServer.controlUrl, isEmpty);
|
||||
expect(secretServer.credential, isEmpty);
|
||||
expect(catalog.servers.last.controlUrl, 'https://127.0.0.1:8443');
|
||||
|
||||
const link = CenterLink(id: 'c1', url: 'https://center.example', account: 'lab');
|
||||
var seq = 0;
|
||||
final merged = mergeCenterCatalog(
|
||||
existing: const [
|
||||
RemoteNode(id: 'manual', name: '手填', baseUrl: 'https://manual.example'),
|
||||
],
|
||||
link: link,
|
||||
catalog: catalog,
|
||||
newId: () => 'new-${seq++}',
|
||||
);
|
||||
final hidden = merged.nodes.firstWhere((node) => node.serverId == 'secret-node');
|
||||
expect(hidden.baseUrl, isEmpty);
|
||||
expect(hidden.confidential, isTrue);
|
||||
expect(merged.credentials.containsKey(hidden.id), isFalse);
|
||||
expect(storedNodeHides(hidden, secret), isTrue);
|
||||
expect(storedNodeHides(hidden, 'node-token-should-not-leak'), isTrue);
|
||||
expect(merged.nodes.any((node) => node.id == 'manual'), isTrue);
|
||||
expect(renameNode(hidden, '别的名字').name, '保密节点');
|
||||
|
||||
final again = SessionConfig.fromJson({
|
||||
...SessionConfig.defaults.toJson(),
|
||||
'nodes': [hidden.toJson()],
|
||||
});
|
||||
expect(again.nodes.single.baseUrl, isEmpty);
|
||||
});
|
||||
|
||||
test('checksum must mention the asset, and install copy stays inside the directory', () {
|
||||
final bytes = [1, 2, 3, 4];
|
||||
expect(checksumMatches('abc other.bin\n', 'client.zip', bytes), isFalse);
|
||||
final digest = 'e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1e1';
|
||||
expect(checksumMatches('$digest client.zip\n', 'client.zip', bytes), isFalse);
|
||||
final want = sha256.convert(bytes).toString();
|
||||
expect(checksumMatches('$want *client.zip\n', 'client.zip', bytes), isTrue);
|
||||
|
||||
final root = Directory.systemTemp.createTempSync('nq-install');
|
||||
addTearDown(() => root.deleteSync(recursive: true));
|
||||
final extracted = Directory('${root.path}/extracted')..createSync();
|
||||
final install = Directory('${root.path}/install')..createSync();
|
||||
File('${extracted.path}/netquality').writeAsStringSync('new');
|
||||
File('${install.path}/kept.txt').writeAsStringSync('stay');
|
||||
copyIntoInstall(extracted, install);
|
||||
expect(File('${install.path}/netquality').readAsStringSync(), 'new');
|
||||
expect(File('${install.path}/kept.txt').readAsStringSync(), 'stay');
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user