aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKitTests/OLMKitGroupTests.m
diff options
context:
space:
mode:
authorRichard van der Hoff <github@rvanderhoff.org.uk>2017-01-17 15:16:16 +0000
committerGitHub <noreply@github.com>2017-01-17 15:16:16 +0000
commita45c3cc80957d61065626089eee4ce664ad1615f (patch)
treec467aafb4df13fc31576e49a7909cc2fe2088328 /xcode/OLMKitTests/OLMKitGroupTests.m
parentc14f4b28b985a3ca8f8ff4218c7a2a74cf65a580 (diff)
parentded15597c6736d33bac74d34251c8527e5fa360f (diff)
Merge pull request #44 from matrix-org/manuroe/olmkit-backup
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