From b78f04f29057743d20c4964942a3601858d6b1b2 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 30 Aug 2024 09:13:02 +0200 Subject: [PATCH] chore(nextcloud)!: Remove deprecated userAgent and cookieJar parameters from NextcloudClient Signed-off-by: provokateurin --- .../nextcloud/lib/src/nextcloud_client.dart | 18 +-- .../nextcloud/test/nextcloud_client_test.dart | 140 +----------------- 2 files changed, 6 insertions(+), 152 deletions(-) diff --git a/packages/nextcloud/lib/src/nextcloud_client.dart b/packages/nextcloud/lib/src/nextcloud_client.dart index e8755522e14..4b62efe649c 100644 --- a/packages/nextcloud/lib/src/nextcloud_client.dart +++ b/packages/nextcloud/lib/src/nextcloud_client.dart @@ -1,8 +1,5 @@ -import 'package:cookie_jar/cookie_jar.dart' as cookie_jar; import 'package:dynamite_runtime/http_client.dart'; import 'package:http/http.dart' as http; -import 'package:nextcloud/src/utils/cookie_jar_client.dart'; -import 'package:universal_io/io.dart'; /// A client configuring the clients for all Nextcloud APIs. /// @@ -24,21 +21,8 @@ class NextcloudClient extends DynamiteClient with http.BaseClient { String? loginName, String? password, String? appPassword, - @Deprecated('Use a custom http client to set the user agent.') String? userAgent, http.Client? httpClient, - @Deprecated('Use a custom http client to persist cookies.') cookie_jar.CookieJar? cookieJar, }) { - var client = httpClient ?? http.Client(); - if (cookieJar != null || userAgent != null) { - client = CookieJarClient( - httpClient: httpClient, - cookieJar: cookieJar, - baseHeaders: { - if (userAgent != null) HttpHeaders.userAgentHeader: userAgent, - }, - ); - } - final authentications = [ if (appPassword != null) DynamiteHttpBearerAuthentication( @@ -53,7 +37,7 @@ class NextcloudClient extends DynamiteClient with http.BaseClient { return NextcloudClient._( baseURL, - httpClient: client, + httpClient: httpClient, authentications: authentications, ); } diff --git a/packages/nextcloud/test/nextcloud_client_test.dart b/packages/nextcloud/test/nextcloud_client_test.dart index c37d849c8a3..2523a7321c2 100644 --- a/packages/nextcloud/test/nextcloud_client_test.dart +++ b/packages/nextcloud/test/nextcloud_client_test.dart @@ -1,140 +1,10 @@ -import 'package:cookie_jar/cookie_jar.dart'; -import 'package:http/http.dart'; -import 'package:http/testing.dart'; import 'package:http_client_conformance_tests/http_client_conformance_tests.dart'; import 'package:nextcloud/nextcloud.dart'; -import 'package:test/test.dart'; void main() { - final uri = Uri.parse('http://example.com'); - group(NextcloudClient, () { - group( - 'Client conformance tests', - () { - testAll( - () => NextcloudClient(Uri()), - canReceiveSetCookieHeaders: true, - canSendCookieHeaders: true, - ); - }, - onPlatform: const { - 'browser': [Skip()], - }, - ); - - group('Cookies', () { - late CookieJar cookieJar; - setUp(() { - cookieJar = CookieJar(); - }); - - test('Cookies', () async { - final mockedClient = MockClient((request) async { - expect(request.headers['cookie'], equals('a=b; a2=b2; a3=b3')); - - return Response( - '', - 200, - headers: { - 'set-cookie': Cookie('c', 'd').toString(), - }, - ); - }); - - final client = NextcloudClient( - uri, - httpClient: mockedClient, - // ignore: deprecated_member_use_from_same_package - cookieJar: cookieJar, - ); - - await cookieJar.saveFromResponse(uri, [ - Cookie('a', 'b'), - Cookie('a2', 'b2'), - Cookie('a3', 'b3'), - ]); - await client.get(uri); - - final cookies = await cookieJar.loadForRequest(uri); - expect(cookies, hasLength(4)); - expect(cookies[0].name, 'a'); - expect(cookies[0].value, 'b'); - expect(cookies.last.name, 'c'); - expect(cookies.last.value, 'd'); - }); - - test('No cookies', () async { - final mockedClient = MockClient((request) async { - expect(request.headers['cookie'], isNull); - return Response('', 200); - }); - - final client = NextcloudClient( - uri, - httpClient: mockedClient, - // ignore: deprecated_member_use_from_same_package - cookieJar: cookieJar, - ); - - await client.get(uri); - }); - }); - - group('headers', () { - test('raw request base headers', () async { - final mockedClient = MockClient((request) async { - expect( - request.headers, - equals({ - 'user-agent': 'Neon', - }), - ); - - return Response( - '', - 200, - ); - }); - - final client = NextcloudClient( - uri, - httpClient: mockedClient, - // ignore: deprecated_member_use_from_same_package - userAgent: 'Neon', - ); - - await client.get(uri); - }); - - test('request overwrites base headers', () async { - final mockedClient = MockClient((request) async { - expect( - request.headers, - equals({ - 'user-agent': 'Cookbook', - }), - ); - - return Response( - '', - 200, - ); - }); - - final client = NextcloudClient( - uri, - httpClient: mockedClient, - // ignore: deprecated_member_use_from_same_package - userAgent: 'Neon', - ); - - await client.get( - uri, - headers: { - 'user-agent': 'Cookbook', - }, - ); - }); - }); - }); + testAll( + () => NextcloudClient(Uri()), + canReceiveSetCookieHeaders: true, + canSendCookieHeaders: true, + ); }