aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKitTests/OLMKitTests.m
diff options
context:
space:
mode:
authorChris Ballinger <chrisballinger@gmail.com>2016-04-09 14:00:30 -0700
committerChris Ballinger <chrisballinger@gmail.com>2016-04-09 14:00:30 -0700
commitf505113fb7a6d61015ad8050b3fb4e26df029150 (patch)
tree0bdaba8f07189f3adc828c2895ce7429d9b3cb3e /xcode/OLMKitTests/OLMKitTests.m
parent719eb543a8d08c4f536ea7933ffb3af0a8553e87 (diff)
Initial test passing
Diffstat (limited to 'xcode/OLMKitTests/OLMKitTests.m')
-rw-r--r--xcode/OLMKitTests/OLMKitTests.m25
1 files changed, 21 insertions, 4 deletions
diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m
index 944d11c..7075057 100644
--- a/xcode/OLMKitTests/OLMKitTests.m
+++ b/xcode/OLMKitTests/OLMKitTests.m
@@ -31,10 +31,27 @@
OLMAccount *alice = [[OLMAccount alloc] initNewAccount];
OLMAccount *bob = [[OLMAccount alloc] initNewAccount];
[bob generateOneTimeKeys:5];
- NSDictionary *identityKeys = bob.identityKeys;
- NSDictionary *oneTimeKeys = bob.oneTimeKeys;
- NSParameterAssert(identityKeys != nil);
- NSParameterAssert(oneTimeKeys != nil);
+ NSDictionary *bobIdKeys = bob.identityKeys;
+ NSString *bobIdKey = bobIdKeys[@"curve25519"];
+ NSDictionary *bobOneTimeKeys = bob.oneTimeKeys;
+ NSParameterAssert(bobIdKey != nil);
+ NSParameterAssert(bobOneTimeKeys != nil);
+ __block NSString *bobOneTimeKey = nil;
+ NSDictionary *bobOtkCurve25519 = bobOneTimeKeys[@"curve25519"];
+ [bobOtkCurve25519 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
+ bobOneTimeKey = obj;
+ }];
+ XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]);
+
+ OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey];
+ NSString *message = @"Hello!";
+ OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message];
+
+ OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext];
+ NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg];
+ XCTAssertEqualObjects(message, plaintext);
+ BOOL success = [bobSession removeOneTimeKeys];
+ XCTAssertTrue(success);
}