On the desktop a saved file (a recovery phrase, recovery codes, an archive with progress) is made the own user's alone (0600, chmod(2) through the C library already in the process) on the emptied file before anything is written, so no other user of the machine reads it; Windows' files keep their folder's rights. On iOS, file_picker (darwin v2.1.2) writes a copy into the app's temporary folder for the system's picker and never removes it, saved or cancelled: it goes once the picker is done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
46 lines
1.6 KiB
Dart
46 lines
1.6 KiB
Dart
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
|
import 'package:path/path.dart' as p;
|
|
|
|
void main() {
|
|
late Directory folder;
|
|
|
|
setUp(() async {
|
|
folder = await Directory.systemTemp.createTemp('file_saver_test');
|
|
});
|
|
tearDown(() => folder.delete(recursive: true));
|
|
|
|
test("a saved file is the own user's alone where the platform has modes, "
|
|
'set before anything is written', () async {
|
|
final path = p.join(folder.path, 'halkyon-recovery-codes.txt');
|
|
// One there before, readable by everyone.
|
|
await File(path).writeAsString('old');
|
|
if (!Platform.isWindows) {
|
|
await Process.run('chmod', ['644', path]);
|
|
}
|
|
|
|
await writePrivately(path, Uint8List.fromList([1, 2, 3]));
|
|
|
|
expect(await File(path).readAsBytes(), [1, 2, 3]);
|
|
if (Platform.isLinux || Platform.isMacOS) {
|
|
expect(File(path).statSync().mode & 0x1ff, 0x180, reason: '0600');
|
|
}
|
|
}, skip: Platform.isWindows ? 'no modes' : false);
|
|
|
|
test("the system picker's copy in the temporary folder is removed, "
|
|
'others left', () async {
|
|
final copy = File(p.join(folder.path, 'halkyon-recovery-phrase.txt'));
|
|
final other = File(p.join(folder.path, 'something-else.txt'));
|
|
await copy.writeAsString('the phrase');
|
|
await other.writeAsString('other');
|
|
|
|
await forgetPickerCopy('halkyon-recovery-phrase.txt', temporary: folder);
|
|
await forgetPickerCopy('not-there.txt', temporary: folder);
|
|
|
|
expect(copy.existsSync(), isFalse);
|
|
expect(other.existsSync(), isTrue);
|
|
});
|
|
}
|