add account test

This commit is contained in:
Adam Velebil 2022-04-14 09:08:33 +02:00
parent 669ee8378e
commit 4bbe996e8e
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
5 changed files with 145 additions and 3 deletions

View File

@ -0,0 +1,93 @@
import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:yubico_authenticator/android/init.dart' as android;
import 'package:yubico_authenticator/app/logging.dart';
import 'package:yubico_authenticator/app/views/no_device_screen.dart';
import 'package:yubico_authenticator/oath/views/account_list.dart';
import 'package:yubico_authenticator/oath/views/oath_screen.dart';
Future<void> addDelay(int ms) async {
await Future<void>.delayed(Duration(milliseconds: ms));
}
int randomNum(int max) {
var r = Random.secure();
return r.nextInt(max);
}
String randomPadded() {
return randomNum(999).toString().padLeft(3, '0');
}
String generateRandomIssuer() {
return 'i' + randomPadded();
}
String generateRandomName() {
return 'n' + randomPadded();
}
String generateRandomSecret() {
final random = Random.secure();
return base64Encode(List.generate(10, (_) => random.nextInt(256)));
}
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
group('end-to-end test', () {
testWidgets('Add account', (WidgetTester tester) async {
final logBuffer = initLogBuffer(1000);
final initializedApp = await android.initialize();
await tester.pumpWidget(LogBuffer(
logBuffer,
child: initializedApp,
));
await tester.pump(const Duration(milliseconds: 500));
expect(find.byType(NoDeviceScreen), findsNothing,
reason: 'No YubiKey connected');
expect(find.byType(OathScreen), findsOneWidget);
await tester.tap(find.byType(FloatingActionButton));
await tester.pump(const Duration(milliseconds: 300));
await tester.tap(find.text('Add account'));
await tester.pump(const Duration(milliseconds: 300));
var issuer = generateRandomIssuer();
var name = generateRandomName();
var secret = generateRandomSecret();
await tester.enterText(find.byKey(const Key('issuer')), issuer);
await tester.enterText(find.byKey(const Key('name')), name);
await tester.enterText(find.byKey(const Key('secret')), secret);
await tester.pump();
await tester.tap(find.byKey(const Key('save_btn')));
await tester.pump(const Duration(milliseconds: 500));
expect(find.byType(OathScreen), findsOneWidget);
await tester.enterText(find.byKey(const Key('search_accounts')), issuer);
await tester.pump(const Duration(milliseconds: 500));
expect(
find.descendant(
of: find.byType(AccountList),
matching: find.textContaining(issuer)),
findsOneWidget);
await tester.pump(const Duration(seconds: 3));
});
});
}

View File

@ -1,5 +1,5 @@
import 'dart:math';
import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@ -7,8 +7,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import '../../app/message.dart';
import '../../app/state.dart';
import '../../app/models.dart';
import '../../app/state.dart';
import '../../widgets/file_drop_target.dart';
import '../../widgets/responsive_dialog.dart';
import '../models.dart';
@ -145,6 +145,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
style: Theme.of(context).textTheme.headline6,
),
TextField(
key: const Key('issuer'),
controller: _issuerController,
autofocus: true,
enabled: issuerRemaining > 0,
@ -161,6 +162,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
},
),
TextField(
key: const Key('name'),
controller: _accountController,
maxLength: max(nameRemaining, 1),
decoration: const InputDecoration(
@ -175,6 +177,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
},
),
TextField(
key: const Key('secret'),
controller: _secretController,
obscureText: _isObscure,
inputFormatters: <TextInputFormatter>[
@ -375,7 +378,7 @@ class _OathAddAccountPageState extends ConsumerState<OathAddAccountPage> {
}
}
: null,
child: const Text('Save'),
child: const Text('Save', key: Key('save_btn')),
),
],
);

View File

@ -94,6 +94,7 @@ class _UnlockedView extends ConsumerWidget {
},
child: Builder(builder: (context) {
return TextFormField(
key: const Key('search_accounts'),
initialValue: ref.read(searchProvider),
decoration: const InputDecoration(
hintText: 'Search accounts',

View File

@ -15,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.0"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.11"
args:
dependency: transitive
description:
@ -209,6 +216,11 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_driver:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
@ -254,6 +266,11 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
glob:
dependency: transitive
description:
@ -282,6 +299,11 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
integration_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
io:
dependency: transitive
description:
@ -583,6 +605,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
sync_http:
dependency: transitive
description:
name: sync_http
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
term_glyph:
dependency: transitive
description:
@ -618,6 +647,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "8.2.0"
watcher:
dependency: transitive
description:
@ -632,6 +668,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
webdriver:
dependency: transitive
description:
name: webdriver
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
win32:
dependency: transitive
description:

View File

@ -49,6 +49,8 @@ dependencies:
desktop_drop: ^0.3.3
dev_dependencies:
integration_test:
sdk: flutter
flutter_test:
sdk: flutter