aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKitTests/OLMKitGroupTests.m
diff options
context:
space:
mode:
authormanuroe <manu@matrix.org>2017-01-17 14:47:41 +0100
committermanuroe <manu@matrix.org>2017-01-17 14:47:41 +0100
commit885b85f5167d2d3ddcbe3de41dc88e8586b01a57 (patch)
treed9d05e75aa7fcf49584cb608ea284899c0eb2cd9 /xcode/OLMKitTests/OLMKitGroupTests.m
parent860740a91ee0efcf3c594ece23ef0a38ddda394e (diff)
OLMKit: Add wrappers for export/import of inbound group sessions
Diffstat (limited to 'xcode/OLMKitTests/OLMKitGroupTests.m')
-rw-r--r--xcode/OLMKitTests/OLMKitGroupTests.m52
1 files changed, 52 insertions, 0 deletions
diff --git a/xcode/OLMKitTests/OLMKitGroupTests.m b/xcode/OLMKitTests/OLMKitGroupTests.m
index ea82295..39ad400 100644
--- a/xcode/OLMKitTests/OLMKitGroupTests.m
+++ b/xcode/OLMKitTests/OLMKitGroupTests.m
@@ -91,4 +91,56 @@
XCTAssertEqualObjects(bobSession2.sessionIdentifier, aliceSession.sessionIdentifier);
}
+- (void)testInboundGroupSessionImportExport {
+
+ NSError *error;
+
+ NSString *sessionKey = @"AgAAAAAwMTIzNDU2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMzQ1Njc4OUFCREVGM" \
+ "DEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkRFRjAxMjM0NTY3ODlBQkNERUYwMTIzND" \
+ "U2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMw0bdg1BDq4Px/slBow06q8n/B9WBfw" \
+ "WYyNOB8DlUmXGGwrFmaSb9bR/eY8xgERrxmP07hFmD9uqA2p8PMHdnV5ysmgufE6oLZ5+" \
+ "8/mWQOW3VVTnDIlnwd8oHUYRuk8TCQ";
+
+ NSString *message = @"AwgAEhAcbh6UpbByoyZxufQ+h2B+8XHMjhR69G8F4+qjMaFlnIXusJZX3r8LnRORG9T3D" \
+ "XFdbVuvIWrLyRfm4i8QRbe8VPwGRFG57B1CtmxanuP8bHtnnYqlwPsD";
+
+ // init first inbound group session, and decrypt */
+ OLMInboundGroupSession *session1 = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:sessionKey error:&error];
+
+ XCTAssertNil(error);
+ XCTAssertTrue(session1.isVerified);
+
+ // decrypt the message
+ NSUInteger messageIndex;
+ NSString *plaintext = [session1 decryptMessage:message messageIndex:&messageIndex error:&error];
+
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(plaintext, @"Message");
+ XCTAssertEqual(messageIndex, 0);
+
+ // export the keys
+ NSString *export = [session1 exportSessionAtMessageIndex:0 error:&error];
+
+ XCTAssertNil(error);
+ XCTAssertGreaterThan(export.length, 0);
+
+ // free the old session to check there is no shared data
+ session1 = nil;
+
+ // import the keys into another inbound group session
+ OLMInboundGroupSession *session2 = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithImportedSession:export error:&error];
+
+ XCTAssertNil(error);
+ XCTAssert(session2);
+ XCTAssertFalse(session2.isVerified);
+
+ // decrypt the message with the new session
+ NSString *plaintext2 = [session2 decryptMessage:message messageIndex:&messageIndex error:&error];
+
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(plaintext2, @"Message");
+ XCTAssertEqual(messageIndex, 0);
+ XCTAssertTrue(session2.isVerified);
+}
+
@end