make crash server URL customizable from environment (#18649)
This commit is contained in:
@@ -37,14 +37,17 @@ const String _kStackTraceFileField = 'DartError';
|
||||
const String _kStackTraceFilename = 'stacktrace_file';
|
||||
|
||||
/// Sends crash reports to Google.
|
||||
///
|
||||
/// There are two ways to override the behavior of this class:
|
||||
///
|
||||
/// * Define a `FLUTTER_CRASH_SERVER_BASE_URL` environment variable that points
|
||||
/// to a custom crash reporting server. This is useful if your development
|
||||
/// environment is behind a firewall and unable to send crash reports to
|
||||
/// Google, or when you wish to use your own server for collecting crash
|
||||
/// reports from Flutter Tools.
|
||||
/// * In tests call [initializeWith] and provide a mock implementation of
|
||||
/// [http.Client].
|
||||
class CrashReportSender {
|
||||
static final Uri _baseUri = new Uri(
|
||||
scheme: 'https',
|
||||
host: _kCrashServerHost,
|
||||
port: 443,
|
||||
path: _kCrashEndpointPath,
|
||||
);
|
||||
|
||||
static CrashReportSender _instance;
|
||||
|
||||
CrashReportSender._(this._client);
|
||||
@@ -60,6 +63,20 @@ class CrashReportSender {
|
||||
final http.Client _client;
|
||||
final Usage _usage = Usage.instance;
|
||||
|
||||
Uri get _baseUrl {
|
||||
final String overrideUrl = platform.environment['FLUTTER_CRASH_SERVER_BASE_URL'];
|
||||
|
||||
if (overrideUrl != null) {
|
||||
return Uri.parse(overrideUrl);
|
||||
}
|
||||
return new Uri(
|
||||
scheme: 'https',
|
||||
host: _kCrashServerHost,
|
||||
port: 443,
|
||||
path: _kCrashEndpointPath,
|
||||
);
|
||||
}
|
||||
|
||||
/// Sends one crash report.
|
||||
///
|
||||
/// The report is populated from data in [error] and [stackTrace].
|
||||
@@ -75,7 +92,7 @@ class CrashReportSender {
|
||||
printStatus('Sending crash report to Google.');
|
||||
|
||||
final String flutterVersion = getFlutterVersion();
|
||||
final Uri uri = _baseUri.replace(
|
||||
final Uri uri = _baseUrl.replace(
|
||||
queryParameters: <String, String>{
|
||||
'product': _kProductId,
|
||||
'version': flutterVersion,
|
||||
|
||||
@@ -120,6 +120,45 @@ void main() {
|
||||
}, overrides: <Type, Generator>{
|
||||
Stdio: () => const _NoStderr(),
|
||||
});
|
||||
|
||||
testUsingContext('can override base URL', () async {
|
||||
Uri uri;
|
||||
CrashReportSender.initializeWith(new MockClient((Request request) async {
|
||||
uri = request.url;
|
||||
return new Response('test-report-id', 200);
|
||||
}));
|
||||
|
||||
final int exitCode = await tools.run(
|
||||
<String>['crash'],
|
||||
<FlutterCommand>[new _CrashCommand()],
|
||||
reportCrashes: true,
|
||||
flutterVersion: 'test-version',
|
||||
);
|
||||
|
||||
expect(exitCode, 1);
|
||||
|
||||
// Verify that we sent the crash report.
|
||||
expect(uri, isNotNull);
|
||||
expect(uri, new Uri(
|
||||
scheme: 'https',
|
||||
host: 'localhost',
|
||||
port: 12345,
|
||||
path: '/fake_server',
|
||||
queryParameters: <String, String>{
|
||||
'product': 'Flutter_Tools',
|
||||
'version' : 'test-version',
|
||||
},
|
||||
));
|
||||
}, overrides: <Type, Generator> {
|
||||
Platform: () => new FakePlatform(
|
||||
operatingSystem: 'linux',
|
||||
environment: <String, String>{
|
||||
'FLUTTER_CRASH_SERVER_BASE_URL': 'https://localhost:12345/fake_server',
|
||||
},
|
||||
script: new Uri(scheme: 'data'),
|
||||
),
|
||||
Stdio: () => const _NoStderr(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user