Skip to content

Commit

Permalink
chore(nextcloud)!: Remove deprecated userAgent and cookieJar paramete…
Browse files Browse the repository at this point in the history
…rs from NextcloudClient

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Aug 30, 2024
1 parent 73c6008 commit b78f04f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 152 deletions.
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
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,
);
}

0 comments on commit b78f04f

Please sign in to comment.