diff options
author | manuroe <manu@matrix.org> | 2016-11-14 16:54:51 +0100 |
---|---|---|
committer | manuroe <manu@matrix.org> | 2016-11-14 16:54:51 +0100 |
commit | cf66af6f2e7c69a3e0712317f8473ab09711d426 (patch) | |
tree | 425ad41ff31014973628daa8054772939e53edcd /xcode/OLMKitTests | |
parent | 27a8c28da4e5c62d8863ee3d30642109d713c4d6 (diff) |
OLMKit: Replaced NSAsserts by NSErrors
Diffstat (limited to 'xcode/OLMKitTests')
-rw-r--r-- | xcode/OLMKitTests/OLMKitGroupTests.m | 14 | ||||
-rw-r--r-- | xcode/OLMKitTests/OLMKitTests.m | 56 |
2 files changed, 42 insertions, 28 deletions
diff --git a/xcode/OLMKitTests/OLMKitGroupTests.m b/xcode/OLMKitTests/OLMKitGroupTests.m index cdfb704..43e2df8 100644 --- a/xcode/OLMKitTests/OLMKitGroupTests.m +++ b/xcode/OLMKitTests/OLMKitGroupTests.m @@ -37,6 +37,7 @@ } - (void)testAliceAndBob { + NSError *error; OLMOutboundGroupSession *aliceSession = [[OLMOutboundGroupSession alloc] initOutboundGroupSession]; XCTAssertGreaterThan(aliceSession.sessionIdentifier.length, 0); @@ -47,18 +48,23 @@ NSString *sessionKey = aliceSession.sessionKey; NSString *message = @"Hello!"; - NSString *aliceToBobMsg = [aliceSession encryptMessage:message]; + NSString *aliceToBobMsg = [aliceSession encryptMessage:message error:&error]; XCTAssertEqual(aliceSession.messageIndex, 1); XCTAssertGreaterThanOrEqual(aliceToBobMsg.length, 0); + XCTAssertNil(error); - OLMInboundGroupSession *bobSession = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:sessionKey]; + OLMInboundGroupSession *bobSession = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:sessionKey error:&error]; XCTAssertEqualObjects(aliceSession.sessionIdentifier, bobSession.sessionIdentifier); + XCTAssertNil(error); NSUInteger messageIndex; - NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg messageIndex:&messageIndex]; + + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg messageIndex:&messageIndex error:&error]; XCTAssertEqualObjects(message, plaintext); + XCTAssertEqual(messageIndex, 0); + XCTAssertNil(error); } - (void)testOutboundGroupSessionSerialization { @@ -76,7 +82,7 @@ OLMOutboundGroupSession *aliceSession = [[OLMOutboundGroupSession alloc] initOutboundGroupSession]; - OLMInboundGroupSession *bobSession = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:aliceSession.sessionKey]; + OLMInboundGroupSession *bobSession = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:aliceSession.sessionKey error:nil]; NSData *bobData = [NSKeyedArchiver archivedDataWithRootObject:bobSession]; OLMInboundGroupSession *bobSession2 = [NSKeyedUnarchiver unarchiveObjectWithData:bobData]; diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m index 7edc062..251c90e 100644 --- a/xcode/OLMKitTests/OLMKitTests.m +++ b/xcode/OLMKitTests/OLMKitTests.m @@ -26,6 +26,8 @@ } - (void)testAliceAndBob { + NSError *error; + OLMAccount *alice = [[OLMAccount alloc] initNewAccount]; OLMAccount *bob = [[OLMAccount alloc] initNewAccount]; [bob generateOneTimeKeys:5]; @@ -41,13 +43,15 @@ }]; XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]); - OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey]; + OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey error:nil]; NSString *message = @"Hello!"; - OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message]; + OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message error:&error]; + XCTAssertNil(error); - OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; - NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; + OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext error:nil]; + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg error:&error]; XCTAssertEqualObjects(message, plaintext); + XCTAssertNil(error); BOOL success = [bob removeOneTimeKeysForSession:bobSession]; XCTAssertTrue(success); } @@ -68,12 +72,12 @@ }]; XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]); - OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey]; + OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey error:nil]; NSString *message = @"Hello I'm Alice!"; - OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message]; + OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message error:nil]; - OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; - NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; + OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext error:nil]; + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg error:nil]; XCTAssertEqualObjects(message, plaintext); BOOL success = [bob removeOneTimeKeysForSession:bobSession]; XCTAssertTrue(success); @@ -82,13 +86,13 @@ NSString *msg2 = @"Isn't life grand?"; NSString *msg3 = @"Let's go to the opera."; - OLMMessage *eMsg1 = [bobSession encryptMessage:msg1]; - OLMMessage *eMsg2 = [bobSession encryptMessage:msg2]; - OLMMessage *eMsg3 = [bobSession encryptMessage:msg3]; + OLMMessage *eMsg1 = [bobSession encryptMessage:msg1 error:nil]; + OLMMessage *eMsg2 = [bobSession encryptMessage:msg2 error:nil]; + OLMMessage *eMsg3 = [bobSession encryptMessage:msg3 error:nil]; - NSString *dMsg1 = [aliceSession decryptMessage:eMsg1]; - NSString *dMsg2 = [aliceSession decryptMessage:eMsg2]; - NSString *dMsg3 = [aliceSession decryptMessage:eMsg3]; + NSString *dMsg1 = [aliceSession decryptMessage:eMsg1 error:nil]; + NSString *dMsg2 = [aliceSession decryptMessage:eMsg2 error:nil]; + NSString *dMsg3 = [aliceSession decryptMessage:eMsg3 error:nil]; XCTAssertEqualObjects(msg1, dMsg1); XCTAssertEqualObjects(msg2, dMsg2); XCTAssertEqualObjects(msg3, dMsg3); @@ -113,6 +117,8 @@ } - (void) testSessionSerialization { + NSError *error; + OLMAccount *alice = [[OLMAccount alloc] initNewAccount]; OLMAccount *bob = [[OLMAccount alloc] initNewAccount]; [bob generateOneTimeKeys:1]; @@ -128,12 +134,14 @@ }]; XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]); - OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey]; + OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey error:nil]; NSString *message = @"Hello I'm Alice!"; - OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message]; + OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message error:&error]; + XCTAssertNil(error); + - OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; - NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; + OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext error:nil]; + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg error:nil]; XCTAssertEqualObjects(message, plaintext); BOOL success = [bob removeOneTimeKeysForSession:bobSession]; XCTAssertTrue(success); @@ -142,16 +150,16 @@ NSString *msg2 = @"Isn't life grand?"; NSString *msg3 = @"Let's go to the opera."; - OLMMessage *eMsg1 = [bobSession encryptMessage:msg1]; - OLMMessage *eMsg2 = [bobSession encryptMessage:msg2]; - OLMMessage *eMsg3 = [bobSession encryptMessage:msg3]; + OLMMessage *eMsg1 = [bobSession encryptMessage:msg1 error:nil]; + OLMMessage *eMsg2 = [bobSession encryptMessage:msg2 error:nil]; + OLMMessage *eMsg3 = [bobSession encryptMessage:msg3 error:nil]; NSData *aliceData = [NSKeyedArchiver archivedDataWithRootObject:aliceSession]; OLMSession *alice2 = [NSKeyedUnarchiver unarchiveObjectWithData:aliceData]; - NSString *dMsg1 = [alice2 decryptMessage:eMsg1]; - NSString *dMsg2 = [alice2 decryptMessage:eMsg2]; - NSString *dMsg3 = [alice2 decryptMessage:eMsg3]; + NSString *dMsg1 = [alice2 decryptMessage:eMsg1 error:nil]; + NSString *dMsg2 = [alice2 decryptMessage:eMsg2 error:nil]; + NSString *dMsg3 = [alice2 decryptMessage:eMsg3 error:nil]; XCTAssertEqualObjects(msg1, dMsg1); XCTAssertEqualObjects(msg2, dMsg2); XCTAssertEqualObjects(msg3, dMsg3); |