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.
96 lines
3.7 KiB
Matlab
96 lines
3.7 KiB
Matlab
10 years ago
|
//
|
||
7 years ago
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
10 years ago
|
//
|
||
|
|
||
8 years ago
|
#import "OWSIdentityManager.h"
|
||
7 years ago
|
#import "OWSPrimaryStorage.h"
|
||
8 years ago
|
#import "OWSRecipientIdentity.h"
|
||
7 years ago
|
#import "OWSUnitTestEnvironment.h"
|
||
7 years ago
|
#import "SSKBaseTest.h"
|
||
7 years ago
|
#import "SSKEnvironment.h"
|
||
7 years ago
|
#import "SecurityUtils.h"
|
||
|
#import <Curve25519Kit/Curve25519.h>
|
||
10 years ago
|
|
||
7 years ago
|
@interface TSStorageIdentityKeyStoreTests : SSKBaseTest
|
||
10 years ago
|
|
||
|
@end
|
||
|
|
||
|
@implementation TSStorageIdentityKeyStoreTests
|
||
|
|
||
7 years ago
|
- (void)setUp
|
||
|
{
|
||
10 years ago
|
[super setUp];
|
||
7 years ago
|
|
||
|
[[OWSPrimaryStorage sharedManager] purgeCollection:OWSPrimaryStorageTrustedKeysCollection];
|
||
8 years ago
|
[OWSRecipientIdentity removeAllObjectsInCollection];
|
||
10 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)tearDown
|
||
|
{
|
||
10 years ago
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||
|
[super tearDown];
|
||
|
}
|
||
|
|
||
7 years ago
|
- (void)testNewEmptyKey
|
||
|
{
|
||
10 years ago
|
NSData *newKey = [SecurityUtils generateRandomBytes:32];
|
||
|
NSString *recipientId = @"test@gmail.com";
|
||
7 years ago
|
|
||
|
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionOutgoing]);
|
||
|
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionIncoming]);
|
||
10 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)testAlreadyRegisteredKey
|
||
|
{
|
||
10 years ago
|
NSData *newKey = [SecurityUtils generateRandomBytes:32];
|
||
|
NSString *recipientId = @"test@gmail.com";
|
||
7 years ago
|
|
||
8 years ago
|
[[OWSIdentityManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
|
||
7 years ago
|
|
||
|
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionOutgoing]);
|
||
|
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionIncoming]);
|
||
10 years ago
|
}
|
||
|
|
||
|
|
||
8 years ago
|
- (void)testChangedKey
|
||
9 years ago
|
{
|
||
8 years ago
|
NSData *originalKey = [SecurityUtils generateRandomBytes:32];
|
||
|
NSString *recipientId = @"test@protonmail.com";
|
||
9 years ago
|
|
||
8 years ago
|
[[OWSIdentityManager sharedManager] saveRemoteIdentity:originalKey recipientId:recipientId];
|
||
7 years ago
|
|
||
|
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionOutgoing]);
|
||
|
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionIncoming]);
|
||
|
|
||
10 years ago
|
NSData *otherKey = [SecurityUtils generateRandomBytes:32];
|
||
7 years ago
|
|
||
|
XCTAssertFalse([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionOutgoing]);
|
||
|
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey
|
||
|
recipientId:recipientId
|
||
|
direction:TSMessageDirectionIncoming]);
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
|
||
7 years ago
|
- (void)testIdentityKey
|
||
|
{
|
||
8 years ago
|
[[OWSIdentityManager sharedManager] generateNewIdentityKey];
|
||
7 years ago
|
|
||
8 years ago
|
XCTAssert([[[OWSIdentityManager sharedManager] identityKeyPair].publicKey length] == 32);
|
||
10 years ago
|
}
|
||
|
|
||
|
@end
|