From 929bd6dba1f9dbd6cfa62d5901556317285e5817 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:04:30 +0200 Subject: [PATCH 1/5] . --- lib/utils/lock_auth.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/lock_auth.dart b/lib/utils/lock_auth.dart index edb7de9dc..ebe2e4be8 100644 --- a/lib/utils/lock_auth.dart +++ b/lib/utils/lock_auth.dart @@ -73,7 +73,7 @@ Future lockAuth({required BuildContext context, required String localizedR authenticationInProgress = false; } } on PlatformException catch (e, s) { - Logger.error('Error: ${e.code}', name: 'token_widgets.dart#lockAuth', error: e, stackTrace: s); + Logger.info("Authentication failed", error: e, stackTrace: s); } return didAuthenticate; } From 5241af5fc7db495e1d112315e36c8fd1e6c5c052 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:07:54 +0200 Subject: [PATCH 2/5] can now cancel authentication on ios --- lib/utils/lock_auth.dart | 1 + lib/utils/logger.dart | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/utils/lock_auth.dart b/lib/utils/lock_auth.dart index ebe2e4be8..100b5c7a0 100644 --- a/lib/utils/lock_auth.dart +++ b/lib/utils/lock_auth.dart @@ -73,6 +73,7 @@ Future lockAuth({required BuildContext context, required String localizedR authenticationInProgress = false; } } on PlatformException catch (e, s) { + authenticationInProgress = false; Logger.info("Authentication failed", error: e, stackTrace: s); } return didAuthenticate; diff --git a/lib/utils/logger.dart b/lib/utils/logger.dart index add87db5d..7d316d484 100644 --- a/lib/utils/logger.dart +++ b/lib/utils/logger.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'dart:io'; import 'dart:isolate'; +import 'dart:math'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/foundation.dart'; @@ -131,9 +132,9 @@ class Logger { static void error(String? message, {required dynamic error, required dynamic stackTrace, String? name}) { final errorString = instance._convertLogToSingleString(message, error: error, stackTrace: stackTrace, name: name, logLevel: LogLevel.ERROR); if (message != null) { - instance._lastError = message.substring(0, 100); + instance._lastError = message.substring(0, min(message.length, 100)); } else if (error != null) { - instance._lastError = error.toString().substring(0, 100); + instance._lastError = error.toString().substring(0, min(error.toString().length, 100)); } instance._logToFile(errorString); instance._showSnackbar(); From 4c5373984b1a96cd550c7cc004d4ca05633fc488 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:27:44 +0200 Subject: [PATCH 3/5] . --- .github/workflows/flutter_build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/flutter_build.yml b/.github/workflows/flutter_build.yml index be7b41f55..fc909ebf2 100644 --- a/.github/workflows/flutter_build.yml +++ b/.github/workflows/flutter_build.yml @@ -30,7 +30,7 @@ jobs: - run: "flutter upgrade" - run: "flutter --version" - run: "flutter pub get" - - run: "flutter build ios --no-codesign" + - run: "flutter build ios -t 'lib/main_netknights.dart' --no-codesign" build_appbundle: name: (Android) @@ -41,7 +41,7 @@ jobs: # matrix job fails. fail-fast: false matrix: - api-level: [ 21,31 ] # [minSdk, most used, newest (30 is not working :(] 19 would be minSDK but does not support x86_64 + api-level: [ 21, 30, 34 ] # [minSdk, most used, newest] target: [ default ] # [default, google_apis] steps: - uses: actions/checkout@v2 @@ -56,5 +56,5 @@ jobs: - run: "flutter --version" - run: "flutter pub get" - run: 'flutter clean' - - run: "flutter build apk --debug" + - run: "flutter build apk -t 'lib/main_netknights.dart' --debug" From f6f5a31011b18fcdf0ae6bc6de6418177a11a276 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:25:22 +0200 Subject: [PATCH 4/5] updated tests --- .github/workflows/test-integration.yaml | 7 +- .../states_test/settings_state_test.dart | 66 +++++++++++++++++++ .../push_request_notifier_test.dart | 22 ++++--- 3 files changed, 84 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-integration.yaml b/.github/workflows/test-integration.yaml index 7f5997541..c835de991 100644 --- a/.github/workflows/test-integration.yaml +++ b/.github/workflows/test-integration.yaml @@ -9,10 +9,15 @@ jobs: runs-on: macos-latest strategy: matrix: - api-level: [29] + api-level: [21, 30, 34] target: [playstore] steps: - uses: actions/checkout@v2 + - uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + - uses: subosito/flutter-action@v1 with: flutter-version: '3.13.2' diff --git a/test/unit_test/model/states_test/settings_state_test.dart b/test/unit_test/model/states_test/settings_state_test.dart index e69de29bb..377690f78 100644 --- a/test/unit_test/model/states_test/settings_state_test.dart +++ b/test/unit_test/model/states_test/settings_state_test.dart @@ -0,0 +1,66 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:privacyidea_authenticator/model/states/settings_state.dart'; + +void main() { + _testSettingsState(); +} + +void _testSettingsState() { + group('SettingsState', () { + final state = SettingsState( + isFirstRun: true, + showGuideOnStart: true, + hideOpts: true, + enablePolling: true, + crashReportRecipients: {'test'}, + localePreference: const Locale('en'), + useSystemLocale: true, + verboseLogging: true, + ); + test('constructor', () { + expect(state.isFirstRun, true); + expect(state.showGuideOnStart, true); + expect(state.hideOpts, true); + expect(state.enablePolling, true); + expect(state.crashReportRecipients, {'test'}); + expect(state.localePreference.toLanguageTag(), const Locale('en').toLanguageTag()); + expect(state.useSystemLocale, true); + expect(state.verboseLogging, true); + }); + test('copyWith', () { + final newState = state.copyWith( + isFirstRun: false, + showGuideOnStart: false, + hideOpts: false, + enablePolling: false, + crashReportRecipients: {'test2'}, + localePreference: const Locale('de'), + useSystemLocale: false, + verboseLogging: false, + ); + expect(state.isFirstRun, true); + expect(state.showGuideOnStart, true); + expect(state.hideOpts, true); + expect(state.enablePolling, true); + expect(state.crashReportRecipients, {'test'}); + expect(state.localePreference.toLanguageTag(), const Locale('en').toLanguageTag()); + expect(state.useSystemLocale, true); + expect(state.verboseLogging, true); + expect(newState.isFirstRun, false); + expect(newState.showGuideOnStart, false); + expect(newState.hideOpts, false); + expect(newState.enablePolling, false); + expect(newState.crashReportRecipients, {'test2'}); + expect(newState.localePreference.toLanguageTag(), const Locale('de').toLanguageTag()); + expect(newState.useSystemLocale, false); + expect(newState.verboseLogging, false); + }); + test('encodeLocale/decodeLocale', () { + const locale = Locale('en'); + final encodedLocale = SettingsState.encodeLocale(locale); + final decodedLocale = SettingsState.decodeLocale(encodedLocale); + expect(locale.toLanguageTag(), decodedLocale.toLanguageTag()); + }); + }); +} diff --git a/test/unit_test/state_notifiers/push_request_notifier_test.dart b/test/unit_test/state_notifiers/push_request_notifier_test.dart index 91f825359..e6adbed70 100644 --- a/test/unit_test/state_notifiers/push_request_notifier_test.dart +++ b/test/unit_test/state_notifiers/push_request_notifier_test.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart'; @@ -23,6 +25,7 @@ class _MockPushProvider extends Mock implements PushProvider { } void simulatePush(PushRequest pushRequest) { + log(pushSubscriber.toString()); pushSubscriber?.newRequest(pushRequest); } } @@ -38,16 +41,14 @@ void _testPushRequestNotifier() { final container = ProviderContainer(); final mockPushProvider = _MockPushProvider(); final mockFirebaseUtils = MockFirebaseUtils(); - final testProvider = StateNotifierProvider((ref) { - final notifier = PushRequestNotifier( - pushProvider: mockPushProvider, - firebaseUtils: mockFirebaseUtils, - ioClient: MockPrivacyIdeaIOClient(), - rsaUtils: MockRsaUtils(), - ); - mockPushProvider.initialize(pushSubscriber: notifier, firebaseUtils: mockFirebaseUtils); - return notifier; - }); + final notifier = PushRequestNotifier( + pushProvider: mockPushProvider, + firebaseUtils: mockFirebaseUtils, + ioClient: MockPrivacyIdeaIOClient(), + rsaUtils: MockRsaUtils(), + ); + final testProvider = StateNotifierProvider((ref) => notifier); + await mockPushProvider.initialize(pushSubscriber: notifier, firebaseUtils: mockFirebaseUtils); final pr = PushRequest( title: 'title', question: 'question', @@ -57,6 +58,7 @@ void _testPushRequestNotifier() { id: 1, expirationDate: DateTime.now().add(const Duration(minutes: 10)), ); + log('1'); mockPushProvider.simulatePush(pr); expect(container.read(testProvider), pr); }); From 3ac87b1dc92b82a09afd5cc9cc4e59087d167d32 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:31:26 +0200 Subject: [PATCH 5/5] . --- .github/workflows/test-integration.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-integration.yaml b/.github/workflows/test-integration.yaml index c835de991..e1bd64ac5 100644 --- a/.github/workflows/test-integration.yaml +++ b/.github/workflows/test-integration.yaml @@ -9,7 +9,7 @@ jobs: runs-on: macos-latest strategy: matrix: - api-level: [21, 30, 34] + api-level: [29] target: [playstore] steps: - uses: actions/checkout@v2