From bbd8b946fc7395a2293d6124627d3b9b75e233b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Tro=C3=ABng?= Date: Mon, 15 Apr 2024 12:06:10 +0200 Subject: [PATCH 1/3] fixing keyless tests --- integration_test/keyless_test.dart | 37 +++++++++++++++++++++--------- lib/home/views/key_actions.dart | 3 +++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/integration_test/keyless_test.dart b/integration_test/keyless_test.dart index e5147a1b7..3a7c31ec1 100644 --- a/integration_test/keyless_test.dart +++ b/integration_test/keyless_test.dart @@ -35,21 +35,22 @@ void main() { }); group('Settings', () { appTestKeyless('Click through all Themes', (WidgetTester tester) async { - var settingDrawerButton = find.byKey(settingDrawerIcon).hitTestable(); - await tester.tap(settingDrawerButton); - await tester.longWait(); + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); + await tester.tap(find.byKey(settingDrawerIcon).hitTestable()); + await tester.shortWait(); await tester.tap(find.byKey(themeModeSetting)); - await tester.longWait(); + await tester.shortWait(); await tester .tap(find.byKey(themeModeOption(ThemeMode.light)).hitTestable()); await tester.longWait(); await tester.tap(find.byKey(themeModeSetting)); - await tester.longWait(); + await tester.shortWait(); await tester .tap(find.byKey(themeModeOption(ThemeMode.dark)).hitTestable()); await tester.longWait(); await tester.tap(find.byKey(themeModeSetting)); - await tester.longWait(); + await tester.shortWait(); await tester .tap(find.byKey(themeModeOption(ThemeMode.system)).hitTestable()); await tester.longWait(); @@ -59,6 +60,8 @@ void main() { var helpDrawerButton = find.byKey(helpDrawerIcon).hitTestable(); appTestKeyless('Check Licenses view', (WidgetTester tester) async { + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); await tester.tap(helpDrawerButton); await tester.shortWait(); var licensesButtonText = find.byKey(licensesButton).hitTestable(); @@ -69,8 +72,10 @@ void main() { }); group('Opening of URLs', () { appTestKeyless('TOS link', (WidgetTester tester) async { + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); await tester.tap(helpDrawerButton); - await tester.longWait(); + await tester.shortWait(); if (isAndroid) { expect(find.byKey(tosButton).hitTestable(), findsOneWidget); } else { @@ -79,8 +84,10 @@ void main() { } }); appTestKeyless('Privacy link', (WidgetTester tester) async { + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); await tester.tap(helpDrawerButton); - await tester.longWait(); + await tester.shortWait(); if (isAndroid) { expect(find.byKey(privacyButton).hitTestable(), findsOneWidget); } else { @@ -89,8 +96,10 @@ void main() { } }); appTestKeyless('Feedback link', (WidgetTester tester) async { + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); await tester.tap(helpDrawerButton); - await tester.longWait(); + await tester.shortWait(); if (isAndroid) { expect(find.byKey(feedbackButton).hitTestable(), findsOneWidget); } else { @@ -99,6 +108,8 @@ void main() { } }); appTestKeyless('Help link', (WidgetTester tester) async { + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); await tester.tap(helpDrawerButton); await tester.longWait(); if (isAndroid) { @@ -112,14 +123,18 @@ void main() { group('Troubleshooting', () { appTestKeyless('Diagnostics Button', skip: isAndroid, (WidgetTester tester) async { + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); await tester.tap(helpDrawerButton); - await tester.longWait(); + await tester.shortWait(); await tester.tap(find.byKey(diagnosticsChip).hitTestable()); await tester.longWait(); }); appTestKeyless('Log button', (WidgetTester tester) async { + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.shortWait(); await tester.tap(helpDrawerButton); - await tester.longWait(); + await tester.shortWait(); await tester.tap(find.byKey(logChip).hitTestable()); await tester.longWait(); }); diff --git a/lib/home/views/key_actions.dart b/lib/home/views/key_actions.dart index 2c130ee07..a12cbd542 100644 --- a/lib/home/views/key_actions.dart +++ b/lib/home/views/key_actions.dart @@ -25,6 +25,7 @@ import '../../app/message.dart'; import '../../app/models.dart'; import '../../app/shortcuts.dart'; import '../../app/views/action_list.dart'; +import '../../app/views/keys.dart'; import '../../app/views/reset_dialog.dart'; import '../../core/models.dart'; import '../../core/state.dart'; @@ -91,6 +92,7 @@ Widget homeBuildActions( ActionListSection(l10n.s_application, children: [ ActionListItem( icon: const Icon(Symbols.settings), + key: settingDrawerIcon, title: l10n.s_settings, subtitle: l10n.l_settings_desc, actionStyle: ActionStyle.primary, @@ -101,6 +103,7 @@ Widget homeBuildActions( ), ActionListItem( icon: const Icon(Symbols.help), + key: helpDrawerIcon, title: l10n.s_help_and_about, subtitle: l10n.l_help_and_about_desc, actionStyle: ActionStyle.primary, From ed17a3e58c0a1375215cb9286758c870f8342f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Tro=C3=ABng?= Date: Wed, 28 Aug 2024 16:00:48 +0200 Subject: [PATCH 2/3] All PIV/PUK tests mended again... --- integration_test/piv_test.dart | 189 ++++++++++++++-------- integration_test/utils/piv_test_util.dart | 134 ++++++++++++--- lib/home/views/key_actions.dart | 2 + lib/piv/views/manage_key_dialog.dart | 2 +- 4 files changed, 239 insertions(+), 88 deletions(-) diff --git a/integration_test/piv_test.dart b/integration_test/piv_test.dart index d31dac6e9..85c6ba48a 100644 --- a/integration_test/piv_test.dart +++ b/integration_test/piv_test.dart @@ -34,87 +34,121 @@ void main() { group('PIV Settings', skip: isAndroid, () { const factoryPin = '123456'; const factoryPuk = '12345678'; - appTest('Reset PIV (settings-init)', (WidgetTester tester) async { + const uno = 'abcdabcd'; + const due = 'bcdabcda'; + const tre = 'cdabcdab'; + + appTest('reset PIV (settings-init)', (WidgetTester tester) async { await tester.resetPiv(); await tester.shortWait(); }); - appTest('Lock PIN, unlock with PUK', (WidgetTester tester) async { - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(managePinAction).hitTestable()); + + appTest('pin lock-unlock', (WidgetTester tester) async { + await tester.resetPiv(); await tester.shortWait(); - await tester.lockPinPuk(); + + await tester.pinView(); + await tester.pivFirst(); + + await tester.longWait(); + await tester.pinView(); + await tester.longWait(); + + await tester.pivLockTest(); + + await tester.sendKeyEvent(LogicalKeyboardKey.escape); await tester.shortWait(); + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.longWait(); + + expect(find.text('Blocked, use PUK to reset'), findsOne); - /// TODO: This expect needs to verify that Pin subtitle is 'Blocked' - /// expect(find.byKey(managePinAction), find.byTooltip('Blocked')); - await tester.shortWait(); await tester.tap(find.byKey(managePinAction).hitTestable()); await tester.shortWait(); - await tester.enterText(find.byKey(pinPukField).hitTestable(), factoryPuk); + + // PUK field is pre-filled + await tester.pivFirst(); + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); + await tester.longWait(); + + expect(find.text('Blocked, use PUK to reset'), findsNothing); + }); + + appTest('lock PUK, lock PIN, factory reset', (WidgetTester tester) async { + await tester.resetPiv(); await tester.shortWait(); - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), factoryPin); + + // set first pin/puk + await tester.pinView(); + await tester.pivFirst(); + await tester.pukView(); + await tester.pivFirst(); + + // lock pin and puk + await tester.pinView(); + await tester.pivLockTest(); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); await tester.shortWait(); - await tester.enterText( - find.byKey(confirmPinPukField).hitTestable(), factoryPin); + await tester.pukView(); + await tester.pivLockTest(); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); await tester.shortWait(); - await tester.tap(find.byKey(saveButton).hitTestable()); + + // verify blockedness + + await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); await tester.shortWait(); + + expect(find.text('Blocked, factory reset needed'), findsAny); + await tester.sendKeyEvent(LogicalKeyboardKey.escape); - await tester.longWait(); - await tester.resetPiv(); - }); - appTest('Lock PUK, lock PIN, factory reset', (WidgetTester tester) async { - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(managePukAction).hitTestable()); await tester.shortWait(); - await tester.lockPinPuk(); + }); + appTest('Change PIN', (WidgetTester tester) async { + await tester.resetPiv(); await tester.shortWait(); - await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); - /// TODO: This expect needs to verify that PUK underline is 'Blocked' - /// expect(find.byKey(managePukAction), find.byTooltip('Blocked')); + //reset factorypin + await tester.pinView(); + await tester.pivFirst(); + // onepin + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), 'firstpin'); await tester.shortWait(); - await tester.tap(find.byKey(managePinAction).hitTestable()); + await tester.enterText(find.byKey(newPinPukField).hitTestable(), uno); await tester.shortWait(); - await tester.lockPinPuk(); + await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), uno); + await tester.shortWait(); + await tester.tap(find.byKey(saveButton).hitTestable()); await tester.shortWait(); - await tester.tap(find.byKey(actionsIconButtonKey).hitTestable()); - - /// TODO: This expect needs to verify that Pin underline is 'Blocked' - /// expect(find.byKey(managePinAction), find.byTooltip('Blocked')); + // onepin + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), uno); await tester.shortWait(); - await tester.tap(find.byKey(managePinAction).hitTestable()); + await tester.enterText(find.byKey(newPinPukField).hitTestable(), due); await tester.shortWait(); - await tester.tap(find.byKey(managePukAction).hitTestable()); + await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), due); await tester.shortWait(); - await tester.sendKeyEvent(LogicalKeyboardKey.escape); - await tester.longWait(); - await tester.resetPiv(); - }); - appTest('Change PIN', (WidgetTester tester) async { - const newpin = '123123'; - await tester.configurePiv(); - await tester.tap(find.byKey(managePinAction).hitTestable()); + await tester.tap(find.byKey(saveButton).hitTestable()); await tester.shortWait(); - await tester.enterText(find.byKey(pinPukField).hitTestable(), factoryPin); + + // onepin + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), due); await tester.shortWait(); - await tester.enterText(find.byKey(newPinPukField).hitTestable(), newpin); + await tester.enterText(find.byKey(newPinPukField).hitTestable(), tre); await tester.shortWait(); - await tester.enterText( - find.byKey(confirmPinPukField).hitTestable(), newpin); + await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), tre); await tester.shortWait(); await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - await tester.configurePiv(); - await tester.tap(find.byKey(managePinAction).hitTestable()); await tester.shortWait(); - await tester.enterText(find.byKey(pinPukField).hitTestable(), newpin); + + // factorpin + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), tre); await tester.shortWait(); await tester.enterText( find.byKey(newPinPukField).hitTestable(), factoryPin); @@ -123,26 +157,52 @@ void main() { find.byKey(confirmPinPukField).hitTestable(), factoryPin); await tester.shortWait(); await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); + await tester.shortWait(); }); appTest('Change PUK', (WidgetTester tester) async { - const newpuk = '12341234'; - await tester.configurePiv(); - await tester.tap(find.byKey(managePukAction).hitTestable()); + await tester.resetPiv(); await tester.shortWait(); - await tester.enterText(find.byKey(pinPukField).hitTestable(), factoryPuk); + + //reset factorypuk + await tester.pinView(); + await tester.pivFirst(); + + // onepin + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), 'firstpin'); await tester.shortWait(); - await tester.enterText(find.byKey(newPinPukField).hitTestable(), newpuk); + await tester.enterText(find.byKey(newPinPukField).hitTestable(), uno); await tester.shortWait(); - await tester.enterText( - find.byKey(confirmPinPukField).hitTestable(), newpuk); + await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), uno); await tester.shortWait(); await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - await tester.configurePiv(); - await tester.tap(find.byKey(managePukAction).hitTestable()); await tester.shortWait(); - await tester.enterText(find.byKey(pinPukField).hitTestable(), newpuk); + + // onepin + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), uno); + await tester.shortWait(); + await tester.enterText(find.byKey(newPinPukField).hitTestable(), due); + await tester.shortWait(); + await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), due); + await tester.shortWait(); + await tester.tap(find.byKey(saveButton).hitTestable()); + await tester.shortWait(); + + // onepin + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), due); + await tester.shortWait(); + await tester.enterText(find.byKey(newPinPukField).hitTestable(), tre); + await tester.shortWait(); + await tester.enterText(find.byKey(confirmPinPukField).hitTestable(), tre); + await tester.shortWait(); + await tester.tap(find.byKey(saveButton).hitTestable()); + await tester.shortWait(); + + // factorpuk + await tester.pinView(); + await tester.enterText(find.byKey(pinPukField).hitTestable(), tre); await tester.shortWait(); await tester.enterText( find.byKey(newPinPukField).hitTestable(), factoryPuk); @@ -151,7 +211,7 @@ void main() { find.byKey(confirmPinPukField).hitTestable(), factoryPuk); await tester.shortWait(); await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); + await tester.shortWait(); }); group('PIV Management Key', () { const newmanagementkey = @@ -162,6 +222,9 @@ void main() { 'aaaabbbbccccaaaabbbbccccaaaabbbbccccaaaabbbbccc'; appTest('Out of bounds managementkey key', (WidgetTester tester) async { + await tester.resetPiv(); + await tester.shortWait(); + await tester.configurePiv(); await tester.shortWait(); await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); diff --git a/integration_test/utils/piv_test_util.dart b/integration_test/utils/piv_test_util.dart index 7b636da56..e58cce943 100644 --- a/integration_test/utils/piv_test_util.dart +++ b/integration_test/utils/piv_test_util.dart @@ -22,30 +22,112 @@ import 'package:yubico_authenticator/piv/keys.dart'; import 'test_util.dart'; extension PIVFunctions on WidgetTester { + static const ett = 'firstpin'; + static const lock1 = 'lockpinn1'; + static const lock2 = 'lockpinn2'; + static const lock3 = 'lockpinn3'; + /// Open the PIV Configuration Future configurePiv() async { - // 1. open PIV view - var pivDrawerButton = find.byKey(pivAppDrawer).hitTestable(); - await tap(pivDrawerButton); - await longWait(); + await tap(find.byKey(pivAppDrawer).hitTestable()); + await shortWait(); + await tap(find.byKey(actionsIconButtonKey).hitTestable()); + await shortWait(); + } + + Future pinView() async { + await tap(find.byKey(pivAppDrawer).hitTestable()); + await shortWait(); await tap(find.byKey(actionsIconButtonKey).hitTestable()); + await shortWait(); + await tap(find.byKey(managePinAction)); + await shortWait(); + } + + Future pukView() async { + await tap(find.byKey(pivAppDrawer).hitTestable()); + await shortWait(); + await tap(find.byKey(actionsIconButtonKey).hitTestable()); + await shortWait(); + await tap(find.byKey(managePukAction)); + await shortWait(); + } + + Future managementKeyView() async { + await tap(find.byKey(pivAppDrawer).hitTestable()); + await shortWait(); + await tap(find.byKey(actionsIconButtonKey).hitTestable()); + await shortWait(); + await tap(find.byKey(manageManagementKeyAction)); + await shortWait(); + } + + Future pivFirst() async { + // when in pin or puk view, remove factorypin/puk + await enterText(find.byKey(newPinPukField), ett); + await shortWait(); + await enterText(find.byKey(confirmPinPukField), ett); + await shortWait(); + await tap(find.byKey(saveButton).hitTestable()); + await shortWait(); + } + + Future pivLockTest() async { + // when in pin or puk view this will lock it + var pintext1 = 'lockpin1'; + await enterText(find.byKey(pinPukField), pintext1); + await shortWait(); + await enterText(find.byKey(newPinPukField), pintext1); + await shortWait(); + await enterText(find.byKey(confirmPinPukField), pintext1); + await shortWait(); + await tap(find.byKey(saveButton).hitTestable()); + await shortWait(); + + var pintext2 = 'lockpin2'; + await enterText(find.byKey(pinPukField), pintext2); + await shortWait(); + await enterText(find.byKey(newPinPukField), pintext2); + await shortWait(); + await enterText(find.byKey(confirmPinPukField), pintext2); + await shortWait(); + await tap(find.byKey(saveButton).hitTestable()); + await shortWait(); + + var pintext3 = 'lockpin3'; + await enterText(find.byKey(pinPukField), pintext3); + await shortWait(); + await enterText(find.byKey(newPinPukField), pintext3); + await shortWait(); + await enterText(find.byKey(confirmPinPukField), pintext3); + await shortWait(); + await tap(find.byKey(saveButton).hitTestable()); await longWait(); } - /// Locks PIN or PUK - Future lockPinPuk() async { - for (var i = 0; i < 3; i += 1) { - var wrongpin = '123456$i'; - await enterText(find.byKey(pinPukField).hitTestable(), wrongpin); - await shortWait(); - await enterText(find.byKey(newPinPukField).hitTestable(), wrongpin); - await shortWait(); - await enterText(find.byKey(confirmPinPukField).hitTestable(), wrongpin); - await shortWait(); - await tap(find.byKey(saveButton).hitTestable()); - await longWait(); - } + Future pivLock() async { + // when in pin or puk view this will lock it + // for (var i = 0; i < 3; i += 1) { + + await enterText(find.byKey(pinPukField), 'skrivhär'); + await shortWait(); + await enterText(find.byKey(newPinPukField), lock1); + await shortWait(); + await enterText(find.byKey(confirmPinPukField), lock1); + await shortWait(); + await tap(find.byKey(saveButton).hitTestable()); + await shortWait(); + await enterText(find.byKey(pinPukField), lock2); + await shortWait(); + await enterText(find.byKey(newPinPukField), lock2); + await shortWait(); + await enterText(find.byKey(confirmPinPukField), lock2); + await shortWait(); + await tap(find.byKey(saveButton).hitTestable()); + await shortWait(); + // } await sendKeyEvent(LogicalKeyboardKey.escape); + await shortWait(); } /// Factory reset Piv application @@ -56,19 +138,23 @@ extension PIVFunctions on WidgetTester { await switchToKey(targetKey); await shortWait(); - /// 2. open the key menu - await tapPopupMenu(targetKey); + /// 2. open the home view + await tap(find.byKey(homeDrawer).hitTestable()); await shortWait(); - await tap(find.byKey(yubikeyFactoryResetMenuButton).hitTestable()); - await longWait(); - /// 3. then toggle 'Piv' in the 'Factory reset' reset_dialog.dart + /// 3. open menu + await tap(find.byKey(actionsIconButtonKey).hitTestable()); + await shortWait(); + await tap(find.byKey(yubikeyFactoryResetMenuButton)); + await shortWait(); + + /// 4. then toggle 'Piv' in the 'Factory reset' reset_dialog.dart await tap(find.byKey(factoryResetPickResetPiv)); await longWait(); - /// 4. Click reset TextButton: done + /// 5. Click reset TextButton: done await tap(find.byKey(factoryResetReset)); - await shortWait(); + await ultraLongWait(); // 5. Verify Resetedness // /// TODO: this expect algorithm is flaky diff --git a/lib/home/views/key_actions.dart b/lib/home/views/key_actions.dart index b0c13e303..de19cf560 100644 --- a/lib/home/views/key_actions.dart +++ b/lib/home/views/key_actions.dart @@ -58,6 +58,7 @@ Widget homeBuildActions( title: deviceData.info.version.major > 4 ? l10n.s_toggle_applications : l10n.s_toggle_interfaces, + key: yubikeyApplicationToggleMenuButton, subtitle: interfacesLocked ? l10n.l_factory_reset_required : (deviceData.info.version.major > 4 @@ -83,6 +84,7 @@ Widget homeBuildActions( ActionListItem( icon: const Icon(Symbols.delete_forever), title: l10n.s_factory_reset, + key: yubikeyFactoryResetMenuButton, subtitle: l10n.l_factory_reset_desc, actionStyle: ActionStyle.primary, onTap: (context) { diff --git a/lib/piv/views/manage_key_dialog.dart b/lib/piv/views/manage_key_dialog.dart index c6fac2c97..f310eb76e 100644 --- a/lib/piv/views/manage_key_dialog.dart +++ b/lib/piv/views/manage_key_dialog.dart @@ -292,7 +292,7 @@ class _ManageKeyDialogState extends ConsumerState { }, ).init(), AppTextField( - key: keys.newPinPukField, + //key: keys.newPinPukField, autofocus: _defaultKeyUsed, autofillHints: const [AutofillHints.newPassword], maxLength: hexLength, From a4923c76d954c8ae9a715296b765cce7def7646c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Tro=C3=ABng?= Date: Tue, 10 Sep 2024 10:30:29 +0200 Subject: [PATCH 3/3] All PIV/PUK flaky tests removed --- integration_test/piv_test.dart | 412 ++++++++++++++------------- lib/app/views/keys.dart | 1 + lib/piv/keys.dart | 1 + lib/piv/views/manage_key_dialog.dart | 2 +- 4 files changed, 218 insertions(+), 198 deletions(-) diff --git a/integration_test/piv_test.dart b/integration_test/piv_test.dart index 85c6ba48a..8cabcf92a 100644 --- a/integration_test/piv_test.dart +++ b/integration_test/piv_test.dart @@ -213,128 +213,146 @@ void main() { await tester.tap(find.byKey(saveButton).hitTestable()); await tester.shortWait(); }); - group('PIV Management Key', () { - const newmanagementkey = - 'aaaabbbbccccaaaabbbbccccaaaabbbbccccaaaabbbbcccc'; - const boundsmanagementkey = - 'llllkkkkmmmmllllkkkkmmmmllllkkkkmmmmllllkkkkmmmm'; - const shortmanagementkey = - 'aaaabbbbccccaaaabbbbccccaaaabbbbccccaaaabbbbccc'; - - appTest('Out of bounds managementkey key', (WidgetTester tester) async { - await tester.resetPiv(); - await tester.shortWait(); - - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); - await tester.longWait(); - // testing out of bounds management key does not work - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), boundsmanagementkey); - await tester.longWait(); - await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - expect(tester.isTextButtonEnabled(saveButton), true); - // TODO assert that errorText and errorIcon are shown - }); - - appTest('Short managementkey key', (WidgetTester tester) async { - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); - await tester.longWait(); - // testing too short management key does not work - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), shortmanagementkey); - await tester.longWait(); - expect(tester.isTextButtonEnabled(saveButton), false); - }); - - appTest('Change managementkey key', (WidgetTester tester) async { - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); - await tester.shortWait(); - // setting newmanagementkey - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), newmanagementkey); - await tester.longWait(); - await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - // verifying newmanagementkey - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); - await tester.shortWait(); - await tester.enterText( - find.byKey(managementKeyField).hitTestable(), newmanagementkey); - await tester.shortWait(); - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), newmanagementkey); - await tester.shortWait(); - await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - await tester.resetPiv(); - }); - appTest('Change managementkey type', (WidgetTester tester) async { - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); - await tester.shortWait(); - // TODO: this needs to use manageManagementKeyAction chip - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), newmanagementkey); - await tester.shortWait(); - await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - - await tester.resetPiv(); - await tester.shortWait(); - }); - appTest('Change managementkey PIN-lock', (WidgetTester tester) async { - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); - await tester.shortWait(); - // testing out of bounds management key does not work - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), newmanagementkey); - await tester.shortWait(); - // TODO: Investigate why chip-tap fails - //await tester.tap(find.byKey(pinLockManagementKeyChip).hitTestable()); - //await tester.shortWait(); - await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - await tester.resetPiv(); - await tester.shortWait(); - }); - - appTest('Random managementkeytype', (WidgetTester tester) async { - await tester.configurePiv(); - await tester.shortWait(); - await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); - await tester.shortWait(); - // rndm 3x, for luck - await tester.tap(find.byKey(managementKeyRefresh).hitTestable()); - await tester.shortWait(); - await tester.tap(find.byKey(managementKeyRefresh).hitTestable()); - await tester.shortWait(); - await tester.tap(find.byKey(managementKeyRefresh).hitTestable()); - await tester.shortWait(); - await tester.enterText( - find.byKey(newPinPukField).hitTestable(), newmanagementkey); - await tester.shortWait(); - await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - await tester.resetPiv(); - }); - - appTest('Reset PIV (settings-exit)', (WidgetTester tester) async { - await tester.resetPiv(); - await tester.shortWait(); - }); - }); + // group('PIV Management Key', () { + // const newmanagementkey = + // 'aaaabbbbccccaaaabbbbccccaaaabbbbccccaaaabbbbcccc'; + // const boundsmanagementkey = + // 'llllkkkkmmmmllllkkkkmmmmllllkkkkmmmmllllkkkkssssllllkkkkmmmmllllkkkkmmmmllllkkkkmmmmllllkkkkmmmm'; + // const shortmanagementkey = + // 'aaaabbbbccccaaaabbbbccccaaaabbbbccccaaaabbbbccc'; + // + // appTest('Out of bounds managementkey key', (WidgetTester tester) async { + // //await tester.resetPiv(); + // await tester.shortWait(); + // + // // short management key + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.longWait(); + // // testing out of bounds management key does not work + // await tester.enterText( + // find.text('New management key').hitTestable(), shortmanagementkey); + // await tester.longWait(); + // + // expect(tester.isTextButtonEnabled(saveButton), false); + // expect(find.text('47/48'), findsOne); + // await tester.sendKeyEvent(LogicalKeyboardKey.escape); + // + // // out of bounds management key + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.shortWait(); + // // testing out of bounds management key does not work + // await tester.enterText( + // find.byKey(newManagementKeyField).hitTestable(), shortmanagementkey); + // await tester.shortWait(); + // + // expect(tester.isTextButtonEnabled(saveButton), false); + // expect(find.text('48/48'), findsOne); + // expect(find.text('llllkkkkmmmmllllkkkkmmmmllllkkkkmmmmllllkkkkssssllllkkkkmmmmllllkkkkmmmmllllkkkkmmmmllllkkkkmmmm'), findsNothing); + // await tester.sendKeyEvent(LogicalKeyboardKey.escape); + // + // + // }); + // + // appTest('Short managementkey key', (WidgetTester tester) async { + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.longWait(); + // // testing too short management key does not work + // await tester.enterText( + // find.byKey(newPinPukField).hitTestable(), shortmanagementkey); + // await tester.longWait(); + // expect(tester.isTextButtonEnabled(saveButton), false); + // }); + // + // appTest('Change managementkey key', (WidgetTester tester) async { + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.shortWait(); + // // setting newmanagementkey + // await tester.enterText( + // find.byKey(newPinPukField).hitTestable(), newmanagementkey); + // await tester.longWait(); + // await tester.tap(find.byKey(saveButton).hitTestable()); + // await tester.longWait(); + // // verifying newmanagementkey + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.shortWait(); + // await tester.enterText( + // find.byKey(managementKeyField).hitTestable(), newmanagementkey); + // await tester.shortWait(); + // await tester.enterText( + // find.byKey(newPinPukField).hitTestable(), newmanagementkey); + // await tester.shortWait(); + // await tester.tap(find.byKey(saveButton).hitTestable()); + // await tester.longWait(); + // await tester.resetPiv(); + // }); + // appTest('Change managementkey type', (WidgetTester tester) async { + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.shortWait(); + // // TODO: this needs to use manageManagementKeyAction chip + // await tester.enterText( + // find.byKey(newPinPukField).hitTestable(), newmanagementkey); + // await tester.shortWait(); + // await tester.tap(find.byKey(saveButton).hitTestable()); + // await tester.longWait(); + // + // await tester.resetPiv(); + // await tester.shortWait(); + // }); + // appTest('Change managementkey PIN-lock', (WidgetTester tester) async { + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.shortWait(); + // // testing out of bounds management key does not work + // await tester.enterText( + // find.byKey(newPinPukField).hitTestable(), newmanagementkey); + // await tester.shortWait(); + // // TODO: Investigate why chip-tap fails + // //await tester.tap(find.byKey(pinLockManagementKeyChip).hitTestable()); + // //await tester.shortWait(); + // await tester.tap(find.byKey(saveButton).hitTestable()); + // await tester.longWait(); + // await tester.resetPiv(); + // await tester.shortWait(); + // }); + // + // appTest('Random managementkeytype', (WidgetTester tester) async { + // await tester.configurePiv(); + // await tester.shortWait(); + // await tester.tap(find.byKey(manageManagementKeyAction).hitTestable()); + // await tester.shortWait(); + // // rndm 3x, for luck + // await tester.tap(find.byKey(managementKeyRefresh).hitTestable()); + // await tester.shortWait(); + // await tester.tap(find.byKey(managementKeyRefresh).hitTestable()); + // await tester.shortWait(); + // await tester.tap(find.byKey(managementKeyRefresh).hitTestable()); + // await tester.shortWait(); + // await tester.enterText( + // find.byKey(newPinPukField).hitTestable(), newmanagementkey); + // await tester.shortWait(); + // await tester.tap(find.byKey(saveButton).hitTestable()); + // await tester.longWait(); + // await tester.resetPiv(); + // }); + // + // appTest('Reset PIV (settings-exit)', (WidgetTester tester) async { + // await tester.resetPiv(); + // await tester.shortWait(); + // }); + // }); }); // Distinguished name schema according to RFC 4514 @@ -366,11 +384,11 @@ void main() { await tester.tap(find.byKey(generateAction).hitTestable()); await tester.longWait(); // 4. enter PIN and click Unlock - await tester.enterText( - find.byKey(managementKeyField).hitTestable(), '123456'); - await tester.longWait(); - await tester.tap(find.byKey(unlockButton).hitTestable()); - await tester.longWait(); + // await tester.enterText( + // find.byKey(managementKeyField).hitTestable(), '123456'); + // await tester.longWait(); + // await tester.tap(find.byKey(unlockButton).hitTestable()); + // await tester.longWait(); // 5. Enter DN await tester.enterText( @@ -394,7 +412,7 @@ void main() { return false; }), findsOneWidget);*/ - await tester.pump(const Duration(milliseconds: 5000)); + await tester.longWait(); // 10. Export Certificate // await tester.tap(find.byKey(exportAction).hitTestable()); // await tester.enterText( @@ -418,11 +436,11 @@ void main() { await tester.tap(find.byKey(generateAction).hitTestable()); await tester.longWait(); // 4. enter PIN and click Unlock - await tester.enterText( - find.byKey(managementKeyField).hitTestable(), '123456'); - await tester.longWait(); - await tester.tap(find.byKey(unlockButton).hitTestable()); - await tester.longWait(); + // await tester.enterText( + // find.byKey(managementKeyField).hitTestable(), '123456'); + // await tester.longWait(); + // await tester.tap(find.byKey(unlockButton).hitTestable()); + // await tester.longWait(); // 5. Enter DN await tester.enterText( @@ -466,11 +484,11 @@ void main() { await tester.tap(find.byKey(generateAction).hitTestable()); await tester.longWait(); // 4. enter PIN and click Unlock - await tester.enterText( - find.byKey(managementKeyField).hitTestable(), '123456'); - await tester.longWait(); - await tester.tap(find.byKey(unlockButton).hitTestable()); - await tester.longWait(); + // await tester.enterText( + // find.byKey(managementKeyField).hitTestable(), '123456'); + // await tester.longWait(); + // await tester.tap(find.byKey(unlockButton).hitTestable()); + // await tester.longWait(); // 5. Enter DN await tester.enterText( @@ -519,11 +537,11 @@ void main() { await tester.tap(find.byKey(generateAction).hitTestable()); await tester.longWait(); // 4. enter PIN and click Unlock - await tester.enterText( - find.byKey(managementKeyField).hitTestable(), '123456'); - await tester.longWait(); - await tester.tap(find.byKey(unlockButton).hitTestable()); - await tester.longWait(); + // await tester.enterText( + // find.byKey(managementKeyField).hitTestable(), '123456'); + // await tester.longWait(); + // await tester.tap(find.byKey(unlockButton).hitTestable()); + // await tester.longWait(); // 5. Enter DN await tester.enterText( @@ -560,59 +578,59 @@ void main() { await tester.tap(find.byKey(deleteButton).hitTestable()); await tester.longWait(); }); - appTest('Import outdated Key+Certificate from file', - (WidgetTester tester) async {}); - - /// TODO fileload needs to be handled - appTest('Import neverexpire Key+Certificate from file', - (WidgetTester tester) async { - /// TODO fileload needs to be handled - }); - appTest('Generate a CSR', (WidgetTester tester) async { - // 1. open PIV view - var pivDrawerButton = find.byKey(pivAppDrawer).hitTestable(); - await tester.tap(pivDrawerButton); - await tester.longWait(); - // 2. click meatball menu for 9e - await tester.tap(find.byKey(meatballButton9e).hitTestable()); - await tester.longWait(); - // 3. click generate - await tester.tap(find.byKey(generateAction).hitTestable()); - await tester.longWait(); - // 4. enter PIN and click Unlock - await tester.enterText( - find.byKey(managementKeyField).hitTestable(), '123456'); - await tester.longWait(); - await tester.tap(find.byKey(unlockButton).hitTestable()); - await tester.longWait(); - - // 5. Enter DN - await tester.enterText( - find.byKey(subjectField).hitTestable(), 'CN=Generate9e-CSR'); - await tester.longWait(); - // 6. Change 'output format': CSR - // enum models.dart, generate_key_dialog.dart - // 7. Choose File Name > Save As > 'File Name generate93-csr' - // TODO: where are files saved? - // 8. click save - await tester.tap(find.byKey(saveButton).hitTestable()); - await tester.longWait(); - // 9 Verify 'No certificate loaded' -/* expect(find.byWidgetPredicate((widget) { - if (widget is TooltipIfTruncated) { - final TooltipIfTruncated textWidget = widget; - if (textWidget.key == certInfoSubjectKey && - textWidget.text == 'CN=Generate9e') { - return true; - } - } - return false; - }), findsOneWidget);*/ - }); - // appTest('Reset PIV (load-exit)', (WidgetTester tester) async { - // /// TODO: investigate why this reset randomly fails! - // await tester.resetPiv(); - // await tester.shortWait(); - // }); +// appTest('Import outdated Key+Certificate from file', +// (WidgetTester tester) async {}); +// +// /// TODO fileload needs to be handled +// appTest('Import neverexpire Key+Certificate from file', +// (WidgetTester tester) async { +// /// TODO fileload needs to be handled +// }); +// appTest('Generate a CSR', (WidgetTester tester) async { +// // 1. open PIV view +// var pivDrawerButton = find.byKey(pivAppDrawer).hitTestable(); +// await tester.tap(pivDrawerButton); +// await tester.longWait(); +// // 2. click meatball menu for 9e +// await tester.tap(find.byKey(meatballButton9e).hitTestable()); +// await tester.longWait(); +// // 3. click generate +// await tester.tap(find.byKey(generateAction).hitTestable()); +// await tester.longWait(); +// // 4. enter PIN and click Unlock +// // await tester.enterText( +// // find.byKey(managementKeyField).hitTestable(), '123456'); +// // await tester.longWait(); +// // await tester.tap(find.byKey(unlockButton).hitTestable()); +// // await tester.longWait(); +// +// // 5. Enter DN +// await tester.enterText( +// find.byKey(subjectField).hitTestable(), 'CN=Generate9e-CSR'); +// await tester.longWait(); +// // 6. Change 'output format': CSR +// // enum models.dart, generate_key_dialog.dart +// // 7. Choose File Name > Save As > 'File Name generate93-csr' +// // TODO: where are files saved? +// // 8. click save +// await tester.tap(find.byKey(saveButton).hitTestable()); +// await tester.longWait(); +// // 9 Verify 'No certificate loaded' +// /* expect(find.byWidgetPredicate((widget) { +// if (widget is TooltipIfTruncated) { +// final TooltipIfTruncated textWidget = widget; +// if (textWidget.key == certInfoSubjectKey && +// textWidget.text == 'CN=Generate9e') { +// return true; +// } +// } +// return false; +// }), findsOneWidget);*/ +// }); +// // appTest('Reset PIV (load-exit)', (WidgetTester tester) async { +// // /// TODO: investigate why this reset randomly fails! +// // await tester.resetPiv(); +// // await tester.shortWait(); +// // }); }); } diff --git a/lib/app/views/keys.dart b/lib/app/views/keys.dart index 33f1e73c1..1ef73f195 100644 --- a/lib/app/views/keys.dart +++ b/lib/app/views/keys.dart @@ -18,6 +18,7 @@ import 'package:flutter/material.dart'; // global keys final scaffoldGlobalKey = GlobalKey(); +final headerSliverGlobalKey = GlobalKey(); // This is global so we can access it from the global Ctrl+F shortcut. final searchField = GlobalKey(); diff --git a/lib/piv/keys.dart b/lib/piv/keys.dart index f822b1726..5070293b2 100644 --- a/lib/piv/keys.dart +++ b/lib/piv/keys.dart @@ -40,6 +40,7 @@ const unlockButton = Key('$_prefix.unlock'); const resetButton = Key('$_prefix.reset'); const managementKeyField = Key('$_prefix.management_key'); +const newManagementKeyField = Key('$_prefix.management_key'); const managementKeyRefresh = Key('$_prefix.management_key_refresh'); const pinPukField = Key('$_prefix.pin_puk'); diff --git a/lib/piv/views/manage_key_dialog.dart b/lib/piv/views/manage_key_dialog.dart index f310eb76e..77aae7e54 100644 --- a/lib/piv/views/manage_key_dialog.dart +++ b/lib/piv/views/manage_key_dialog.dart @@ -292,7 +292,7 @@ class _ManageKeyDialogState extends ConsumerState { }, ).init(), AppTextField( - //key: keys.newPinPukField, + key: keys.newManagementKeyField, autofocus: _defaultKeyUsed, autofillHints: const [AutofillHints.newPassword], maxLength: hexLength,