Skip to content

Commit

Permalink
Merge branch 'release/0.23.6/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed May 19, 2022
2 parents 6cb7100 + ac45ca2 commit 4c9efc0
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Changes in 0.23.6 (2022-05-19)

No significant changes.


## Changes in 0.23.5 (2022-05-18)

✨ Features
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MatrixSDK"
s.version = "0.23.5"
s.version = "0.23.6"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down
6 changes: 5 additions & 1 deletion MatrixSDK/Crypto/Data/MXMegolmSessionData.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#import "MXMegolmSessionData.h"
#import "MXSharedHistoryKeyService.h"
#import "MXSDKOptions.h"

@implementation MXMegolmSessionData

Expand All @@ -29,7 +30,10 @@ + (id)modelFromJSON:(NSDictionary *)JSONDictionary
MXJSONModelSetString(sessionData.roomId, JSONDictionary[@"room_id"]);
MXJSONModelSetString(sessionData.sessionId, JSONDictionary[@"session_id"]);
MXJSONModelSetString(sessionData.sessionKey, JSONDictionary[@"session_key"]);
MXJSONModelSetBoolean(sessionData.sharedHistory, JSONDictionary[kMXSharedHistoryKeyName]);
if (MXSDKOptions.sharedInstance.enableRoomSharedHistoryOnInvite)
{
MXJSONModelSetBoolean(sessionData.sharedHistory, JSONDictionary[kMXSharedHistoryKeyName]);
}
MXJSONModelSetString(sessionData.algorithm, JSONDictionary[@"algorithm"]);
MXJSONModelSetArray(sessionData.forwardingCurve25519KeyChain, JSONDictionary[@"forwarding_curve25519_key_chain"])
}
Expand Down
5 changes: 5 additions & 0 deletions MatrixSDK/Crypto/MXCrypto.m
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,11 @@ - (BOOL)isRoomEncrypted:(NSString *)roomId

- (BOOL)isRoomSharingHistory:(NSString *)roomId
{
if (!MXSDKOptions.sharedInstance.enableRoomSharedHistoryOnInvite)
{
return NO;
}

MXRoom *room = [self.mxSession roomWithRoomId:roomId];
MXRoomHistoryVisibility visibility = room.summary.historyVisibility;
return [visibility isEqualToString:kMXRoomHistoryVisibilityWorldReadable] || [visibility isEqualToString:kMXRoomHistoryVisibilityShared];
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MatrixSDKVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

#import <Foundation/Foundation.h>

NSString *const MatrixSDKVersion = @"0.23.5";
NSString *const MatrixSDKVersion = @"0.23.6";
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class MXMegolmEncryptionTests: XCTestCase {
return store?.inboundGroupSessions().last?.sharedHistory == true
}

func testResetsSessionIfRoomVisibilityChanges() {
func test_resetsSession_ifRoomVisibilityChanges() {
MXSDKOptions.sharedInstance().enableRoomSharedHistoryOnInvite = true

// The following tests that oubound session Id (and therefore the related inbound session Id)
// is reset whenever the room's history visibility changes from shared to not shared.
Expand Down Expand Up @@ -122,4 +123,78 @@ class MXMegolmEncryptionTests: XCTestCase {
}
}
}

func test_doesNotResetsSession_ifRoomVisibilityChanges_andFeatureDisabled() {
MXSDKOptions.sharedInstance().enableRoomSharedHistoryOnInvite = false

// The following tests that if the feature is disabled, then outbound session Id
// is not reset when room visibility changes
e2eData.doE2ETestWithAlice(inARoom: self) { session, roomId, expectation in

let room = session?.room(withRoomId: roomId)

// 1st set of messages
room?.sendTextMessages(messages: ["Hi", "Hello"]) { _ in

// After first few messages we only expect one inbound and one outbound session
let sessionIds1 = self.storedSessionIds(in: session)
XCTAssertEqual(sessionIds1.outbound.count, 1)
XCTAssertEqual(sessionIds1.inbound.count, 1)
XCTAssertEqual(sessionIds1.inbound, sessionIds1.outbound)
XCTAssertFalse(self.isSharedHistoryInLastSession(for: session))

// 2nd set of messages
room?.sendTextMessages(messages: ["Hi", "Hello"]) { _ in

// After second batch of messages nothing has changed that would require resetting
// of sessions, therefore sessionIds are unchanged
let sessionIds2 = self.storedSessionIds(in: session)
XCTAssertEqual(sessionIds2, sessionIds1)
XCTAssertFalse(self.isSharedHistoryInLastSession(for: session))

// Changing room visibility from shared by default to more restrictive will not reset session keys
room?.setHistoryVisibility(.joined) { _ in

// 3rd set of messages
room?.sendTextMessages(messages: ["Hi", "Hello"]) { _ in

// Sessions are identical as before
let sessionIds3 = self.storedSessionIds(in: session)
XCTAssertEqual(sessionIds3.outbound.count, 1)
XCTAssertEqual(sessionIds3.outbound, sessionIds2.outbound)
XCTAssertEqual(sessionIds3.inbound.count, 1)
XCTAssertEqual(sessionIds3.inbound, sessionIds1.outbound)
XCTAssertFalse(self.isSharedHistoryInLastSession(for: session))

// 4th set of messages
room?.sendTextMessages(messages: ["Hi", "Hello"]) { _ in
// After fourth batch of messages nothing has changed that would require resetting
// of sessions, therefore sessionIds are unchanged
let sessionIds4 = self.storedSessionIds(in: session)
XCTAssertEqual(sessionIds4, sessionIds3)
XCTAssertFalse(self.isSharedHistoryInLastSession(for: session))

// Final visibility change back to shared will still not reset sessions
room?.setHistoryVisibility(.worldReadable) { _ in
room?.sendTextMessages(messages: ["Hi", "Hello"]) { _ in

// Sessions are still identical as before
let sessionIds5 = self.storedSessionIds(in: session)
XCTAssertEqual(sessionIds5.outbound.count, 1)
XCTAssertEqual(sessionIds5.outbound, sessionIds4.outbound)
XCTAssertEqual(sessionIds5.inbound.count, 1)
XCTAssertEqual(sessionIds5.inbound, sessionIds1.outbound)
XCTAssertFalse(self.isSharedHistoryInLastSession(for: session))

session?.close()
expectation?.fulfill()
}
}
}
}
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions MatrixSDKTests/Crypto/Data/MXMegolmSessionDataUnitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import Foundation

class MXMegolmSessionDataUnitTests: XCTestCase {
func testCanInitWithJSONDictionary() {
MXSDKOptions.sharedInstance().enableRoomSharedHistoryOnInvite = true

let jsonDictionary: [String: Any] = [
"sender_key": "A",
"sender_claimed_keys": ["B": "C"],
Expand All @@ -42,6 +44,18 @@ class MXMegolmSessionDataUnitTests: XCTestCase {
XCTAssertEqual(data?.forwardingCurve25519KeyChain, ["H", "I"])
}

func testIgnoreSharedHistoryIfFlagDisabled() {
MXSDKOptions.sharedInstance().enableRoomSharedHistoryOnInvite = false
let jsonDictionary: [String: Any] = [
"org.matrix.msc3061.shared_history": true,
]

let data = MXMegolmSessionData(fromJSON: jsonDictionary)

XCTAssertNotNil(data)
XCTAssertEqual(data?.sharedHistory, false)
}

func testJsonDictionary() {
let data = MXMegolmSessionData()
data.senderKey = "A"
Expand Down
6 changes: 5 additions & 1 deletion MatrixSDKTests/MXCryptoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3235,7 +3235,11 @@ - (void)testIsRoomSharingHistory
@[kMXRoomHistoryVisibilityWorldReadable, @(YES)]
];

// Visibility is set to shared by default
// Visibility is set to not shared by default
XCTAssertFalse([session.crypto isRoomSharingHistory:roomId]);

// But can be enabled with a build flag
MXSDKOptions.sharedInstance.enableRoomSharedHistoryOnInvite = YES;
XCTAssertTrue([session.crypto isRoomSharingHistory:roomId]);

MXRoom *room = [session roomWithRoomId:roomId];
Expand Down

0 comments on commit 4c9efc0

Please sign in to comment.