fix(auth): GitHub-only accounts go 30 days after GitHub's end, on the register alone, one failure holding back none

The reading of the full reading's fixes found that a member, which keeps
no addresses, would delete everyone it holds with a GitHub ID as if
GitHub were their only way in (D1); that each deletion delivered every
pending notice, so with a member hanging the daily run grew quadratic,
and one failing person aborted it, forgetting no GitHub ID (D2); and that
a GITHUB_SIGN_IN_ENDS set wrong deleted data at the next daily run.

forgetGitHubAccounts now does nothing on a member and waits 30 days after
the end (gitHubAccountsKeptAfterEnd), keeping the accounts and IDs while a
wrong date can be put right; deletes each GitHub-only account on its own,
a failure logged by type, that person's GitHub ID kept for the next run;
and tells the members once, after all of them (deletePerson's tellMembers).

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-21 16:05:57 +02:00
commit f9880e6989
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -232,13 +232,102 @@ void main() {
throwsA(_refusal(GitHubSignInRefusal.ended)),
);
});
expect(await forgetGitHubAccounts(session, now: ends), 1);
// For 30 days after, nothing goes: a date set wrong can be put
// right meanwhile.
expect(
await forgetGitHubAccounts(
session,
now: ends.add(
gitHubAccountsKeptAfterEnd - const Duration(minutes: 1),
),
),
0,
);
expect(await AuthUser.db.findById(session, ben), isNotNull);
expect(await GitHubAccount.db.count(session), 1);
expect(
await forgetGitHubAccounts(
session,
now: ends.add(gitHubAccountsKeptAfterEnd),
),
1,
);
expect(await GitHubAccount.db.count(session), 0);
// Ben signed in with GitHub alone and never set a password up: his
// account goes with it (the full reading's M1), no way in left.
expect(await AuthUser.db.findById(session, ben), isNull);
});
test('a member forgets nothing and deletes nobody: it keeps no '
"addresses, so everyone there would look GitHub's alone (the "
"reading of the fixes' D1)", () async {
useBase(
sessionBuilder,
accounts: MemberOfRegister(Uri.parse('http://learn.test:8082')),
);
final ends = DateTime.utc(2027, 1, 22);
useGitHubSignInEnds(session.serverpod, ends);
expect(
await forgetGitHubAccounts(
session,
now: ends.add(gitHubAccountsKeptAfterEnd),
),
0,
);
expect(await AuthUser.db.findById(session, ben), isNotNull);
expect(await GitHubAccount.db.count(session), 1);
});
test('a deletion that fails holds back nobody else, keeps that '
"person's GitHub ID for the next run, and members are tried once "
'for each account, not once per account deleted (the reading of '
"the fixes' D2)", () async {
final notifier = _HangingMembers();
useBase(
sessionBuilder,
accounts: HoldsRegister(members: [Uri.parse('http://todo.test')]),
deletePersonData: [
(session, person, transaction) async {
if (person == ben) {
throw StateError('the host failed');
}
return null;
},
],
);
MemberNotifier.use(session.serverpod, notifier);
addTearDown(() => MemberNotifier.use(session.serverpod, null));
final dana = (await AuthServices.instance.authUsers.create(
session,
scopes: {identified},
)).id;
final emil = (await AuthServices.instance.authUsers.create(
session,
scopes: {identified},
)).id;
await GitHubAccount.db.insert(session, [
GitHubAccount(userIdentifier: '4004', authUserId: dana),
GitHubAccount(userIdentifier: '5005', authUserId: emil),
]);
final ends = DateTime.utc(2027, 1, 22);
useGitHubSignInEnds(session.serverpod, ends);
await forgetGitHubAccounts(
session,
now: ends.add(gitHubAccountsKeptAfterEnd),
);
expect(await AuthUser.db.findById(session, dana), isNull);
expect(await AuthUser.db.findById(session, emil), isNull);
expect(await AuthUser.db.findById(session, ben), isNotNull);
expect(await _gitHubAccount(session, '1001'), isNotNull);
expect(await GitHubAccount.db.count(session), 1);
// Dana's notice and Emil's, each tried once.
expect(notifier.told, hasLength(2));
expect(notifier.told.toSet(), {dana, emil});
});
test('at its end keeps the account of someone with an address too, '
'forgetting only the GitHub ID', () async {
final carl = (await AuthServices.instance.authUsers.create(
@ -259,7 +348,13 @@ void main() {
);
final ends = DateTime.utc(2027, 1, 22);
useGitHubSignInEnds(session.serverpod, ends);
expect(await forgetGitHubAccounts(session, now: ends), 2);
expect(
await forgetGitHubAccounts(
session,
now: ends.add(gitHubAccountsKeptAfterEnd),
),
2,
);
expect(await AuthUser.db.findById(session, carl), isNotNull);
expect(await AuthUser.db.findById(session, ben), isNull);
expect(await GitHubAccount.db.count(session), 0);
@ -268,6 +363,25 @@ void main() {
});
}
/// Members that never answer, noting each account they were told is gone.
final class _HangingMembers implements MemberNotifier {
final told = <UuidValue>[];
@override
Future<bool> accountGone(Uri member, UuidValue account) async {
told.add(account);
return false;
}
@override
Future<bool> sessionsEnded(
Uri member,
UuidValue account, {
required DateTime endedBefore,
UuidValue? keepSession,
}) async => false;
}
/// The loopback callback the desktop apps use.
const _redirectUri = 'http://127.0.0.1:43823/github-callback';