Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request from GHSA-789p-78mj-hfmc
  • Loading branch information
typfel committed May 7, 2021
1 parent 46f3f9e commit 35af3f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Source/Model/User/ZMUser.swift
Expand Up @@ -250,20 +250,28 @@ extension ZMUser {

public static var previewImageDownloadFilter: NSPredicate {
let assetIdExists = NSPredicate(format: "(%K != nil)", ZMUser.previewProfileAssetIdentifierKey)
let assetIdIsValid = NSPredicate { (user, _) -> Bool in
guard let user = user as? ZMUser else { return false }
return user.previewProfileAssetIdentifier?.isValidAssetID ?? false
}
let notCached = NSPredicate() { (user, _) -> Bool in
guard let user = user as? ZMUser else { return false }
return user.imageSmallProfileData == nil
}
return NSCompoundPredicate(andPredicateWithSubpredicates: [assetIdExists, notCached])
return NSCompoundPredicate(andPredicateWithSubpredicates: [assetIdExists, assetIdIsValid, notCached])
}

public static var completeImageDownloadFilter: NSPredicate {
let assetIdExists = NSPredicate(format: "(%K != nil)", ZMUser.completeProfileAssetIdentifierKey)
let assetIdIsValid = NSPredicate { (user, _) -> Bool in
guard let user = user as? ZMUser else { return false }
return user.completeProfileAssetIdentifier?.isValidAssetID ?? false
}
let notCached = NSPredicate() { (user, _) -> Bool in
guard let user = user as? ZMUser else { return false }
return user.imageMediumData == nil
}
return NSCompoundPredicate(andPredicateWithSubpredicates: [assetIdExists, notCached])
return NSCompoundPredicate(andPredicateWithSubpredicates: [assetIdExists, assetIdIsValid, notCached])
}

public func updateAndSyncProfileAssetIdentifiers(previewIdentifier: String, completeIdentifier: String) {
Expand Down
13 changes: 13 additions & 0 deletions Tests/Source/Model/User/ZMUserTests+Swift.swift
Expand Up @@ -223,6 +223,19 @@ extension ZMUserTests_Swift {
XCTAssertFalse(predicate.evaluate(with: user))
}
}

func testThatCompleteImageDownloadFilterDoesNotPickUpUsersWithInvalidAssetId() {
syncMOC.performGroupedBlockAndWait {
// GIVEN
let predicate = ZMUser.completeImageDownloadFilter
let user = ZMUser(remoteID: UUID.create(), createIfNeeded: true, in: self.syncMOC)
user?.completeProfileAssetIdentifier = "not+valid+id"
user?.setImage(data: "foo".data(using: .utf8), size: .complete)

// THEN
XCTAssertFalse(predicate.evaluate(with: user))
}
}

func testThatPreviewImageDownloadFilterDoesNotPickUpUsersWithCachedImages() {
syncMOC.performGroupedBlockAndWait {
Expand Down

0 comments on commit 35af3f6

Please sign in to comment.