@@ -15,6 +15,13 @@ import {
1515 createLegacyServerSet ,
1616 createModernServerSet ,
1717 createSetWithCategory ,
18+ createModernOnlyClientSet ,
19+ createMinimalLegacyServerSet ,
20+ createStrictServerSet ,
21+ createUnknownServerSet ,
22+ createModernCompatibleServerSet ,
23+ createCompatibleClientSet ,
24+ createModernClientSet ,
1825 type AlgorithmSet
1926} from './algorithm-test-fixtures.js'
2027
@@ -148,21 +155,8 @@ describe('analyzeAlgorithms', () => {
148155
149156 describe ( 'preset suggestion' , ( ) => {
150157 it ( 'suggests legacy preset for servers with only legacy algorithms' , ( ) => {
151- // Modern client with no overlap with legacy server
152- const client : AlgorithmSet = {
153- kex : [ 'curve25519-sha256' ] ,
154- serverHostKey : [ 'ssh-ed25519' ] ,
155- cipher : [ 'aes256-gcm@openssh.com' ] ,
156- mac : [ 'hmac-sha2-256' ] ,
157- compress : [ 'none' ]
158- }
159- const server : AlgorithmSet = {
160- kex : [ 'diffie-hellman-group14-sha1' ] ,
161- serverHostKey : [ 'ssh-rsa' ] ,
162- cipher : [ 'aes128-cbc' ] ,
163- mac : [ 'hmac-sha1' ] ,
164- compress : [ 'none' ]
165- }
158+ const client = createModernOnlyClientSet ( )
159+ const server = createMinimalLegacyServerSet ( )
166160
167161 const analysis = analyzeAlgorithms ( client , server )
168162 expect ( analysis . suggestedPreset ) . toBe ( 'legacy' )
@@ -179,20 +173,8 @@ describe('analyzeAlgorithms', () => {
179173
180174 describe ( 'env var suggestions' , ( ) => {
181175 it ( 'generates suggestions for mismatched categories' , ( ) => {
182- const client : AlgorithmSet = {
183- kex : [ 'curve25519-sha256' ] ,
184- serverHostKey : [ 'ssh-ed25519' ] ,
185- cipher : [ 'aes256-gcm@openssh.com' ] ,
186- mac : [ 'hmac-sha2-256' ] ,
187- compress : [ 'none' ]
188- }
189- const server : AlgorithmSet = {
190- kex : [ 'diffie-hellman-group14-sha1' ] ,
191- serverHostKey : [ 'ssh-rsa' ] ,
192- cipher : [ 'aes128-cbc' ] ,
193- mac : [ 'hmac-sha1' ] ,
194- compress : [ 'none' ]
195- }
176+ const client = createModernOnlyClientSet ( )
177+ const server = createMinimalLegacyServerSet ( )
196178
197179 const analysis = analyzeAlgorithms ( client , server )
198180
@@ -203,20 +185,12 @@ describe('analyzeAlgorithms', () => {
203185 } )
204186
205187 it ( 'does not generate suggestions for categories with matches' , ( ) => {
188+ // Client with KEX fallback that matches server
206189 const client : AlgorithmSet = {
207- kex : [ 'curve25519-sha256' , 'diffie-hellman-group14-sha1' ] ,
208- serverHostKey : [ 'ssh-ed25519' ] ,
209- cipher : [ 'aes256-gcm@openssh.com' ] ,
210- mac : [ 'hmac-sha2-256' ] ,
211- compress : [ 'none' ]
212- }
213- const server : AlgorithmSet = {
214- kex : [ 'diffie-hellman-group14-sha1' ] ,
215- serverHostKey : [ 'ssh-rsa' ] ,
216- cipher : [ 'aes128-cbc' ] ,
217- mac : [ 'hmac-sha1' ] ,
218- compress : [ 'none' ]
190+ ...createModernOnlyClientSet ( ) ,
191+ kex : [ 'curve25519-sha256' , 'diffie-hellman-group14-sha1' ]
219192 }
193+ const server = createMinimalLegacyServerSet ( )
220194
221195 const analysis = analyzeAlgorithms ( client , server )
222196
@@ -235,61 +209,18 @@ describe('analyzeAlgorithms', () => {
235209 } )
236210} )
237211
238- describe ( 'suggestPreset' , ( ) => {
239- it ( 'suggests strict preset for strict-compatible servers' , ( ) => {
240- const server : AlgorithmSet = {
241- kex : [ 'ecdh-sha2-nistp256' , 'curve25519-sha256' ] ,
242- serverHostKey : [ 'ecdsa-sha2-nistp256' , 'ssh-ed25519' ] ,
243- cipher : [ 'aes256-gcm@openssh.com' , 'aes128-gcm@openssh.com' ] ,
244- mac : [ 'hmac-sha2-256' , 'hmac-sha2-512' ] ,
245- compress : [ 'none' ]
246- }
247-
248- expect ( suggestPreset ( server ) ) . toBe ( 'strict' )
249- } )
250-
251- it ( 'suggests modern preset for servers that need modern but not strict' , ( ) => {
252- // Server only supports algorithms in modern preset but NOT in strict preset
253- const server : AlgorithmSet = {
254- kex : [ 'ecdh-sha2-nistp384' ] , // In modern, NOT in strict
255- serverHostKey : [ 'ecdsa-sha2-nistp384' ] , // In modern, NOT in strict
256- cipher : [ 'aes128-ctr' ] , // In modern, NOT in strict
257- mac : [ 'hmac-sha2-512' ] , // In modern, NOT in strict
258- compress : [ 'none' ]
259- }
260-
261- expect ( suggestPreset ( server ) ) . toBe ( 'modern' )
262- } )
263-
264- it ( 'suggests legacy preset for legacy servers' , ( ) => {
265- const server : AlgorithmSet = {
266- kex : [ 'diffie-hellman-group14-sha1' , 'diffie-hellman-group1-sha1' ] ,
267- serverHostKey : [ 'ssh-rsa' , 'ssh-dss' ] ,
268- cipher : [ 'aes128-cbc' , '3des-cbc' ] ,
269- mac : [ 'hmac-sha1' , 'hmac-md5' ] ,
270- compress : [ 'none' ]
271- }
272-
273- expect ( suggestPreset ( server ) ) . toBe ( 'legacy' )
274- } )
275-
276- it ( 'returns null for servers with completely incompatible algorithms' , ( ) => {
277- const server : AlgorithmSet = {
278- kex : [ 'unknown-kex-algorithm' ] ,
279- serverHostKey : [ 'unknown-hostkey' ] ,
280- cipher : [ 'unknown-cipher' ] ,
281- mac : [ 'unknown-mac' ] ,
282- compress : [ 'none' ]
283- }
284-
285- expect ( suggestPreset ( server ) ) . toBeNull ( )
286- } )
287-
288- it ( 'handles empty server algorithm set' , ( ) => {
289- const server = createEmptyAlgorithmSet ( )
212+ // Test cases for suggestPreset function
213+ const PRESET_TEST_CASES = [
214+ { name : 'strict-compatible server' , createServer : createStrictServerSet , expected : 'strict' } ,
215+ { name : 'modern-compatible server' , createServer : createModernCompatibleServerSet , expected : 'modern' } ,
216+ { name : 'legacy server' , createServer : createLegacyServerSet , expected : 'legacy' } ,
217+ { name : 'unknown server' , createServer : createUnknownServerSet , expected : null } ,
218+ { name : 'empty server' , createServer : createEmptyAlgorithmSet , expected : 'strict' }
219+ ] as const
290220
291- // Empty set should match any preset since there are no requirements
292- expect ( suggestPreset ( server ) ) . toBe ( 'strict' )
221+ describe ( 'suggestPreset' , ( ) => {
222+ it . each ( PRESET_TEST_CASES ) ( 'returns $expected for $name' , ( { createServer, expected } ) => {
223+ expect ( suggestPreset ( createServer ( ) ) ) . toBe ( expected )
293224 } )
294225} )
295226
@@ -347,20 +278,8 @@ describe('generateEnvVarSuggestions', () => {
347278
348279describe ( 'Integration: realistic algorithm mismatch scenarios' , ( ) => {
349280 it ( 'analyzes modern client vs legacy server' , ( ) => {
350- const client : AlgorithmSet = {
351- kex : [ 'curve25519-sha256' , 'ecdh-sha2-nistp256' ] ,
352- serverHostKey : [ 'ssh-ed25519' , 'ecdsa-sha2-nistp256' ] ,
353- cipher : [ 'aes256-gcm@openssh.com' , 'aes128-gcm@openssh.com' ] ,
354- mac : [ 'hmac-sha2-256-etm@openssh.com' , 'hmac-sha2-256' ] ,
355- compress : [ 'none' , 'zlib@openssh.com' ]
356- }
357- const server : AlgorithmSet = {
358- kex : [ 'diffie-hellman-group14-sha1' ] ,
359- serverHostKey : [ 'ssh-rsa' ] ,
360- cipher : [ 'aes128-cbc' , '3des-cbc' ] ,
361- mac : [ 'hmac-sha1' ] ,
362- compress : [ 'none' ]
363- }
281+ const client = createModernClientSet ( )
282+ const server = createMinimalLegacyServerSet ( )
364283
365284 const analysis = analyzeAlgorithms ( client , server )
366285
@@ -381,20 +300,8 @@ describe('Integration: realistic algorithm mismatch scenarios', () => {
381300 } )
382301
383302 it ( 'analyzes compatible client and server' , ( ) => {
384- const client : AlgorithmSet = {
385- kex : [ 'curve25519-sha256' , 'ecdh-sha2-nistp256' , 'diffie-hellman-group14-sha1' ] ,
386- serverHostKey : [ 'ssh-ed25519' , 'ssh-rsa' ] ,
387- cipher : [ 'aes256-gcm@openssh.com' , 'aes128-cbc' ] ,
388- mac : [ 'hmac-sha2-256' , 'hmac-sha1' ] ,
389- compress : [ 'none' ]
390- }
391- const server : AlgorithmSet = {
392- kex : [ 'diffie-hellman-group14-sha1' ] ,
393- serverHostKey : [ 'ssh-rsa' ] ,
394- cipher : [ 'aes128-cbc' ] ,
395- mac : [ 'hmac-sha1' ] ,
396- compress : [ 'none' ]
397- }
303+ const client = createCompatibleClientSet ( )
304+ const server = createMinimalLegacyServerSet ( )
398305
399306 const analysis = analyzeAlgorithms ( client , server )
400307
0 commit comments