mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-25 03:03:50 +03:00
7f093d97a2
This changes the currentDeviceDataNotifier to use an AsyncValue instead of a nullable YubiKeyData to allow for error states, and handles such a state for NFC readers when a non-YubiKey is present.
98 lines
3.0 KiB
Dart
98 lines
3.0 KiB
Dart
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/views/device_error_screen.dart';
|
|
import 'package:yubico_authenticator/core/state.dart';
|
|
import 'package:yubico_authenticator/desktop/init.dart' as desktop;
|
|
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 Widget initializedApp;
|
|
if (isDesktop) {
|
|
initializedApp = await desktop.initialize([]);
|
|
} else if (isAndroid) {
|
|
initializedApp = await android.initialize();
|
|
} else {
|
|
throw UnimplementedError('Platform not supported');
|
|
}
|
|
|
|
await tester.pumpWidget(initializedApp);
|
|
await tester.pump(const Duration(milliseconds: 500));
|
|
|
|
expect(find.byType(DeviceErrorScreen), 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));
|
|
});
|
|
});
|
|
}
|