Filter Android update offers by installed signing certificate
This commit is contained in:
@@ -10,6 +10,65 @@ import 'package:pipelines_app/features/updates/app_updates.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test('newer differently signed APK is skipped for compatible peer', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final signer = 'a' * 64;
|
||||
final compatible = SavedServer.validated(
|
||||
id: 'compatible',
|
||||
name: 'Mac',
|
||||
endpoints: ['wss://compatible.test/connect'],
|
||||
);
|
||||
final different = SavedServer.validated(
|
||||
id: 'different',
|
||||
name: 'Linux',
|
||||
endpoints: ['wss://different.test/connect'],
|
||||
);
|
||||
final update = await newestServerUpdate(
|
||||
[different, compatible],
|
||||
read: (base, headers) async {
|
||||
final parsed = AppUpdate.parse(
|
||||
jsonEncode({
|
||||
'versionCode': base.host == 'different.test' ? 30 : 20,
|
||||
'apk': 'pipelines.apk',
|
||||
'signingCertificateSha256': base.host == 'different.test'
|
||||
? 'b' * 64
|
||||
: signer,
|
||||
}),
|
||||
base,
|
||||
installedSignature: signer.toUpperCase(),
|
||||
);
|
||||
if (parsed == null) throw const FormatException('Incompatible signer');
|
||||
return parsed;
|
||||
},
|
||||
);
|
||||
expect(update.versionCode, 20);
|
||||
expect(update.sourceName, 'Mac');
|
||||
expect(update.signingCertificateSha256, signer);
|
||||
final base = Uri.parse('https://compatible.test/updates/');
|
||||
for (final invalid in ['', 'sha256:bad', 42, 'g' * 64]) {
|
||||
expect(
|
||||
AppUpdate.parse(
|
||||
jsonEncode({
|
||||
'versionCode': 40,
|
||||
'apk': 'pipelines.apk',
|
||||
'signingCertificateSha256': invalid,
|
||||
}),
|
||||
base,
|
||||
installedSignature: signer,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
}
|
||||
// Legacy feeds retain OS installer validation rather than disappearing.
|
||||
expect(
|
||||
AppUpdate.parse(
|
||||
'{"versionCode":1,"apk":"pipelines.apk"}',
|
||||
base,
|
||||
installedSignature: signer,
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
});
|
||||
test(
|
||||
'retained update refuses credentials after alias/profile removal',
|
||||
() async {
|
||||
|
||||
Reference in New Issue
Block a user