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'
14
14
export class SshKeyPair {
15
15
private publicKeyPath : string
16
16
private lifeTimeout : Timeout
17
- private deleted : boolean = false
18
17
19
18
private constructor (
20
19
private readonly keyPath : string ,
@@ -79,12 +78,12 @@ export class SshKeyPair {
79
78
if ( ! this . lifeTimeout . completed ) {
80
79
this . lifeTimeout . cancel ( )
81
80
}
82
-
83
- this . deleted = true
84
81
}
85
82
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
88
87
}
89
88
90
89
public timeAlive ( ) : number {
Original file line number Diff line number Diff line change @@ -126,4 +126,32 @@ describe('SshKeyUtility', async function () {
126
126
sinon . assert . calledOnce ( deleteStub )
127
127
sinon . restore ( )
128
128
} )
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
+ } )
129
157
} )
You can’t perform that action at this time.
0 commit comments