MCPcopy Create free account
hub / github.com/Driver-C/tryssh / TestDecryptConfig_WithEncryptedData

Function TestDecryptConfig_WithEncryptedData

pkg/config/loader_test.go:416–436  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

414}
415
416func TestDecryptConfig_WithEncryptedData(t *testing.T) {
417 os.Setenv("TRYSSH_MASTER_KEY", "testpassword123")
418 defer os.Unsetenv("TRYSSH_MASTER_KEY")
419 clearMasterKeyForTest()
420
421 key := deriveTestKey(t, "testpassword123")
422 encPass, err := utils.Encrypt("mysecret", key)
423 assert.NoError(t, err)
424
425 conf := &MainConfig{}
426 conf.Main.Ports = []string{"22"}
427 conf.Main.Passwords = []string{encPass}
428 conf.ServerLists = []ServerListConfig{
429 {IP: "10.0.0.1", Port: "22", User: "root", Password: encPass},
430 }
431
432 err = decryptConfig(conf)
433 assert.NoError(t, err)
434 assert.Equal(t, "mysecret", conf.Main.Passwords[0])
435 assert.Equal(t, "mysecret", conf.ServerLists[0].Password)
436}
437
438func TestDecryptConfig_WrongKey(t *testing.T) {
439 // Set master key to "testpassword123"

Callers

nothing calls this directly

Calls 4

EncryptFunction · 0.92
clearMasterKeyForTestFunction · 0.85
deriveTestKeyFunction · 0.85
decryptConfigFunction · 0.85

Tested by

no test coverage detected