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.
64 lines
1.9 KiB
Objective-C
64 lines
1.9 KiB
Objective-C
//
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "OWSPrimaryStorage+PreKeyStore.h"
|
|
#import "SSKBaseTest.h"
|
|
|
|
@interface TSStoragePreKeyStoreTests : SSKBaseTest
|
|
|
|
@end
|
|
|
|
@implementation TSStoragePreKeyStoreTests
|
|
|
|
- (void)setUp
|
|
{
|
|
[super setUp];
|
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
}
|
|
|
|
- (void)tearDown
|
|
{
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
[super tearDown];
|
|
}
|
|
|
|
- (void)testGeneratingAndStoringPreKeys
|
|
{
|
|
NSArray *generatedKeys = [[OWSPrimaryStorage sharedManager] generatePreKeyRecords];
|
|
|
|
|
|
XCTAssert([generatedKeys count] == 100, @"Not hundred keys generated");
|
|
|
|
[[OWSPrimaryStorage sharedManager] storePreKeyRecords:generatedKeys];
|
|
|
|
PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject];
|
|
PreKeyRecord *firstPreKeyRecord = [generatedKeys firstObject];
|
|
|
|
XCTAssert([[[OWSPrimaryStorage sharedManager] loadPreKey:lastPreKeyRecord.Id].keyPair.publicKey
|
|
isEqualToData:lastPreKeyRecord.keyPair.publicKey]);
|
|
|
|
XCTAssert([[[OWSPrimaryStorage sharedManager] loadPreKey:firstPreKeyRecord.Id].keyPair.publicKey
|
|
isEqualToData:firstPreKeyRecord.keyPair.publicKey]);
|
|
}
|
|
|
|
|
|
- (void)testRemovingPreKeys
|
|
{
|
|
NSArray *generatedKeys = [[OWSPrimaryStorage sharedManager] generatePreKeyRecords];
|
|
|
|
XCTAssert([generatedKeys count] == 100, @"Not hundred keys generated");
|
|
|
|
[[OWSPrimaryStorage sharedManager] storePreKeyRecords:generatedKeys];
|
|
|
|
PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject];
|
|
PreKeyRecord *firstPreKeyRecord = [generatedKeys firstObject];
|
|
|
|
[[OWSPrimaryStorage sharedManager] removePreKey:lastPreKeyRecord.Id];
|
|
|
|
XCTAssertThrows([[OWSPrimaryStorage sharedManager] loadPreKey:lastPreKeyRecord.Id]);
|
|
XCTAssertNoThrow([[OWSPrimaryStorage sharedManager] loadPreKey:firstPreKeyRecord.Id]);
|
|
}
|
|
|
|
@end
|