From b073cd9aa8654348c575a2ab90fb4828014a82f3 Mon Sep 17 00:00:00 2001 From: Dat PHAM HOANG Date: Thu, 15 Aug 2024 16:38:11 +0700 Subject: [PATCH] Use full baseUrl instead of baseUrl's origin --- .../network/dynamic_url_interceptor_test.dart | 80 +++++++++++++++++++ .../reloadable/reloadable_controller.dart | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 core/test/data/network/dynamic_url_interceptor_test.dart diff --git a/core/test/data/network/dynamic_url_interceptor_test.dart b/core/test/data/network/dynamic_url_interceptor_test.dart new file mode 100644 index 000000000..6815eb117 --- /dev/null +++ b/core/test/data/network/dynamic_url_interceptor_test.dart @@ -0,0 +1,80 @@ +import 'package:core/data/network/config/dynamic_url_interceptors.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('setJmapUrl test', () { + test('should set jmapUrl to the full URI', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com/basicauth'; + + dynamicUrlInterceptors.setJmapUrl(fullUri); + + expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri)); + }); + + test('should set jmapUrl to the full URI when url have multiple sub-paths', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com/basicauth/jmap'; + + dynamicUrlInterceptors.setJmapUrl(fullUri); + + expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri)); + }); + + test('should set jmapUrl to the full URI when url have no sub-paths', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com'; + + dynamicUrlInterceptors.setJmapUrl(fullUri); + + expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri)); + }); + + test('should set jmapUrl to the full URI when url have port and sub-paths', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com:8080/basicauth/jmap/'; + + dynamicUrlInterceptors.setJmapUrl(fullUri); + + expect(dynamicUrlInterceptors.jmapUrl, equals(fullUri)); + }); + }); + + group('changeBaseUrl test', () { + test('should set baseUrl to the full URI', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com/basicauth'; + + dynamicUrlInterceptors.changeBaseUrl(fullUri); + + expect(dynamicUrlInterceptors.baseUrl, equals(fullUri)); + }); + + test('should set baseUrl to the full URI when url have multiple sub-paths', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com/basicauth/jmap'; + + dynamicUrlInterceptors.changeBaseUrl(fullUri); + + expect(dynamicUrlInterceptors.baseUrl, equals(fullUri)); + }); + + test('should set baseUrl to the full URI when url have no sub-paths', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com'; + + dynamicUrlInterceptors.changeBaseUrl(fullUri); + + expect(dynamicUrlInterceptors.baseUrl, equals(fullUri)); + }); + + test('should set baseUrl to the full URI when url have port and sub-paths', () { + final dynamicUrlInterceptors = DynamicUrlInterceptors(); + const fullUri = 'https://example.com:8080/basicauth/jmap/'; + + dynamicUrlInterceptors.changeBaseUrl(fullUri); + + expect(dynamicUrlInterceptors.baseUrl, equals(fullUri)); + }); + }); +} \ No newline at end of file diff --git a/lib/features/base/reloadable/reloadable_controller.dart b/lib/features/base/reloadable/reloadable_controller.dart index d788c09d2..e294fdf76 100644 --- a/lib/features/base/reloadable/reloadable_controller.dart +++ b/lib/features/base/reloadable/reloadable_controller.dart @@ -83,7 +83,7 @@ abstract class ReloadableController extends BaseController { void _handleGetCredentialSuccess(GetCredentialViewState success) { _setDataToInterceptors( - baseUrl: success.baseUrl.origin, + baseUrl: success.baseUrl.toString(), userName: success.userName, password: success.password); getSessionAction();