54 lines
1.6 KiB
Dart
54 lines
1.6 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hepan_everyday/services/diagnostic_log.dart';
|
|
|
|
void main() {
|
|
test(
|
|
'logs retain only ten minutes across reopening and omit login secrets',
|
|
() async {
|
|
final directory = await Directory.systemTemp.createTemp('tp-log-test');
|
|
addTearDown(() => directory.delete(recursive: true));
|
|
var now = DateTime.utc(2026, 10, 15, 10);
|
|
final log = DiagnosticLog(clock: () => now);
|
|
addTearDown(log.dispose);
|
|
await log.attach(directory);
|
|
log.add('old_event');
|
|
now = now.add(const Duration(minutes: 11));
|
|
log.navigation(
|
|
'graduate',
|
|
'finished',
|
|
'https://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/73?ticket=SECRET&username=PERSON',
|
|
);
|
|
log.add(
|
|
'read_failed',
|
|
fields: {'code': 'no_timetable', 'password': 'SECRET'},
|
|
);
|
|
await log.flush();
|
|
final restored = DiagnosticLog(clock: () => now);
|
|
addTearDown(restored.dispose);
|
|
await restored.attach(directory);
|
|
final text = utf8.decode(await restored.export());
|
|
expect(text, contains('navigation_finished'));
|
|
expect(text, contains('timetable'));
|
|
expect(text, contains('no_timetable'));
|
|
for (final value in [
|
|
'old_event',
|
|
'SECRET',
|
|
'PERSON',
|
|
'ticket',
|
|
'"password"',
|
|
'https://',
|
|
]) {
|
|
expect(text, isNot(contains(value)));
|
|
}
|
|
now = now.add(const Duration(minutes: 11));
|
|
expect(
|
|
utf8.decode(await restored.export()),
|
|
isNot(contains('no_timetable')),
|
|
);
|
|
},
|
|
);
|
|
}
|