π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Trim Cast transport tests
Neeraj Gupta4bf54e31ca47
diff --git a/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_message_codec.dart b/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_message_codec.dartindex 32f7f336b4..3d63813d3c 100644--- a/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_message_codec.dart+++ b/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_message_codec.dart@@ -17,13 +17,13 @@ final class CastEnvelope {});}-Uint8List encodeCastEnvelope({+Uint8List encodeCastFrame({required String sourceID,required String destinationID,required String namespace,required String payload,}) {- return _encodeCastEnvelope(+ final envelope = _encodeCastEnvelope(sourceID: sourceID,destinationID: destinationID,namespace: namespace,@@ -31,36 +31,6 @@ Uint8List encodeCastEnvelope({payloadField: 6,payload: utf8.encode(payload),);-}--Uint8List encodeBinaryCastEnvelope({- required String sourceID,- required String destinationID,- required String namespace,- required Uint8List payload,-}) {- return _encodeCastEnvelope(- sourceID: sourceID,- destinationID: destinationID,- namespace: namespace,- payloadType: 1,- payloadField: 7,- payload: payload,- );-}--Uint8List encodeCastFrame({- required String sourceID,- required String destinationID,- required String namespace,- required String payload,-}) {- final envelope = encodeCastEnvelope(- sourceID: sourceID,- destinationID: destinationID,- namespace: namespace,- payload: payload,- );return _frame(envelope);}@@ -70,10 +40,12 @@ Uint8List encodeBinaryCastFrame({required String namespace,required Uint8List payload,}) {- final envelope = encodeBinaryCastEnvelope(+ final envelope = _encodeCastEnvelope(sourceID: sourceID,destinationID: destinationID,namespace: namespace,+ payloadType: 1,+ payloadField: 7,payload: payload,);return _frame(envelope);diff --git a/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_pairing.dart b/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_pairing.dartindex 4edbbd3ebe..356caebbc4 100644--- a/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_pairing.dart+++ b/mobile/apps/photos/plugins/ente_cast/lib/src/cast/cast_pairing.dart@@ -8,7 +8,6 @@ const castPairRequestNamespace = "urn:x-cast:pair-request";Future<String> waitForPairCode({required Stream<ChromecastMessage> messages,required Stream<ChromecastConnectionState> states,- required ChromecastConnectionState initialState,required void Function() start,required void Function() sendPairRequest,required Duration timeout,@@ -85,9 +84,6 @@ Future<String> waitForPairCode({} catch (error, stackTrace) {completeError(error, stackTrace);}- if (initialState == ChromecastConnectionState.connected) {- requestPairCode();- }try {return await pairCode.future.timeout(diff --git a/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart b/mobile/apps/photos/plugins/ente_cast/lib/src/service.dartindex dabe466703..b4482e59ec 100644--- a/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart+++ b/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart@@ -141,7 +141,6 @@ class CastService {return await waitForPairCode(messages: connection.messages,states: connection.states,- initialState: connection.state,start: () => connection.launch(_appID),sendPairRequest: () => connection.send(castPairRequestNamespace, {"collectionID": ?collectionID,diff --git a/mobile/apps/photos/plugins/ente_cast/test/cast_device_auth_test.dart b/mobile/apps/photos/plugins/ente_cast/test/cast_device_auth_test.dartindex 7dcbb75ba9..88f7885d9c 100644--- a/mobile/apps/photos/plugins/ente_cast/test/cast_device_auth_test.dart+++ b/mobile/apps/photos/plugins/ente_cast/test/cast_device_auth_test.dart@@ -14,32 +14,6 @@ void main() {expect(encodeCastAuthChallenge(nonce), [10, 20, 18, 16, ...nonce, 24, 1]);});- test("decodes the device credentials from an auth response", () {- final nonce = Uint8List.fromList(List.filled(16, 7));-- final response = decodeCastAuthResponse(- _authResponse(- signature: [1, 2],- clientCertificate: [3, 4],- intermediates: [- [5],- [6],- ],- nonce: nonce,- hashAlgorithm: 1,- ),- );-- expect(response.signature, [1, 2]);- expect(response.clientAuthCertificate, [3, 4]);- expect(response.intermediateCertificates, [- [5],- [6],- ]);- expect(response.senderNonce, nonce);- expect(response.hashAlgorithm, 1);- });-test("verifies the nonce and TLS certificate signed by the receiver",() async {@@ -202,7 +176,7 @@ Uint8List _authResponse({return (ProtoWriter()..writeBytes(2, response.takeBytes())).takeBytes();}-final class _FakeCertificate implements X509Certificate {+final class _FakeCertificate extends Fake implements X509Certificate {_FakeCertificate(this.der, {DateTime? endValidity}): _endValidity = endValidity;@@ -215,19 +189,7 @@ final class _FakeCertificate implements X509Certificate {DateTime get endValidity =>_endValidity ?? DateTime.now().add(const Duration(days: 1));- @override- String get issuer => "issuer";-- @override- String get pem => "";-- @override- Uint8List get sha1 => Uint8List(0);-@overrideDateTime get startValidity =>DateTime.now().subtract(const Duration(days: 1));-- @override- String get subject => "subject";}diff --git a/mobile/apps/photos/plugins/ente_cast/test/cast_message_codec_test.dart b/mobile/apps/photos/plugins/ente_cast/test/cast_message_codec_test.dartindex 0cb2118207..e300f83ad7 100644--- a/mobile/apps/photos/plugins/ente_cast/test/cast_message_codec_test.dart+++ b/mobile/apps/photos/plugins/ente_cast/test/cast_message_codec_test.dart@@ -1,76 +1,26 @@+import "dart:convert";import "dart:typed_data";import "package:ente_cast/src/cast/cast_message_codec.dart";import "package:flutter_test/flutter_test.dart";void main() {- test("encodes the Cast message fields", () {- final bytes = encodeCastEnvelope(+ test("encodes text and binary Cast frames", () {+ final text = encodeCastFrame(sourceID: "s",destinationID: "d",namespace: "n",payload: "{}",);-- expect(- bytes,- Uint8List.fromList([- 8,- 0,- 18,- 1,- 115,- 26,- 1,- 100,- 34,- 1,- 110,- 40,- 0,- 50,- 2,- 123,- 125,- ]),- );- });-- test("decodes length-delimited Cast fields", () {- final encoded = encodeCastEnvelope(- sourceID: "client-123",- destinationID: "receiver-0",- namespace: "urn:x-cast:pair-request",- payload: '{"collectionID":42}',- );-- final decoded = decodeCastEnvelope(encoded);-- expect(decoded.namespace, "urn:x-cast:pair-request");- expect(decoded.payload, '{"collectionID":42}');- expect(decoded.binaryPayload, isNull);- });-- test("encodes and decodes binary Cast fields", () {- final encoded = encodeBinaryCastEnvelope(- sourceID: "sender-0",- destinationID: "receiver-0",- namespace: "urn:x-cast:com.google.cast.tp.deviceauth",+ final binary = encodeBinaryCastFrame(+ sourceID: "s",+ destinationID: "d",+ namespace: "n",payload: Uint8List.fromList([0, 1, 255]),);- final decoded = decodeCastEnvelope(encoded);-- expect(decoded.namespace, "urn:x-cast:com.google.cast.tp.deviceauth");- expect(decoded.payload, isNull);- expect(decoded.binaryPayload, [0, 1, 255]);- });-- test("rejects a truncated Cast message", () {- expect(- () => decodeCastEnvelope(Uint8List.fromList([34, 5, 1])),- throwsFormatException,- );+ expect(base64Encode(text), "AAAAEQgAEgFzGgFkIgFuKAAyAnt9");+ expect(base64Encode(binary), "AAAAEggAEgFzGgFkIgFuKAE6AwAB/w==");});test("decodes fragmented and consecutive Cast frames", () {diff --git a/mobile/apps/photos/plugins/ente_cast/test/cast_pairing_test.dart b/mobile/apps/photos/plugins/ente_cast/test/cast_pairing_test.dartindex e76d2ed3e0..fab2e09a2e 100644--- a/mobile/apps/photos/plugins/ente_cast/test/cast_pairing_test.dart+++ b/mobile/apps/photos/plugins/ente_cast/test/cast_pairing_test.dart@@ -15,7 +15,6 @@ void main() {final result = waitForPairCode(messages: messages.stream,states: states.stream,- initialState: ChromecastConnectionState.connecting,start: () {},sendPairRequest: () => pairRequests++,timeout: const Duration(seconds: 1),@@ -43,7 +42,6 @@ void main() {final result = waitForPairCode(messages: messages.stream,states: states.stream,- initialState: ChromecastConnectionState.connecting,start: () => messages.add(const ChromecastMessage(namespace: ChromecastConnection.receiverNamespace,@@ -58,42 +56,4 @@ void main() {await messages.close();await states.close();});-- test("surfaces a connection that closes before pairing", () async {- final messages = StreamController<ChromecastMessage>.broadcast(sync: true);- final states = StreamController<ChromecastConnectionState>.broadcast(- sync: true,- );- final result = waitForPairCode(- messages: messages.stream,- states: states.stream,- initialState: ChromecastConnectionState.connecting,- start: () => states.add(ChromecastConnectionState.closed),- sendPairRequest: () {},- timeout: const Duration(seconds: 1),- );-- await expectLater(result, throwsA(isA<CastPairingException>()));- await messages.close();- await states.close();- });-- test("times out when the receiver never returns a code", () async {- final messages = StreamController<ChromecastMessage>.broadcast(sync: true);- final states = StreamController<ChromecastConnectionState>.broadcast(- sync: true,- );- final result = waitForPairCode(- messages: messages.stream,- states: states.stream,- initialState: ChromecastConnectionState.connecting,- start: () {},- sendPairRequest: () {},- timeout: const Duration(milliseconds: 1),- );-- await expectLater(result, throwsA(isA<TimeoutException>()));- await messages.close();- await states.close();- });}diff --git a/mobile/apps/photos/plugins/ente_cast/test/multicast_lock_test.dart b/mobile/apps/photos/plugins/ente_cast/test/multicast_lock_test.dartindex 3debf7d8c8..c679313395 100644--- a/mobile/apps/photos/plugins/ente_cast/test/multicast_lock_test.dart+++ b/mobile/apps/photos/plugins/ente_cast/test/multicast_lock_test.dart@@ -5,38 +5,17 @@ import "package:flutter_test/flutter_test.dart";void main() {TestWidgetsFlutterBinding.ensureInitialized();- const channel = MethodChannel("io.ente.cast/test-multicast");- final events = <String>[];-- setUp(() {- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger- .setMockMethodCallHandler(channel, (call) async {- events.add(call.method);- return null;- });- });-- tearDown(() {- TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger- .setMockMethodCallHandler(channel, null);- events.clear();- });-- test("holds the multicast lock for the action", () async {- final result = await withMulticastLock(- () async {- events.add("action");- return 42;- },- acquireLock: true,- channel: channel,- );-- expect(result, 42);- expect(events, ["acquire", "action", "release"]);- });-test("releases the multicast lock when the action fails", () async {+ const channel = MethodChannel("io.ente.cast/test-multicast");+ final events = <String>[];+ final messenger =+ TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;+ messenger.setMockMethodCallHandler(channel, (call) async {+ events.add(call.method);+ return null;+ });+ addTearDown(() => messenger.setMockMethodCallHandler(channel, null));+final result = withMulticastLock<void>(() async {events.add("action");@@ -49,14 +28,4 @@ void main() {await expectLater(result, throwsStateError);expect(events, ["acquire", "action", "release"]);});-- test("does not call the platform channel outside Android", () async {- await withMulticastLock(- () async => events.add("action"),- acquireLock: false,- channel: channel,- );-- expect(events, ["action"]);- });}diff --git a/mobile/apps/photos/test/services/auto_cast_service_test.dart b/mobile/apps/photos/test/services/auto_cast_service_test.dartindex e39f850274..9ba77ff0cc 100644--- a/mobile/apps/photos/test/services/auto_cast_service_test.dart+++ b/mobile/apps/photos/test/services/auto_cast_service_test.dart@@ -5,23 +5,6 @@ import "package:photos/models/collection/collection.dart";import "package:photos/services/auto_cast_service.dart";void main() {- test("stopping revokes the server session returned while pairing", () async {- final transport = _FakeCastService();- final gateway = _FakeCastGateway();- final service = AutoCastService(- transport: transport,- gateway: gateway,- encodePayload: (_, _, _) => "encrypted-payload",- );- final device = Object();-- await service.connect(device, _FakeCollection());- await service.stop(device);-- expect(gateway.revokedDeviceIDs, ["device-id"]);- expect(transport.stoppedDevices, [device]);- });-test("stopping disconnects the device when server revocation fails",() async {