Skip to content

Commit

Permalink
Verify BaseResponsev2.url
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Jan 9, 2024
1 parent 661f5d6 commit 892ae29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions pkgs/http_client_conformance_tests/lib/src/redirect_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ void testRedirect(Client client, {bool redirectAlwaysAllowed = false}) async {
});
tearDownAll(() => httpServerChannel.sink.add(null));

test('no redirect', () async {
final request = Request('GET', Uri.http(host, '/'))
..followRedirects = false;
final response = await client.send(request);
expect(response.statusCode, 200);
expect(response.isRedirect, false);
if (response is BaseResponseV2) {
expect((response as BaseResponseV2).url, Uri.http(host, '/'));
}
});

test('disallow redirect', () async {
final request = Request('GET', Uri.http(host, '/1'))
..followRedirects = false;
final response = await client.send(request);
expect(response.statusCode, 302);
expect(response.isRedirect, true);
if (response is BaseResponseV2) {
expect((response as BaseResponseV2).url, Uri.http(host, '/1'));
}
}, skip: redirectAlwaysAllowed ? 'redirects always allowed' : false);

test('disallow redirect, 0 maxRedirects', () async {
Expand All @@ -42,6 +56,9 @@ void testRedirect(Client client, {bool redirectAlwaysAllowed = false}) async {
final response = await client.send(request);
expect(response.statusCode, 302);
expect(response.isRedirect, true);
if (response is BaseResponseV2) {
expect((response as BaseResponseV2).url, Uri.http(host, '/1'));
}
}, skip: redirectAlwaysAllowed ? 'redirects always allowed' : false);

test('allow redirect', () async {
Expand All @@ -50,6 +67,9 @@ void testRedirect(Client client, {bool redirectAlwaysAllowed = false}) async {
final response = await client.send(request);
expect(response.statusCode, 200);
expect(response.isRedirect, false);
if (response is BaseResponseV2) {
expect((response as BaseResponseV2).url, Uri.http(host, '/'));
}
});

test('allow redirect, 0 maxRedirects', () async {
Expand All @@ -69,6 +89,9 @@ void testRedirect(Client client, {bool redirectAlwaysAllowed = false}) async {
final response = await client.send(request);
expect(response.statusCode, 200);
expect(response.isRedirect, false);
if (response is BaseResponseV2) {
expect((response as BaseResponseV2).url, Uri.http(host, '/'));
}
}, skip: redirectAlwaysAllowed ? 'redirects always allowed' : false);

test('too many redirects', () async {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/http_client_conformance_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment:
dependencies:
async: ^2.8.2
dart_style: ^2.2.3
http: ^1.0.0
http: ^1.2.0
stream_channel: ^2.1.1
test: ^1.21.2

Expand Down

0 comments on commit 892ae29

Please sign in to comment.