From aca13021d67f1cb7b30a9864975d36ae1fbf5859 Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Mon, 24 Aug 2026 19:05:01 -0700 Subject: [PATCH] refactor(mobile): remove duplicate lease self-validation Signed-off-by: Tom Brow Co-authored-by: Codex Ai-assisted: true --- mobile/lib/shared/push/dev_push_lease.dart | 96 ------------------- .../test/shared/push/dev_push_lease_test.dart | 40 -------- 2 files changed, 136 deletions(-) diff --git a/mobile/lib/shared/push/dev_push_lease.dart b/mobile/lib/shared/push/dev_push_lease.dart index 2a41c3220d..9108c104b0 100644 --- a/mobile/lib/shared/push/dev_push_lease.dart +++ b/mobile/lib/shared/push/dev_push_lease.dart @@ -367,11 +367,6 @@ Future publishBuzzDevPushLease({ for (final subscription in subscriptions) subscription.toJson(), ], }; - validateBuzzPushLeasePlaintext( - plaintextMap, - maxEndpointLength: descriptor.maxEndpointLength, - maxStringLength: descriptor.maxStringLength, - ); final plaintext = jsonEncode(plaintextMap); if (utf8.encode(plaintext).length > descriptor.maxPlaintextLength) { throw const FormatException('lease plaintext exceeds the advertised limit'); @@ -469,7 +464,6 @@ Future publishBuzzPushLeaseTombstone({ 'generation': generation, 'active': false, }; - validateBuzzPushLeaseTombstonePlaintext(plaintextMap); final plaintext = jsonEncode(plaintextMap); if (utf8.encode(plaintext).length > descriptor.maxPlaintextLength) { throw const FormatException('lease plaintext exceeds the advertised limit'); @@ -521,96 +515,6 @@ Future publishBuzzPushLeaseTombstoneThroughRelay({ now: now, ); -void validateBuzzPushLeaseTombstonePlaintext(Map plaintext) { - _requireExactKeys( - plaintext, - required: const {'v', 'origin', 'generation', 'active'}, - allowed: const {'v', 'origin', 'generation', 'active'}, - name: 'lease tombstone plaintext', - ); - if (plaintext['v'] != 1 || plaintext['active'] != false) { - throw const FormatException('lease tombstone must be inactive v1'); - } - _canonicalOrigin(plaintext['origin']); - final generation = _positiveInt(plaintext['generation'], name: 'generation'); - if (generation > _maxSafeJsonInteger) { - throw const FormatException( - 'generation exceeds the safe JSON integer range', - ); - } -} - -void validateBuzzPushLeasePlaintext( - Map plaintext, { - int maxEndpointLength = 4096, - int maxStringLength = 512, -}) { - _requireExactKeys( - plaintext, - required: const { - 'v', - 'origin', - 'app_profile', - 'transport', - 'endpoint', - 'generation', - 'active', - 'subscriptions', - }, - allowed: const { - 'v', - 'origin', - 'app_profile', - 'transport', - 'endpoint', - 'generation', - 'active', - 'subscriptions', - }, - name: 'lease plaintext', - ); - if (plaintext['v'] != 1) { - throw const FormatException('lease version must be 1'); - } - final origin = _canonicalOrigin(plaintext['origin']); - _checkStringLength(origin, maxStringLength, name: 'origin'); - if (plaintext['app_profile'] != buzzDevPushAppProfile) { - throw const FormatException('lease app_profile must be buzz-ios-dogfood'); - } - if (plaintext['transport'] != buzzPushTransport) { - throw const FormatException('lease transport must be apns'); - } - _checkStringLength( - buzzDevPushAppProfile, - maxStringLength, - name: 'app_profile', - ); - _checkStringLength(buzzPushTransport, maxStringLength, name: 'transport'); - final endpoint = _nonEmptyString(plaintext['endpoint'], name: 'endpoint'); - _checkStringLength(endpoint, maxEndpointLength, name: 'endpoint'); - final generation = _positiveInt(plaintext['generation'], name: 'generation'); - if (generation > _maxSafeJsonInteger) { - throw const FormatException( - 'generation exceeds the safe JSON integer range', - ); - } - if (plaintext['active'] != true) { - throw const FormatException('push lease must be active'); - } - - final subscriptions = _mapList( - plaintext['subscriptions'], - name: 'subscriptions', - ); - if (subscriptions.isEmpty || - subscriptions.length > buzzPushMaxSubscriptions) { - throw const FormatException('push lease subscription count is invalid'); - } - for (final subscription in subscriptions) { - BuzzPushSubscription.fromJson(subscription); - } -} - void _validateGrant( BuzzPushEndpointGrant grant, BuzzPushLeaseDescriptor descriptor, diff --git a/mobile/test/shared/push/dev_push_lease_test.dart b/mobile/test/shared/push/dev_push_lease_test.dart index 6da2dd2116..e174941f74 100644 --- a/mobile/test/shared/push/dev_push_lease_test.dart +++ b/mobile/test/shared/push/dev_push_lease_test.dart @@ -166,46 +166,6 @@ void main() { }, ); - test('strict plaintext validator accepts message kinds only', () { - final valid = { - 'v': 1, - 'origin': 'wss://tenant.example:8443', - 'app_profile': 'buzz-ios-dogfood', - 'transport': 'apns', - 'endpoint': 'opaque-grant', - 'generation': 1, - 'active': true, - 'subscriptions': [ - { - 'filter': { - 'kinds': [7], - '#p': [signer.public], - }, - 'class': 'default', - }, - ], - }; - - expect( - () => validateBuzzPushLeasePlaintext(valid), - throwsA( - isA().having( - (error) => error.message, - 'message', - 'Push filter contains invalid kinds.', - ), - ), - ); - - ((valid['subscriptions'] as List).single['filter'] as Map)['kinds'] = [ - 9, - 40002, - 45001, - 45003, - ]; - expect(() => validateBuzzPushLeasePlaintext(valid), returnsNormally); - }); - test('propagates relay rejection instead of accepting locally', () async { await expectLater( publishBuzzDevPushLease(