feat(base)!: no anonymous accounts on the server (ADR 0020, D25)
All checks were successful
CI / check (push) Successful in 30m13s
CI / deploy (push) Has been skipped

The server's half of D25: every account has a way in, and the anonymous
accounts left from before go with the daily pruning.

- The module signs nobody in anonymously: `anonymousIdp` and
  `gitHubUpgrade` are gone, and so is linking GitHub at the register.
- A password is set only by someone whose address is theirs (a
  `firstPassword` code) or who signs in with GitHub alone (a fresh
  sign-in and a `signUp` code); an anonymous account is refused
  `wrongCredentials` before any code is used.
- SimpleLogin refuses to link onto a caller without `identified`
  (`wrongCaller`), the member's endpoint too, so nothing turns an
  anonymous account into one with a way in.
- `pruneAnonymousPeople` deletes every anonymous account left, however
  new, never one identified. Learn and Todo schedule it as
  `prune-accounts` and cancel the old `prune-abandoned-anonymous-people`
  entry once.
- Learn: someone without `identified` keeps no files;
  `FILE_LIMIT_ANONYMOUS_MB` is gone. `minimumAppBuild` is 23, as builds
  up to 22 start with an anonymous account.
- Learn's sync tests make their person and session by SQL in the
  development database, as Serverpod stores sessions.
- Docs, store listings and ADRs 0010, 0014, 0016, 0017 and 0019 amended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-24 16:07:27 +02:00
commit 87671208df
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
3 changed files with 837 additions and 1353 deletions

View file

@ -58,15 +58,14 @@ void main() {
spaces.clear();
});
TestSessionBuilder signedIn(
UuidValue person, {
Set<Scope> scopes = const {},
}) => sessionBuilder.copyWith(
authentication: AuthenticationOverride.authenticationInfo(
person.uuid,
scopes,
),
);
/// [person]'s session, `identified` unless [scopes] say otherwise.
TestSessionBuilder signedIn(UuidValue person, {Set<Scope>? scopes}) =>
sessionBuilder.copyWith(
authentication: AuthenticationOverride.authenticationInfo(
person.uuid,
scopes ?? {identified},
),
);
/// Adds [bytes] as [person], as the app does: asks how to upload them,
/// uploads them unless the server has them, and finishes the upload.
@ -74,7 +73,7 @@ void main() {
UuidValue person,
List<int> bytes, {
String? as,
Set<Scope> scopes = const {},
Set<Scope>? scopes,
bool? encrypted,
}) async {
final hash = as ?? sha256.convert(bytes).toString();
@ -387,8 +386,7 @@ void main() {
group('room', () {
setUp(() {
fileLimits = const FileLimits(
anonymousBytes: 10,
identifiedBytes: 20,
identifiedBytes: 10,
instanceBytes: 1000,
);
});
@ -400,7 +398,7 @@ void main() {
.having((e) => e.usedBytes, 'usedBytes', used),
);
test('an anonymous person keeps no more than their room', () async {
test('a person keeps no more than their room', () async {
expect(await add(alice, List.filled(8, 1)), isTrue);
await expectLater(
@ -413,15 +411,18 @@ void main() {
);
});
test('an identified person keeps more', () async {
expect(
await add(alice, List.filled(15, 1), scopes: {identified}),
isTrue,
);
test('an anonymous account left from before keeps nothing '
'(ADR 0020, D25)', () async {
await expectLater(
add(bob, List.filled(15, 1)),
add(bob, [1], scopes: const {}),
refused(instanceFull: false, used: 0),
);
expect(
(await endpoints.asset.usage(
signedIn(bob, scopes: const {}),
)).limitBytes,
0,
);
});
test('an allowance gives one person more, and nobody else', () async {
@ -441,8 +442,7 @@ void main() {
// Whatever other tests left behind counts too: the room is set
// from what the instance holds now.
fileLimits = FileLimits(
anonymousBytes: 10,
identifiedBytes: 20,
identifiedBytes: 10,
instanceBytes: await _instanceBytes(session) + 12,
);
expect(await add(alice, List.filled(8, 1)), isTrue);
@ -550,8 +550,7 @@ void main() {
expect((usage.usedBytes, usage.limitBytes), (4, 10));
fileLimits = FileLimits(
anonymousBytes: 10,
identifiedBytes: 20,
identifiedBytes: 10,
instanceBytes: await _instanceBytes(session) + 2,
);
final tight = await endpoints.asset.usage(signedIn(alice));

View file

@ -68,7 +68,10 @@ void main() {
});
// halkyon_base's pruning, with Learn's deletion as it runs on the server.
withServerpod('Pruning abandoned anonymous people', (sessionBuilder, _) {
withServerpod('Pruning anonymous people (ADR 0020, D25)', (
sessionBuilder,
_,
) {
late Session session;
final now = DateTime.now().toUtc();
DateTime daysAgo(int days) => now.subtract(Duration(days: days));
@ -78,47 +81,29 @@ void main() {
session = sessionBuilder.build();
});
test(
'deletes anonymous people unused for 90 days, and only them',
() async {
final unused = await _newAnonymousPerson(
session,
createdAt: daysAgo(100),
);
await _lastUsed(session, unused, daysAgo(95));
final neverSignedIn = await _newAnonymousPerson(
session,
createdAt: daysAgo(100),
);
final recentlyUsed = await _newAnonymousPerson(
session,
createdAt: daysAgo(100),
);
await _lastUsed(session, recentlyUsed, daysAgo(10));
final newcomer = await _newAnonymousPerson(
session,
createdAt: daysAgo(5),
);
final identifiedPerson = (await AuthServices.instance.authUsers.create(
session,
scopes: {identified},
)).id;
await _lastUsed(session, identifiedPerson, daysAgo(365));
test('deletes every anonymous account left, however lately used, and '
'nobody identified', () async {
final old = await _newAnonymousPerson(session, createdAt: daysAgo(100));
final recentlyUsed = await _newAnonymousPerson(session);
await _lastUsed(session, recentlyUsed, daysAgo(1));
final identifiedPerson = (await AuthServices.instance.authUsers.create(
session,
scopes: {identified},
)).id;
await _lastUsed(session, identifiedPerson, daysAgo(365));
final pruned = await pruneAbandonedAnonymousPeople(session, now: now);
// Others may have been left by earlier runs.
expect(await pruneAnonymousPeople(session), greaterThanOrEqualTo(2));
expect(pruned, 2);
expect(await AuthUser.db.findById(session, unused), isNull);
expect(await AuthUser.db.findById(session, neverSignedIn), isNull);
for (final kept in [recentlyUsed, newcomer, identifiedPerson]) {
expect(await AuthUser.db.findById(session, kept), isNotNull);
}
},
);
expect(await AuthUser.db.findById(session, old), isNull);
expect(await AuthUser.db.findById(session, recentlyUsed), isNull);
expect(await AuthUser.db.findById(session, identifiedPerson), isNotNull);
});
});
}
/// A person as the app's first launch creates them: anonymous.
/// An anonymous account, as the app made them on its first start until
/// ADR 0020, D25, left from before.
Future<UuidValue> _newAnonymousPerson(
Session session, {
DateTime? createdAt,

View file

@ -2008,13 +2008,11 @@ class _FilePruningFutureCall {
}
class _PruningFutureCall {
Future<void> pruneAnonymousPeople(
_ist.TestSessionBuilder sessionBuilder,
) async {
Future<void> pruneAccounts(_ist.TestSessionBuilder sessionBuilder) async {
var _localUniqueSession =
(sessionBuilder as _ist.InternalTestSessionBuilder).internalBuild();
try {
await _iip9210p.PruningPruneAnonymousPeopleFutureCall().invoke(
await _iip9210p.PruningPruneAccountsFutureCall().invoke(
_localUniqueSession,
null,
);