Skip to content

Commit 8b5fbbf

Browse files
committed
TF-4268 Fix guard against invalid paywall property types
1 parent a74c681 commit 8b5fbbf

12 files changed

Lines changed: 37 additions & 35 deletions

lib/features/mailbox_dashboard/data/network/linagora_ecosystem_api.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ class LinagoraEcosystemApi {
3434
final linagoraEcosystem = await getLinagoraEcosystem(baseUrl);
3535

3636
final paywallProperty =
37-
linagoraEcosystem.properties?[LinagoraEcosystemIdentifier.paywallURL]
38-
as ApiUrlLinagoraEcosystem?;
37+
linagoraEcosystem.properties?[LinagoraEcosystemIdentifier.paywallURL];
3938
log('LinagoraEcosystemApi::getPaywallUrl: paywallProperty = $paywallProperty');
4039

41-
if (paywallProperty == null) {
42-
throw NotFoundPaywallUrl();
43-
} else {
40+
if (paywallProperty is ApiUrlLinagoraEcosystem) {
4441
return PaywallUrlPattern(paywallProperty.value);
4542
}
43+
throw NotFoundPaywallUrl();
4644
}
4745
}

lib/features/mailbox_dashboard/domain/state/get_linagora_ecosystem_state.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import 'package:core/presentation/state/failure.dart';
22
import 'package:core/presentation/state/success.dart';
33
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/linagora_ecosystem/linagora_ecosystem.dart';
44

5-
class GettingLinagraEcosystem extends LoadingState {}
5+
class GettingLinagoraEcosystem extends LoadingState {}
66

7-
class GetLinagraEcosystemSuccess extends UIState {
7+
class GetLinagoraEcosystemSuccess extends UIState {
88
final LinagoraEcosystem linagoraEcosystem;
99

10-
GetLinagraEcosystemSuccess(this.linagoraEcosystem);
10+
GetLinagoraEcosystemSuccess(this.linagoraEcosystem);
1111

1212
@override
1313
List<Object> get props => [linagoraEcosystem];
1414
}
1515

16-
class GetLinagraEcosystemFailure extends FeatureFailure {
17-
GetLinagraEcosystemFailure(dynamic exception) : super(exception: exception);
16+
class GetLinagoraEcosystemFailure extends FeatureFailure {
17+
GetLinagoraEcosystemFailure(dynamic exception) : super(exception: exception);
1818
}

lib/features/mailbox_dashboard/domain/usecases/get_linagora_ecosystem_interactor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ class GetLinagoraEcosystemInteractor {
1111

1212
Stream<Either<Failure, Success>> execute(String baseUrl) async* {
1313
try {
14-
yield Right(GettingLinagraEcosystem());
14+
yield Right(GettingLinagoraEcosystem());
1515
final linagoraEcosystem =
1616
await _ecosystemRepository.getLinagoraEcosystem(baseUrl);
17-
yield Right(GetLinagraEcosystemSuccess(linagoraEcosystem));
17+
yield Right(GetLinagoraEcosystemSuccess(linagoraEcosystem));
1818
} catch (e) {
19-
yield Left(GetLinagraEcosystemFailure(e));
19+
yield Left(GetLinagoraEcosystemFailure(e));
2020
}
2121
}
2222
}

lib/features/mailbox_dashboard/presentation/controller/linagora_ecosystem_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LinagoraEcosystemController with SentryEcosystemMixin {
5151
}
5252

5353
Future<void> handleGetLinagoraEcosystemSuccess(
54-
GetLinagraEcosystemSuccess success,
54+
GetLinagoraEcosystemSuccess success,
5555
) async {
5656
if (!PlatformInfo.isAndroid) return;
5757

@@ -67,7 +67,7 @@ class LinagoraEcosystemController with SentryEcosystemMixin {
6767
}
6868

6969
Future<void> handleGetLinagoraEcosystemFailure(
70-
GetLinagraEcosystemFailure failure,
70+
GetLinagoraEcosystemFailure failure,
7171
) async {
7272
logWarning('LinagoraEcosystemController:handleGetLinagoraEcosystemFailure: $failure');
7373
}

lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class MailboxDashBoardController extends ReloadableController
545545
updateTextFormattingMenuState(success.isDisplayed);
546546
} else if (success is GetAIScribeConfigSuccess) {
547547
handleLoadAIScribeConfigSuccess(success.aiScribeConfig);
548-
} else if (success is GetLinagraEcosystemSuccess) {
548+
} else if (success is GetLinagoraEcosystemSuccess) {
549549
_ecosystemController?.handleGetLinagoraEcosystemSuccess(success);
550550
} else {
551551
super.handleSuccessViewState(success);
@@ -597,7 +597,7 @@ class MailboxDashBoardController extends ReloadableController
597597
updateTextFormattingMenuState(false);
598598
} else if (failure is GetAIScribeConfigFailure) {
599599
handleLoadAIScribeConfigFailure();
600-
} else if (failure is GetLinagraEcosystemFailure) {
600+
} else if (failure is GetLinagoraEcosystemFailure) {
601601
_ecosystemController?.handleGetLinagoraEcosystemFailure(failure);
602602
} else {
603603
super.handleFailureViewState(failure);

lib/features/mailbox_dashboard/presentation/mixin/sentry_ecosystem_mixin.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mixin SentryEcosystemMixin {
1515
SentryConfigLinagoraEcosystem ecosystemConfig,
1616
) async {
1717
if (ecosystemConfig.enabled != true) {
18-
logWarning('SentryEcosystemMixin::_setUpSentry: Sentry is disabled');
18+
logWarning('SentryEcosystemMixin::setUpSentry: Sentry is disabled');
1919
return;
2020
}
2121

@@ -24,13 +24,13 @@ mixin SentryEcosystemMixin {
2424

2525
if (dsn == null || dsn.isEmpty) {
2626
logWarning(
27-
'SentryEcosystemMixin::_setUpSentry: Sentry DSN is invalid (null or empty)');
27+
'SentryEcosystemMixin::setUpSentry: Sentry DSN is invalid (null or empty)');
2828
return;
2929
}
3030

3131
if (env == null || env.isEmpty) {
3232
logWarning(
33-
'SentryEcosystemMixin::_setUpSentry: Sentry Environment is invalid (null or empty)');
33+
'SentryEcosystemMixin::setUpSentry: Sentry Environment is invalid (null or empty)');
3434
return;
3535
}
3636

lib/features/push_notification/presentation/listener/email_change_listener.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ class EmailChangeListener extends ChangeListener {
151151
consumeState(_getStoredEmailStateInteractor!.execute(_session!, _accountId!));
152152
} else {
153153
logError(
154-
'GetStoredEmailStateInteractor is null',
154+
'GetStoredEmailStateInteractor/session/accountId missing '
155+
'(interactorNull=${_getStoredEmailStateInteractor == null}, '
156+
'sessionNull=${_session == null}, accountIdNull=${_accountId == null})',
155157
);
156158
}
157159
}

lib/main/runner/app_error_handlers.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:ui';
22

33
import 'package:core/utils/app_logger.dart';
4+
import 'package:core/utils/build_utils.dart';
45
import 'package:flutter/material.dart';
56

67
/// Configures global error handlers for both Flutter framework and Platform dispatcher.
@@ -23,7 +24,7 @@ void setupErrorHooks() {
2324
exception: error,
2425
stackTrace: stack,
2526
);
26-
// Return true to prevent the app from crashing.
27-
return true;
27+
// Return true in release to prevent crashes; false in debug to surface errors.
28+
return BuildUtils.isReleaseMode;
2829
};
2930
}

test/features/linagora_ecosystem/deserialize_linagora_ecosystem_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void main() {
356356
);
357357
});
358358

359-
test('Should treat unknown object as DefaultLinagoraEcosystem', () {
359+
test('Should treat unknown object with app-like properties as AppLinagoraEcosystem', () {
360360
const jsonString = '''
361361
{
362362
"unknownConfig": {

test/features/linagora_ecosystem/get_linagora_ecosystem_interactor_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ void main() {
4141
predicate<Either>(
4242
(either) => either.fold(
4343
(_) => false,
44-
(success) => success is GettingLinagraEcosystem,
44+
(success) => success is GettingLinagoraEcosystem,
4545
),
4646
),
4747
predicate<Either>(
4848
(either) => either.fold(
4949
(_) => false,
5050
(success) =>
51-
success is GetLinagraEcosystemSuccess &&
51+
success is GetLinagoraEcosystemSuccess &&
5252
success.linagoraEcosystem == ecosystem,
5353
),
5454
),
@@ -79,13 +79,13 @@ void main() {
7979
predicate<Either>(
8080
(either) => either.fold(
8181
(_) => false,
82-
(success) => success is GettingLinagraEcosystem,
82+
(success) => success is GettingLinagoraEcosystem,
8383
),
8484
),
8585
predicate<Either>(
8686
(either) => either.fold(
8787
(failure) =>
88-
failure is GetLinagraEcosystemFailure &&
88+
failure is GetLinagoraEcosystemFailure &&
8989
failure.exception == tException,
9090
(_) => false,
9191
),

0 commit comments

Comments
 (0)