@@ -3,7 +3,6 @@ package com.coder.toolbox.settings
3
3
import com.coder.toolbox.store.BINARY_NAME
4
4
import com.coder.toolbox.store.CODER_SSH_CONFIG_OPTIONS
5
5
import com.coder.toolbox.store.CoderSettingsStore
6
- import com.coder.toolbox.store.DEFAULT_URL
7
6
import com.coder.toolbox.store.DISABLE_AUTOSTART
8
7
import com.coder.toolbox.store.ENABLE_BINARY_DIR_FALLBACK
9
8
import com.coder.toolbox.store.ENABLE_DOWNLOADS
@@ -277,108 +276,6 @@ internal class CoderSettingsTest {
277
276
assertEquals(false , settings.readOnly().requireTokenAuth)
278
277
}
279
278
280
- @Test
281
- fun testDefaultURL () {
282
- val tmp = Path .of(System .getProperty(" java.io.tmpdir" ))
283
- val dir = tmp.resolve(" coder-toolbox-test/test-default-url" )
284
- var env = Environment (mapOf (" CODER_CONFIG_DIR" to dir.toString()))
285
- dir.toFile().deleteRecursively()
286
-
287
- // No config.
288
- var settings = CoderSettingsStore (pluginTestSettingsStore(), env, logger)
289
- assertEquals(null , settings.defaultURL())
290
-
291
- // Read from global config.
292
- val globalConfigPath = Path .of(settings.readOnly().globalConfigDir)
293
- globalConfigPath.toFile().mkdirs()
294
- globalConfigPath.resolve(" url" ).toFile().writeText(" url-from-global-config" )
295
- settings = CoderSettingsStore (pluginTestSettingsStore(), env, logger)
296
- assertEquals(" url-from-global-config" to SettingSource .CONFIG , settings.defaultURL())
297
-
298
- // Read from environment.
299
- env =
300
- Environment (
301
- mapOf (
302
- " CODER_URL" to " url-from-env" ,
303
- " CODER_CONFIG_DIR" to dir.toString(),
304
- ),
305
- )
306
- settings = CoderSettingsStore (pluginTestSettingsStore(), env, logger)
307
- assertEquals(" url-from-env" to SettingSource .ENVIRONMENT , settings.defaultURL())
308
-
309
- // Read from settings.
310
- settings =
311
- CoderSettingsStore (
312
- pluginTestSettingsStore(
313
- DEFAULT_URL to " url-from-settings" ,
314
- ),
315
- env,
316
- logger
317
- )
318
- assertEquals(" url-from-settings" to SettingSource .SETTINGS , settings.defaultURL())
319
- }
320
-
321
- @Test
322
- fun testToken () {
323
- val tmp = Path .of(System .getProperty(" java.io.tmpdir" ))
324
- val url = URL (" http://test.deployment.coder.com" )
325
- val dir = tmp.resolve(" coder-toolbox-test/test-default-token" )
326
- val env =
327
- Environment (
328
- mapOf (
329
- " CODER_CONFIG_DIR" to dir.toString(),
330
- " LOCALAPPDATA" to dir.toString(),
331
- " XDG_DATA_HOME" to dir.toString(),
332
- " HOME" to dir.toString(),
333
- ),
334
- )
335
- dir.toFile().deleteRecursively()
336
-
337
- // No config.
338
- var settings = CoderSettingsStore (pluginTestSettingsStore(), env, logger)
339
- assertEquals(null , settings.readOnly().token(url))
340
-
341
- val globalConfigPath = Path .of(settings.readOnly().globalConfigDir)
342
- globalConfigPath.toFile().mkdirs()
343
- globalConfigPath.resolve(" url" ).toFile().writeText(url.toString())
344
- globalConfigPath.resolve(" session" ).toFile().writeText(" token-from-global-config" )
345
-
346
- // Ignore global config if it does not match.
347
- assertEquals(null , settings.readOnly().token(URL (" http://some.random.url" )))
348
-
349
- // Read from global config.
350
- assertEquals(" token-from-global-config" to SettingSource .CONFIG , settings.readOnly().token(url))
351
-
352
- // Compares exactly.
353
- assertEquals(null , settings.readOnly().token(url.withPath(" /test" )))
354
-
355
- val deploymentConfigPath = settings.readOnly().dataDir(url).resolve(" config" )
356
- deploymentConfigPath.toFile().mkdirs()
357
- deploymentConfigPath.resolve(" url" ).toFile().writeText(" url-from-deployment-config" )
358
- deploymentConfigPath.resolve(" session" ).toFile().writeText(" token-from-deployment-config" )
359
-
360
- // Read from deployment config.
361
- assertEquals(" token-from-deployment-config" to SettingSource .DEPLOYMENT_CONFIG , settings.readOnly().token(url))
362
-
363
- // Only compares host .
364
- assertEquals(
365
- " token-from-deployment-config" to SettingSource .DEPLOYMENT_CONFIG ,
366
- settings.readOnly().token(url.withPath(" /test" ))
367
- )
368
-
369
- // Ignore if using mTLS.
370
- settings =
371
- CoderSettingsStore (
372
- pluginTestSettingsStore(
373
- TLS_KEY_PATH to " key" ,
374
- TLS_CERT_PATH to " cert" ,
375
- ),
376
- env,
377
- logger
378
- )
379
- assertEquals(null , settings.readOnly().token(url))
380
- }
381
-
382
279
@Test
383
280
fun testDefaults () {
384
281
// Test defaults for the remaining settings.
0 commit comments