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
3 changed files with 429 additions and 3835 deletions
|
|
@ -1,156 +0,0 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
import 'package:halkyon_ui/halkyon_ui.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/pump_app.dart';
|
||||
import '../../../support/test_dependencies.dart';
|
||||
|
||||
void main() {
|
||||
late FakeAuthGateway auth;
|
||||
late MemorySignInAddresses addresses;
|
||||
|
||||
setUp(() {
|
||||
auth = FakeAuthGateway();
|
||||
addresses = MemorySignInAddresses();
|
||||
});
|
||||
|
||||
Future<void> openProfile(WidgetTester tester) async {
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(authGateway: auth, signInAddresses: addresses),
|
||||
);
|
||||
await openTab(tester, 'Profile');
|
||||
}
|
||||
|
||||
/// The sheet's text field.
|
||||
final inSheet = find.descendant(
|
||||
of: find.byType(SheetScaffold),
|
||||
matching: find.byType(TextField),
|
||||
);
|
||||
|
||||
/// Types [address] and sends a code to it, then types [code].
|
||||
Future<void> signInWith(
|
||||
WidgetTester tester,
|
||||
String address, {
|
||||
String code = 'CODE-1',
|
||||
}) async {
|
||||
await tester.enterText(inSheet, address);
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Send code'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text("We mailed a code to $address. It's valid for 15 minutes."),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.enterText(inSheet, code);
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Continue'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('an anonymous person continues with email: the address, then '
|
||||
'the code mailed to it, and their progress is kept with their account, '
|
||||
'which shows the address', (tester) async {
|
||||
await openProfile(tester);
|
||||
|
||||
await tester.tap(find.text('Continue with email'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.textContaining('keeps only a fingerprint of your address'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await signInWith(tester, 'anna@example.org');
|
||||
|
||||
expect(find.text('Signed in with anna@example.org.'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Your progress is kept with your account.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Ways to sign in'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(ListTile, 'anna@example.org'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Add GitHub'), findsOneWidget);
|
||||
expect(addresses.addresses, {'anonymous-1': 'anna@example.org'});
|
||||
});
|
||||
|
||||
testWidgets('a wrong code says so, and a new one can be asked for', (
|
||||
tester,
|
||||
) async {
|
||||
await openProfile(tester);
|
||||
await tester.tap(find.text('Continue with email'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await signInWith(tester, 'anna@example.org', code: 'CODE-9');
|
||||
|
||||
expect(find.text("That code isn't right."), findsOneWidget);
|
||||
await tester.tap(find.text('Send a new code'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('A new code is on its way.'), findsOneWidget);
|
||||
expect(auth.mailed, hasLength(2));
|
||||
});
|
||||
|
||||
testWidgets('no email sign-in where the instance offers none', (
|
||||
tester,
|
||||
) async {
|
||||
auth.offersEmail = false;
|
||||
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.text('Continue with email'), findsNothing);
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('someone who signs in with GitHub adds an email address', (
|
||||
tester,
|
||||
) async {
|
||||
auth = FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
)..gitHubPeople.add('github-person');
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.text('Ways to sign in'), findsOneWidget);
|
||||
expect(find.text('Add GitHub'), findsNothing);
|
||||
await tester.tap(find.text('Add an email address'));
|
||||
await tester.pumpAndSettle();
|
||||
await signInWith(tester, 'carla@example.org');
|
||||
|
||||
expect(
|
||||
find.widgetWithText(ListTile, 'carla@example.org'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Add an email address'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("someone identified whose address is another account's is "
|
||||
'told so, and stays who they are', (tester) async {
|
||||
auth =
|
||||
FakeAuthGateway(
|
||||
status: const SignedIn(
|
||||
authUserId: 'github-person',
|
||||
isIdentified: true,
|
||||
),
|
||||
)
|
||||
..gitHubPeople.add('github-person')
|
||||
..addressOwners['ben@example.org'] = 'ben';
|
||||
await openProfile(tester);
|
||||
|
||||
await tester.tap(find.text('Add an email address'));
|
||||
await tester.pumpAndSettle();
|
||||
await signInWith(tester, 'ben@example.org');
|
||||
|
||||
expect(
|
||||
find.text(
|
||||
'ben@example.org already signs in to another account. To switch to '
|
||||
'it, sign out first.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(auth.emailSwitches, 0);
|
||||
expect(
|
||||
auth.status,
|
||||
const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_app/testing.dart';
|
||||
import 'package:halkyon_ui/halkyon_ui.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/pump_app.dart';
|
||||
import '../../../support/test_dependencies.dart';
|
||||
|
||||
/// The profile's way to keep an account with a password and an
|
||||
/// authenticator (ADR 0017), as halkyon_app's section shows it in Learn.
|
||||
void main() {
|
||||
late FakeAuthGateway auth;
|
||||
late FakePasswordGateway passwords;
|
||||
late MemoryAccountKeyStore keys;
|
||||
|
||||
setUp(() {
|
||||
auth = FakeAuthGateway();
|
||||
passwords = FakePasswordGateway(auth);
|
||||
keys = MemoryAccountKeyStore();
|
||||
});
|
||||
|
||||
Future<void> openProfile(WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(412, 2000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await pumpApp(
|
||||
tester,
|
||||
testDependencies(
|
||||
authGateway: auth,
|
||||
passwordGateway: passwords,
|
||||
accountKeys: keys,
|
||||
),
|
||||
);
|
||||
await openTab(tester, 'Profile');
|
||||
}
|
||||
|
||||
Finder field(String label) => find.widgetWithText(TextField, label);
|
||||
|
||||
Future<void> next(WidgetTester tester, String label) async {
|
||||
final button = find.descendant(
|
||||
of: find.byType(SheetScaffold),
|
||||
matching: find.widgetWithText(FilledButton, label),
|
||||
);
|
||||
await tester.ensureVisible(button);
|
||||
await tester.tap(button);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('an anonymous person keeps their account with a password: the '
|
||||
'address, the phrase checked, the code, the authenticator', (
|
||||
tester,
|
||||
) async {
|
||||
await openProfile(tester);
|
||||
|
||||
await tester.tap(find.text('Set up a password'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(field('Email address'), 'anna@example.org');
|
||||
await next(tester, 'Continue');
|
||||
await tester.enterText(field('New password'), 'correct horse');
|
||||
await tester.enterText(field('New password again'), 'correct horse');
|
||||
await next(tester, 'Continue');
|
||||
await next(tester, "I've written it down");
|
||||
final words = wordsOf(fakePhrase);
|
||||
final labels = [
|
||||
for (final element in find.byType(TextField).evaluate())
|
||||
if ((element.widget as TextField).decoration?.labelText
|
||||
case final label? when label.startsWith('Word '))
|
||||
label,
|
||||
];
|
||||
for (final label in labels) {
|
||||
await tester.enterText(
|
||||
field(label),
|
||||
words[int.parse(label.substring('Word '.length)) - 1],
|
||||
);
|
||||
}
|
||||
await next(tester, 'Continue');
|
||||
await tester.enterText(
|
||||
field('Code from the email'),
|
||||
passwords.codeFor('anna@example.org'),
|
||||
);
|
||||
await next(tester, 'Continue');
|
||||
await tester.enterText(
|
||||
field('Code from your authenticator app'),
|
||||
fakeTotpCode,
|
||||
);
|
||||
await next(tester, 'Continue');
|
||||
await next(tester, "I've kept them");
|
||||
|
||||
expect(
|
||||
auth.status,
|
||||
const SignedIn(authUserId: 'anonymous-1', isIdentified: true),
|
||||
);
|
||||
expect(find.text('Your progress is kept with your account.'), findsOne);
|
||||
expect(keys.kept.keys, ['anonymous-1']);
|
||||
expect(passwords.accounts['anna@example.org']!.finished, isTrue);
|
||||
await tester.dragUntilVisible(
|
||||
find.text('Change password'),
|
||||
find.byType(ListView).last,
|
||||
const Offset(0, -200),
|
||||
);
|
||||
expect(find.text('Change password'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('someone who signs in with GitHub is told when it ends, and '
|
||||
'offered a password', (tester) async {
|
||||
auth = FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
)..gitHubPeople.add('github-person');
|
||||
passwords = FakePasswordGateway(auth)
|
||||
..gitHubPeople.add('github-person')
|
||||
..gitHubEnds = DateTime.utc(2027, 1, 22);
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.textContaining('Sign-in with GitHub ends on'), findsOneWidget);
|
||||
expect(find.text('Set up a password'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('no password where the instance offers none', (tester) async {
|
||||
passwords.offered = false;
|
||||
|
||||
await openProfile(tester);
|
||||
|
||||
expect(find.text('Set up a password'), findsNothing);
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ void main() {
|
|||
expect(find.text('Signed out'), findsOneWidget);
|
||||
expect(find.text('Start on learn.example.org:'), findsOneWidget);
|
||||
expect(find.text('Sign in with GitHub'), findsOneWidget);
|
||||
expect(find.text('Continue with email'), findsOneWidget);
|
||||
expect(find.text('Create an account'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Start without an account'));
|
||||
await tester.pumpAndSettle();
|
||||
|
|
@ -176,26 +176,6 @@ void main() {
|
|||
expect(gateway.status, const SignedOut());
|
||||
});
|
||||
|
||||
testWidgets('from there, an email address starts without an account and '
|
||||
'asks for the address on Profile', (tester) async {
|
||||
await openSettings(tester);
|
||||
await tester.tap(find.text('Sign out'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign out').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Continue with email'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'anonymous-2', isIdentified: false),
|
||||
);
|
||||
// The email sign-in, over the Profile tab.
|
||||
expect(find.text('Continue with email'), findsWidgets);
|
||||
expect(find.byType(TextField), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('deleting the account asks first; Cancel keeps it', (
|
||||
tester,
|
||||
) async {
|
||||
|
|
|
|||
Loading…
Reference in a new issue