@@ -38,25 +38,36 @@ describe('SshKeyUtility', async function () {
3838 sinon . restore ( )
3939 } )
4040
41- describe ( 'generateSshKeys' , async function ( ) {
42- it ( 'generates key in target file' , async function ( ) {
43- const contents = await vscode . workspace . fs . readFile ( vscode . Uri . file ( keyPath ) )
44- assert . notStrictEqual ( contents . length , 0 )
45- } )
46-
47- it ( 'generates unique key each time' , async function ( ) {
48- const beforeContent = await vscode . workspace . fs . readFile ( vscode . Uri . file ( keyPath ) )
49- keyPair = await SshKeyPair . getSshKeyPair ( keyPath , 30000 )
50- const afterContent = await vscode . workspace . fs . readFile ( vscode . Uri . file ( keyPath ) )
51- assert . notStrictEqual ( beforeContent , afterContent )
52- } )
53-
54- it ( 'uses ed25519 algorithm to generate the keys' , async function ( ) {
55- const process = new ChildProcess ( `ssh-keygen` , [ '-vvv' , '-l' , '-f' , keyPath ] )
56- const result = await process . run ( )
57- // Check private key header for algorithm name
58- assert . strictEqual ( result . stdout . includes ( '[ED25519 256]' ) , true )
59- } )
41+ it ( 'generates key in target file' , async function ( ) {
42+ const contents = await fs . readFile ( vscode . Uri . file ( keyPath ) )
43+ assert . notStrictEqual ( contents . length , 0 )
44+ } )
45+
46+ it ( 'generates unique key each time' , async function ( ) {
47+ const beforeContent = await fs . readFile ( vscode . Uri . file ( keyPath ) )
48+ keyPair = await SshKeyPair . getSshKeyPair ( keyPath , 30000 )
49+ const afterContent = await fs . readFile ( vscode . Uri . file ( keyPath ) )
50+ assert . notStrictEqual ( beforeContent , afterContent )
51+ } )
52+
53+ it ( 'defaults to ed25519 key type' , async function ( ) {
54+ const process = new ChildProcess ( `ssh-keygen` , [ '-vvv' , '-l' , '-f' , keyPath ] )
55+ const result = await process . run ( )
56+ // Check private key header for algorithm name
57+ assert . strictEqual ( result . stdout . includes ( '[ED25519 256]' ) , true )
58+ } )
59+
60+ it ( 'falls back on rsa if ed25519 not available' , async function ( ) {
61+ await keyPair . delete ( )
62+ const stub = sinon . stub ( SshKeyPair , 'tryKeyGen' )
63+ stub . onFirstCall ( ) . resolves ( false )
64+ stub . callThrough ( )
65+ keyPair = await SshKeyPair . getSshKeyPair ( keyPath , 30000 )
66+ const process = new ChildProcess ( `ssh-keygen` , [ '-vvv' , '-l' , '-f' , keyPath ] )
67+ const result = await process . run ( )
68+ // Check private key header for algorithm name
69+ assert . strictEqual ( result . stdout . includes ( '[RSA' ) , true )
70+ stub . restore ( )
6071 } )
6172
6273 it ( 'properly names the public key' , function ( ) {
@@ -70,10 +81,10 @@ describe('SshKeyUtility', async function () {
7081
7182 it ( 'does overwrite existing keys on get call' , async function ( ) {
7283 const generateStub = sinon . spy ( SshKeyPair , 'generateSshKeyPair' )
73- const keyBefore = await vscode . workspace . fs . readFile ( vscode . Uri . file ( keyPath ) )
84+ const keyBefore = await fs . readFile ( vscode . Uri . file ( keyPath ) )
7485 keyPair = await SshKeyPair . getSshKeyPair ( keyPath , 30000 )
7586
76- const keyAfter = await vscode . workspace . fs . readFile ( vscode . Uri . file ( keyPath ) )
87+ const keyAfter = await fs . readFile ( vscode . Uri . file ( keyPath ) )
7788 sinon . assert . calledOnce ( generateStub )
7889
7990 assert . notStrictEqual ( keyBefore , keyAfter )
0 commit comments