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.
		
		
		
		
		
			
		
			
				
	
	
		
			76 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			76 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Objective-C
		
	
| //
 | |
| //  Copyright (c) 2017 Open Whisper Systems. All rights reserved.
 | |
| //
 | |
| 
 | |
| #import <XCTest/XCTest.h>
 | |
| #import <25519/Curve25519.h>
 | |
| 
 | |
| #import "OWSUnitTestEnvironment.h"
 | |
| #import "SecurityUtils.h"
 | |
| #import "OWSIdentityManager.h"
 | |
| #import "OWSRecipientIdentity.h"
 | |
| #import "TSStorageManager.h"
 | |
| #import "TextSecureKitEnv.h"
 | |
| 
 | |
| @interface TSStorageIdentityKeyStoreTests : XCTestCase
 | |
| 
 | |
| @end
 | |
| 
 | |
| @implementation TSStorageIdentityKeyStoreTests
 | |
| 
 | |
| - (void)setUp {
 | |
|     [super setUp];
 | |
|     
 | |
|     [[TSStorageManager sharedManager] purgeCollection:@"TSStorageManagerTrustedKeysCollection"];
 | |
|     [OWSRecipientIdentity removeAllObjectsInCollection];
 | |
| }
 | |
| 
 | |
| - (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 = [SecurityUtils generateRandomBytes:32];
 | |
|     NSString *recipientId = @"test@gmail.com";
 | |
|     
 | |
|     XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
 | |
|     XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
 | |
| }
 | |
| 
 | |
| - (void)testAlreadyRegisteredKey {
 | |
|     NSData *newKey = [SecurityUtils generateRandomBytes:32];
 | |
|     NSString *recipientId = @"test@gmail.com";
 | |
|     
 | |
|     [[OWSIdentityManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
 | |
|     
 | |
|     XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
 | |
|     XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
 | |
| }
 | |
| 
 | |
| 
 | |
| - (void)testChangedKey
 | |
| {
 | |
|     NSData *originalKey = [SecurityUtils generateRandomBytes:32];
 | |
|     NSString *recipientId = @"test@protonmail.com";
 | |
| 
 | |
|     [[OWSIdentityManager sharedManager] saveRemoteIdentity:originalKey recipientId:recipientId];
 | |
|     
 | |
|     XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
 | |
|     XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
 | |
|     
 | |
|     NSData *otherKey = [SecurityUtils generateRandomBytes:32];
 | |
|     
 | |
|     XCTAssertFalse([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
 | |
|     XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
 | |
| }
 | |
| 
 | |
| 
 | |
| - (void)testIdentityKey {
 | |
|     [[OWSIdentityManager sharedManager] generateNewIdentityKey];
 | |
|     
 | |
|     XCTAssert([[[OWSIdentityManager sharedManager] identityKeyPair].publicKey length] == 32);
 | |
| }
 | |
| 
 | |
| @end
 |