Unverified Commit 0566971d authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tool] Throw tool exit on malformed storage url override (#38637)

parent 7a138ca5
...@@ -8,6 +8,7 @@ import '../base/context.dart'; ...@@ -8,6 +8,7 @@ import '../base/context.dart';
import '../globals.dart'; import '../globals.dart';
import 'common.dart'; import 'common.dart';
import 'io.dart'; import 'io.dart';
import 'platform.dart';
const int kNetworkProblemExitCode = 50; const int kNetworkProblemExitCode = 50;
...@@ -53,6 +54,19 @@ Future<List<int>> _attempt(Uri url, { bool onlyHeaders = false }) async { ...@@ -53,6 +54,19 @@ Future<List<int>> _attempt(Uri url, { bool onlyHeaders = false }) async {
} else { } else {
request = await httpClient.getUrl(url); request = await httpClient.getUrl(url);
} }
} on ArgumentError catch (error) {
final String overrideUrl = platform.environment['FLUTTER_STORAGE_BASE_URL'];
if (overrideUrl != null && url.toString().contains(overrideUrl)) {
printError(error.toString());
throwToolExit(
'The value of FLUTTER_STORAGE_BASE_URL ($overrideUrl) could not be '
'parsed as a valid url. Please see https://flutter.dev/community/china '
'for an example of how to use it.\n'
'Full URL: $url',
exitCode: kNetworkProblemExitCode,);
}
printError(error.toString());
rethrow;
} on HandshakeException catch (error) { } on HandshakeException catch (error) {
printTrace(error.toString()); printTrace(error.toString());
throwToolExit( throwToolExit(
......
...@@ -7,6 +7,7 @@ import 'dart:typed_data'; ...@@ -7,6 +7,7 @@ import 'dart:typed_data';
import 'package:flutter_tools/src/base/io.dart' as io; import 'package:flutter_tools/src/base/io.dart' as io;
import 'package:flutter_tools/src/base/net.dart'; import 'package:flutter_tools/src/base/net.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:quiver/testing/async.dart'; import 'package:quiver/testing/async.dart';
import '../../src/common.dart'; import '../../src/common.dart';
...@@ -105,7 +106,32 @@ void main() { ...@@ -105,7 +106,32 @@ void main() {
), ),
}); });
testUsingContext('retry from HttpException', () async { testUsingContext('check for bad override on ArgumentError', () async {
String error;
FakeAsync().run((FakeAsync time) {
fetchUrl(Uri.parse('example.invalid/')).then((List<int> value) {
error = 'test completed unexpectedly';
}, onError: (dynamic exception) {
error = 'test failed: $exception';
});
expect(testLogger.statusText, '');
time.elapse(const Duration(milliseconds: 10000));
expect(testLogger.statusText, '');
});
expect(error, startsWith('test failed'));
expect(testLogger.errorText, contains('Invalid argument'));
expect(error, contains('FLUTTER_STORAGE_BASE_URL'));
}, overrides: <Type, Generator>{
HttpClientFactory: () => () => MockHttpClientThrowing(
ArgumentError('test exception handling'),
),
Platform: () => FakePlatform.fromPlatform(const LocalPlatform())
..environment = <String, String>{
'FLUTTER_STORAGE_BASE_URL': 'example.invalid'
},
});
testUsingContext('retry from HttpException', () async {
String error; String error;
FakeAsync().run((FakeAsync time) { FakeAsync().run((FakeAsync time) {
fetchUrl(Uri.parse('http://example.invalid/')).then((List<int> value) { fetchUrl(Uri.parse('http://example.invalid/')).then((List<int> value) {
...@@ -183,7 +209,7 @@ testUsingContext('retry from HttpException', () async { ...@@ -183,7 +209,7 @@ testUsingContext('retry from HttpException', () async {
class MockHttpClientThrowing implements io.HttpClient { class MockHttpClientThrowing implements io.HttpClient {
MockHttpClientThrowing(this.exception); MockHttpClientThrowing(this.exception);
final Exception exception; final Object exception;
@override @override
Future<io.HttpClientRequest> getUrl(Uri url) async { Future<io.HttpClientRequest> getUrl(Uri url) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment