management tests resolved

This commit is contained in:
Joakim Troëng 2024-09-10 12:20:54 +02:00
parent 65c4e664c0
commit 630d32ce0a
2 changed files with 288 additions and 229 deletions

View File

@ -17,245 +17,288 @@
@Tags(['desktop', 'management']) @Tags(['desktop', 'management'])
library; library;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart'; import 'package:integration_test/integration_test.dart';
import 'package:yubico_authenticator/app/views/keys.dart' as app_keys; import 'package:yubico_authenticator/management/views/keys.dart';
import 'package:yubico_authenticator/management/views/keys.dart'
as management_keys;
import 'utils/test_util.dart'; import 'utils/test_util.dart';
Key _getCapabilityWidgetKey(bool isUsb, String name) => // Key _getCapabilityWidgetKey(bool isUsb, String name) =>
Key('management.keys.capability.${isUsb ? 'usb' : 'nfc'}.$name'); // Key('management.keys.capability.${isUsb ? 'usb' : 'nfc'}.$name');
//
Future<FilterChip?> _getCapabilityWidget(Key key) async { // Future<FilterChip?> _getCapabilityWidget(Key key) async {
return find.byKey(key).hitTestable().evaluate().single.widget as FilterChip; // return find.byKey(key).hitTestable().evaluate().single.widget as FilterChip;
} // }
void main() { void main() {
var binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); var binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive; binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
group('Management UI tests', () {
appTest('Drawer items exist', (WidgetTester tester) async {
await tester.openDrawer();
expect(find.byKey(app_keys.managementAppDrawer).hitTestable(),
findsOneWidget);
});
});
group('Toggle Applications on key', () { group('Toggle Applications on key', () {
appTest('Toggle OTP', (WidgetTester tester) async { appTest('Toggle all but PIV 1', (WidgetTester tester) async {
await tester.openManagementScreen(); await tester.openHomeAndToggleScreen();
// find USB OTP capability
var usbOtpKey = _getCapabilityWidgetKey(true, 'OTP');
var otpChip = await _getCapabilityWidget(usbOtpKey);
if (otpChip != null) {
// we expect OTP to be enabled on the Key for this test
expect(otpChip.selected, equals(true));
await tester.tap(find.byKey(usbOtpKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.shortWait();
}
await tester.openManagementScreen();
if (otpChip != null) {
await tester.tap(find.byKey(usbOtpKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
// no management screen visible now
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.longWait();
}
});
appTest('Toggle PIV', (WidgetTester tester) async {
await tester.openManagementScreen();
var usbPivKey = _getCapabilityWidgetKey(true, 'PIV');
var pivChip = await _getCapabilityWidget(usbPivKey);
// find USB PIV capability
if (pivChip != null) {
expect(pivChip.selected, equals(true));
await tester.tap(find.byKey(usbPivKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.shortWait();
}
await tester.openManagementScreen();
if (pivChip != null) {
// we expect PIV to be enabled on the Key for this test
await tester.tap(find.byKey(usbPivKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
// no management screen visible now
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.longWait();
}
});
appTest('Toggle OATH', (WidgetTester tester) async {
await tester.openManagementScreen();
// find USB OATH capability
var usbOathKey = _getCapabilityWidgetKey(true, 'OATH');
var oathChip = await _getCapabilityWidget(usbOathKey);
if (oathChip != null) {
// we expect OATH to be enabled on the Key for this test
expect(oathChip.selected, equals(true));
await tester.tap(find.byKey(usbOathKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.shortWait();
}
await tester.openManagementScreen();
if (oathChip != null) {
await tester.tap(find.byKey(usbOathKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
// no management screen visible now
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.longWait();
}
});
appTest('Toggle OpenPGP', (WidgetTester tester) async {
await tester.openManagementScreen();
// find USB OPENPGP capability
var usbPgpKey = _getCapabilityWidgetKey(true, 'OpenPGP');
var pgpChip = await _getCapabilityWidget(usbPgpKey);
if (pgpChip != null) {
// we expect OPENPGP to be enabled on the Key for this test
expect(pgpChip.selected, equals(true));
await tester.tap(find.byKey(usbPgpKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.shortWait();
}
await tester.openManagementScreen();
if (pgpChip != null) {
await tester.tap(find.byKey(usbPgpKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
// no management screen visible now
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.longWait();
}
});
appTest('Toggle YubiHSM Auth', (WidgetTester tester) async {
await tester.openManagementScreen();
// find USB YubiHSM Auth capability
var usbHsmKey = _getCapabilityWidgetKey(true, 'YubiHSM Auth');
var hsmChip = await _getCapabilityWidget(usbHsmKey);
if (hsmChip != null) {
// we expect YubiHSM Auth to be enabled on the Key for this test
expect(hsmChip.selected, equals(true));
await tester.tap(find.byKey(usbHsmKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.shortWait();
}
await tester.openManagementScreen();
if (hsmChip != null) {
await tester.tap(find.byKey(usbHsmKey));
await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey));
// long wait
await tester.ultraLongWait();
// no management screen visible now
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.longWait();
}
});
});
appTest('Toggle FIDO U2F', (WidgetTester tester) async {
await tester.openManagementScreen();
// find USB FIDO U2F capability
var usbU2fKey = _getCapabilityWidgetKey(true, 'FIDO U2F');
var u2fChip = await _getCapabilityWidget(usbU2fKey);
if (u2fChip != null) {
// we expect FIDO U2F to be enabled on the Key for this test
expect(u2fChip.selected, equals(true));
await tester.tap(find.byKey(usbU2fKey));
await tester.shortWait(); await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey)); await tester.tap(find.text('Yubico OTP').hitTestable());
// long wait
await tester.ultraLongWait();
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.shortWait(); await tester.shortWait();
} await tester.tap(find.text('OATH').hitTestable());
await tester.openManagementScreen();
if (u2fChip != null) {
await tester.tap(find.byKey(usbU2fKey));
await tester.shortWait(); await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey)); await tester.tap(find.text('OpenPGP').hitTestable());
// long wait await tester.shortWait();
await tester.ultraLongWait(); await tester.tap(find.text('YubiHSM Auth').hitTestable());
await tester.shortWait();
// no management screen visible now await tester.tap(find.text('FIDO U2F').hitTestable());
expect(find.byKey(management_keys.screenKey), findsNothing); await tester.shortWait();
await tester.tap(find.text('FIDO2').hitTestable());
await tester.shortWait();
await tester.tap(find.byKey(saveButtonKey).hitTestable());
await tester.longWait(); await tester.longWait();
} });
}); appTest('Toggle all but PIV 2', (WidgetTester tester) async {
appTest('Toggle FIDO2', (WidgetTester tester) async { await tester.openHomeAndToggleScreen();
await tester.openManagementScreen();
// find USB FIDO2 capability
var usbFido2Key = _getCapabilityWidgetKey(true, 'FIDO2');
var fido2Chip = await _getCapabilityWidget(usbFido2Key);
if (fido2Chip != null) {
// we expect FIDO2 to be enabled on the Key for this test
expect(fido2Chip.selected, equals(true));
await tester.tap(find.byKey(usbFido2Key));
await tester.shortWait(); await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey)); await tester.tap(find.text('Yubico OTP').hitTestable());
// long wait
await tester.ultraLongWait();
expect(find.byKey(management_keys.screenKey), findsNothing);
await tester.shortWait(); await tester.shortWait();
} await tester.tap(find.text('OATH').hitTestable());
await tester.openManagementScreen();
if (fido2Chip != null) {
await tester.tap(find.byKey(usbFido2Key));
await tester.shortWait(); await tester.shortWait();
await tester.tap(find.byKey(management_keys.saveButtonKey)); await tester.tap(find.text('OpenPGP').hitTestable());
// long wait await tester.shortWait();
await tester.ultraLongWait(); await tester.tap(find.text('YubiHSM Auth').hitTestable());
await tester.shortWait();
// no management screen visible now await tester.tap(find.text('FIDO U2F').hitTestable());
expect(find.byKey(management_keys.screenKey), findsNothing); await tester.shortWait();
await tester.tap(find.text('FIDO2').hitTestable());
await tester.shortWait();
await tester.tap(find.byKey(saveButtonKey).hitTestable());
await tester.longWait(); await tester.longWait();
} });
}); });
// group('OLD: Toggle Applications on key', () {
// appTest('Toggle OTP', (WidgetTester tester) async {
// await tester.openHomeAndToggleScreen();
// await tester.shortWait();
// await tester.tap(find.text('Yubico OTP').hitTestable());
// await tester.shortWait();
// await tester.tap(find.byKey(saveButtonKey).hitTestable());
// await tester.ultraLongWait();
//
// // TODO: expecter that the Yubico OTP is not present
//
// await tester.openHomeAndToggleScreen();
// await tester.shortWait();
// await tester.tap(find.text('Yubico OTP').hitTestable());
// await tester.shortWait();
// await tester.tap(find.byKey(saveButtonKey).hitTestable());
// await tester.ultraLongWait();
//
// // TODO: this is old method of doing this test, review if usable.
// // find USB OTP capability
// // var usbOtpKey = _getCapabilityWidgetKey(true, 'Yubico OTP');
// // var otpChip = await _getCapabilityWidget(usbOtpKey);
// // if (otpChip != null) {
// // // we expect OTP to be enabled on the Key for this test
// // expect(otpChip.selected, equals(true));
// // await tester.tap(find.byKey(usbOtpKey));
// // await tester.shortWait();
// // await tester.tap(find.byKey(management_keys.saveButtonKey));
// // // long wait
// // await tester.ultraLongWait();
// // expect(find.byKey(management_keys.screenKey), findsNothing);
// // await tester.shortWait();
// // }
// // await tester.openToggleScreen();
// // if (otpChip != null) {
// // await tester.tap(find.byKey(usbOtpKey));
// // await tester.shortWait();
// // await tester.tap(find.byKey(management_keys.saveButtonKey));
// // // long wait
// // await tester.ultraLongWait();
// //
// // // no management screen visible now
// // expect(find.byKey(management_keys.screenKey), findsNothing);
// // await tester.longWait();
// // }
// });
// appTest('Toggle PIV', (WidgetTester tester) async {
// await tester.openToggleScreen();
// var usbPivKey = _getCapabilityWidgetKey(true, 'PIV');
// var pivChip = await _getCapabilityWidget(usbPivKey);
//
// // find USB PIV capability
// if (pivChip != null) {
// expect(pivChip.selected, equals(true));
// await tester.tap(find.byKey(usbPivKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.shortWait();
// }
// await tester.openToggleScreen();
// if (pivChip != null) {
// // we expect PIV to be enabled on the Key for this test
// await tester.tap(find.byKey(usbPivKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
//
// // no management screen visible now
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.longWait();
// }
// });
//
// appTest('Toggle OATH', (WidgetTester tester) async {
// await tester.openToggleScreen();
//
// // find USB OATH capability
// var usbOathKey = _getCapabilityWidgetKey(true, 'OATH');
// var oathChip = await _getCapabilityWidget(usbOathKey);
// if (oathChip != null) {
// // we expect OATH to be enabled on the Key for this test
// expect(oathChip.selected, equals(true));
// await tester.tap(find.byKey(usbOathKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.shortWait();
// }
// await tester.openToggleScreen();
// if (oathChip != null) {
// await tester.tap(find.byKey(usbOathKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
//
// // no management screen visible now
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.longWait();
// }
// });
// appTest('Toggle OpenPGP', (WidgetTester tester) async {
// await tester.openToggleScreen();
//
// // find USB OPENPGP capability
// var usbPgpKey = _getCapabilityWidgetKey(true, 'OpenPGP');
// var pgpChip = await _getCapabilityWidget(usbPgpKey);
// if (pgpChip != null) {
// // we expect OPENPGP to be enabled on the Key for this test
// expect(pgpChip.selected, equals(true));
// await tester.tap(find.byKey(usbPgpKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.shortWait();
// }
// await tester.openToggleScreen();
// if (pgpChip != null) {
// await tester.tap(find.byKey(usbPgpKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
//
// // no management screen visible now
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.longWait();
// }
// });
// appTest('Toggle YubiHSM Auth', (WidgetTester tester) async {
// await tester.openToggleScreen();
//
// // find USB YubiHSM Auth capability
// var usbHsmKey = _getCapabilityWidgetKey(true, 'YubiHSM Auth');
// var hsmChip = await _getCapabilityWidget(usbHsmKey);
// if (hsmChip != null) {
// // we expect YubiHSM Auth to be enabled on the Key for this test
// expect(hsmChip.selected, equals(true));
// await tester.tap(find.byKey(usbHsmKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.shortWait();
// }
// await tester.openToggleScreen();
// if (hsmChip != null) {
// await tester.tap(find.byKey(usbHsmKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
//
// // no management screen visible now
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.longWait();
// }
// });
// });
// appTest('Toggle FIDO U2F', (WidgetTester tester) async {
// await tester.openToggleScreen();
//
// // find USB FIDO U2F capability
// var usbU2fKey = _getCapabilityWidgetKey(true, 'FIDO U2F');
// var u2fChip = await _getCapabilityWidget(usbU2fKey);
// if (u2fChip != null) {
// // we expect FIDO U2F to be enabled on the Key for this test
// expect(u2fChip.selected, equals(true));
// await tester.tap(find.byKey(usbU2fKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.shortWait();
// }
// await tester.openToggleScreen();
// if (u2fChip != null) {
// await tester.tap(find.byKey(usbU2fKey));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
//
// // no management screen visible now
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.longWait();
// }
// });
// appTest('Toggle FIDO2', (WidgetTester tester) async {
// await tester.openToggleScreen();
//
// // find USB FIDO2 capability
// var usbFido2Key = _getCapabilityWidgetKey(true, 'FIDO2');
// var fido2Chip = await _getCapabilityWidget(usbFido2Key);
// if (fido2Chip != null) {
// // we expect FIDO2 to be enabled on the Key for this test
// expect(fido2Chip.selected, equals(true));
// await tester.tap(find.byKey(usbFido2Key));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.shortWait();
// }
// await tester.openToggleScreen();
// if (fido2Chip != null) {
// await tester.tap(find.byKey(usbFido2Key));
// await tester.shortWait();
// await tester.tap(find.byKey(management_keys.saveButtonKey));
// // long wait
// await tester.ultraLongWait();
//
// // no management screen visible now
// expect(find.byKey(management_keys.screenKey), findsNothing);
// await tester.longWait();
// }
// });
} }

View File

@ -22,7 +22,6 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:yubico_authenticator/app/views/device_picker.dart'; import 'package:yubico_authenticator/app/views/device_picker.dart';
import 'package:yubico_authenticator/app/views/keys.dart'; import 'package:yubico_authenticator/app/views/keys.dart';
import 'package:yubico_authenticator/core/state.dart'; import 'package:yubico_authenticator/core/state.dart';
import 'package:yubico_authenticator/management/views/keys.dart';
import 'android/util.dart' as android_test_util; import 'android/util.dart' as android_test_util;
import 'desktop/util.dart' as desktop_test_util; import 'desktop/util.dart' as desktop_test_util;
@ -235,15 +234,32 @@ extension AppWidgetTester on WidgetTester {
} }
/// Management screen /// Management screen
Future<void> openManagementScreen() async { Future<void> openHomeAndToggleScreen() async {
if (!isDrawerOpened()) { // if (!isDrawerOpened()) {
await openDrawer(); // await openDrawer();
} // }
await tap(find.byKey(managementAppDrawer).hitTestable()); await tap(find.byKey(homeDrawer).hitTestable());
await pump(const Duration(milliseconds: 500)); await shortWait();
expect(find.byKey(screenKey), findsOneWidget); await openToggleScreen();
//expect(find.byKey(screenKey), findsOneWidget);
}
/// Toggle Application screen
Future<void> openToggleScreen() async {
// if (!isDrawerOpened()) {
// await openDrawer();
// }
await tap(find.byKey(actionsIconButtonKey).hitTestable());
await shortWait();
await tap(find.byKey(yubikeyApplicationToggleMenuButton).hitTestable());
await shortWait();
//expect(find.byKey(screenKey), findsOneWidget);
} }
/// Retrieve a list of test approved serial numbers. /// Retrieve a list of test approved serial numbers.