mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			116 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			116 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			Objective-C
		
	
//
 | 
						|
//  Copyright (c) 2018 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 <SessionCurve25519Kit/Curve25519.h>
 | 
						|
#import <SessionCoreKit/Randomness.h>
 | 
						|
 | 
						|
extern NSString *const OWSPrimaryStorageTrustedKeysCollection;
 | 
						|
 | 
						|
@interface TSStorageIdentityKeyStoreTests : SSKBaseTestObjC
 | 
						|
 | 
						|
@end
 | 
						|
 | 
						|
@implementation TSStorageIdentityKeyStoreTests
 | 
						|
 | 
						|
- (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];
 | 
						|
}
 | 
						|
 | 
						|
- (void)testNewEmptyKey
 | 
						|
{
 | 
						|
    NSData *newKey = [Randomness generateRandomBytes:32];
 | 
						|
    NSString *recipientId = @"test@gmail.com";
 | 
						|
 | 
						|
    [self
 | 
						|
        readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
 | 
						|
            XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
 | 
						|
                                                                   recipientId:recipientId
 | 
						|
                                                                     direction:TSMessageDirectionOutgoing
 | 
						|
                                                               protocolContext:transaction]);
 | 
						|
            XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
 | 
						|
                                                                   recipientId:recipientId
 | 
						|
                                                                     direction:TSMessageDirectionIncoming
 | 
						|
                                                               protocolContext:transaction]);
 | 
						|
        }];
 | 
						|
}
 | 
						|
 | 
						|
- (void)testAlreadyRegisteredKey
 | 
						|
{
 | 
						|
    NSData *newKey = [Randomness generateRandomBytes:32];
 | 
						|
    NSString *recipientId = @"test@gmail.com";
 | 
						|
 | 
						|
    [self
 | 
						|
        readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
 | 
						|
            [[OWSIdentityManager sharedManager] saveRemoteIdentity:newKey
 | 
						|
                                                       recipientId:recipientId
 | 
						|
                                                   protocolContext:transaction];
 | 
						|
 | 
						|
            XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
 | 
						|
                                                                   recipientId:recipientId
 | 
						|
                                                                     direction:TSMessageDirectionOutgoing
 | 
						|
                                                               protocolContext:transaction]);
 | 
						|
            XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
 | 
						|
                                                                   recipientId:recipientId
 | 
						|
                                                                     direction:TSMessageDirectionIncoming
 | 
						|
                                                               protocolContext:transaction]);
 | 
						|
        }];
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
- (void)testChangedKey
 | 
						|
{
 | 
						|
    NSData *originalKey = [Randomness generateRandomBytes:32];
 | 
						|
    NSString *recipientId = @"test@protonmail.com";
 | 
						|
 | 
						|
    [self
 | 
						|
        readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
 | 
						|
            [[OWSIdentityManager sharedManager] saveRemoteIdentity:originalKey
 | 
						|
                                                       recipientId:recipientId
 | 
						|
                                                   protocolContext:transaction];
 | 
						|
 | 
						|
            XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey
 | 
						|
                                                                   recipientId:recipientId
 | 
						|
                                                                     direction:TSMessageDirectionOutgoing
 | 
						|
                                                               protocolContext:transaction]);
 | 
						|
            XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey
 | 
						|
                                                                   recipientId:recipientId
 | 
						|
                                                                     direction:TSMessageDirectionIncoming
 | 
						|
                                                               protocolContext:transaction]);
 | 
						|
 | 
						|
            NSData *otherKey = [Randomness generateRandomBytes:32];
 | 
						|
 | 
						|
            XCTAssertFalse([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey
 | 
						|
                                                                        recipientId:recipientId
 | 
						|
                                                                          direction:TSMessageDirectionOutgoing
 | 
						|
                                                                    protocolContext:transaction]);
 | 
						|
            XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey
 | 
						|
                                                                   recipientId:recipientId
 | 
						|
                                                                     direction:TSMessageDirectionIncoming
 | 
						|
                                                               protocolContext:transaction]);
 | 
						|
        }];
 | 
						|
}
 | 
						|
 | 
						|
- (void)testIdentityKey
 | 
						|
{
 | 
						|
    [[OWSIdentityManager sharedManager] generateNewIdentityKeyPair];
 | 
						|
 | 
						|
    XCTAssert([[[OWSIdentityManager sharedManager] identityKeyPair].publicKey length] == 32);
 | 
						|
}
 | 
						|
 | 
						|
@end
 |