Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Jan 5, 2024
1 parent ed7f7ff commit e64a3f4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions integration_test/two_step_rollout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import 'package:privacyidea_authenticator/state_notifiers/settings_notifier.dart
import 'package:privacyidea_authenticator/state_notifiers/token_folder_notifier.dart';
import 'package:privacyidea_authenticator/state_notifiers/token_notifier.dart';
import 'package:privacyidea_authenticator/utils/app_customizer.dart';
import 'package:privacyidea_authenticator/utils/logger.dart';
import 'package:privacyidea_authenticator/utils/riverpod_providers.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/token_widgets/hotp_token_widgets/hotp_token_widget_tile.dart';
import 'package:privacyidea_authenticator/views/main_view/main_view_widgets/token_widgets/totp_token_widgets/totp_token_widget_tile.dart';
import 'package:privacyidea_authenticator/widgets/widget_keys.dart';

import '../test/tests_app_wrapper.dart';
Expand Down Expand Up @@ -74,40 +77,49 @@ void main() {

Future<void> _addTwoStepHotpTokenTest(WidgetTester tester) async {
await pumpUntilFindNWidgets(tester, find.byType(MainView), 1, const Duration(seconds: 10));
Logger.info('Adding HOTP Token');
globalRef!.read(tokenProvider.notifier).addTokenFromOtpAuth(
otpAuth:
'otpauth://hotp/OATH0001DBD0?secret=AALIBQJMOGEE7SAVEZ5D3K2ADO7MVFQD&counter=1&digits=6&issuer=privacyIDEA&2step_salt=8&2step_output=20&2step_difficulty=10000');
Logger.info('Finding phone part dialog');
await pumpUntilFindNWidgets(tester, find.text(AppLocalizationsEn().phonePart), 1, const Duration(seconds: 20));
expect(find.text(AppLocalizationsEn().phonePart), findsOneWidget);
final finder = find.byKey(twoStepDialogContent);
expect(finder, findsOneWidget);
final text = finder.evaluate().single.widget as Text;
final phonePart = text.data;
Logger.info('Checking phone part exists and has correct length');
expect(phonePart, isNotNull);
expect(phonePart, isNotEmpty);
// step_output=20
expect(phonePart!.replaceAll(' ', '').length, 20);
expect(find.text(AppLocalizationsEn().dismiss), findsOneWidget);
Logger.info('Dismissing dialog');
await tester.tap(find.text(AppLocalizationsEn().dismiss));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(HOTPTokenWidgetTile), 1, const Duration(seconds: 10));
}

Future<void> _addTwoStepTotpTokenTest(WidgetTester tester) async {
await pumpUntilFindNWidgets(tester, find.byType(MainView), 1, const Duration(seconds: 10));
Logger.info('Adding TOTP Token');
globalRef!.read(tokenProvider.notifier).addTokenFromOtpAuth(
otpAuth:
'otpauth://totp/TOTP00009D5F?secret=NZ4OPONKAAGDFN2QHV26ZWYVTLFER4C6&period=30&digits=6&issuer=privacyIDEA&2step_salt=8&2step_output=20&2step_difficulty=10000');
Logger.info('Finding phone part dialog');
await pumpUntilFindNWidgets(tester, find.text(AppLocalizationsEn().phonePart), 1, const Duration(seconds: 20));
expect(find.text(AppLocalizationsEn().phonePart), findsOneWidget);
final finder = find.byKey(twoStepDialogContent);
expect(finder, findsOneWidget);
final text = finder.evaluate().single.widget as Text;
final phonePart = text.data;
Logger.info('Checking phone part exists and has correct length');
expect(phonePart, isNotNull);
expect(phonePart, isNotEmpty);
// step_output=20
expect(phonePart!.replaceAll(' ', '').length, 20);
expect(find.text(AppLocalizationsEn().dismiss), findsOneWidget);
Logger.info('Dismissing dialog');
await tester.tap(find.text(AppLocalizationsEn().dismiss));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(TOTPTokenWidgetTile), 1, const Duration(seconds: 10));
//cannot "await tester.pumpAndSettle();" because of the infinite TOTP animation.
}

0 comments on commit e64a3f4

Please sign in to comment.