import { SecureStore } from '../../extension/util/SecureStore' ; import { SecureStoreFactory } from '../../extension/util/SecureStoreFactory' ; import { KeytarSecureStore } from '../../extension/util/KeytarSecureStore' ; import { ModuleUtil } from '../../extension/util/ModuleUtil' ; import { FileSystemSecureStore } from '../../extension/util/FileSystemSecureStore' ; import * as chai from 'chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import * as path from 'path' ; import * as sinon from 'sinon' ; import * as vscode from 'vscode' ; import { SettingConfigurations } from '../../extension/configurations' ; import { FileSystemUtil } from 'ibm-blockchain-platform-common' ; chai . should ( ) ; chai . use ( chaiAsPromised ) ; describe ( 'SecureStoreFactory' , ( ) => { let sandbox ; beforeEach ( ( ) => { sandbox = sinon . createSandbox ( ) ; } ) ; afterEach ( ( ) => { sandbox . restore ( ) ; } ) ; describe ( '#getSecureStore' , ( ) => { it ( 'should return a keytar secure store if keytar is available' , async ( ) => { sandbox . stub ( ModuleUtil , 'getCoreNodeModule' ) . withArgs ( 'keytar' ) . returns ( { fake : 'keytar' } ) ; const secureStore = await SecureStoreFactory . getSecureStore ( ) ; secureStore . should . be . an . instanceOf ( KeytarSecureStore ) ; secureStore [ 'keytar' ] . should . deep . equal ( { fake : 'keytar' } ) ; } ) ; it ( 'should return a file system secure store if keytar is not available' , async ( ) => { sandbox . stub ( ModuleUtil , 'getCoreNodeModule' ) . withArgs ( 'keytar' ) . returns ( undefined ) ; const secureStore = await SecureStoreFactory . getSecureStore ( ) ; secureStore . should . be . an . instanceOf ( FileSystemSecureStore ) ; const extensionDirectory = vscode . workspace . getConfiguration ( ) . get ( SettingConfigurations . EXTENSION_DIRECTORY ) ; const resolvedExtensionDirectory = FileSystemUtil . getDirPath ( extensionDirectory ) ; const storePath = path . join ( resolvedExtensionDirectory , 'ibm-blockchain-platform.store' ) ; secureStore [ 'path' ] . should . equal ( storePath ) ; } ) ; } ) ; } ) ;