TF-3484 Add unit test to verify get oidc configuration when check oidc available fail
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -4,13 +4,20 @@ import 'package:core/presentation/resources/image_paths.dart';
|
|||||||
import 'package:core/presentation/utils/app_toast.dart';
|
import 'package:core/presentation/utils/app_toast.dart';
|
||||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||||
import 'package:core/utils/application_manager.dart';
|
import 'package:core/utils/application_manager.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:mockito/annotations.dart';
|
import 'package:mockito/annotations.dart';
|
||||||
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:model/oidc/response/oidc_link_dto.dart';
|
||||||
|
import 'package:model/oidc/response/oidc_response.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
import 'package:tmail_ui_user/features/caching/caching_manager.dart';
|
||||||
import 'package:tmail_ui_user/features/home/domain/usecases/get_session_interactor.dart';
|
import 'package:tmail_ui_user/features/home/domain/usecases/get_session_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart';
|
import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/data/network/oidc_error.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/exceptions/login_exception.dart';
|
import 'package:tmail_ui_user/features/login/domain/exceptions/login_exception.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/state/check_oidc_is_available_state.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/domain/state/get_oidc_configuration_state.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/state/get_token_oidc_state.dart';
|
import 'package:tmail_ui_user/features/login/domain/state/get_token_oidc_state.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/usecases/authenticate_oidc_on_browser_interactor.dart';
|
import 'package:tmail_ui_user/features/login/domain/usecases/authenticate_oidc_on_browser_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/usecases/authentication_user_interactor.dart';
|
import 'package:tmail_ui_user/features/login/domain/usecases/authentication_user_interactor.dart';
|
||||||
@@ -28,6 +35,7 @@ import 'package:tmail_ui_user/features/login/domain/usecases/get_token_oidc_inte
|
|||||||
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_url_on_mobile_interactor.dart';
|
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_url_on_mobile_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_username_on_mobile_interactor.dart';
|
import 'package:tmail_ui_user/features/login/domain/usecases/save_login_username_on_mobile_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/usecases/update_account_cache_interactor.dart';
|
import 'package:tmail_ui_user/features/login/domain/usecases/update_account_cache_interactor.dart';
|
||||||
|
import 'package:tmail_ui_user/features/login/presentation/extensions/handle_openid_configuration.dart';
|
||||||
import 'package:tmail_ui_user/features/login/presentation/login_controller.dart';
|
import 'package:tmail_ui_user/features/login/presentation/login_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/login/presentation/login_form_type.dart';
|
import 'package:tmail_ui_user/features/login/presentation/login_form_type.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_manager.dart';
|
import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_manager.dart';
|
||||||
@@ -106,85 +114,87 @@ void main() {
|
|||||||
|
|
||||||
late LoginController loginController;
|
late LoginController loginController;
|
||||||
|
|
||||||
group('Test handleFailureViewState with GetTokenOIDCFailure', () {
|
setUp(() {
|
||||||
setUp(() {
|
mockAuthenticationInteractor = MockAuthenticationInteractor();
|
||||||
mockAuthenticationInteractor = MockAuthenticationInteractor();
|
mockCheckOIDCIsAvailableInteractor = MockCheckOIDCIsAvailableInteractor();
|
||||||
mockCheckOIDCIsAvailableInteractor = MockCheckOIDCIsAvailableInteractor();
|
mockGetOIDCConfigurationInteractor = MockGetOIDCConfigurationInteractor();
|
||||||
mockGetOIDCConfigurationInteractor = MockGetOIDCConfigurationInteractor();
|
mockGetTokenOIDCInteractor = MockGetTokenOIDCInteractor();
|
||||||
mockGetTokenOIDCInteractor = MockGetTokenOIDCInteractor();
|
mockAuthenticateOidcOnBrowserInteractor = MockAuthenticateOidcOnBrowserInteractor();
|
||||||
mockAuthenticateOidcOnBrowserInteractor = MockAuthenticateOidcOnBrowserInteractor();
|
mockGetAuthenticationInfoInteractor = MockGetAuthenticationInfoInteractor();
|
||||||
mockGetAuthenticationInfoInteractor = MockGetAuthenticationInfoInteractor();
|
mockGetStoredOidcConfigurationInteractor = MockGetStoredOidcConfigurationInteractor();
|
||||||
mockGetStoredOidcConfigurationInteractor = MockGetStoredOidcConfigurationInteractor();
|
mockSaveLoginUrlOnMobileInteractor = MockSaveLoginUrlOnMobileInteractor();
|
||||||
mockSaveLoginUrlOnMobileInteractor = MockSaveLoginUrlOnMobileInteractor();
|
mockGetAllRecentLoginUrlOnMobileInteractor = MockGetAllRecentLoginUrlOnMobileInteractor();
|
||||||
mockGetAllRecentLoginUrlOnMobileInteractor = MockGetAllRecentLoginUrlOnMobileInteractor();
|
mockSaveLoginUsernameOnMobileInteractor = MockSaveLoginUsernameOnMobileInteractor();
|
||||||
mockSaveLoginUsernameOnMobileInteractor = MockSaveLoginUsernameOnMobileInteractor();
|
mockGetAllRecentLoginUsernameOnMobileInteractor = MockGetAllRecentLoginUsernameOnMobileInteractor();
|
||||||
mockGetAllRecentLoginUsernameOnMobileInteractor = MockGetAllRecentLoginUsernameOnMobileInteractor();
|
mockDNSLookupToGetJmapUrlInteractor = MockDNSLookupToGetJmapUrlInteractor();
|
||||||
mockDNSLookupToGetJmapUrlInteractor = MockDNSLookupToGetJmapUrlInteractor();
|
mockSignInTwakeWorkplaceInteractor = MockSignInTwakeWorkplaceInteractor();
|
||||||
mockSignInTwakeWorkplaceInteractor = MockSignInTwakeWorkplaceInteractor();
|
|
||||||
|
|
||||||
// mock reloadable controller
|
// mock reloadable controller
|
||||||
mockGetSessionInteractor = MockGetSessionInteractor();
|
mockGetSessionInteractor = MockGetSessionInteractor();
|
||||||
mockGetAuthenticatedAccountInteractor = MockGetAuthenticatedAccountInteractor();
|
mockGetAuthenticatedAccountInteractor = MockGetAuthenticatedAccountInteractor();
|
||||||
mockUpdateAccountCacheInteractor = MockUpdateAccountCacheInteractor();
|
mockUpdateAccountCacheInteractor = MockUpdateAccountCacheInteractor();
|
||||||
|
|
||||||
//mock base controller
|
//mock base controller
|
||||||
mockCachingManager = MockCachingManager();
|
mockCachingManager = MockCachingManager();
|
||||||
mockLanguageCacheManager = MockLanguageCacheManager();
|
mockLanguageCacheManager = MockLanguageCacheManager();
|
||||||
mockAuthorizationInterceptors = MockAuthorizationInterceptors();
|
mockAuthorizationInterceptors = MockAuthorizationInterceptors();
|
||||||
mockDynamicUrlInterceptors = MockDynamicUrlInterceptors();
|
mockDynamicUrlInterceptors = MockDynamicUrlInterceptors();
|
||||||
mockDeleteCredentialInteractor = MockDeleteCredentialInteractor();
|
mockDeleteCredentialInteractor = MockDeleteCredentialInteractor();
|
||||||
mockLogoutOidcInteractor = MockLogoutOidcInteractor();
|
mockLogoutOidcInteractor = MockLogoutOidcInteractor();
|
||||||
mockDeleteAuthorityOidcInteractor = MockDeleteAuthorityOidcInteractor();
|
mockDeleteAuthorityOidcInteractor = MockDeleteAuthorityOidcInteractor();
|
||||||
mockAppToast = MockAppToast();
|
mockAppToast = MockAppToast();
|
||||||
mockImagePaths = MockImagePaths();
|
mockImagePaths = MockImagePaths();
|
||||||
mockResponsiveUtils = MockResponsiveUtils();
|
mockResponsiveUtils = MockResponsiveUtils();
|
||||||
mockUuid = MockUuid();
|
mockUuid = MockUuid();
|
||||||
mockApplicationManager = MockApplicationManager();
|
mockApplicationManager = MockApplicationManager();
|
||||||
mockToastManager = MockToastManager();
|
mockToastManager = MockToastManager();
|
||||||
mockTwakeAppManager = MockTwakeAppManager();
|
mockTwakeAppManager = MockTwakeAppManager();
|
||||||
|
|
||||||
Get.put<GetSessionInteractor>(mockGetSessionInteractor);
|
|
||||||
Get.put<GetAuthenticatedAccountInteractor>(mockGetAuthenticatedAccountInteractor);
|
|
||||||
Get.put<UpdateAccountCacheInteractor>(mockUpdateAccountCacheInteractor);
|
|
||||||
Get.put<CachingManager>(mockCachingManager);
|
|
||||||
Get.put<LanguageCacheManager>(mockLanguageCacheManager);
|
|
||||||
Get.put<AuthorizationInterceptors>(mockAuthorizationInterceptors);
|
|
||||||
Get.put<AuthorizationInterceptors>(
|
|
||||||
mockAuthorizationInterceptors,
|
|
||||||
tag: BindingTag.isolateTag,
|
|
||||||
);
|
|
||||||
Get.put<DynamicUrlInterceptors>(mockDynamicUrlInterceptors);
|
|
||||||
Get.put<DeleteCredentialInteractor>(mockDeleteCredentialInteractor);
|
|
||||||
Get.put<LogoutOidcInteractor>(mockLogoutOidcInteractor);
|
|
||||||
Get.put<DeleteAuthorityOidcInteractor>(mockDeleteAuthorityOidcInteractor);
|
|
||||||
Get.put<AppToast>(mockAppToast);
|
|
||||||
Get.put<ImagePaths>(mockImagePaths);
|
|
||||||
Get.put<ResponsiveUtils>(mockResponsiveUtils);
|
|
||||||
Get.put<Uuid>(mockUuid);
|
|
||||||
Get.put<ApplicationManager>(mockApplicationManager);
|
|
||||||
Get.put<ToastManager>(mockToastManager);
|
|
||||||
Get.put<TwakeAppManager>(mockTwakeAppManager);
|
|
||||||
Get.testMode = true;
|
|
||||||
|
|
||||||
loginController = LoginController(
|
|
||||||
mockAuthenticationInteractor,
|
|
||||||
mockCheckOIDCIsAvailableInteractor,
|
|
||||||
mockGetOIDCConfigurationInteractor,
|
|
||||||
mockGetTokenOIDCInteractor,
|
|
||||||
mockAuthenticateOidcOnBrowserInteractor,
|
|
||||||
mockGetAuthenticationInfoInteractor,
|
|
||||||
mockGetStoredOidcConfigurationInteractor,
|
|
||||||
mockSaveLoginUrlOnMobileInteractor,
|
|
||||||
mockGetAllRecentLoginUrlOnMobileInteractor,
|
|
||||||
mockSaveLoginUsernameOnMobileInteractor,
|
|
||||||
mockGetAllRecentLoginUsernameOnMobileInteractor,
|
|
||||||
mockDNSLookupToGetJmapUrlInteractor,
|
|
||||||
mockSignInTwakeWorkplaceInteractor,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
Get.put<GetSessionInteractor>(mockGetSessionInteractor);
|
||||||
|
Get.put<GetAuthenticatedAccountInteractor>(mockGetAuthenticatedAccountInteractor);
|
||||||
|
Get.put<UpdateAccountCacheInteractor>(mockUpdateAccountCacheInteractor);
|
||||||
|
Get.put<CachingManager>(mockCachingManager);
|
||||||
|
Get.put<LanguageCacheManager>(mockLanguageCacheManager);
|
||||||
|
Get.put<AuthorizationInterceptors>(mockAuthorizationInterceptors);
|
||||||
|
Get.put<AuthorizationInterceptors>(
|
||||||
|
mockAuthorizationInterceptors,
|
||||||
|
tag: BindingTag.isolateTag,
|
||||||
|
);
|
||||||
|
Get.put<DynamicUrlInterceptors>(mockDynamicUrlInterceptors);
|
||||||
|
Get.put<DeleteCredentialInteractor>(mockDeleteCredentialInteractor);
|
||||||
|
Get.put<LogoutOidcInteractor>(mockLogoutOidcInteractor);
|
||||||
|
Get.put<DeleteAuthorityOidcInteractor>(mockDeleteAuthorityOidcInteractor);
|
||||||
|
Get.put<AppToast>(mockAppToast);
|
||||||
|
Get.put<ImagePaths>(mockImagePaths);
|
||||||
|
Get.put<ResponsiveUtils>(mockResponsiveUtils);
|
||||||
|
Get.put<Uuid>(mockUuid);
|
||||||
|
Get.put<ApplicationManager>(mockApplicationManager);
|
||||||
|
Get.put<ToastManager>(mockToastManager);
|
||||||
|
Get.put<TwakeAppManager>(mockTwakeAppManager);
|
||||||
|
Get.testMode = true;
|
||||||
|
|
||||||
|
dotenv.testLoad(mergeWith: {
|
||||||
|
'SERVER_URL': 'https://example.com'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
loginController = LoginController(
|
||||||
|
mockAuthenticationInteractor,
|
||||||
|
mockCheckOIDCIsAvailableInteractor,
|
||||||
|
mockGetOIDCConfigurationInteractor,
|
||||||
|
mockGetTokenOIDCInteractor,
|
||||||
|
mockAuthenticateOidcOnBrowserInteractor,
|
||||||
|
mockGetAuthenticationInfoInteractor,
|
||||||
|
mockGetStoredOidcConfigurationInteractor,
|
||||||
|
mockSaveLoginUrlOnMobileInteractor,
|
||||||
|
mockGetAllRecentLoginUrlOnMobileInteractor,
|
||||||
|
mockSaveLoginUsernameOnMobileInteractor,
|
||||||
|
mockGetAllRecentLoginUsernameOnMobileInteractor,
|
||||||
|
mockDNSLookupToGetJmapUrlInteractor,
|
||||||
|
mockSignInTwakeWorkplaceInteractor,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('Test handleFailureViewState with GetTokenOIDCFailure', () {
|
||||||
test('WHEN handleFailureViewState is called with GetTokenOIDCFailure \n'
|
test('WHEN handleFailureViewState is called with GetTokenOIDCFailure \n'
|
||||||
'AND loginFormType is dnsLookup \n'
|
'AND loginFormType is dnsLookup \n'
|
||||||
'BUT EXCEPTION is not NoSuitableBrowserForOIDCException \n'
|
'BUT EXCEPTION is not NoSuitableBrowserForOIDCException \n'
|
||||||
@@ -230,7 +240,81 @@ void main() {
|
|||||||
final failure = GetTokenOIDCFailure(NoSuitableBrowserForOIDCException());
|
final failure = GetTokenOIDCFailure(NoSuitableBrowserForOIDCException());
|
||||||
loginController.handleFailureViewState(failure);
|
loginController.handleFailureViewState(failure);
|
||||||
|
|
||||||
expect(loginController.loginFormType.value, equals(LoginFormType.baseUrlForm));
|
expect(loginController.loginFormType.value,
|
||||||
|
equals(LoginFormType.baseUrlForm));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('LoginController::handleFailureViewState::', () {
|
||||||
|
test('should call _getOIDCConfigurationInteractor when failure is CheckOIDCIsAvailableFailure', () {
|
||||||
|
// Arrange
|
||||||
|
final failure = CheckOIDCIsAvailableFailure(CanNotFoundOIDCLinks());
|
||||||
|
loginController.onBaseUrlChange('https://example.com');
|
||||||
|
// Act
|
||||||
|
loginController.handleFailureViewState(failure);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
verify(mockGetOIDCConfigurationInteractor.execute(any)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should update loginFormType when failure is GetOIDCConfigurationFromBaseUrlFailure', () {
|
||||||
|
// Arrange
|
||||||
|
final failure = GetOIDCConfigurationFromBaseUrlFailure(Exception());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
loginController.handleFailureViewState(failure);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(loginController.loginFormType.value, LoginFormType.retry);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('LoginController::handleUrgentException::', () {
|
||||||
|
test('should call _getOIDCConfigurationInteractor when failure is CheckOIDCIsAvailableFailure', () {
|
||||||
|
// Arrange
|
||||||
|
final failure = CheckOIDCIsAvailableFailure(CanNotFoundOIDCLinks());
|
||||||
|
loginController.onBaseUrlChange('https://example.com');
|
||||||
|
// Act
|
||||||
|
loginController.handleUrgentException(failure: failure);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
verify(mockGetOIDCConfigurationInteractor.execute(any)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should update loginFormType when failure is GetOIDCConfigurationFromBaseUrlFailure', () {
|
||||||
|
// Arrange
|
||||||
|
final failure = GetOIDCConfigurationFromBaseUrlFailure(Exception());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
loginController.handleUrgentException(failure: failure);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(loginController.loginFormType.value, LoginFormType.retry);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('LoginController::handleSuccessViewState::', () {
|
||||||
|
test('should not call _getOIDCConfigurationInteractor when success is CheckOIDCIsAvailableSuccess', () {
|
||||||
|
// Arrange
|
||||||
|
const baseUrl = 'https://example.com';
|
||||||
|
final oidcResponse = OIDCResponse(
|
||||||
|
'subject',
|
||||||
|
[
|
||||||
|
OIDCLinkDto(
|
||||||
|
Uri.parse(baseUrl),
|
||||||
|
Uri.parse(baseUrl),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
final success = CheckOIDCIsAvailableSuccess(oidcResponse);
|
||||||
|
loginController.onBaseUrlChange(baseUrl);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
loginController.handleSuccessViewState(success);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
verifyNever(loginController.tryGetOIDCConfigurationFromBaseUrl(Uri.parse(baseUrl)));
|
||||||
|
verify(loginController.getOIDCConfiguration(oidcResponse)).called(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user