Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove invalid status line tests and replace them with valid status line tests #1018

Merged
merged 13 commits into from
Sep 15, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void hybridMain(StreamChannel<Object?> channel) async {
socket.writeAll(
[
statusLine,
'Access-Control-Allow-Origin: *',
'Content-Length: 0',
'\r\n', // Add \r\n at the end of this header section.
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import 'package:test/test.dart';
import 'response_status_line_server_vm.dart'
if (dart.library.html) 'response_status_line_server_web.dart';

/// Tests that the [Client] correctly processes the response status line.
/// Tests that the [Client] correctly processes the response status line (e.g.
/// 'HTTP/1.1 200 OK\r\n').
///
/// Clients behavior varies considerably if the status line is not valid.
void testResponseStatusLine(Client client) async {
group('response status line', () {
late String host;
Expand All @@ -23,17 +26,20 @@ void testResponseStatusLine(Client client) async {
host = 'localhost:${await httpServerQueue.next}';
});

test(
'without status code',
() async {
httpServerChannel.sink.add('HTTP/1.1 OK');
await expectLater(
client.get(Uri.http(host, '')),
throwsA(isA<ClientException>()),
);
},
skip:
'Enable after https://github.com/dart-lang/http/issues/1013 is fixed',
);
test('complete', () async {
httpServerChannel.sink.add('HTTP/1.1 201 Created');
final response = await client.get(Uri.http(host, ''));
expect(response.statusCode, 201);
expect(response.reasonPhrase, 'Created');
});

test('no reason phrase', () async {
httpServerChannel.sink.add('HTTP/1.1 201');
final response = await client.get(Uri.http(host, ''));
expect(response.statusCode, 201);
// An empty Reason-Phrase is allowed according to RFC-2616. Any of these
// interpretations seem reasonable.
expect(response.reasonPhrase, anyOf(isNull, '', 'Created'));
});
});
}
Loading