@@ -3,8 +3,10 @@ package com.coder.gateway.cli
3
3
import com.coder.gateway.cli.ex.MissingVersionException
4
4
import com.coder.gateway.cli.ex.ResponseException
5
5
import com.coder.gateway.cli.ex.SSHConfigFormatException
6
- import com.coder.gateway.settings.CoderSettingsState
6
+ import com.coder.gateway.settings.CODER_SSH_CONFIG_OPTIONS
7
7
import com.coder.gateway.settings.CoderSettings
8
+ import com.coder.gateway.settings.CoderSettingsState
9
+ import com.coder.gateway.settings.Environment
8
10
import com.coder.gateway.util.InvalidVersionException
9
11
import com.coder.gateway.util.OS
10
12
import com.coder.gateway.util.SemVer
@@ -238,34 +240,43 @@ internal class CoderCLIManagerTest {
238
240
val input : String? ,
239
241
val output : String ,
240
242
val remove : String ,
241
- val headerCommand : String? ,
243
+ val headerCommand : String = " " ,
242
244
val disableAutostart : Boolean =false ,
243
- val features : Features ? =null ,
245
+ val features : Features =Features (),
246
+ val extraConfig : String =" " ,
247
+ val env : Environment =Environment (),
244
248
)
245
249
246
250
@Test
247
251
fun testConfigureSSH () {
252
+ val extraConfig= listOf (
253
+ " ServerAliveInterval 5" ,
254
+ " ServerAliveCountMax 3" ).joinToString(System .lineSeparator())
248
255
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" ),
262
269
if (getOS()== OS .WINDOWS ) {
263
270
SSHTest (listOf (" header" ),null ," header-command-windows" ," blank" ,""" "C:\Program Files\My Header Command\HeaderCommand.exe" --url="%CODER_URL%" --test="foo bar"""" )
264
271
}else {
265
272
SSHTest (listOf (" header" ),null ," header-command" ," blank" ," my-header-command --url=\" \$ CODER_URL\" --test=\" foo bar\" --literal='\$ CODER_URL'" )
266
273
},
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))),
269
280
)
270
281
271
282
val newlineRe= " \r ?\n " .toRegex()
@@ -274,8 +285,10 @@ internal class CoderCLIManagerTest {
274
285
val settings= CoderSettings (CoderSettingsState (
275
286
disableAutostart= it.disableAutostart,
276
287
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)
279
292
280
293
val ccm= CoderCLIManager (URL (" https://test.coder.invalid" ), settings)
281
294
@@ -295,12 +308,12 @@ internal class CoderCLIManagerTest {
295
308
.replace(" /tmp/coder-gateway/test.coder.invalid/coder-linux-amd64" , escape(ccm.localBinaryPath.toString()))
296
309
297
310
// Add workspaces.
298
- ccm.configSsh(it.workspaces.toSet(), it.features? : Features () )
311
+ ccm.configSsh(it.workspaces.toSet(), it.features)
299
312
300
313
assertEquals(expectedConf, settings.sshConfigPath.toFile().readText())
301
314
302
315
// Remove configuration.
303
- ccm.configSsh(emptySet(), it.features? : Features () )
316
+ ccm.configSsh(emptySet(), it.features)
304
317
305
318
// Remove is the configuration we expect after removing.
306
319
assertEquals(