@@ -7,6 +7,7 @@ import 'package:http/http.dart' as http;
77import 'package:http/testing.dart' as http_testing;
88import 'package:nostr/nostr.dart' as nostr;
99import 'package:pointycastle/digests/sha256.dart' ;
10+ import 'package:buzz/shared/auth/auth_provider.dart' ;
1011import 'package:buzz/shared/relay/relay.dart' ;
1112
1213void main () {
@@ -153,6 +154,43 @@ void main() {
153154 expect (session.state.reconnectAttempt, 1 );
154155 });
155156
157+ test ('classifies relay internal auth errors as transient' , () {
158+ expect (
159+ classifyRelayAuthFailure (
160+ 'error: internal error checking restriction state' ,
161+ ),
162+ isNot (isA <RelayAuthRejectedException >()),
163+ );
164+ expect (
165+ classifyRelayAuthFailure ('restricted: access revoked' ),
166+ isA <RelayAuthRejectedException >(),
167+ );
168+ });
169+
170+ test (
171+ 'stops reconnecting and signs out after explicit auth rejection' ,
172+ () async {
173+ final session = RelaySessionNotifier ();
174+ final auth = _FakeAuthNotifier ();
175+ final container = ProviderContainer (
176+ overrides: [
177+ relaySessionProvider.overrideWith (() => session),
178+ authProvider.overrideWith (() => auth),
179+ ],
180+ );
181+ addTearDown (container.dispose);
182+ container.read (relaySessionProvider);
183+
184+ session.debugHandleDisconnected (
185+ const RelayAuthRejectedException ('invalid key' ),
186+ );
187+ await Future <void >.delayed (Duration .zero);
188+
189+ expect (session.state.status, SessionStatus .disconnected);
190+ expect (auth.signOutCount, 1 );
191+ },
192+ );
193+
156194 test ('does not schedule reconnects after background disconnect' , () {
157195 final session = RelaySessionNotifier ();
158196 final container = ProviderContainer (
@@ -258,6 +296,19 @@ void main() {
258296 );
259297}
260298
299+ class _FakeAuthNotifier extends AuthNotifier {
300+ int signOutCount = 0 ;
301+
302+ @override
303+ Future <AuthState > build () async =>
304+ const AuthState (status: AuthStatus .unauthenticated);
305+
306+ @override
307+ Future <void > signOut () async {
308+ signOutCount++ ;
309+ }
310+ }
311+
261312const _channelId = '11111111-1111-4111-8111-111111111111' ;
262313
263314class _FakeRelayConfigNotifier extends RelayConfigNotifier {
0 commit comments