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