@@ -3,8 +3,10 @@ package com.coder.gateway.cli
33import com.coder.gateway.cli.ex.MissingVersionException
44import com.coder.gateway.cli.ex.ResponseException
55import com.coder.gateway.cli.ex.SSHConfigFormatException
6- import com.coder.gateway.settings.CoderSettingsState
6+ import com.coder.gateway.settings.CODER_SSH_CONFIG_OPTIONS
77import com.coder.gateway.settings.CoderSettings
8+ import com.coder.gateway.settings.CoderSettingsState
9+ import com.coder.gateway.settings.Environment
810import com.coder.gateway.util.InvalidVersionException
911import com.coder.gateway.util.OS
1012import com.coder.gateway.util.SemVer
@@ -238,34 +240,43 @@ internal class CoderCLIManagerTest {
238240 val input : String? ,
239241 val output : String ,
240242 val remove : String ,
241- val headerCommand : String? ,
243+ val headerCommand : String = " " ,
242244 val disableAutostart : Boolean = false ,
243- val features : Features ? = null ,
245+ val features : Features = Features (),
246+ val extraConfig : String = " " ,
247+ val env : Environment = Environment (),
244248 )
245249
246250 @Test
247251 fun testConfigureSSH () {
252+ val extraConfig = listOf (
253+ " ServerAliveInterval 5" ,
254+ " ServerAliveCountMax 3" ).joinToString(System .lineSeparator())
248255 val tests = listOf (
249- SSHTest (listOf (" foo" , " bar" ), null ," multiple-workspaces" , " blank" , null ),
250- SSHTest (listOf (" foo" , " bar" ), null ," multiple-workspaces" , " blank" , null ),
251- SSHTest (listOf (" foo-bar" ), " blank" , " append-blank" , " blank" , null ),
252- SSHTest (listOf (" foo-bar" ), " blank-newlines" , " append-blank-newlines" , " blank" , null ),
253- SSHTest (listOf (" foo-bar" ), " existing-end" , " replace-end" , " no-blocks" , null ),
254- SSHTest (listOf (" foo-bar" ), " existing-end-no-newline" , " replace-end-no-newline" , " no-blocks" , null ),
255- SSHTest (listOf (" foo-bar" ), " existing-middle" , " replace-middle" , " no-blocks" , null ),
256- SSHTest (listOf (" foo-bar" ), " existing-middle-and-unrelated" , " replace-middle-ignore-unrelated" , " no-related-blocks" , null ),
257- SSHTest (listOf (" foo-bar" ), " existing-only" , " replace-only" , " blank" , null ),
258- SSHTest (listOf (" foo-bar" ), " existing-start" , " replace-start" , " no-blocks" , null ),
259- SSHTest (listOf (" foo-bar" ), " no-blocks" , " append-no-blocks" , " no-blocks" , null ),
260- SSHTest (listOf (" foo-bar" ), " no-related-blocks" , " append-no-related-blocks" , " no-related-blocks" , null ),
261- SSHTest (listOf (" foo-bar" ), " no-newline" , " append-no-newline" , " no-blocks" , null ),
256+ SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" ),
257+ SSHTest (listOf (" foo" , " bar" ), null , " multiple-workspaces" , " blank" ),
258+ SSHTest (listOf (" foo-bar" ), " blank" , " append-blank" , " blank" ),
259+ SSHTest (listOf (" foo-bar" ), " blank-newlines" , " append-blank-newlines" , " blank" ),
260+ SSHTest (listOf (" foo-bar" ), " existing-end" , " replace-end" , " no-blocks" ),
261+ SSHTest (listOf (" foo-bar" ), " existing-end-no-newline" , " replace-end-no-newline" , " no-blocks" ),
262+ SSHTest (listOf (" foo-bar" ), " existing-middle" , " replace-middle" , " no-blocks" ),
263+ SSHTest (listOf (" foo-bar" ), " existing-middle-and-unrelated" , " replace-middle-ignore-unrelated" , " no-related-blocks" ),
264+ SSHTest (listOf (" foo-bar" ), " existing-only" , " replace-only" , " blank" ),
265+ SSHTest (listOf (" foo-bar" ), " existing-start" , " replace-start" , " no-blocks" ),
266+ SSHTest (listOf (" foo-bar" ), " no-blocks" , " append-no-blocks" , " no-blocks" ),
267+ SSHTest (listOf (" foo-bar" ), " no-related-blocks" , " append-no-related-blocks" , " no-related-blocks" ),
268+ SSHTest (listOf (" foo-bar" ), " no-newline" , " append-no-newline" , " no-blocks" ),
262269 if (getOS() == OS .WINDOWS ) {
263270 SSHTest (listOf (" header" ), null , " header-command-windows" , " blank" , """ "C:\Program Files\My Header Command\HeaderCommand.exe" --url="%CODER_URL%" --test="foo bar"""" )
264271 } else {
265272 SSHTest (listOf (" header" ), null , " header-command" , " blank" , " my-header-command --url=\" \$ CODER_URL\" --test=\" foo bar\" --literal='\$ CODER_URL'" )
266273 },
267- SSHTest (listOf (" foo" ), null , " disable-autostart" , " blank" , null , true , Features (true )),
268- SSHTest (listOf (" foo" ), null , " no-disable-autostart" , " blank" , null , true , Features (false )),
274+ SSHTest (listOf (" foo" ), null , " disable-autostart" , " blank" , " " , true , Features (true )),
275+ SSHTest (listOf (" foo" ), null , " no-disable-autostart" , " blank" , " " , true , Features (false )),
276+ SSHTest (listOf (" extra" ), null , " extra-config" , " blank" ,
277+ extraConfig = extraConfig),
278+ SSHTest (listOf (" extra" ), null , " extra-config" , " blank" ,
279+ env = Environment (mapOf (CODER_SSH_CONFIG_OPTIONS to extraConfig))),
269280 )
270281
271282 val newlineRe = " \r ?\n " .toRegex()
@@ -274,8 +285,10 @@ internal class CoderCLIManagerTest {
274285 val settings = CoderSettings (CoderSettingsState (
275286 disableAutostart = it.disableAutostart,
276287 dataDirectory = tmpdir.resolve(" configure-ssh" ).toString(),
277- headerCommand = it.headerCommand ? : " " ),
278- sshConfigPath = tmpdir.resolve(it.input + " _to_" + it.output + " .conf" ))
288+ headerCommand = it.headerCommand,
289+ sshConfigOptions = it.extraConfig),
290+ sshConfigPath = tmpdir.resolve(it.input + " _to_" + it.output + " .conf" ),
291+ env = it.env)
279292
280293 val ccm = CoderCLIManager (URL (" https://test.coder.invalid" ), settings)
281294
@@ -295,12 +308,12 @@ internal class CoderCLIManagerTest {
295308 .replace(" /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64" , escape(ccm.localBinaryPath.toString()))
296309
297310 // Add workspaces.
298- ccm.configSsh(it.workspaces.toSet(), it.features ? : Features () )
311+ ccm.configSsh(it.workspaces.toSet(), it.features)
299312
300313 assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
301314
302315 // Remove configuration.
303- ccm.configSsh(emptySet(), it.features ? : Features () )
316+ ccm.configSsh(emptySet(), it.features)
304317
305318 // Remove is the configuration we expect after removing.
306319 assertEquals(
0 commit comments