Hide PII from doctor validators for GitHub template (#96250)
This commit is contained in:
@@ -313,6 +313,14 @@ void main() {
|
||||
}, overrides: <Type, Generator>{
|
||||
Usage: () => testUsage,
|
||||
});
|
||||
|
||||
testUsingContext('sending events can be skipped', () async {
|
||||
await FakePassingDoctor(logger).diagnose(verbose: false, sendEvent: false);
|
||||
|
||||
expect(testUsage.events, isEmpty);
|
||||
}, overrides: <Type, Generator>{
|
||||
Usage: () => testUsage,
|
||||
});
|
||||
});
|
||||
|
||||
group('doctor with fake validators', () {
|
||||
@@ -456,6 +464,78 @@ void main() {
|
||||
'! Doctor found issues in 4 categories.\n'
|
||||
));
|
||||
});
|
||||
|
||||
testUsingContext('validate PII can be hidden', () async {
|
||||
expect(await FakePiiDoctor(logger).diagnose(showPii: false), isTrue);
|
||||
expect(logger.statusText, equals(
|
||||
'[✓] PII Validator\n'
|
||||
' • Does not contain PII\n'
|
||||
'\n'
|
||||
'• No issues found!\n'
|
||||
));
|
||||
logger.clear();
|
||||
// PII shown.
|
||||
expect(await FakePiiDoctor(logger).diagnose(), isTrue);
|
||||
expect(logger.statusText, equals(
|
||||
'[✓] PII Validator\n'
|
||||
' • Contains PII path/to/username\n'
|
||||
'\n'
|
||||
'• No issues found!\n'
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('doctor diagnosis wrapper', () {
|
||||
TestUsage testUsage;
|
||||
BufferLogger logger;
|
||||
|
||||
setUp(() {
|
||||
testUsage = TestUsage();
|
||||
logger = BufferLogger.test();
|
||||
});
|
||||
|
||||
testUsingContext('PII separated, events only sent once', () async {
|
||||
final Doctor fakeDoctor = FakePiiDoctor(logger);
|
||||
final DoctorText doctorText = DoctorText(logger, doctor: fakeDoctor);
|
||||
const String expectedPiiText = '[✓] PII Validator\n'
|
||||
' • Contains PII path/to/username\n'
|
||||
'\n'
|
||||
'• No issues found!\n';
|
||||
const String expectedPiiStrippedText =
|
||||
'[✓] PII Validator\n'
|
||||
' • Does not contain PII\n'
|
||||
'\n'
|
||||
'• No issues found!\n';
|
||||
|
||||
// Run each multiple times to make sure the logger buffer is being cleared,
|
||||
// and that events are only sent once.
|
||||
expect(await doctorText.text, expectedPiiText);
|
||||
expect(await doctorText.text, expectedPiiText);
|
||||
|
||||
expect(await doctorText.piiStrippedText, expectedPiiStrippedText);
|
||||
expect(await doctorText.piiStrippedText, expectedPiiStrippedText);
|
||||
|
||||
// Only one event sent.
|
||||
expect(testUsage.events, <TestUsageEvent>[
|
||||
const TestUsageEvent(
|
||||
'doctor-result',
|
||||
'PiiValidator',
|
||||
label: 'installed',
|
||||
),
|
||||
]);
|
||||
}, overrides: <Type, Generator>{
|
||||
Usage: () => testUsage,
|
||||
});
|
||||
|
||||
testUsingContext('without PII has same text and PII-stripped text', () async {
|
||||
final Doctor fakeDoctor = FakePassingDoctor(logger);
|
||||
final DoctorText doctorText = DoctorText(logger, doctor: fakeDoctor);
|
||||
final String piiText = await doctorText.text;
|
||||
expect(piiText, isNotEmpty);
|
||||
expect(piiText, await doctorText.piiStrippedText);
|
||||
}, overrides: <Type, Generator>{
|
||||
Usage: () => testUsage,
|
||||
});
|
||||
});
|
||||
|
||||
testUsingContext('validate non-verbose output wrapping', () async {
|
||||
@@ -535,7 +615,6 @@ void main() {
|
||||
));
|
||||
});
|
||||
|
||||
|
||||
group('doctor with grouped validators', () {
|
||||
testUsingContext('validate diagnose combines validator output', () async {
|
||||
expect(await FakeGroupedDoctor(logger).diagnose(), isTrue);
|
||||
@@ -666,6 +745,9 @@ class NoOpDoctor implements Doctor {
|
||||
bool verbose = true,
|
||||
bool showColor = true,
|
||||
AndroidLicenseValidator androidLicenseValidator,
|
||||
bool showPii = true,
|
||||
List<ValidatorTask> startedValidatorTasks,
|
||||
bool sendEvent = true,
|
||||
}) async => true;
|
||||
|
||||
@override
|
||||
@@ -694,6 +776,18 @@ class PassingValidator extends DoctorValidator {
|
||||
}
|
||||
}
|
||||
|
||||
class PiiValidator extends DoctorValidator {
|
||||
PiiValidator() : super('PII Validator');
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validate() async {
|
||||
const List<ValidationMessage> messages = <ValidationMessage>[
|
||||
ValidationMessage('Contains PII path/to/username', piiStrippedMessage: 'Does not contain PII'),
|
||||
];
|
||||
return const ValidationResult(ValidationType.installed, messages);
|
||||
}
|
||||
}
|
||||
|
||||
class MissingValidator extends DoctorValidator {
|
||||
MissingValidator() : super('Missing Validator');
|
||||
|
||||
@@ -840,6 +934,19 @@ class FakeQuietDoctor extends Doctor {
|
||||
}
|
||||
}
|
||||
|
||||
/// A doctor that passes and contains PII that can be hidden.
|
||||
class FakePiiDoctor extends Doctor {
|
||||
FakePiiDoctor(Logger logger) : super(logger: logger);
|
||||
|
||||
List<DoctorValidator> _validators;
|
||||
@override
|
||||
List<DoctorValidator> get validators {
|
||||
return _validators ??= <DoctorValidator>[
|
||||
PiiValidator(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/// A doctor with a validator that throws an exception.
|
||||
class FakeCrashingDoctor extends Doctor {
|
||||
FakeCrashingDoctor(Logger logger) : super(logger: logger);
|
||||
|
||||
@@ -17,6 +17,7 @@ import 'package:flutter_tools/src/commands/build.dart';
|
||||
import 'package:flutter_tools/src/commands/config.dart';
|
||||
import 'package:flutter_tools/src/commands/doctor.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/doctor_validator.dart';
|
||||
import 'package:flutter_tools/src/features.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
@@ -368,6 +369,9 @@ class FakeDoctor extends Fake implements Doctor {
|
||||
bool verbose = true,
|
||||
bool showColor = true,
|
||||
AndroidLicenseValidator androidLicenseValidator,
|
||||
bool showPii = true,
|
||||
List<ValidatorTask> startedValidatorTasks,
|
||||
bool sendEvent = true,
|
||||
}) async {
|
||||
return diagnoseSucceeds;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/crash_reporting.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:test/fake.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/fake_http_client.dart';
|
||||
@@ -76,7 +78,7 @@ void main() {
|
||||
expect(logger.traceText, contains('Crash report sent (report ID: test-report-id)'));
|
||||
}
|
||||
|
||||
testWithoutContext('CrashReporter.informUser provides basic instructions', () async {
|
||||
testWithoutContext('CrashReporter.informUser provides basic instructions without PII', () async {
|
||||
final CrashReporter crashReporter = CrashReporter(
|
||||
fileSystem: fs,
|
||||
logger: logger,
|
||||
@@ -91,12 +93,16 @@ void main() {
|
||||
command: 'arg1 arg2 arg3',
|
||||
error: Exception('Dummy exception'),
|
||||
stackTrace: StackTrace.current,
|
||||
doctorText: 'Fake doctor text'),
|
||||
// Spaces are URL query encoded in the output, make it one word to make this test simpler.
|
||||
doctorText: FakeDoctorText('Ignored', 'NoPIIFakeDoctorText'),
|
||||
),
|
||||
file,
|
||||
);
|
||||
|
||||
expect(logger.errorText, contains('A crash report has been written to ${file.path}.'));
|
||||
expect(logger.statusText, contains('NoPIIFakeDoctorText'));
|
||||
expect(logger.statusText, isNot(contains('Ignored')));
|
||||
expect(logger.statusText, contains('https://github.com/flutter/flutter/issues/new'));
|
||||
expect(logger.errorText, contains('A crash report has been written to ${file.path}.'));
|
||||
});
|
||||
|
||||
testWithoutContext('suppress analytics', () async {
|
||||
@@ -379,3 +385,16 @@ class CrashingCrashReportSender extends MockClient {
|
||||
throw exception;
|
||||
});
|
||||
}
|
||||
|
||||
class FakeDoctorText extends Fake implements DoctorText {
|
||||
FakeDoctorText(String text, String piiStrippedText)
|
||||
: _text = text, _piiStrippedText = piiStrippedText;
|
||||
|
||||
@override
|
||||
Future<String> get text async => _text;
|
||||
final String _text;
|
||||
|
||||
@override
|
||||
Future<String> get piiStrippedText async => _piiStrippedText;
|
||||
final String _piiStrippedText;
|
||||
}
|
||||
|
||||
@@ -308,4 +308,7 @@ class FakeError extends Error {
|
||||
StackTrace get stackTrace => StackTrace.fromString('''
|
||||
#0 _File.open.<anonymous closure> (dart:io/file_impl.dart:366:9)
|
||||
#1 _rootRunUnary (dart:async/zone.dart:1141:38)''');
|
||||
|
||||
@override
|
||||
String toString() => 'PII to ignore';
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ void main() {
|
||||
expect(sentDetails.command, 'flutter crash');
|
||||
expect(sentDetails.error, 'an exception % --');
|
||||
expect(sentDetails.stackTrace.toString(), contains('CrashingFlutterCommand.runCommand'));
|
||||
expect(sentDetails.doctorText, contains('[✓] Flutter'));
|
||||
expect(await sentDetails.doctorText.text, contains('[✓] Flutter'));
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => FakePlatform(
|
||||
environment: <String, String>{
|
||||
|
||||
Reference in New Issue
Block a user