fix and simplify YubiKey serial number validation

This commit is contained in:
Adam Velebil 2022-09-13 09:52:48 +02:00
parent 0bf7e898ab
commit a64bec8216
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
2 changed files with 28 additions and 30 deletions

View File

@ -14,29 +14,16 @@ void main() {
if (isAndroid) {
/// default android parameters
startupParams = {
startupParams.addAll({
'dlg.beta.enabled': false,
'delay.startup': 5,
/// we need to ignore serial numbers until we collect it
'ignore_serial_number': true
};
});
testWidgets('Android app boot', (WidgetTester tester) async {
/// delay first start
await tester.startUp(startupParams);
/// remove delay.startup
startupParams.remove('delay.startup');
});
}
testWidgets('Collect device info', (WidgetTester tester) async {
await tester.startUp(startupParams);
/// parses the YubiKey information from UI elements
await tester.getDeviceInfo();
startupParams.remove('ignore_serial_number');
/// from now only approved serial numbers will be allowed to run the tests
});
group('OATH UI validation', () {
testWidgets('Menu items exist', (WidgetTester tester) async {
await tester.startUp(startupParams);

View File

@ -26,6 +26,7 @@ const veryLongWaitS = 10; // seconds
String? yubiKeyName;
String? yubiKeyFirmware;
String? yubiKeySerialNumber;
bool collectedYubiKeyInformation = false;
extension AppWidgetTester on WidgetTester {
Future<void> shortestWait() async {
@ -55,23 +56,20 @@ extension AppWidgetTester on WidgetTester {
}
Future<void> startUp([Map<dynamic, dynamic>? startUpParams]) async {
var ignoreSerialNumber =
startUpParams?.containsKey('ignore_serial_number') ?? false;
if (!ignoreSerialNumber) {
if (!approvedYubiKeys.contains(yubiKeySerialNumber)) {
testLog(false,
'The connected key is refused by the tests: $yubiKeySerialNumber');
expect(approvedYubiKeys.contains(yubiKeySerialNumber), equals(true));
}
var result = isAndroid == true
? await AndroidTestUtils.startUp(this, startUpParams)
: await pumpWidget(
await getAuthenticatorApp(), const Duration(milliseconds: 2000));
await getDeviceInfo();
if (!approvedYubiKeys.contains(yubiKeySerialNumber)) {
testLog(false,
'The connected key is refused by the tests: $yubiKeySerialNumber');
expect(approvedYubiKeys.contains(yubiKeySerialNumber), equals(true));
}
if (isAndroid) {
return AndroidTestUtils.startUp(this, startUpParams);
} else {
/// desktop
return await pumpWidget(
await getAuthenticatorApp(), const Duration(milliseconds: 2000));
}
return result;
}
void testLog(bool quiet, String message) {
@ -82,6 +80,10 @@ extension AppWidgetTester on WidgetTester {
/// get key information
Future<void> getDeviceInfo() async {
if (collectedYubiKeyInformation) {
return;
}
await tapDeviceButton();
var deviceInfo = find.byKey(app_keys.deviceInfoListTile);
@ -105,10 +107,19 @@ extension AppWidgetTester on WidgetTester {
}
}
// close the opened menu
await tapAt(const Offset(0, 0));
await longWait();
testLog(false,
'Connected YubiKey: $yubiKeySerialNumber/$yubiKeyFirmware - $yubiKeyName');
if (!approvedYubiKeys.contains(yubiKeySerialNumber)) {
testLog(false,
'Connected YubiKey (SN: $yubiKeySerialNumber) is not approved for integration tests');
exit(-1);
}
collectedYubiKeyInformation = true;
}
}