File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ type sshKeyType = 'rsa' | 'ed25519'
1414export class SshKeyPair {
1515 private publicKeyPath : string
1616 private lifeTimeout : Timeout
17- private deleted : boolean = false
1817
1918 private constructor (
2019 private readonly keyPath : string ,
@@ -79,12 +78,12 @@ export class SshKeyPair {
7978 if ( ! this . lifeTimeout . completed ) {
8079 this . lifeTimeout . cancel ( )
8180 }
82-
83- this . deleted = true
8481 }
8582
86- public isDeleted ( ) : boolean {
87- return this . deleted
83+ public async isDeleted ( ) : Promise < boolean > {
84+ const privateKeyDeleted = ! ( await fs . existsFile ( this . getPrivateKeyPath ( ) ) )
85+ const publicKeyDeleted = ! ( await fs . existsFile ( this . getPublicKeyPath ( ) ) )
86+ return privateKeyDeleted || publicKeyDeleted
8887 }
8988
9089 public timeAlive ( ) : number {
Original file line number Diff line number Diff line change @@ -126,4 +126,32 @@ describe('SshKeyUtility', async function () {
126126 sinon . assert . calledOnce ( deleteStub )
127127 sinon . restore ( )
128128 } )
129+
130+ it ( 'determines deleted status based on file system' , async function ( ) {
131+ await fs . delete ( keyPair . getPrivateKeyPath ( ) )
132+ await fs . delete ( keyPair . getPublicKeyPath ( ) )
133+
134+ assert ( keyPair . isDeleted ( ) )
135+ } )
136+
137+ describe ( 'isDeleted' , async function ( ) {
138+ it ( 'returns false if key files exist' , async function ( ) {
139+ assert . strictEqual ( await keyPair . isDeleted ( ) , false )
140+ } )
141+
142+ it ( 'returns true if key files do not exist' , async function ( ) {
143+ await keyPair . delete ( )
144+ assert . strictEqual ( await keyPair . isDeleted ( ) , true )
145+ } )
146+
147+ it ( 'returns true if private key remains' , async function ( ) {
148+ await fs . delete ( keyPair . getPublicKeyPath ( ) )
149+ assert . strictEqual ( await keyPair . isDeleted ( ) , true )
150+ } )
151+
152+ it ( 'returns true if public key remains' , async function ( ) {
153+ await fs . delete ( keyPair . getPrivateKeyPath ( ) )
154+ assert . strictEqual ( await keyPair . isDeleted ( ) , true )
155+ } )
156+ } )
129157} )
You can’t perform that action at this time.
0 commit comments