feat(auth)!: codes by mail no longer sign in
ADR 0017, step 3 (D4: nobody signs in with email codes yet, so the password replaces them outright). `emailCode.verifyCode`, `emailSignIn.signIn` and the switch token go, with the register's `verifySignInCode` and `completeEmailSwitch` and their operations between services. `emailCode.sendCode` stays, now without a session (signing up and getting back in have none), as what proves an address for a password's setup, a sign-up, a setup never finished and the resets; `accountRecovery.sendCode`, which did that for the resets, goes. The `switchChallengeId` column stays: Serverpod's challenges still link a completion token, and older servers read it during a deploy. The apps: halkyon_app's email sign-in (its bloc, sheet, gateway calls and the start screen's Continue with email) goes; Learn's profile and Todo's account sheet show `AccountSecuritySection` (a password set up by someone anonymous or signing in with GitHub, whose end it names; the authenticators; changing the password; new recovery codes and phrase), which reads anew after every change the repository makes. BREAKING CHANGE: Learn's `minimumAppBuild` is 22: builds up to 21 sign in with the endpoints that went. Todo was never released and stays at build 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
735dfa892a
commit
ae57cbe864
2 changed files with 429 additions and 3835 deletions
|
|
@ -1,242 +0,0 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
|
||||
void main() {
|
||||
const anonymous = SignedIn(authUserId: 'anonymous-1', isIdentified: false);
|
||||
|
||||
late FakeAuthGateway gateway;
|
||||
late MemorySignInAddresses addresses;
|
||||
|
||||
/// Whether this device holds content a switch would leave behind.
|
||||
late bool holdsContent;
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeAuthGateway(status: anonymous);
|
||||
addresses = MemorySignInAddresses();
|
||||
holdsContent = false;
|
||||
});
|
||||
|
||||
EmailSignInBloc newBloc({String language = 'en'}) {
|
||||
final bloc = EmailSignInBloc(
|
||||
AuthRepository(gateway, addresses),
|
||||
deviceHoldsContent: () async => holdsContent,
|
||||
language: language,
|
||||
);
|
||||
addTearDown(bloc.close);
|
||||
return bloc;
|
||||
}
|
||||
|
||||
/// A bloc waiting for the code mailed to [address].
|
||||
Future<EmailSignInBloc> codeMailed(String address) async {
|
||||
final bloc = newBloc()..add(EmailSignInEventCodeRequested(address));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(isA<EmailSignInStateCode>()),
|
||||
);
|
||||
return bloc;
|
||||
}
|
||||
|
||||
test('starts at the address', () {
|
||||
expect(newBloc().state, const EmailSignInStateAddress());
|
||||
});
|
||||
|
||||
test("mails a code in the app's language, and the code makes the address "
|
||||
"the person's: they keep everything and become identified", () async {
|
||||
final bloc = newBloc(language: 'de')
|
||||
..add(const EmailSignInEventCodeRequested(' Anna@Example.org '));
|
||||
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsInOrder([
|
||||
const EmailSignInStateAddress(sending: true),
|
||||
const EmailSignInStateCode(
|
||||
address: 'anna@example.org',
|
||||
request: 'request-1',
|
||||
),
|
||||
]),
|
||||
);
|
||||
expect(gateway.mailed.single.language, 'de');
|
||||
|
||||
bloc.add(const EmailSignInEventCodeEntered('code-1'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsInOrder([
|
||||
const EmailSignInStateCode(
|
||||
address: 'anna@example.org',
|
||||
request: 'request-1',
|
||||
checking: true,
|
||||
),
|
||||
const EmailSignInStateLinked(address: 'anna@example.org'),
|
||||
]),
|
||||
);
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'anonymous-1', isIdentified: true),
|
||||
);
|
||||
expect(addresses.addresses, {'anonymous-1': 'anna@example.org'});
|
||||
});
|
||||
|
||||
test('says what is wrong with an address, and with a code, and takes the '
|
||||
'next try', () async {
|
||||
final bloc = newBloc()..add(const EmailSignInEventCodeRequested('anna'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsInOrder([
|
||||
const EmailSignInStateAddress(sending: true),
|
||||
const EmailSignInStateAddress(
|
||||
problem: EmailSignInProblem.notAnAddress,
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
bloc.add(const EmailSignInEventCodeRequested('anna@example.org'));
|
||||
await expectLater(bloc.stream, emitsThrough(isA<EmailSignInStateCode>()));
|
||||
bloc.add(const EmailSignInEventCodeEntered('CODE-9'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(
|
||||
const EmailSignInStateCode(
|
||||
address: 'anna@example.org',
|
||||
request: 'request-1',
|
||||
problem: EmailSignInProblem.wrongCode,
|
||||
),
|
||||
),
|
||||
);
|
||||
bloc.add(const EmailSignInEventCodeEntered('CODE-1'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(const EmailSignInStateLinked(address: 'anna@example.org')),
|
||||
);
|
||||
});
|
||||
|
||||
test('mails a new code on request, and goes back to the address', () async {
|
||||
final bloc = await codeMailed('anna@example.org');
|
||||
|
||||
bloc.add(const EmailSignInEventCodeResent());
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsInOrder([
|
||||
const EmailSignInStateCode(
|
||||
address: 'anna@example.org',
|
||||
request: 'request-1',
|
||||
checking: true,
|
||||
),
|
||||
const EmailSignInStateCode(
|
||||
address: 'anna@example.org',
|
||||
request: 'request-2',
|
||||
resent: true,
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
bloc.add(const EmailSignInEventAddressReopened());
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emits(const EmailSignInStateAddress()),
|
||||
);
|
||||
});
|
||||
|
||||
test("another person's address: a device holding nothing switches to "
|
||||
'them straight away', () async {
|
||||
gateway.addressOwners['ben@example.org'] = 'ben';
|
||||
final bloc = await codeMailed('ben@example.org');
|
||||
|
||||
bloc.add(const EmailSignInEventCodeEntered('CODE-1'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(const EmailSignInStateSwitching()),
|
||||
);
|
||||
await pumpEventQueue();
|
||||
|
||||
expect(gateway.emailSwitches, 1);
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'ben', isIdentified: true),
|
||||
);
|
||||
expect(addresses.addresses, {'ben': 'ben@example.org'});
|
||||
});
|
||||
|
||||
test('a device holding content asks first: declining changes nothing, '
|
||||
'confirming switches', () async {
|
||||
gateway.addressOwners['ben@example.org'] = 'ben';
|
||||
holdsContent = true;
|
||||
final bloc = await codeMailed('ben@example.org');
|
||||
|
||||
bloc.add(const EmailSignInEventCodeEntered('CODE-1'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(
|
||||
const EmailSignInStateConfirmSwitch(
|
||||
address: 'ben@example.org',
|
||||
switchToken: 'switch:ben@example.org',
|
||||
),
|
||||
),
|
||||
);
|
||||
bloc.add(const EmailSignInEventSwitchDeclined());
|
||||
await expectLater(bloc.stream, emits(const EmailSignInStateAddress()));
|
||||
expect(gateway.emailSwitches, 0);
|
||||
expect(gateway.status, anonymous);
|
||||
|
||||
bloc.add(const EmailSignInEventCodeRequested('ben@example.org'));
|
||||
await expectLater(bloc.stream, emitsThrough(isA<EmailSignInStateCode>()));
|
||||
bloc.add(const EmailSignInEventCodeEntered('CODE-2'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(isA<EmailSignInStateConfirmSwitch>()),
|
||||
);
|
||||
bloc.add(const EmailSignInEventSwitchConfirmed());
|
||||
await expectLater(bloc.stream, emits(const EmailSignInStateSwitching()));
|
||||
await pumpEventQueue();
|
||||
expect(gateway.emailSwitches, 1);
|
||||
});
|
||||
|
||||
test("someone identified whose address is another person's is told so, "
|
||||
'never switched: their own account stays theirs', () async {
|
||||
gateway = FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'carla', isIdentified: true),
|
||||
)..addressOwners['ben@example.org'] = 'ben';
|
||||
final bloc = await codeMailed('ben@example.org');
|
||||
|
||||
bloc.add(const EmailSignInEventCodeEntered('CODE-1'));
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(const EmailSignInStateTaken(address: 'ben@example.org')),
|
||||
);
|
||||
expect(gateway.emailSwitches, 0);
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'carla', isIdentified: true),
|
||||
);
|
||||
});
|
||||
|
||||
test("says when the instance couldn't send the mail", () async {
|
||||
gateway.emailError = const EmailSignInFailed(
|
||||
EmailSignInProblem.mailFailed,
|
||||
);
|
||||
final bloc = newBloc()
|
||||
..add(const EmailSignInEventCodeRequested('anna@example.org'));
|
||||
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsInOrder([
|
||||
const EmailSignInStateAddress(sending: true),
|
||||
const EmailSignInStateAddress(problem: EmailSignInProblem.mailFailed),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test("says when the instance can't be reached", () async {
|
||||
gateway.emailError = Exception('offline');
|
||||
final bloc = newBloc()
|
||||
..add(const EmailSignInEventCodeRequested('anna@example.org'));
|
||||
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsInOrder([
|
||||
const EmailSignInStateAddress(sending: true),
|
||||
const EmailSignInStateAddress(problem: EmailSignInProblem.failed),
|
||||
]),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -154,25 +154,6 @@ void main() {
|
|||
expect(gateway.gitHubSwitches, 0);
|
||||
});
|
||||
|
||||
test('with an email address from there, it starts without an account and '
|
||||
'asks for the address', () async {
|
||||
start(signedOut: true);
|
||||
bloc.add(const SessionEventStarted());
|
||||
await expectLater(bloc.stream, emits(const SessionStateSignedOut()));
|
||||
|
||||
bloc.add(const SessionEventEmailRequested());
|
||||
|
||||
await expectLater(
|
||||
bloc.stream,
|
||||
emitsThrough(
|
||||
const SessionStateActive(
|
||||
SignedIn(authUserId: 'anonymous-1', isIdentified: false),
|
||||
signsInWithEmail: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('a session the server ended asks how to start too', () async {
|
||||
const stored = SignedIn(authUserId: 'github-1', isIdentified: true);
|
||||
start(status: stored);
|
||||
|
|
|
|||
Loading…
Reference in a new issue