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>
107 lines
3.3 KiB
Dart
107 lines
3.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
|
import 'package:halkyon_base_client/halkyon_base_client.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/testing.dart';
|
|
|
|
/// [refusal] as an instance sends it: named by its module.
|
|
String sent(SerializableException refusal) => jsonEncode({
|
|
'className':
|
|
'halkyon_base.${switch (refusal) {
|
|
EmailSignInRefusedException() => 'EmailSignInRefusedException',
|
|
GitHubSignInRefusedException() => 'GitHubSignInRefusedException',
|
|
PasswordRefusedException() => 'PasswordRefusedException',
|
|
_ => throw ArgumentError.value(refusal),
|
|
}}',
|
|
'data': (refusal as SerializableModel).toJson(),
|
|
});
|
|
|
|
void main() {
|
|
test("reads the refusals an instance sends under halkyon_base's name, as "
|
|
"an app's own generated protocol does", () {
|
|
final protocol = BaseProtocol();
|
|
|
|
expect(
|
|
protocol.decodeWithType(
|
|
sent(
|
|
EmailSignInRefusedException(reason: EmailSignInRefusal.wrongCode),
|
|
),
|
|
),
|
|
isA<EmailSignInRefusedException>().having(
|
|
(refusal) => refusal.reason,
|
|
'reason',
|
|
EmailSignInRefusal.wrongCode,
|
|
),
|
|
);
|
|
expect(
|
|
protocol.decodeWithType(
|
|
sent(
|
|
GitHubSignInRefusedException(
|
|
reason: GitHubSignInRefusal.unknownAccount,
|
|
),
|
|
),
|
|
),
|
|
isA<GitHubSignInRefusedException>().having(
|
|
(refusal) => refusal.reason,
|
|
'reason',
|
|
GitHubSignInRefusal.unknownAccount,
|
|
),
|
|
);
|
|
});
|
|
|
|
test("calls halkyon_base's endpoints at the instance, and passes its "
|
|
'refusals on as themselves', () async {
|
|
final asked = <String>[];
|
|
final client = BaseClient(
|
|
'https://learn.example.org/',
|
|
httpClientOverride: MockClient((request) async {
|
|
asked.add(request.url.toString());
|
|
return switch (request.url.path) {
|
|
'/halkyon_base.instance/basics' => http.Response(
|
|
jsonEncode(
|
|
InstanceBasics(
|
|
app: 'learn',
|
|
emailSignIn: true,
|
|
sourceCodeUrl: 'https://code.example.org/learn',
|
|
minimumAppBuild: 21,
|
|
dataLocation: 'EU',
|
|
).toJson(),
|
|
),
|
|
200,
|
|
),
|
|
'/halkyon_base.passwordSignIn/begin' => http.Response(
|
|
sent(
|
|
PasswordRefusedException(
|
|
reason: PasswordRefusal.tooManyAttempts,
|
|
),
|
|
),
|
|
400,
|
|
),
|
|
_ => http.Response('', 404),
|
|
};
|
|
}),
|
|
);
|
|
addTearDown(client.close);
|
|
|
|
final basics = await client.modules.instance.basics();
|
|
expect(basics.emailSignIn, isTrue);
|
|
expect(basics.minimumAppBuild, 21);
|
|
expect(basics.dataLocation, 'EU');
|
|
await expectLater(
|
|
client.modules.passwordSignIn.begin(address: 'anna@example.org'),
|
|
throwsA(
|
|
isA<PasswordRefusedException>().having(
|
|
(refusal) => refusal.reason,
|
|
'reason',
|
|
PasswordRefusal.tooManyAttempts,
|
|
),
|
|
),
|
|
);
|
|
expect(asked, [
|
|
'https://learn.example.org/halkyon_base.instance/basics',
|
|
'https://learn.example.org/halkyon_base.passwordSignIn/begin',
|
|
]);
|
|
});
|
|
}
|