Skip to content

Commit b4ea8ac

Browse files
committed
Fix "Unexpected security result code"
1 parent f716460 commit b4ea8ac

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

‎.github/workflows/e2e-tests.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ jobs:
142142
# GitHub's Apple Silicon runners can't run Docker, so HumHub runs natively
143143
# here (scripts/e2e/native/), copied out of the same image as for Android.
144144
runs-on: macos-15
145-
timeout-minutes: 60
145+
# The first build takes ~20 min, and `flutter test` rebuilds for each file.
146+
timeout-minutes: 90
146147
env:
147148
HUMHUB_IMAGE_TAG: ${{ inputs.humhub_image_tag || '1.18' }}
148149
E2E_BACKEND: native

‎integration_test/support/e2e_test.dart‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import 'package:flutter_test/flutter_test.dart';
55
const _screenshotMarker = 'E2E_SCREENSHOT:';
66

77
/// Integration tests on a device have no timeout by default, so a hanging test
8-
/// (e.g. on a system alert) would block the whole CI job.
9-
const _testTimeout = Timeout(Duration(minutes: 5));
8+
/// (e.g. on a system alert) would block the whole CI job. Applied to [body], so
9+
/// a timeout also gets a screenshot; the test's own timeout is the fallback.
10+
const _bodyTimeout = Duration(minutes: 5);
11+
const _testTimeout = Timeout(Duration(minutes: 6));
1012

1113
/// [testWidgets] that requests a screenshot of the device when [body] fails.
1214
///
@@ -16,7 +18,7 @@ const _testTimeout = Timeout(Duration(minutes: 5));
1618
void e2eTest(String description, WidgetTesterCallback body) {
1719
testWidgets(description, (tester) async {
1820
try {
19-
await body(tester);
21+
await body(tester).timeout(_bodyTimeout);
2022
} catch (_) {
2123
// ignore: avoid_print
2224
print('$_screenshotMarker${_slug(description)}');

‎lib/util/storage_service.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class SecureStorageService {
4444
try {
4545
await _instance.write(key: key, value: value);
4646
} on PlatformException catch (e) {
47-
if (e.code == '-25299') {
47+
// On iOS the plugin reports code "Unexpected security result code" with
48+
// the OSStatus in details.
49+
if (e.code == '-25299' || '${e.details}' == '-25299') {
4850
await _instance.delete(key: key);
4951
await _instance.write(key: key, value: value);
5052
} else {

‎scripts/e2e/run_ios.sh‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,18 @@ rm -rf "$videos_dir" "$screenshots_dir"
7171
mkdir -p "$videos_dir" "$screenshots_dir"
7272

7373
# HumHub.initApp() awaits the notification permission request, and the test
74-
# can't answer the system alert. Install the app once and pre-grant it;
75-
# `flutter test` installs over it, which keeps the permission.
74+
# can't answer the system alert. So the app is installed and the permission
75+
# granted before every test file: `flutter test` installs over it, which keeps
76+
# the permission, but uninstalls the app when it's done.
7677
echo "Building the app for the simulator..."
7778
flutter build ios --simulator --debug --target integration_test/app_launch_test.dart 2>&1 | tee "$logs_dir/ios_build.txt"
78-
xcrun simctl install "$SIMULATOR" build/ios/iphonesimulator/Runner.app
79-
applesimutils --byId "$SIMULATOR" --bundle "$PACKAGE" --setPermissions notifications=YES > /dev/null
79+
80+
# Whichever build is there (`flutter test` replaces it), it only has to carry
81+
# the bundle id.
82+
install_app() {
83+
xcrun simctl install "$SIMULATOR" build/ios/iphonesimulator/Runner.app
84+
applesimutils --byId "$SIMULATOR" --bundle "$PACKAGE" --setPermissions notifications=YES > /dev/null
85+
}
8086

8187
xcrun simctl spawn "$SIMULATOR" log stream --level debug --style compact \
8288
--predicate 'process == "Runner"' > "$logs_dir/simulator.log" 2>&1 &
@@ -89,6 +95,8 @@ xcrun simctl spawn "$SIMULATOR" log stream --style compact \
8995
*E2E_SCREENSHOT:*)
9096
name="${line##*E2E_SCREENSHOT:}"
9197
name="${name//[^a-z0-9-]/}"
98+
# log stream's header line repeats the predicate.
99+
[ -n "$name" ] || continue
92100
xcrun simctl io "$SIMULATOR" screenshot "$screenshots_dir/$name.png" > /dev/null 2>&1 < /dev/null
93101
echo "Screenshot of failed test: $screenshots_dir/$name.png"
94102
;;
@@ -126,6 +134,7 @@ for test_file in integration_test/*_test.dart; do
126134
name="$(basename "$test_file" .dart)"
127135
# A leftover app process would start the recording before the build.
128136
xcrun simctl terminate "$SIMULATOR" "$PACKAGE" > /dev/null 2>&1 || true
137+
install_app
129138
start_recording "$name"
130139
flutter test "$test_file" \
131140
-d "$SIMULATOR" \

0 commit comments

Comments
 (0)