diff --git a/integration_test/management_test.dart b/integration_test/management_test.dart index 72a03c5d..7dba02ae 100644 --- a/integration_test/management_test.dart +++ b/integration_test/management_test.dart @@ -17,245 +17,288 @@ @Tags(['desktop', 'management']) library; -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_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' - as management_keys; +import 'package:yubico_authenticator/management/views/keys.dart'; import 'utils/test_util.dart'; -Key _getCapabilityWidgetKey(bool isUsb, String name) => - Key('management.keys.capability.${isUsb ? 'usb' : 'nfc'}.$name'); - -Future _getCapabilityWidget(Key key) async { - return find.byKey(key).hitTestable().evaluate().single.widget as FilterChip; -} +// Key _getCapabilityWidgetKey(bool isUsb, String name) => +// Key('management.keys.capability.${isUsb ? 'usb' : 'nfc'}.$name'); +// +// Future _getCapabilityWidget(Key key) async { +// return find.byKey(key).hitTestable().evaluate().single.widget as FilterChip; +// } void main() { var binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); 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', () { - appTest('Toggle OTP', (WidgetTester tester) async { - await tester.openManagementScreen(); - - // 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)); + appTest('Toggle all but PIV 1', (WidgetTester tester) async { + await tester.openHomeAndToggleScreen(); 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.tap(find.text('Yubico OTP').hitTestable()); await tester.shortWait(); - } - await tester.openManagementScreen(); - if (u2fChip != null) { - await tester.tap(find.byKey(usbU2fKey)); + await tester.tap(find.text('OATH').hitTestable()); 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.tap(find.text('OpenPGP').hitTestable()); + await tester.shortWait(); + await tester.tap(find.text('YubiHSM Auth').hitTestable()); + await tester.shortWait(); + await tester.tap(find.text('FIDO U2F').hitTestable()); + await tester.shortWait(); + await tester.tap(find.text('FIDO2').hitTestable()); + await tester.shortWait(); + await tester.tap(find.byKey(saveButtonKey).hitTestable()); await tester.longWait(); - } - }); - appTest('Toggle FIDO2', (WidgetTester tester) async { - 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)); + }); + appTest('Toggle all but PIV 2', (WidgetTester tester) async { + await tester.openHomeAndToggleScreen(); 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.tap(find.text('Yubico OTP').hitTestable()); await tester.shortWait(); - } - await tester.openManagementScreen(); - if (fido2Chip != null) { - await tester.tap(find.byKey(usbFido2Key)); + await tester.tap(find.text('OATH').hitTestable()); 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.tap(find.text('OpenPGP').hitTestable()); + await tester.shortWait(); + await tester.tap(find.text('YubiHSM Auth').hitTestable()); + await tester.shortWait(); + await tester.tap(find.text('FIDO U2F').hitTestable()); + await tester.shortWait(); + await tester.tap(find.text('FIDO2').hitTestable()); + await tester.shortWait(); + await tester.tap(find.byKey(saveButtonKey).hitTestable()); 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(); + // } + // }); } diff --git a/integration_test/utils/test_util.dart b/integration_test/utils/test_util.dart index fbc75541..8d15e2f6 100644 --- a/integration_test/utils/test_util.dart +++ b/integration_test/utils/test_util.dart @@ -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/keys.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 'desktop/util.dart' as desktop_test_util; @@ -235,15 +234,32 @@ extension AppWidgetTester on WidgetTester { } /// Management screen - Future openManagementScreen() async { - if (!isDrawerOpened()) { - await openDrawer(); - } + Future openHomeAndToggleScreen() async { + // if (!isDrawerOpened()) { + // await openDrawer(); + // } - await tap(find.byKey(managementAppDrawer).hitTestable()); - await pump(const Duration(milliseconds: 500)); + await tap(find.byKey(homeDrawer).hitTestable()); + await shortWait(); - expect(find.byKey(screenKey), findsOneWidget); + await openToggleScreen(); + + //expect(find.byKey(screenKey), findsOneWidget); + } + + /// Toggle Application screen + Future 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.