Unverified Commit b142c9bb authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

catch failure to parse FLUTTER_STORAGE_BASE_URL (#43599)

parent 450a7248
...@@ -482,16 +482,23 @@ abstract class CachedArtifact extends ArtifactSet { ...@@ -482,16 +482,23 @@ abstract class CachedArtifact extends ArtifactSet {
/// Template method to perform artifact update. /// Template method to perform artifact update.
Future<void> updateInner(); Future<void> updateInner();
String get _storageBaseUrl { @visibleForTesting
String get storageBaseUrl {
final String overrideUrl = platform.environment['FLUTTER_STORAGE_BASE_URL']; final String overrideUrl = platform.environment['FLUTTER_STORAGE_BASE_URL'];
if (overrideUrl == null) { if (overrideUrl == null) {
return 'https://storage.googleapis.com'; return 'https://storage.googleapis.com';
} }
// verify that this is a valid URI.
try {
Uri.parse(overrideUrl);
} on FormatException catch (err) {
throwToolExit('"FLUTTER_STORAGE_BASE_URL" contains an invalid URI:\n$err');
}
_maybeWarnAboutStorageOverride(overrideUrl); _maybeWarnAboutStorageOverride(overrideUrl);
return overrideUrl; return overrideUrl;
} }
Uri _toStorageUri(String path) => Uri.parse('$_storageBaseUrl/$path'); Uri _toStorageUri(String path) => Uri.parse('$storageBaseUrl/$path');
/// Download an archive from the given [url] and unzip it to [location]. /// Download an archive from the given [url] and unzip it to [location].
Future<void> _downloadArchive(String message, Uri url, Directory location, bool verifier(File f), void extractor(File f, Directory d)) { Future<void> _downloadArchive(String message, Uri url, Directory location, bool verifier(File f), void extractor(File f, Directory d)) {
...@@ -587,7 +594,7 @@ class FlutterWebSdk extends CachedArtifact { ...@@ -587,7 +594,7 @@ class FlutterWebSdk extends CachedArtifact {
} else if (platform.isWindows) { } else if (platform.isWindows) {
platformName += 'windows-x64'; platformName += 'windows-x64';
} }
final Uri url = Uri.parse('$_storageBaseUrl/flutter_infra/flutter/$version/$platformName.zip'); final Uri url = Uri.parse('$storageBaseUrl/flutter_infra/flutter/$version/$platformName.zip');
await _downloadZipArchive('Downloading Web SDK...', url, location); await _downloadZipArchive('Downloading Web SDK...', url, location);
// This is a temporary work-around for not being able to safely download into a shared directory. // This is a temporary work-around for not being able to safely download into a shared directory.
for (FileSystemEntity entity in location.listSync(recursive: true)) { for (FileSystemEntity entity in location.listSync(recursive: true)) {
...@@ -652,7 +659,7 @@ abstract class EngineCachedArtifact extends CachedArtifact { ...@@ -652,7 +659,7 @@ abstract class EngineCachedArtifact extends CachedArtifact {
@override @override
Future<void> updateInner() async { Future<void> updateInner() async {
final String url = '$_storageBaseUrl/flutter_infra/flutter/$version/'; final String url = '$storageBaseUrl/flutter_infra/flutter/$version/';
final Directory pkgDir = cache.getCacheDir('pkg'); final Directory pkgDir = cache.getCacheDir('pkg');
for (String pkgName in getPackageDirs()) { for (String pkgName in getPackageDirs()) {
...@@ -687,7 +694,7 @@ abstract class EngineCachedArtifact extends CachedArtifact { ...@@ -687,7 +694,7 @@ abstract class EngineCachedArtifact extends CachedArtifact {
Future<bool> checkForArtifacts(String engineVersion) async { Future<bool> checkForArtifacts(String engineVersion) async {
engineVersion ??= version; engineVersion ??= version;
final String url = '$_storageBaseUrl/flutter_infra/flutter/$engineVersion/'; final String url = '$storageBaseUrl/flutter_infra/flutter/$engineVersion/';
bool exists = false; bool exists = false;
for (String pkgName in getPackageDirs()) { for (String pkgName in getPackageDirs()) {
...@@ -1111,7 +1118,7 @@ class IosUsbArtifacts extends CachedArtifact { ...@@ -1111,7 +1118,7 @@ class IosUsbArtifacts extends CachedArtifact {
} }
@visibleForTesting @visibleForTesting
Uri get archiveUri => Uri.parse('$_storageBaseUrl/flutter_infra/ios-usb-dependencies${cache.useUnsignedMacBinaries ? '/unsigned' : ''}/$name/$version/$name.zip'); Uri get archiveUri => Uri.parse('$storageBaseUrl/flutter_infra/ios-usb-dependencies${cache.useUnsignedMacBinaries ? '/unsigned' : ''}/$name/$version/$name.zip');
} }
// Many characters are problematic in filenames, especially on Windows. // Many characters are problematic in filenames, especially on Windows.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart'; import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
...@@ -202,6 +203,18 @@ void main() { ...@@ -202,6 +203,18 @@ void main() {
); );
} }
}); });
testUsingContext('Invalid URI for FLUTTER_STORAGE_BASE_URL throws ToolExit', () async {
when(platform.environment).thenReturn(const <String, String>{
'FLUTTER_STORAGE_BASE_URL': ' http://foo',
});
final Cache cache = Cache();
final CachedArtifact artifact = MaterialFonts(cache);
expect(() => artifact.storageBaseUrl, throwsA(isInstanceOf<ToolExit>()));
}, overrides: <Type, Generator>{
Platform: () => MockPlatform(),
});
}); });
testUsingContext('flattenNameSubdirs', () { testUsingContext('flattenNameSubdirs', () {
...@@ -379,3 +392,4 @@ class MockIosUsbArtifacts extends Mock implements IosUsbArtifacts {} ...@@ -379,3 +392,4 @@ class MockIosUsbArtifacts extends Mock implements IosUsbArtifacts {}
class MockInternetAddress extends Mock implements InternetAddress {} class MockInternetAddress extends Mock implements InternetAddress {}
class MockCache extends Mock implements Cache {} class MockCache extends Mock implements Cache {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {} class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
class MockPlatform extends Mock implements Platform {}
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