mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 21:54:00 +01:00
The geofence needs HOME_LAT/HOME_LON, but those say where I live, so the committed policy asset is generated with --redact-home and the real values are pushed to app-private storage instead. push_home_location.sh greps config_secrets.sh rather than sourcing it -- that file holds other secrets and this script has no business evaluating them -- and refuses the shipped REDACTED_* placeholder with a message naming the file to fill in, rather than writing whatever the parse happened to land on. Private storage was chosen for its lifetime as much as its permissions: it does not survive an uninstall, so reinstalling forces re-provisioning instead of silently inheriting a stale home. The default umask left the file 666, so the script chmods it 600; the shell user gets Permission denied, and the /data/local/tmp staging copy is removed after the transfer. Every read failure returns null rather than throwing. Null reaches the enforcement layer as location-unknown, which already fails closed into enforcing -- so a corrupt coordinates file cannot become an unlock, and cannot crash the service either. Workout detection replaces a root-only SQLite read of StrongLifts' private database. The manual source is time-boxed rather than a plain toggle, because a workout mode left on by accident is indistinguishable from having no exception at all. The guarded wrapper catches broadly and times out: nothing about a workout probe failing should be able to stop enforcement running. The combined source can name which signal opened the exception, so the UI can explain an unlock rather than presenting it as magic. Only the two sources verified to exist on this device will be wired -- com.kuhy.workout_app exposes nothing readable and org.runnerup is not installed. HideTestReceiver is deleted. It proved setApplicationHidden persistence, which is what it was for, but it applied policy from an exported receiver and that has no place in a build that will later hold device owner. Confirmed absent from the rebuilt and reinstalled APK. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AwepyL5Lxs5QKbKkMpxxxL
88 lines
2.7 KiB
Dart
88 lines
2.7 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:focus_owner/home_location.dart';
|
|
|
|
void main() {
|
|
late Directory dir;
|
|
late HomeLocationStore store;
|
|
|
|
setUp(() {
|
|
dir = Directory.systemTemp.createTempSync('home_loc_test');
|
|
store = HomeLocationStore(File('${dir.path}/${HomeLocationStore.fileName}'));
|
|
});
|
|
|
|
tearDown(() => dir.deleteSync(recursive: true));
|
|
|
|
group('read', () {
|
|
test('returns null when nothing is provisioned', () async {
|
|
expect(await store.read(), isNull);
|
|
});
|
|
|
|
test('round-trips written coordinates', () async {
|
|
await store.write(52.2297, 21.0122);
|
|
final read = await store.read();
|
|
expect(read?.latitude, closeTo(52.2297, 1e-9));
|
|
expect(read?.longitude, closeTo(21.0122, 1e-9));
|
|
});
|
|
|
|
test('returns null on malformed JSON rather than throwing', () async {
|
|
// A corrupt file must read as "location unknown", which the enforcement
|
|
// layer treats as fail-closed. Throwing here would crash the service.
|
|
await store.file.writeAsString('not json at all');
|
|
expect(await store.read(), isNull);
|
|
});
|
|
|
|
test('returns null when the document is not an object', () async {
|
|
await store.file.writeAsString('[1, 2, 3]');
|
|
expect(await store.read(), isNull);
|
|
});
|
|
|
|
test('returns null when a coordinate is missing', () async {
|
|
await store.file.writeAsString('{"latitude": 52.2}');
|
|
expect(await store.read(), isNull);
|
|
});
|
|
|
|
test('returns null when a coordinate is not a number', () async {
|
|
// This is the shape the shipped REDACTED_* placeholder would produce if
|
|
// it ever reached the device.
|
|
await store.file
|
|
.writeAsString('{"latitude": "REDACTED_LAT", "longitude": 21.0}');
|
|
expect(await store.read(), isNull);
|
|
});
|
|
|
|
test('returns null for out-of-range coordinates', () async {
|
|
await store.file.writeAsString('{"latitude": 91.0, "longitude": 21.0}');
|
|
expect(await store.read(), isNull);
|
|
});
|
|
});
|
|
|
|
group('write', () {
|
|
test('rejects an impossible latitude', () {
|
|
expect(() => store.write(91, 0), throwsArgumentError);
|
|
});
|
|
|
|
test('rejects an impossible longitude', () {
|
|
expect(() => store.write(0, 181), throwsArgumentError);
|
|
});
|
|
|
|
test('accepts the poles and the antimeridian', () async {
|
|
await store.write(90, 180);
|
|
expect((await store.read())?.latitude, 90);
|
|
});
|
|
});
|
|
|
|
group('clear', () {
|
|
test('removes provisioned coordinates', () async {
|
|
await store.write(52.2297, 21.0122);
|
|
await store.clear();
|
|
expect(await store.read(), isNull);
|
|
});
|
|
|
|
test('is a no-op when nothing is stored', () async {
|
|
await store.clear();
|
|
expect(await store.read(), isNull);
|
|
});
|
|
});
|
|
}
|