π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Preserve upload resolver guards
Neeraj Gupta7492e4304f3e
diff --git a/mobile/apps/photos/lib/module/upload/service/existing_upload_resolver.dart b/mobile/apps/photos/lib/module/upload/service/existing_upload_resolver.dartindex 103749933b..a11308d7c4 100644--- a/mobile/apps/photos/lib/module/upload/service/existing_upload_resolver.dart+++ b/mobile/apps/photos/lib/module/upload/service/existing_upload_resolver.dart@@ -1,6 +1,5 @@import "package:collection/collection.dart";import "package:logging/logging.dart";-import "package:photos/core/configuration.dart";import "package:photos/core/event_bus.dart";import "package:photos/db/files_db.dart";import "package:photos/events/files_updated_event.dart";@@ -15,7 +14,6 @@ typedef FindUploadedFiles =FileType fileType,int ownerID,);-typedef GetOwnerID = int Function();typedef DeleteGeneratedFile = Future<void> Function(int generatedID);typedef UpdateUploadedFileLocalID =Future<void> Function(int uploadedFileID, String localID);@@ -35,13 +33,11 @@ typedef EmitLocalPhotosUpdated = void Function(LocalPhotosUpdatedEvent event);class ExistingUploadResolver {ExistingUploadResolver({required FindUploadedFiles findUploadedFiles,- required GetOwnerID getOwnerID,required DeleteGeneratedFile deleteGeneratedFile,required UpdateUploadedFileLocalID updateUploadedFileLocalID,required LinkExistingUpload linkExistingUpload,required EmitLocalPhotosUpdated emitLocalPhotosUpdated,}) : _findUploadedFiles = findUploadedFiles,- _getOwnerID = getOwnerID,_deleteGeneratedFile = deleteGeneratedFile,_updateUploadedFileLocalID = updateUploadedFileLocalID,_linkExistingUpload = linkExistingUpload,@@ -50,7 +46,6 @@ class ExistingUploadResolver {factory ExistingUploadResolver.forApp() => ExistingUploadResolver(findUploadedFiles: (hash, fileType, ownerID) =>FilesDB.instance.getUploadedFilesWithHash(hash, fileType, ownerID),- getOwnerID: () => Configuration.instance.getUserID()!,deleteGeneratedFile: (generatedID) =>FilesDB.instance.deleteByGeneratedID(generatedID),updateUploadedFileLocalID: (uploadedFileID, localID) =>@@ -71,7 +66,6 @@ class ExistingUploadResolver {final _logger = Logger("ExistingUploadResolver");final FindUploadedFiles _findUploadedFiles;- final GetOwnerID _getOwnerID;final DeleteGeneratedFile _deleteGeneratedFile;final UpdateUploadedFileLocalID _updateUploadedFileLocalID;final LinkExistingUpload _linkExistingUpload;@@ -82,6 +76,7 @@ class ExistingUploadResolver {required String fileHash,required EnteFile fileToUpload,required int targetCollectionID,+ required int? ownerID,}) async {if (fileToUpload.uploadedFileID != null) {// This should never happen. Avoid mapping an already-uploaded row because@@ -89,12 +84,15 @@ class ExistingUploadResolver {_logger.severe("Critical: file is already uploaded, skipped mapping");return null;}+ if (ownerID == null) {+ return null;+ }final isSandboxFile = fileToUpload.isSharedMediaToAppSandbox;final existingUploadedFiles = await _findUploadedFiles(fileHash,fileToUpload.fileType,- _getOwnerID(),+ ownerID,);if (existingUploadedFiles.isEmpty) {return null;@@ -127,7 +125,6 @@ class ExistingUploadResolver {"fileMissingLocal: \n toUpload ${fileToUpload.tag} ""\n existing: ${fileMissingLocal.tag}",);- fileMissingLocal.localID = fileToUpload.localID;await _updateUploadedFileLocalID(fileMissingLocal.uploadedFileID!,fileToUpload.localID!,@@ -136,6 +133,7 @@ class ExistingUploadResolver {await _deleteGeneratedFile(fileToUpload.generatedID!);}_emitDeletedEvent(fileToUpload, "fileMissingLocal");+ fileMissingLocal.localID = fileToUpload.localID;return fileMissingLocal;}diff --git a/mobile/apps/photos/lib/module/upload/service/file_uploader.dart b/mobile/apps/photos/lib/module/upload/service/file_uploader.dartindex f8ebab8d22..870f423fd2 100644--- a/mobile/apps/photos/lib/module/upload/service/file_uploader.dart+++ b/mobile/apps/photos/lib/module/upload/service/file_uploader.dart@@ -458,6 +458,7 @@ class FileUploader {fileHash: mediaUploadData.fileHash,fileToUpload: file,targetCollectionID: collectionID,+ ownerID: Configuration.instance.getUserID(),);if (mappedFile != null) {debugPrint(diff --git a/mobile/apps/photos/test/module/upload/service/existing_upload_resolver_test.dart b/mobile/apps/photos/test/module/upload/service/existing_upload_resolver_test.dartindex 5acc4713fd..474d5f7855 100644--- a/mobile/apps/photos/test/module/upload/service/existing_upload_resolver_test.dart+++ b/mobile/apps/photos/test/module/upload/service/existing_upload_resolver_test.dart@@ -13,7 +13,16 @@ void main() {expect(await fixture.resolve(pending), isNull);expect(fixture.calls, isEmpty);- expect(fixture.ownerIDCalls, 0);+ });++ test("missing owner skips lookup and mapping", () async {+ final fixture = _Fixture();++ expect(+ await fixture.resolve(_file(localID: "local"), ownerID: null),+ isNull,+ );+ expect(fixture.calls, isEmpty);});test("no hash matches continues uploading", () async {@@ -21,7 +30,6 @@ void main() {expect(await fixture.resolve(_file(localID: "local")), isNull);expect(fixture.calls, ["find:hash:${FileType.image.index}:10"]);- expect(fixture.ownerIDCalls, 1);});test("hash lookup failure propagates without side effects", () async {@@ -232,6 +240,7 @@ void main() {"find:hash:${FileType.image.index}:10","update:12:local",]);+ expect(existing.localID, isNull);expect(fixture.events, isEmpty);});@@ -288,10 +297,6 @@ class _Fixture {if (findError != null) throw findError!;return this.existingFiles;},- getOwnerID: () {- ownerIDCalls++;- return ownerID;- },deleteGeneratedFile: (generatedID) async {calls.add("delete:$generatedID");if (deleteError != null) throw deleteError!;@@ -324,7 +329,7 @@ class _Fixture {}static const fileHash = "hash";- static const ownerID = 10;+ static const defaultOwnerID = 10;static const targetCollectionID = 20;final List<EnteFile> existingFiles;@@ -339,12 +344,14 @@ class _Fixture {Object? emitError;Object? updateError;Object? linkError;- var ownerIDCalls = 0;-- Future<EnteFile?> resolve(EnteFile pending) => resolver.resolve(+ Future<EnteFile?> resolve(+ EnteFile pending, {+ int? ownerID = defaultOwnerID,+ }) => resolver.resolve(fileHash: fileHash,fileToUpload: pending,targetCollectionID: targetCollectionID,+ ownerID: ownerID,);}