diff --git a/mobile/lib/shared/community/community_provider.dart b/mobile/lib/shared/community/community_provider.dart index 9cd24db0e8..f1e0cdef2b 100644 --- a/mobile/lib/shared/community/community_provider.dart +++ b/mobile/lib/shared/community/community_provider.dart @@ -130,7 +130,9 @@ Future _deactivateCommunityPushLease( } final decoded = nostr.Nip19.decode(payload: nsec); final memberPubkey = community.pubkey ?? nostr.Keys(decoded.data).public; - final descriptor = await fetchBuzzPushLeaseDescriptor(community.relayUrl); + final descriptor = await fetchBuzzPushLeaseDescriptor( + canonicalBuzzPushRelayHttpUrl(community.relayUrl), + ); final matchingGrant = (await readBuzzPushEndpointGrants()) .where( (grant) => diff --git a/mobile/test/shared/community/push_opt_out_url_test.dart b/mobile/test/shared/community/push_opt_out_url_test.dart new file mode 100644 index 0000000000..12d9b637a4 --- /dev/null +++ b/mobile/test/shared/community/push_opt_out_url_test.dart @@ -0,0 +1,56 @@ +import 'package:buzz/shared/community/community.dart'; +import 'package:buzz/shared/community/community_provider.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:http/http.dart' as http; +import 'package:http/testing.dart'; +import 'package:nostr/nostr.dart' as nostr; + +void main() { + for (final scheme in ['ws', 'wss', 'http', 'https']) { + test( + 'opt-out fetches relay metadata over HTTP for $scheme community', + () async { + final container = ProviderContainer(); + addTearDown(container.dispose); + final community = Community.create( + name: 'Test', + relayUrl: '$scheme://relay.example:8443', + nsec: nostr.Keys.generate().nsec, + ); + final requests = []; + final client = MockClient((request) async { + requests.add(request); + // Stop at the HTTP boundary, before native grants or publication. + return http.Response('test unavailable', 503); + }); + addTearDown(client.close); + + await http.runWithClient(() async { + await expectLater( + container.read(communityPushLeaseDeactivatorProvider)( + community, + generation: 2, + ), + throwsA( + isA().having( + (error) => error.message, + 'message', + contains('NIP-11 request failed with HTTP 503'), + ), + ), + ); + }, () => client); + + final httpScheme = scheme == 'ws' || scheme == 'http' + ? 'http' + : 'https'; + expect( + requests.single.url, + Uri.parse('$httpScheme://relay.example:8443/'), + ); + expect(requests.single.headers['Accept'], 'application/nostr+json'); + }, + ); + } +}