Skip to content

Commit

Permalink
webauthn screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamVe committed Dec 20, 2023
1 parent f24a21f commit 07dce96
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
59 changes: 44 additions & 15 deletions integration_test/screenshot_tool/get_screenshots.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import 'package:integration_test/integration_test.dart';
import 'package:screenshot/screenshot.dart';
import 'package:yubico_authenticator/app/views/keys.dart';
import 'package:yubico_authenticator/desktop/init.dart';
import 'package:yubico_authenticator/fido/keys.dart';

ScreenshotController controller = ScreenshotController();
var controller = ScreenshotController();

int screenshotNum = 0;

Expand All @@ -37,8 +38,8 @@ String screenshotOutputDir =

extension TakeScreenshot on WidgetTester {
Future<void> tapAndTake(Key tap, String description,
{Duration delayAfterTap = Duration.zero}) async {
await tapKey(tap, delayAfterTap);
{int delayMs = 0}) async {
await tapKey(tap, Duration(milliseconds: delayMs));
await takeScreenshot(description);
}

Expand All @@ -47,10 +48,12 @@ extension TakeScreenshot on WidgetTester {
if (delay != Duration.zero) {
await pump(delay);
}
await pumpAndSettle();
}

Future<void> closeDialog() async {
await tapAt(const Offset(0, 0));
await pumpAndSettle();
}

Future<void> takeScreenshot(String description) async {
Expand Down Expand Up @@ -108,24 +111,50 @@ void main() {
.writeAsString(script.join('\n'));
});

startScreenshotSession('Initialization', (WidgetTester tester) async {
await tester.takeScreenshot('Startup screen');
startScreenshotSession('Initialization', (t) async {
await t.takeScreenshot('Startup screen');
await t.pumpAndSettle();
});

startScreenshotSession('About', (WidgetTester tester) async {
await tester.tapAndTake(helpDrawerIcon, 'Dialog');
await tester.tapAndTake(logChip, 'Click `Copy log` feedback');
await tester.tapAndTake(diagnosticsChip, 'Click `Diagnostics` feedback');
await tester.tapAndTake(
startScreenshotSession('About', (t) async {
await t.tapAndTake(helpDrawerIcon, 'Dialog');
await t.tapAndTake(logChip, 'Click `Copy log` feedback', delayMs: 2000);
await t.tapAndTake(diagnosticsChip, 'Click `Diagnostics` feedback',
delayMs: 2000);
await t.tapAndTake(
logLevelsChip,
'Click `Log levels`',
delayAfterTap: const Duration(milliseconds: 100),
delayMs: 500,
);
await tester.closeDialog();
await t.closeDialog();
});

startScreenshotSession('Settings', (WidgetTester tester) async {
await tester.tapAndTake(settingDrawerIcon, 'Dialog');
await tester.closeDialog();
startScreenshotSession('Settings', (t) async {
await t.tapAndTake(settingDrawerIcon, 'Dialog');
await t.tapAndTake(themeModeSetting, 'Available themes');
await t.closeDialog();
});

startScreenshotSession('WebAuthn', (t) async {
await t.tapAndTake(fidoAppDrawer, 'FIDO view');
await t.tapAndTake(actionsIconButtonKey, 'Configure view');
await t.tapAndTake(managePinAction, 'Manage PIN dialog');
await t.enterText(find.byKey(pinPukField), '1234567');
await t.pumpAndSettle();
// write something in the other fields to enable the save button
await t.enterText(find.byKey(newPinPukField), '11111111');
await t.pumpAndSettle();
await t.enterText(find.byKey(confirmPinPukField), '11111111');
await t.pumpAndSettle();
await t.tapAndTake(saveButton, 'Wrong PIN');
await t.enterText(find.byKey(newPinPukField), '111');
await t.pumpAndSettle();
await t.enterText(find.byKey(confirmPinPukField), '111');
await t.pumpAndSettle();
await t.tapAndTake(saveButton, 'Short new PIN');
await t.tapKey(cancelButton);
await t.tapKey(actionsIconButtonKey);
await t.tapAndTake(resetAction, 'Reset dialog');
await t.closeDialog();
});
}
1 change: 1 addition & 0 deletions lib/app/views/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ const screenshotChip = Key('$_prefix.screenshot_chip');

// misc buttons
const closeButton = Key('$_prefix.close_button');
const cancelButton = Key('$_prefix.cancel_button');
5 changes: 5 additions & 0 deletions lib/fido/views/pin_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import '../../desktop/models.dart';
import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_form_field.dart';
import '../../widgets/responsive_dialog.dart';
import '../keys.dart';
import '../models.dart';
import '../state.dart';

Expand Down Expand Up @@ -66,6 +67,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
title: Text(hasPin ? l10n.s_change_pin : l10n.s_set_pin),
actions: [
TextButton(
key: saveButton,
onPressed: isValid ? _submit : null,
child: Text(l10n.s_save),
),
Expand All @@ -78,6 +80,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
if (hasPin) ...[
Text(l10n.p_enter_current_pin_or_reset_no_puk),
AppTextFormField(
key: pinPukField,
initialValue: _currentPin,
autofocus: true,
obscureText: _isObscureCurrent,
Expand Down Expand Up @@ -112,6 +115,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
Text(l10n.p_enter_new_fido2_pin(minPinLength)),
// TODO: Set max characters based on UTF-8 bytes
AppTextFormField(
key: newPinPukField,
initialValue: _newPin,
autofocus: !hasPin,
obscureText: _isObscureNew,
Expand Down Expand Up @@ -142,6 +146,7 @@ class _FidoPinDialogState extends ConsumerState<FidoPinDialog> {
},
),
AppTextFormField(
key: confirmPinPukField,
initialValue: _confirmPin,
obscureText: _isObscureConfirm,
autofillHints: const [AutofillHints.password],
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/responsive_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../app/views/keys.dart';
import '../core/state.dart';

class ResponsiveDialog extends StatefulWidget {
Expand Down Expand Up @@ -86,6 +87,7 @@ class _ResponsiveDialogState extends State<ResponsiveDialog> {
),
actions: [
TextButton(
key: cancelButton,
child: Text(cancelText),
onPressed: () {
widget.onCancel?.call();
Expand Down

0 comments on commit 07dce96

Please sign in to comment.