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.
		
		
		
		
		
			
		
			
				
	
	
		
			109 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			109 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			Swift
		
	
| // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
 | |
| 
 | |
| import Foundation
 | |
| import GRDB
 | |
| 
 | |
| import Quick
 | |
| import Nimble
 | |
| 
 | |
| @testable import SessionUtilitiesKit
 | |
| 
 | |
| class IdentitySpec: QuickSpec {
 | |
|     override class func spec() {
 | |
|         // MARK: Configuration
 | |
|         
 | |
|         @TestState var mockStorage: Storage! = SynchronousStorage(
 | |
|             customWriter: try! DatabaseQueue(),
 | |
|             migrationTargets: [
 | |
|                 SNUtilitiesKit.self
 | |
|             ]
 | |
|         )
 | |
|         
 | |
|         // MARK: - an Identity
 | |
|         describe("an Identity") {
 | |
|             // MARK: -- correctly retrieves the user user public key
 | |
|             it("correctly retrieves the user user public key") {
 | |
|                 mockStorage.write { db in
 | |
|                     try Identity(variant: .x25519PublicKey, data: "Test1".data(using: .utf8)!).insert(db)
 | |
|                 }
 | |
|                 
 | |
|                 mockStorage.read { db in
 | |
|                     expect(Identity.fetchUserPublicKey(db))
 | |
|                         .to(equal("Test1".data(using: .utf8)))
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             // MARK: -- correctly retrieves the user private key
 | |
|             it("correctly retrieves the user private key") {
 | |
|                 mockStorage.write { db in
 | |
|                     try Identity(variant: .x25519PrivateKey, data: "Test2".data(using: .utf8)!).insert(db)
 | |
|                 }
 | |
|                 
 | |
|                 mockStorage.read { db in
 | |
|                     expect(Identity.fetchUserPrivateKey(db))
 | |
|                         .to(equal("Test2".data(using: .utf8)))
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             // MARK: -- correctly retrieves the user key pair
 | |
|             it("correctly retrieves the user key pair") {
 | |
|                 mockStorage.write { db in
 | |
|                     try Identity(variant: .x25519PublicKey, data: "Test3".data(using: .utf8)!).insert(db)
 | |
|                     try Identity(variant: .x25519PrivateKey, data: "Test4".data(using: .utf8)!).insert(db)
 | |
|                 }
 | |
|                 
 | |
|                 mockStorage.read { db in
 | |
|                     let keyPair = Identity.fetchUserKeyPair(db)
 | |
|                     
 | |
|                     expect(keyPair?.publicKey)
 | |
|                         .to(equal("Test3".data(using: .utf8)?.bytes))
 | |
|                     expect(keyPair?.secretKey)
 | |
|                         .to(equal("Test4".data(using: .utf8)?.bytes))
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             // MARK: -- correctly determines if the user exists
 | |
|             it("correctly determines if the user exists") {
 | |
|                 mockStorage.write { db in
 | |
|                     try Identity(variant: .x25519PublicKey, data: "Test3".data(using: .utf8)!).insert(db)
 | |
|                     try Identity(variant: .x25519PrivateKey, data: "Test4".data(using: .utf8)!).insert(db)
 | |
|                 }
 | |
|                 
 | |
|                 mockStorage.read { db in
 | |
|                     expect(Identity.userExists(db))
 | |
|                         .to(equal(true))
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             // MARK: -- correctly retrieves the user ED25519 key pair
 | |
|             it("correctly retrieves the user ED25519 key pair") {
 | |
|                 mockStorage.write { db in
 | |
|                     try Identity(variant: .ed25519PublicKey, data: "Test5".data(using: .utf8)!).insert(db)
 | |
|                     try Identity(variant: .ed25519SecretKey, data: "Test6".data(using: .utf8)!).insert(db)
 | |
|                 }
 | |
|                 
 | |
|                 mockStorage.read { db in
 | |
|                     let keyPair = Identity.fetchUserEd25519KeyPair(db)
 | |
|                     
 | |
|                     expect(keyPair?.publicKey)
 | |
|                         .to(equal("Test5".data(using: .utf8)?.bytes))
 | |
|                     expect(keyPair?.secretKey)
 | |
|                         .to(equal("Test6".data(using: .utf8)?.bytes))
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             // MARK: -- correctly retrieves the hex encoded seed
 | |
|             it("correctly retrieves the hex encoded seed") {
 | |
|                 mockStorage.write { db in
 | |
|                     try Identity(variant: .seed, data: "Test7".data(using: .utf8)!).insert(db)
 | |
|                 }
 | |
|                 
 | |
|                 mockStorage.read { db in
 | |
|                     expect(Identity.fetchHexEncodedSeed(db))
 | |
|                         .to(equal("5465737437"))
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |