- Migrate protocol stores to KVStores - Introduce AnyDatabaseQueue - Move messaging pipeline to AnyTransactions - Migrate specialized PushDecrypt job to generic JobQueue
119 lines
4.5 KiB
Objective-C
119 lines
4.5 KiB
Objective-C
//
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "MockSSKEnvironment.h"
|
|
#import "OWSIdentityManager.h"
|
|
#import "OWSPrimaryStorage.h"
|
|
#import "OWSRecipientIdentity.h"
|
|
#import "SSKBaseTestObjC.h"
|
|
#import "SSKEnvironment.h"
|
|
#import "YapDatabaseConnection+OWS.h"
|
|
#import <Curve25519Kit/Curve25519.h>
|
|
#import <SignalCoreKit/Randomness.h>
|
|
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
|
|
|
extern NSString *const OWSPrimaryStorageTrustedKeysCollection;
|
|
|
|
@interface OWSIdentityManagerTests : SSKBaseTestObjC
|
|
|
|
@end
|
|
|
|
@implementation OWSIdentityManagerTests
|
|
|
|
- (void)setUp
|
|
{
|
|
[super setUp];
|
|
}
|
|
|
|
- (void)tearDown
|
|
{
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
[super tearDown];
|
|
}
|
|
|
|
- (OWSIdentityManager *)identityManager
|
|
{
|
|
return [OWSIdentityManager sharedManager];
|
|
}
|
|
|
|
- (void)testNewEmptyKey
|
|
{
|
|
NSData *newKey = [Randomness generateRandomBytes:32];
|
|
NSString *recipientId = @"test@gmail.com";
|
|
|
|
[self writeWithBlock:^(SDSAnyWriteTransaction *transaction) {
|
|
XCTAssert([self.identityManager isTrustedIdentityKey:newKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionOutgoing
|
|
transaction:transaction]);
|
|
XCTAssert([self.identityManager isTrustedIdentityKey:newKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionIncoming
|
|
transaction:transaction]);
|
|
}];
|
|
}
|
|
|
|
- (void)testAlreadyRegisteredKey
|
|
{
|
|
NSData *newKey = [Randomness generateRandomBytes:32];
|
|
NSString *recipientId = @"test@gmail.com";
|
|
|
|
[self writeWithBlock:^(SDSAnyWriteTransaction *transaction) {
|
|
[self.identityManager saveRemoteIdentity:newKey
|
|
recipientId:recipientId
|
|
transaction:transaction];
|
|
|
|
XCTAssert([self.identityManager isTrustedIdentityKey:newKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionOutgoing
|
|
transaction:transaction]);
|
|
XCTAssert([self.identityManager isTrustedIdentityKey:newKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionIncoming
|
|
transaction:transaction]);
|
|
}];
|
|
}
|
|
|
|
|
|
- (void)testChangedKey
|
|
{
|
|
NSData *originalKey = [Randomness generateRandomBytes:32];
|
|
NSString *recipientId = @"test@protonmail.com";
|
|
|
|
[self writeWithBlock:^(SDSAnyWriteTransaction *transaction) {
|
|
[self.identityManager saveRemoteIdentity:originalKey
|
|
recipientId:recipientId
|
|
transaction:transaction];
|
|
|
|
XCTAssert([self.identityManager isTrustedIdentityKey:originalKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionOutgoing
|
|
transaction:transaction]);
|
|
XCTAssert([self.identityManager isTrustedIdentityKey:originalKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionIncoming
|
|
transaction:transaction]);
|
|
|
|
NSData *otherKey = [Randomness generateRandomBytes:32];
|
|
|
|
XCTAssertFalse([self.identityManager isTrustedIdentityKey:otherKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionOutgoing
|
|
transaction:transaction]);
|
|
XCTAssert([self.identityManager isTrustedIdentityKey:otherKey
|
|
recipientId:recipientId
|
|
direction:TSMessageDirectionIncoming
|
|
transaction:transaction]);
|
|
}];
|
|
}
|
|
|
|
- (void)testIdentityKey
|
|
{
|
|
[self.identityManager generateNewIdentityKey];
|
|
|
|
XCTAssert([[self.identityManager identityKeyPair].publicKey length] == 32);
|
|
}
|
|
|
|
@end
|