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
6 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);
|
||||
|
|
|
|||
|
|
@ -68,86 +68,4 @@ void main() {
|
|||
expect(gateway.accountDeletions, 1);
|
||||
expect(gateway.status, const SignedOut());
|
||||
});
|
||||
|
||||
group('signing in with an email address', () {
|
||||
late FakeAuthGateway gateway;
|
||||
late MemorySignInAddresses addresses;
|
||||
late AuthRepository auth;
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'anonymous-1', isIdentified: false),
|
||||
);
|
||||
addresses = MemorySignInAddresses();
|
||||
auth = AuthRepository(gateway, addresses);
|
||||
});
|
||||
|
||||
test("a code for a new address makes it the person's, and this device "
|
||||
'remembers it for them, to show', () async {
|
||||
final request = await auth.sendEmailCode(
|
||||
'anna@example.org',
|
||||
language: 'en',
|
||||
);
|
||||
|
||||
final outcome = await auth.verifyEmailCode(
|
||||
request,
|
||||
'CODE-1',
|
||||
address: 'anna@example.org',
|
||||
);
|
||||
|
||||
expect(outcome, const EmailLinked());
|
||||
expect(auth.isIdentified, isTrue);
|
||||
expect(await auth.emailAddress(), 'anna@example.org');
|
||||
});
|
||||
|
||||
test("a code for another person's address changes nothing here; "
|
||||
'switching remembers the address for the person switched to, not '
|
||||
'the one left', () async {
|
||||
gateway.addressOwners['ben@example.org'] = 'ben';
|
||||
final request = await auth.sendEmailCode(
|
||||
'ben@example.org',
|
||||
language: 'en',
|
||||
);
|
||||
|
||||
final outcome = await auth.verifyEmailCode(
|
||||
request,
|
||||
'CODE-1',
|
||||
address: 'ben@example.org',
|
||||
);
|
||||
expect(outcome, isA<EmailTakenByAnotherPerson>());
|
||||
expect(auth.isIdentified, isFalse);
|
||||
expect(addresses.addresses, isEmpty);
|
||||
|
||||
await auth.switchToEmail(
|
||||
(outcome as EmailTakenByAnotherPerson).switchToken,
|
||||
address: 'ben@example.org',
|
||||
);
|
||||
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'ben', isIdentified: true),
|
||||
);
|
||||
expect(addresses.addresses, {'ben': 'ben@example.org'});
|
||||
expect(await auth.emailAddress(), 'ben@example.org');
|
||||
});
|
||||
|
||||
test('a wrong code remembers nothing', () async {
|
||||
final request = await auth.sendEmailCode(
|
||||
'anna@example.org',
|
||||
language: 'en',
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
auth.verifyEmailCode(request, 'CODE-9', address: 'anna@example.org'),
|
||||
throwsA(
|
||||
isA<EmailSignInFailed>().having(
|
||||
(failure) => failure.problem,
|
||||
'problem',
|
||||
EmailSignInProblem.wrongCode,
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(addresses.addresses, isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
|
|
@ -19,8 +20,8 @@ final class _MemoryStorage() implements ClientAuthSuccessStorage {
|
|||
}
|
||||
|
||||
/// An instance's halkyon_base as the network shows it: anonymous sign-ins
|
||||
/// get `anonymous-token`, its basics offer GitHub and email, and an address
|
||||
/// belongs to Ben, whom a switch signs in as with `ben-token`.
|
||||
/// get `anonymous-token`, its basics offer GitHub and passwords, and a
|
||||
/// sign-up makes Ben, signed in with `ben-token`.
|
||||
final class _Instance() {
|
||||
static final anonymous = UuidValue.withValidation(
|
||||
'0191f0c4-1111-7000-8000-000000000001',
|
||||
|
|
@ -32,9 +33,6 @@ final class _Instance() {
|
|||
/// Each call, by its endpoint and method, with the session it carried.
|
||||
final calls = <({String call, String? session})>[];
|
||||
|
||||
/// What mailing a code is refused for, while set.
|
||||
EmailSignInRefusal? sendRefused;
|
||||
|
||||
http.Client client() => MockClient((request) async {
|
||||
final call = request.url.path.substring(1);
|
||||
calls.add((call: call, session: request.headers['authorization']));
|
||||
|
|
@ -56,24 +54,7 @@ final class _Instance() {
|
|||
),
|
||||
200,
|
||||
),
|
||||
'halkyon_base.emailCode/sendCode' => switch (sendRefused) {
|
||||
final reason? => http.Response(
|
||||
sent({
|
||||
'className': 'halkyon_base.EmailSignInRefusedException',
|
||||
'data': EmailSignInRefusedException(reason: reason).toJson(),
|
||||
}),
|
||||
400,
|
||||
),
|
||||
null => http.Response(
|
||||
sent('0191f0c4-3333-7000-8000-000000000003'),
|
||||
200,
|
||||
),
|
||||
},
|
||||
'halkyon_base.emailCode/verifyCode' => http.Response(
|
||||
sent(EmailCodeAccepted(switchToken: 'switch-to-ben').toJson()),
|
||||
200,
|
||||
),
|
||||
'halkyon_base.emailSignIn/signIn' => http.Response(
|
||||
'halkyon_base.passwordSignIn/signUp' => http.Response(
|
||||
sent(_session(ben, 'ben-token', identified: true)),
|
||||
200,
|
||||
),
|
||||
|
|
@ -137,47 +118,51 @@ void main() {
|
|||
|
||||
test('tells what the instance offers from its basics', () async {
|
||||
expect(await gateway.gitHubClientId(), 'github-client');
|
||||
expect(await gateway.offersEmailSignIn(), isTrue);
|
||||
});
|
||||
|
||||
test("the instance's refusals to mail a code arrive in the package's own "
|
||||
'words', () async {
|
||||
test('a session granted elsewhere (a sign-up with a password, without '
|
||||
"this device's session) takes its place, deleting the anonymous "
|
||||
'account left behind as itself', () async {
|
||||
await gateway.signInAnonymously();
|
||||
instance.sendRefused = EmailSignInRefusal.tooManyCodes;
|
||||
final passwords = ServerpodPasswordGateway(
|
||||
app,
|
||||
base: app.modules,
|
||||
httpClient: instance.client,
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
gateway.sendEmailCode('ben@example.org', language: 'en'),
|
||||
throwsA(
|
||||
isA<EmailSignInFailed>().having(
|
||||
(failure) => failure.problem,
|
||||
'problem',
|
||||
EmailSignInProblem.tooManyCodes,
|
||||
final grant = await passwords.signUp(
|
||||
PasswordSetup(
|
||||
salt: ByteData(16),
|
||||
costs: PasswordCosts(
|
||||
algorithm: 'argon2id13',
|
||||
opsLimit: 3,
|
||||
memLimit: 64 * 1024 * 1024,
|
||||
),
|
||||
verifier: ByteData(384),
|
||||
encryptionPublicKey: ByteData(32),
|
||||
signingPublicKey: ByteData(32),
|
||||
passwordKeys: WrappedKeys(
|
||||
nonce: ByteData(24),
|
||||
cipherText: ByteData(112),
|
||||
),
|
||||
recoveryKeys: WrappedKeys(
|
||||
nonce: ByteData(24),
|
||||
cipherText: ByteData(112),
|
||||
),
|
||||
),
|
||||
request: '0191f0c4-3333-7000-8000-000000000003',
|
||||
code: 'K7QXM2PD',
|
||||
);
|
||||
});
|
||||
|
||||
test("switching to an address's person signs in without this device's "
|
||||
'session, then deletes the anonymous account left behind as '
|
||||
'itself', () async {
|
||||
await gateway.signInAnonymously();
|
||||
final request = await gateway.sendEmailCode(
|
||||
'ben@example.org',
|
||||
language: 'en',
|
||||
);
|
||||
final outcome = await gateway.verifyEmailCode(request, 'K7QXM2PD');
|
||||
expect(outcome, const EmailTakenByAnotherPerson('switch-to-ben'));
|
||||
|
||||
expect(await gateway.switchToEmail('switch-to-ben'), '${_Instance.ben}');
|
||||
await gateway.useSession(grant);
|
||||
|
||||
expect(
|
||||
gateway.status,
|
||||
SignedIn(authUserId: '${_Instance.ben}', isIdentified: true),
|
||||
);
|
||||
final signIn = instance.calls.singleWhere(
|
||||
(call) => call.call == 'halkyon_base.emailSignIn/signIn',
|
||||
final signUp = instance.calls.singleWhere(
|
||||
(call) => call.call == 'halkyon_base.passwordSignIn/signUp',
|
||||
);
|
||||
expect(signIn.session, isNull, reason: 'no session goes with it');
|
||||
expect(signUp.session, isNull, reason: 'no session goes with it');
|
||||
final deletion = instance.calls.singleWhere(
|
||||
(call) => call.call == 'halkyon_base.account/delete',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,204 +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';
|
||||
|
||||
void main() {
|
||||
late FakeAuthGateway gateway;
|
||||
late TestAppDependencies dependencies;
|
||||
|
||||
/// Whether this device holds content a switch would leave behind.
|
||||
late bool holdsContent;
|
||||
|
||||
/// What the sheet returned once it closed.
|
||||
late List<String?> returned;
|
||||
|
||||
setUp(() {
|
||||
gateway = FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'anonymous-1', isIdentified: false),
|
||||
);
|
||||
dependencies = TestAppDependencies(gateway: gateway);
|
||||
holdsContent = false;
|
||||
returned = [];
|
||||
});
|
||||
|
||||
/// Opens the sheet, in [locale].
|
||||
Future<void> open(
|
||||
WidgetTester tester, {
|
||||
Locale locale = const Locale('en'),
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(412, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
testApp(
|
||||
Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () async => returned.add(
|
||||
await showEmailSignInSheet(
|
||||
context,
|
||||
deviceHoldsContent: () async => holdsContent,
|
||||
),
|
||||
),
|
||||
child: const Text('Open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
dependencies: dependencies,
|
||||
locale: locale,
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Open'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// 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]. A switch to
|
||||
/// another person shows a spinner until their app replaces the whole
|
||||
/// subtree, which a test never settles: [switches] pumps frames instead.
|
||||
Future<void> signInWith(
|
||||
WidgetTester tester,
|
||||
String address, {
|
||||
String code = 'CODE-1',
|
||||
bool switches = false,
|
||||
}) 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'));
|
||||
if (switches) {
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
} else {
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
|
||||
testWidgets('an anonymous person continues with email: the address, then '
|
||||
'the code mailed to it, after which the address is theirs', (
|
||||
tester,
|
||||
) async {
|
||||
await open(tester);
|
||||
expect(
|
||||
find.textContaining('keeps only a fingerprint of your address'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await signInWith(tester, 'anna@example.org');
|
||||
|
||||
expect(returned, ['anna@example.org']);
|
||||
expect(gateway.mailed.single.language, 'en');
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'anonymous-1', isIdentified: true),
|
||||
);
|
||||
expect(dependencies.addresses.addresses, {
|
||||
'anonymous-1': 'anna@example.org',
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('the mail is worded in German for someone who reads the app in '
|
||||
'German', (tester) async {
|
||||
await open(tester, locale: const Locale('de'));
|
||||
await tester.enterText(inSheet, 'anna@example.org');
|
||||
await tester.tap(find.widgetWithText(FilledButton, 'Code senden'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.mailed.single.language, 'de');
|
||||
});
|
||||
|
||||
testWidgets('a wrong code says so, and a new one can be asked for', (
|
||||
tester,
|
||||
) async {
|
||||
await open(tester);
|
||||
|
||||
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(gateway.mailed, hasLength(2));
|
||||
});
|
||||
|
||||
testWidgets("another person's address switches at once where the device "
|
||||
'holds nothing', (tester) async {
|
||||
gateway.addressOwners['ben@example.org'] = 'ben';
|
||||
await open(tester);
|
||||
|
||||
await signInWith(tester, 'ben@example.org', switches: true);
|
||||
|
||||
expect(gateway.emailSwitches, 1);
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'ben', isIdentified: true),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets("another person's address asks first where the device holds "
|
||||
"content, in the app's own words: staying changes nothing, switching "
|
||||
'switches', (tester) async {
|
||||
gateway.addressOwners['ben@example.org'] = 'ben';
|
||||
holdsContent = true;
|
||||
await open(tester);
|
||||
|
||||
await signInWith(tester, 'ben@example.org');
|
||||
|
||||
expect(
|
||||
find.text('Switch to the account of ben@example.org?'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(
|
||||
"The notes on this device can't be combined with it yet: if you "
|
||||
'switch, they are deleted.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('Stay anonymous'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.emailSwitches, 0);
|
||||
|
||||
await signInWith(tester, 'ben@example.org', code: 'CODE-2');
|
||||
await tester.tap(find.text('Switch'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(gateway.emailSwitches, 1);
|
||||
});
|
||||
|
||||
testWidgets("someone identified whose address is another account's is "
|
||||
'told so, and stays who they are', (tester) async {
|
||||
gateway = FakeAuthGateway(
|
||||
status: const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
)..addressOwners['ben@example.org'] = 'ben';
|
||||
dependencies = TestAppDependencies(gateway: gateway);
|
||||
await open(tester);
|
||||
|
||||
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(gateway.emailSwitches, 0);
|
||||
expect(
|
||||
gateway.status,
|
||||
const SignedIn(authUserId: 'github-person', isIdentified: true),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -4,8 +4,8 @@ import 'package:halkyon_app/halkyon_app.dart';
|
|||
import 'package:halkyon_app/testing.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
/// A signed-in person's app as a test makes one: whose it is, whether
|
||||
/// they asked to continue with email, and a way to sign out.
|
||||
/// A signed-in person's app as a test makes one: whose it is, and a way to
|
||||
/// sign out.
|
||||
class const _PersonApp(final SignedIn person) extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) => MaterialApp(
|
||||
|
|
@ -16,10 +16,6 @@ class const _PersonApp(final SignedIn person) extends StatelessWidget {
|
|||
builder: (context) => Column(
|
||||
children: [
|
||||
Text('App of ${person.authUserId}'),
|
||||
if (context.watch<SessionBloc>().state case SessionStateActive(
|
||||
signsInWithEmail: true,
|
||||
))
|
||||
const Text('Asks for the address'),
|
||||
TextButton(
|
||||
onPressed: () => context.read<SessionBloc>().add(
|
||||
const SessionEventSignOutRequested(),
|
||||
|
|
@ -86,7 +82,7 @@ void main() {
|
|||
expect(find.text('Signed out'), findsOneWidget);
|
||||
expect(find.text('Start on test.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);
|
||||
expect(
|
||||
find.text('Use another instance'),
|
||||
findsNothing,
|
||||
|
|
@ -127,27 +123,14 @@ void main() {
|
|||
expect(gateway.signIns, 0);
|
||||
});
|
||||
|
||||
testWidgets('from there, an email address starts without an account and '
|
||||
'asks for the address in the app', (tester) async {
|
||||
await dependencies.signedOut.write(signedOut: true);
|
||||
await start(tester);
|
||||
|
||||
await tester.tap(find.text('Continue with email'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('App of anonymous-1'), findsOneWidget);
|
||||
expect(find.text('Asks for the address'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('offers only the ways the instance has', (tester) async {
|
||||
gateway
|
||||
..offersGitHub = false
|
||||
..offersEmail = false;
|
||||
gateway.offersGitHub = false;
|
||||
dependencies.passwordGateway.offered = false;
|
||||
await dependencies.signedOut.write(signedOut: true);
|
||||
await start(tester);
|
||||
|
||||
expect(find.text('Sign in with GitHub'), findsNothing);
|
||||
expect(find.text('Continue with email'), findsNothing);
|
||||
expect(find.text('Create an account'), findsNothing);
|
||||
expect(find.text('Start without an account'), findsOneWidget);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue