Skip to content

Commit

Permalink
Merge pull request #2447 from nextcloud/chore/nextcloud/remove-deprec…
Browse files Browse the repository at this point in the history
…ated-useragent-cookiejar
  • Loading branch information
provokateurin authored Aug 30, 2024
2 parents 6e9e5d2 + 4ce78c1 commit 44179e9
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 261 deletions.
8 changes: 0 additions & 8 deletions packages/neon_framework/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.1"
cookie_jar:
dependency: transitive
description:
name: cookie_jar
sha256: a6ac027d3ed6ed756bfce8f3ff60cb479e266f3b0fdabd6242b804b6765e52de
url: "https://pub.dev"
source: hosted
version: "4.0.8"
cookie_store:
dependency: "direct overridden"
description:
Expand Down
18 changes: 1 addition & 17 deletions packages/nextcloud/lib/src/nextcloud_client.dart
Original file line number Diff line number Diff line change
@@ -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.
///
Expand All @@ -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(
Expand All @@ -53,7 +37,7 @@ class NextcloudClient extends DynamiteClient with http.BaseClient {

return NextcloudClient._(
baseURL,
httpClient: client,
httpClient: httpClient,
authentications: authentications,
);
}
Expand Down
77 changes: 0 additions & 77 deletions packages/nextcloud/lib/src/utils/cookie_jar_client.dart

This file was deleted.

1 change: 0 additions & 1 deletion packages/nextcloud/lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export 'cookie_jar_client.dart';
export 'date_time.dart';
export 'http_date_parser.dart';
1 change: 0 additions & 1 deletion packages/nextcloud/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies:
built_collection: ^5.0.0
built_value: ^8.9.0
collection: ^1.0.0
cookie_jar: ^4.0.7
crypto: ^3.0.0
crypton: ^2.0.0
dynamite_runtime: ^0.5.0
Expand Down
140 changes: 5 additions & 135 deletions packages/nextcloud/test/nextcloud_client_test.dart
Original file line number Diff line number Diff line change
@@ -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,
);
}
22 changes: 0 additions & 22 deletions packages/nextcloud/test/utils/cookie_jar_client_test.dart

This file was deleted.

0 comments on commit 44179e9

Please sign in to comment.