Merge commit '394fd672'
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:pipelines_app/features/updates/app_updates_io.dart' as io;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
||||
import 'package:pipelines_app/core/session/server_session.dart';
|
||||
import 'package:pipelines_app/features/updates/app_updates.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test(
|
||||
'retained update refuses credentials after alias/profile removal',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final source = SavedServer.validated(
|
||||
id: 'source',
|
||||
name: 'Home',
|
||||
endpoints: ['wss://home.test/connect'],
|
||||
);
|
||||
var current = [source];
|
||||
final update = await newestServerUpdate(
|
||||
current,
|
||||
stillTrusted: (server, uri) =>
|
||||
updateSourceStillTrusted(current, server, uri),
|
||||
read: (base, headers) async => AppUpdate(
|
||||
versionCode: 12,
|
||||
versionName: '',
|
||||
apk: base.resolve('app.apk'),
|
||||
),
|
||||
);
|
||||
current = [];
|
||||
expect(() => update.headersFor!(update.apk), throwsStateError);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'downloads authenticate their source, verify digest and remove failed partials',
|
||||
() async {
|
||||
final previousOverrides = HttpOverrides.current;
|
||||
HttpOverrides.global = null;
|
||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
|
||||
final directory = await Directory.systemTemp.createTemp('update-test-');
|
||||
final payload = utf8.encode('archive fixture');
|
||||
final cookies = <String?>[];
|
||||
server.listen((request) async {
|
||||
cookies.add(request.headers.value('cookie'));
|
||||
request.response.add(payload);
|
||||
await request.response.close();
|
||||
});
|
||||
final uri = Uri.parse('http://127.0.0.1:${server.port}/archive.zip');
|
||||
AppUpdate candidate(String digest) => AppUpdate(
|
||||
versionCode: 12,
|
||||
versionName: '',
|
||||
apk: uri,
|
||||
platform: 'macos',
|
||||
sha256: digest,
|
||||
headersFor: (_) => {'Cookie': 'source=second'},
|
||||
);
|
||||
try {
|
||||
final file = await io.downloadUpdate(
|
||||
candidate(sha256.convert(payload).toString()),
|
||||
directory,
|
||||
);
|
||||
expect(await file.readAsBytes(), payload);
|
||||
await file.delete();
|
||||
await expectLater(
|
||||
io.downloadUpdate(candidate('0' * 64), directory),
|
||||
throwsFormatException,
|
||||
);
|
||||
expect(await directory.list().toList(), isEmpty);
|
||||
expect(cookies, ['source=second', 'source=second']);
|
||||
} finally {
|
||||
await server.close(force: true);
|
||||
await directory.delete(recursive: true);
|
||||
HttpOverrides.global = previousOverrides;
|
||||
}
|
||||
},
|
||||
);
|
||||
test(
|
||||
'desktop metadata rejects wrong architecture, platform and escaped URLs',
|
||||
() {
|
||||
final base = Uri.parse('https://host/updates/macos/');
|
||||
final value = <String, Object>{
|
||||
'versionCode': 42,
|
||||
'platform': 'macos',
|
||||
'architectures': ['arm64'],
|
||||
'file': 'Pipelines-macos-42.zip',
|
||||
};
|
||||
AppUpdate? parse() => AppUpdate.parse(
|
||||
jsonEncode(value),
|
||||
base,
|
||||
platform: 'macos',
|
||||
architecture: 'arm64',
|
||||
);
|
||||
expect(parse()!.platform, 'macos');
|
||||
value['architectures'] = ['x64'];
|
||||
expect(parse(), isNull);
|
||||
value['architectures'] = ['arm64'];
|
||||
value['platform'] = 'linux';
|
||||
expect(parse(), isNull);
|
||||
value['platform'] = 'macos';
|
||||
value['file'] = 'https://evil/archive.zip';
|
||||
expect(parse(), isNull);
|
||||
value['file'] = '../archive.zip';
|
||||
expect(parse(), isNull);
|
||||
value['file'] = 'archive.zip';
|
||||
value['versionCode'] = 42.5;
|
||||
expect(parse(), isNull);
|
||||
},
|
||||
);
|
||||
test(
|
||||
'all saved machines checked with isolated auth without switching active server',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'pipelines.session.v2.first.cookie': 'session=first',
|
||||
'pipelines.session.v2.second.cookie': 'session=second',
|
||||
});
|
||||
final a = Uri.parse('wss://first.test/connect');
|
||||
final b = Uri.parse('wss://second.test/connect');
|
||||
await ServerSession.activateServer(id: 'first', endpoints: [a]);
|
||||
final calls = <String>[];
|
||||
final update = await newestServerUpdate(
|
||||
[
|
||||
SavedServer.validated(id: 'first', name: 'Mac', endpoints: ['$a']),
|
||||
SavedServer.validated(id: 'second', name: 'Linux', endpoints: ['$b']),
|
||||
SavedServer.validated(
|
||||
id: 'offline',
|
||||
name: 'Offline',
|
||||
endpoints: ['wss://offline.test/connect'],
|
||||
),
|
||||
],
|
||||
read: (base, headers) async {
|
||||
calls.add(base.host);
|
||||
expect(headers(Uri.parse('https://untrusted.test/')), isEmpty);
|
||||
if (base.host == 'offline.test') throw StateError('offline');
|
||||
final second = base.host == 'second.test';
|
||||
expect(
|
||||
headers(base)['Cookie'],
|
||||
second ? 'session=second' : 'session=first',
|
||||
);
|
||||
return AppUpdate(
|
||||
versionCode: second ? 20 : 10,
|
||||
versionName: '',
|
||||
apk: base.resolve('pipelines.apk'),
|
||||
);
|
||||
},
|
||||
);
|
||||
expect(calls, containsAll(['first.test', 'second.test', 'offline.test']));
|
||||
expect(update.versionCode, 20);
|
||||
expect(update.sourceName, 'Linux');
|
||||
expect(
|
||||
update.headersFor!(Uri.parse('https://second.test/'))['Cookie'],
|
||||
'session=second',
|
||||
);
|
||||
expect(update.headersFor!(Uri.parse('https://first.test/')), isEmpty);
|
||||
expect(ServerSession.serverId, 'first');
|
||||
expect(ServerSession.headersFor(a)['Cookie'], 'session=first');
|
||||
final firstReader = await ServerSession.credentialReader(
|
||||
id: 'first',
|
||||
endpoints: [a],
|
||||
);
|
||||
await ServerSession.signOut();
|
||||
expect(firstReader(a), isEmpty);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/updates/launch_update_dialog.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('desktop prompt identifies source and archive action', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => showLaunchUpdateDialog(
|
||||
context,
|
||||
web: false,
|
||||
cupertino: false,
|
||||
nativePlatform: 'linux',
|
||||
sourceName: 'Home Linux',
|
||||
),
|
||||
child: const Text('Check'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Check'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('from Home Linux'), findsOneWidget);
|
||||
expect(find.textContaining('extract the archive'), findsOneWidget);
|
||||
expect(find.text('Download'), findsOneWidget);
|
||||
expect(find.textContaining('Android'), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user