From 0cda16d9236e6aa28f37339f3ba4be5cc30690f9 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Thu, 22 Dec 2022 18:13:24 +0100 Subject: [PATCH 1/7] Add kMXSessionDidFailToDecryptEventsNotification --- MatrixSDK/MXSession.h | 13 +++++++++++++ MatrixSDK/MXSession.m | 8 ++++++++ MatrixSDK/Room/Polls/PollAggregator.swift | 10 ++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/MatrixSDK/MXSession.h b/MatrixSDK/MXSession.h index 352b907bfb..fce4d614d7 100644 --- a/MatrixSDK/MXSession.h +++ b/MatrixSDK/MXSession.h @@ -302,6 +302,14 @@ FOUNDATION_EXPORT NSString *const kMXSessionDidUpdateGroupUsersNotification; */ FOUNDATION_EXPORT NSString *const kMXSessionDidUpdatePublicisedGroupsForUsersNotification; +/** + Posted when MXSession fails to decrypt a list of events. + + The passed userInfo dictionary contains: + - `kMXSessionNotificationEventsArrayKey` the list of the events the session fails to decrypt. + */ +FOUNDATION_EXPORT NSString *const kMXSessionDidFailToDecryptEventsNotification; + #pragma mark - Notifications keys /** The key in notification userInfo dictionary representating the roomId. @@ -339,6 +347,11 @@ FOUNDATION_EXPORT NSString *const kMXSessionNotificationErrorKey; */ FOUNDATION_EXPORT NSString *const kMXSessionNotificationUserIdsArrayKey; +/** + The key in notification userInfo dictionary representating a list of events. + */ +FOUNDATION_EXPORT NSString *const kMXSessionNotificationEventsArrayKey; + #pragma mark - Other constants /** diff --git a/MatrixSDK/MXSession.m b/MatrixSDK/MXSession.m index 0d516684e1..97eaa71fb2 100644 --- a/MatrixSDK/MXSession.m +++ b/MatrixSDK/MXSession.m @@ -71,6 +71,7 @@ NSString *const kMXSessionDidUpdateGroupRoomsNotification = @"kMXSessionDidUpdateGroupRoomsNotification"; NSString *const kMXSessionDidUpdateGroupUsersNotification = @"kMXSessionDidUpdateGroupUsersNotification"; NSString *const kMXSessionDidUpdatePublicisedGroupsForUsersNotification = @"kMXSessionDidUpdatePublicisedGroupsForUsersNotification"; +NSString *const kMXSessionDidFailToDecryptEventsNotification = @"kMXSessionDidFailToDecryptEventsNotification"; NSString *const kMXSessionNotificationRoomIdKey = @"roomId"; NSString *const kMXSessionNotificationGroupKey = @"group"; @@ -79,6 +80,7 @@ NSString *const kMXSessionNotificationSyncResponseKey = @"syncResponse"; NSString *const kMXSessionNotificationErrorKey = @"error"; NSString *const kMXSessionNotificationUserIdsArrayKey = @"userIds"; +NSString *const kMXSessionNotificationEventsArrayKey = @"events"; NSString *const kMXSessionNoRoomTag = @"m.recent"; // Use the same value as matrix-react-sdk @@ -5000,6 +5002,12 @@ - (void)decryptEvents:(NSArray *)events } } + if (failedEvents.count > 0) { + [NSNotificationCenter.defaultCenter postNotificationName:kMXSessionDidFailToDecryptEventsNotification + object:self + userInfo:@{ kMXSessionNotificationEventsArrayKey: failedEvents }]; + } + onComplete(failedEvents); }]; } diff --git a/MatrixSDK/Room/Polls/PollAggregator.swift b/MatrixSDK/Room/Polls/PollAggregator.swift index e896631d55..7c5b6c054d 100644 --- a/MatrixSDK/Room/Polls/PollAggregator.swift +++ b/MatrixSDK/Room/Polls/PollAggregator.swift @@ -77,8 +77,12 @@ public class PollAggregator { self.pollStartEventId = pollStartEventId self.pollBuilder = PollBuilder() - NotificationCenter.default.addObserver(self, selector: #selector(handleRoomDataFlush), name: NSNotification.Name.mxRoomDidFlushData, object: self.room) - + NotificationCenter.default.addObserver(self, selector: #selector(handleRoomDataFlush), name: .mxRoomDidFlushData, object: self.room) + setupEditListener() + try buildPollStartContent() + } + + private func setupEditListener() { editEventsListener = session.aggregations.listenToEditsUpdate(inRoom: self.room.roomId) { [weak self] event in guard let self = self, self.pollStartEventId == event.relatesTo.eventId @@ -92,8 +96,6 @@ public class PollAggregator { self.delegate?.pollAggregator(self, didFailWithError: PollAggregatorError.invalidPollStartEvent) } } - - try buildPollStartContent() } private func buildPollStartContent() throws { From 0fd79b42f11b40ef1b95d61a92c3f5e05d520952 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Fri, 23 Dec 2022 11:58:04 +0100 Subject: [PATCH 2/7] Handle decryption errors in PollAggregator --- MatrixSDK/Room/Polls/PollAggregator.swift | 33 ++++++++++++++++++++--- MatrixSDK/Room/Polls/PollBuilder.swift | 3 ++- MatrixSDK/Room/Polls/PollModels.swift | 2 ++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/MatrixSDK/Room/Polls/PollAggregator.swift b/MatrixSDK/Room/Polls/PollAggregator.swift index 7c5b6c054d..0f0ed94647 100644 --- a/MatrixSDK/Room/Polls/PollAggregator.swift +++ b/MatrixSDK/Room/Polls/PollAggregator.swift @@ -52,6 +52,7 @@ public class PollAggregator { private var events: [MXEvent] = [] private var hasBeenEdited = false + private var relatedErroredEvents: Set = [] public private(set) var poll: PollProtocol! { didSet { @@ -82,6 +83,25 @@ public class PollAggregator { try buildPollStartContent() } + public func handleErroredRelatedEventsIds(_ ids: Set?, to parentEvent: String) { + guard parentEvent == pollStartEventId else { + return + } + + let newErroredEvents = ids ?? [] + guard relatedErroredEvents != newErroredEvents else { + return + } + + relatedErroredEvents = newErroredEvents + + self.poll = pollBuilder.build(pollStartEventContent: pollStartEventContent, + events: events, + currentUserIdentifier: session.myUserId, + hasBeenEdited: hasBeenEdited, + hasDecryptionError: hasDecryptionError) + } + private func setupEditListener() { editEventsListener = session.aggregations.listenToEditsUpdate(inRoom: self.room.roomId) { [weak self] event in guard let self = self, @@ -113,7 +133,8 @@ public class PollAggregator { poll = pollBuilder.build(pollStartEventContent: eventContent, events: events, currentUserIdentifier: session.myUserId, - hasBeenEdited: hasBeenEdited) + hasBeenEdited: hasBeenEdited, + hasDecryptionError: hasDecryptionError) reloadPollData() } @@ -151,13 +172,15 @@ public class PollAggregator { self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, events: self.events, currentUserIdentifier: self.session.myUserId, - hasBeenEdited: self.hasBeenEdited) + hasBeenEdited: self.hasBeenEdited, + hasDecryptionError: self.hasDecryptionError) } as Any self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, events: self.events, currentUserIdentifier: self.session.myUserId, - hasBeenEdited: self.hasBeenEdited) + hasBeenEdited: self.hasBeenEdited, + hasDecryptionError: self.hasDecryptionError) self.delegate?.pollAggregatorDidEndLoading(self) @@ -169,4 +192,8 @@ public class PollAggregator { self.delegate?.pollAggregator(self, didFailWithError: error) } } + + private var hasDecryptionError: Bool { + relatedErroredEvents.isEmpty == false + } } diff --git a/MatrixSDK/Room/Polls/PollBuilder.swift b/MatrixSDK/Room/Polls/PollBuilder.swift index 97c77501a2..c558e9be73 100644 --- a/MatrixSDK/Room/Polls/PollBuilder.swift +++ b/MatrixSDK/Room/Polls/PollBuilder.swift @@ -22,10 +22,11 @@ struct PollBuilder { static let maxAnswerOptionCount = 20 } - func build(pollStartEventContent: MXEventContentPollStart, events: [MXEvent], currentUserIdentifier: String, hasBeenEdited: Bool = false) -> PollProtocol { + func build(pollStartEventContent: MXEventContentPollStart, events: [MXEvent], currentUserIdentifier: String, hasBeenEdited: Bool = false, hasDecryptionError: Bool = false) -> PollProtocol { let poll = Poll() poll.hasBeenEdited = hasBeenEdited + poll.hasDecryptionError = hasDecryptionError poll.text = pollStartEventContent.question poll.maxAllowedSelections = max(1, pollStartEventContent.maxSelections.uintValue) diff --git a/MatrixSDK/Room/Polls/PollModels.swift b/MatrixSDK/Room/Polls/PollModels.swift index 4d426b45cb..f8f565cca7 100644 --- a/MatrixSDK/Room/Polls/PollModels.swift +++ b/MatrixSDK/Room/Polls/PollModels.swift @@ -37,6 +37,7 @@ public protocol PollProtocol { var isClosed: Bool { get } var totalAnswerCount: UInt { get } var hasBeenEdited: Bool { get } + var hasDecryptionError: Bool { get } } class PollAnswerOption: PollAnswerOptionProtocol { @@ -56,6 +57,7 @@ class Poll: PollProtocol { var maxAllowedSelections: UInt = 1 var isClosed: Bool = false var hasBeenEdited: Bool = false + var hasDecryptionError: Bool = false var totalAnswerCount: UInt { return self.answerOptions.reduce(0) { $0 + $1.count} From 1eafd7f766749dd94b9594982487e94a980a0d4d Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Fri, 23 Dec 2022 12:55:37 +0100 Subject: [PATCH 3/7] Add MXSession UT --- MatrixSDKTests/MXSessionTests.m | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/MatrixSDKTests/MXSessionTests.m b/MatrixSDKTests/MXSessionTests.m index 486389c721..c1b88bbc1f 100644 --- a/MatrixSDKTests/MXSessionTests.m +++ b/MatrixSDKTests/MXSessionTests.m @@ -1509,6 +1509,31 @@ - (void)testMXSDKOptionsWellknownDomainUrl }]; } +#pragma mark Failing decryption + +-(void)testNotificationIsCorrectAfterDecryptionFailure +{ + MXEvent* fakeEncryptedEvent = [MXEvent modelFromJSON:@{ + @"event_id": @"abc", + @"type": kMXEventTypeStringRoomEncrypted, + @"content": @{ @"garbage": @"0000" } + }]; + + [matrixSDKTestsData doMXSessionTestWithBob:self readyToTest:^(MXSession *mxSession, XCTestExpectation *expectation) { + [NSNotificationCenter.defaultCenter addObserverForName:kMXSessionDidFailToDecryptEventsNotification object:mxSession queue:nil usingBlock:^(NSNotification * _Nonnull notification) { + XCTAssertTrue(mxSession == notification.object); + NSArray* events = notification.userInfo[kMXSessionNotificationEventsArrayKey]; + XCTAssertTrue(fakeEncryptedEvent == events.firstObject); + [expectation fulfill]; + }]; + + [mxSession enableCrypto:YES + success:^{ [mxSession decryptEvents:@[fakeEncryptedEvent] inTimeline:nil onComplete:^(NSArray *failedEvents) {}]; } + failure:^(NSError *error) { XCTFail();} + ]; + }]; +} + #pragma mark Account Data tests -(void)testAccountDataIsDeletedLocally From b59a5a38f69db0ae832f0b860d8d7807d5c54819 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Fri, 23 Dec 2022 13:21:56 +0100 Subject: [PATCH 4/7] Add PollAggregator UTs --- MatrixSDKTests/MXPollAggregatorTests.swift | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/MatrixSDKTests/MXPollAggregatorTests.swift b/MatrixSDKTests/MXPollAggregatorTests.swift index da236d8b26..2809e2cea7 100644 --- a/MatrixSDKTests/MXPollAggregatorTests.swift +++ b/MatrixSDKTests/MXPollAggregatorTests.swift @@ -155,6 +155,38 @@ class MXPollAggregatorTest: XCTestCase { } } + func testErrorsAreIgnoredForOtherPolls() { + createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in + self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) + self.pollAggregator.handleErroredRelatedEventsIds(["A", "B"], to: "someId") + XCTAssertFalse(self.pollAggregator.poll.hasDecryptionError) + expectation.fulfill() + } + } + + func testNoErrorsAreIgnored() { + createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in + self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) + self.pollAggregator.handleErroredRelatedEventsIds([], to: pollStartEvent.eventId) + XCTAssertFalse(self.pollAggregator.poll.hasDecryptionError) + expectation.fulfill() + } + } + + func testErrorsAreConsideredWhenRelatedToThisPoll() { + createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in + self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) + + self.pollAggregator.delegate = PollAggregatorBlockWrapper(dataUpdateCallback: { + XCTAssertTrue(self.pollAggregator.poll.hasDecryptionError) + expectation.fulfill() + self.pollAggregator.delegate = nil + }) + + self.pollAggregator.handleErroredRelatedEventsIds(["A", "B"], to: pollStartEvent.eventId) + } + } + // MARK: - Private func createScenarioForBobAndAlice(_ readyToTest: @escaping (MXSession, MXSession, MXRoom, MXRoom, MXEvent, XCTestExpectation) -> Void) { From 9402e2f82eef022fbab3169370cb77668c5c3e55 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Fri, 23 Dec 2022 13:33:14 +0100 Subject: [PATCH 5/7] Add changelog.d file --- changelog.d/pr-1673.change | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/pr-1673.change diff --git a/changelog.d/pr-1673.change b/changelog.d/pr-1673.change new file mode 100644 index 0000000000..490e464b75 --- /dev/null +++ b/changelog.d/pr-1673.change @@ -0,0 +1 @@ +Polls: handle decryption errors. From 7a29bc6bc5f6972427c8f6c71af39c2fe051eba9 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Wed, 4 Jan 2023 11:27:19 +0100 Subject: [PATCH 6/7] Improve property name --- MatrixSDK/Room/Polls/PollAggregator.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MatrixSDK/Room/Polls/PollAggregator.swift b/MatrixSDK/Room/Polls/PollAggregator.swift index 0f0ed94647..4189a81e6f 100644 --- a/MatrixSDK/Room/Polls/PollAggregator.swift +++ b/MatrixSDK/Room/Polls/PollAggregator.swift @@ -52,7 +52,7 @@ public class PollAggregator { private var events: [MXEvent] = [] private var hasBeenEdited = false - private var relatedErroredEvents: Set = [] + private var relatedUndecryptableEvents: Set = [] public private(set) var poll: PollProtocol! { didSet { @@ -88,12 +88,12 @@ public class PollAggregator { return } - let newErroredEvents = ids ?? [] - guard relatedErroredEvents != newErroredEvents else { + let newUndecryptableEvents = ids ?? [] + guard relatedUndecryptableEvents != newUndecryptableEvents else { return } - relatedErroredEvents = newErroredEvents + relatedUndecryptableEvents = newUndecryptableEvents self.poll = pollBuilder.build(pollStartEventContent: pollStartEventContent, events: events, @@ -194,6 +194,6 @@ public class PollAggregator { } private var hasDecryptionError: Bool { - relatedErroredEvents.isEmpty == false + relatedUndecryptableEvents.isEmpty == false } } From 2338d3311622fe591cf977f99c02a64e19642b29 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Mon, 9 Jan 2023 13:23:58 +0100 Subject: [PATCH 7/7] Refactor decryption errors logic --- MatrixSDK/MXSession.h | 14 --------- MatrixSDK/MXSession.m | 10 +------ MatrixSDK/Room/Polls/PollAggregator.swift | 33 ++-------------------- MatrixSDK/Room/Polls/PollBuilder.swift | 4 +-- MatrixSDKTests/MXPollAggregatorTests.swift | 32 --------------------- MatrixSDKTests/MXSessionTests.m | 25 ---------------- 6 files changed, 6 insertions(+), 112 deletions(-) diff --git a/MatrixSDK/MXSession.h b/MatrixSDK/MXSession.h index fce4d614d7..df449e087f 100644 --- a/MatrixSDK/MXSession.h +++ b/MatrixSDK/MXSession.h @@ -302,14 +302,6 @@ FOUNDATION_EXPORT NSString *const kMXSessionDidUpdateGroupUsersNotification; */ FOUNDATION_EXPORT NSString *const kMXSessionDidUpdatePublicisedGroupsForUsersNotification; -/** - Posted when MXSession fails to decrypt a list of events. - - The passed userInfo dictionary contains: - - `kMXSessionNotificationEventsArrayKey` the list of the events the session fails to decrypt. - */ -FOUNDATION_EXPORT NSString *const kMXSessionDidFailToDecryptEventsNotification; - #pragma mark - Notifications keys /** The key in notification userInfo dictionary representating the roomId. @@ -347,12 +339,6 @@ FOUNDATION_EXPORT NSString *const kMXSessionNotificationErrorKey; */ FOUNDATION_EXPORT NSString *const kMXSessionNotificationUserIdsArrayKey; -/** - The key in notification userInfo dictionary representating a list of events. - */ -FOUNDATION_EXPORT NSString *const kMXSessionNotificationEventsArrayKey; - - #pragma mark - Other constants /** Fake tag used to identify rooms that do not have tags in `roomsWithTag` and `roomsByTags` methods. diff --git a/MatrixSDK/MXSession.m b/MatrixSDK/MXSession.m index 97eaa71fb2..222ce9ef84 100644 --- a/MatrixSDK/MXSession.m +++ b/MatrixSDK/MXSession.m @@ -71,7 +71,6 @@ NSString *const kMXSessionDidUpdateGroupRoomsNotification = @"kMXSessionDidUpdateGroupRoomsNotification"; NSString *const kMXSessionDidUpdateGroupUsersNotification = @"kMXSessionDidUpdateGroupUsersNotification"; NSString *const kMXSessionDidUpdatePublicisedGroupsForUsersNotification = @"kMXSessionDidUpdatePublicisedGroupsForUsersNotification"; -NSString *const kMXSessionDidFailToDecryptEventsNotification = @"kMXSessionDidFailToDecryptEventsNotification"; NSString *const kMXSessionNotificationRoomIdKey = @"roomId"; NSString *const kMXSessionNotificationGroupKey = @"group"; @@ -80,7 +79,6 @@ NSString *const kMXSessionNotificationSyncResponseKey = @"syncResponse"; NSString *const kMXSessionNotificationErrorKey = @"error"; NSString *const kMXSessionNotificationUserIdsArrayKey = @"userIds"; -NSString *const kMXSessionNotificationEventsArrayKey = @"events"; NSString *const kMXSessionNoRoomTag = @"m.recent"; // Use the same value as matrix-react-sdk @@ -5001,13 +4999,7 @@ - (void)decryptEvents:(NSArray *)events [failedEvents addObject:event]; } } - - if (failedEvents.count > 0) { - [NSNotificationCenter.defaultCenter postNotificationName:kMXSessionDidFailToDecryptEventsNotification - object:self - userInfo:@{ kMXSessionNotificationEventsArrayKey: failedEvents }]; - } - + onComplete(failedEvents); }]; } diff --git a/MatrixSDK/Room/Polls/PollAggregator.swift b/MatrixSDK/Room/Polls/PollAggregator.swift index 4189a81e6f..7c5b6c054d 100644 --- a/MatrixSDK/Room/Polls/PollAggregator.swift +++ b/MatrixSDK/Room/Polls/PollAggregator.swift @@ -52,7 +52,6 @@ public class PollAggregator { private var events: [MXEvent] = [] private var hasBeenEdited = false - private var relatedUndecryptableEvents: Set = [] public private(set) var poll: PollProtocol! { didSet { @@ -83,25 +82,6 @@ public class PollAggregator { try buildPollStartContent() } - public func handleErroredRelatedEventsIds(_ ids: Set?, to parentEvent: String) { - guard parentEvent == pollStartEventId else { - return - } - - let newUndecryptableEvents = ids ?? [] - guard relatedUndecryptableEvents != newUndecryptableEvents else { - return - } - - relatedUndecryptableEvents = newUndecryptableEvents - - self.poll = pollBuilder.build(pollStartEventContent: pollStartEventContent, - events: events, - currentUserIdentifier: session.myUserId, - hasBeenEdited: hasBeenEdited, - hasDecryptionError: hasDecryptionError) - } - private func setupEditListener() { editEventsListener = session.aggregations.listenToEditsUpdate(inRoom: self.room.roomId) { [weak self] event in guard let self = self, @@ -133,8 +113,7 @@ public class PollAggregator { poll = pollBuilder.build(pollStartEventContent: eventContent, events: events, currentUserIdentifier: session.myUserId, - hasBeenEdited: hasBeenEdited, - hasDecryptionError: hasDecryptionError) + hasBeenEdited: hasBeenEdited) reloadPollData() } @@ -172,15 +151,13 @@ public class PollAggregator { self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, events: self.events, currentUserIdentifier: self.session.myUserId, - hasBeenEdited: self.hasBeenEdited, - hasDecryptionError: self.hasDecryptionError) + hasBeenEdited: self.hasBeenEdited) } as Any self.poll = self.pollBuilder.build(pollStartEventContent: self.pollStartEventContent, events: self.events, currentUserIdentifier: self.session.myUserId, - hasBeenEdited: self.hasBeenEdited, - hasDecryptionError: self.hasDecryptionError) + hasBeenEdited: self.hasBeenEdited) self.delegate?.pollAggregatorDidEndLoading(self) @@ -192,8 +169,4 @@ public class PollAggregator { self.delegate?.pollAggregator(self, didFailWithError: error) } } - - private var hasDecryptionError: Bool { - relatedUndecryptableEvents.isEmpty == false - } } diff --git a/MatrixSDK/Room/Polls/PollBuilder.swift b/MatrixSDK/Room/Polls/PollBuilder.swift index c558e9be73..44d17127f1 100644 --- a/MatrixSDK/Room/Polls/PollBuilder.swift +++ b/MatrixSDK/Room/Polls/PollBuilder.swift @@ -22,11 +22,11 @@ struct PollBuilder { static let maxAnswerOptionCount = 20 } - func build(pollStartEventContent: MXEventContentPollStart, events: [MXEvent], currentUserIdentifier: String, hasBeenEdited: Bool = false, hasDecryptionError: Bool = false) -> PollProtocol { + func build(pollStartEventContent: MXEventContentPollStart, events: [MXEvent], currentUserIdentifier: String, hasBeenEdited: Bool = false) -> PollProtocol { let poll = Poll() poll.hasBeenEdited = hasBeenEdited - poll.hasDecryptionError = hasDecryptionError + poll.hasDecryptionError = events.contains(where: { $0.isEncrypted && $0.clear == nil }) poll.text = pollStartEventContent.question poll.maxAllowedSelections = max(1, pollStartEventContent.maxSelections.uintValue) diff --git a/MatrixSDKTests/MXPollAggregatorTests.swift b/MatrixSDKTests/MXPollAggregatorTests.swift index 2809e2cea7..da236d8b26 100644 --- a/MatrixSDKTests/MXPollAggregatorTests.swift +++ b/MatrixSDKTests/MXPollAggregatorTests.swift @@ -155,38 +155,6 @@ class MXPollAggregatorTest: XCTestCase { } } - func testErrorsAreIgnoredForOtherPolls() { - createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in - self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) - self.pollAggregator.handleErroredRelatedEventsIds(["A", "B"], to: "someId") - XCTAssertFalse(self.pollAggregator.poll.hasDecryptionError) - expectation.fulfill() - } - } - - func testNoErrorsAreIgnored() { - createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in - self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) - self.pollAggregator.handleErroredRelatedEventsIds([], to: pollStartEvent.eventId) - XCTAssertFalse(self.pollAggregator.poll.hasDecryptionError) - expectation.fulfill() - } - } - - func testErrorsAreConsideredWhenRelatedToThisPoll() { - createScenarioForBobAndAlice { bobSession, aliceSession, bobRoom, aliceRoom, pollStartEvent, expectation in - self.pollAggregator = try! PollAggregator(session: bobSession, room: bobRoom, pollStartEventId: pollStartEvent.eventId) - - self.pollAggregator.delegate = PollAggregatorBlockWrapper(dataUpdateCallback: { - XCTAssertTrue(self.pollAggregator.poll.hasDecryptionError) - expectation.fulfill() - self.pollAggregator.delegate = nil - }) - - self.pollAggregator.handleErroredRelatedEventsIds(["A", "B"], to: pollStartEvent.eventId) - } - } - // MARK: - Private func createScenarioForBobAndAlice(_ readyToTest: @escaping (MXSession, MXSession, MXRoom, MXRoom, MXEvent, XCTestExpectation) -> Void) { diff --git a/MatrixSDKTests/MXSessionTests.m b/MatrixSDKTests/MXSessionTests.m index c1b88bbc1f..486389c721 100644 --- a/MatrixSDKTests/MXSessionTests.m +++ b/MatrixSDKTests/MXSessionTests.m @@ -1509,31 +1509,6 @@ - (void)testMXSDKOptionsWellknownDomainUrl }]; } -#pragma mark Failing decryption - --(void)testNotificationIsCorrectAfterDecryptionFailure -{ - MXEvent* fakeEncryptedEvent = [MXEvent modelFromJSON:@{ - @"event_id": @"abc", - @"type": kMXEventTypeStringRoomEncrypted, - @"content": @{ @"garbage": @"0000" } - }]; - - [matrixSDKTestsData doMXSessionTestWithBob:self readyToTest:^(MXSession *mxSession, XCTestExpectation *expectation) { - [NSNotificationCenter.defaultCenter addObserverForName:kMXSessionDidFailToDecryptEventsNotification object:mxSession queue:nil usingBlock:^(NSNotification * _Nonnull notification) { - XCTAssertTrue(mxSession == notification.object); - NSArray* events = notification.userInfo[kMXSessionNotificationEventsArrayKey]; - XCTAssertTrue(fakeEncryptedEvent == events.firstObject); - [expectation fulfill]; - }]; - - [mxSession enableCrypto:YES - success:^{ [mxSession decryptEvents:@[fakeEncryptedEvent] inTimeline:nil onComplete:^(NSArray *failedEvents) {}]; } - failure:^(NSError *error) { XCTFail();} - ]; - }]; -} - #pragma mark Account Data tests -(void)testAccountDataIsDeletedLocally