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

Function TestEncryptConfigForSave_EncryptsPassword

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

Source from the content-addressed store, hash-verified

381}
382
383func TestEncryptConfigForSave_EncryptsPassword(t *testing.T) {
384 os.Unsetenv("TRYSSH_MASTER_KEY")
385 clearMasterKeyForTest()
386
387 // Set env var and get key BEFORE clearing cache again
388 os.Setenv("TRYSSH_MASTER_KEY", "testpassword123")
389 defer os.Unsetenv("TRYSSH_MASTER_KEY")
390 key, err := utils.GetMasterKey()
391 require.NoError(t, err)
392
393 conf := &MainConfig{}
394 conf.Main.Ports = []string{"22"}
395 conf.Main.Passwords = []string{"secret", ""}
396 conf.ServerLists = []ServerListConfig{
397 {IP: "10.0.0.1", Port: "22", User: "root", Password: "cached"},
398 }
399
400 result, encErr := encryptConfigForSave(conf)
401 require.NoError(t, encErr)
402 require.NotNil(t, result)
403 // Original should not be modified
404 assert.Equal(t, "secret", conf.Main.Passwords[0])
405 // Result should be encrypted
406 assert.True(t, utils.IsEncrypted(result.Main.Passwords[0]))
407 assert.False(t, utils.IsEncrypted(result.Main.Passwords[1]), "empty string should not be encrypted")
408 assert.True(t, utils.IsEncrypted(result.ServerLists[0].Password))
409
410 // Verify decryption round-trip
411 dec, decErr := utils.Decrypt(result.Main.Passwords[0], key)
412 assert.NoError(t, decErr)
413 assert.Equal(t, "secret", dec)
414}
415
416func TestDecryptConfig_WithEncryptedData(t *testing.T) {
417 os.Setenv("TRYSSH_MASTER_KEY", "testpassword123")

Callers

nothing calls this directly

Calls 5

GetMasterKeyFunction · 0.92
IsEncryptedFunction · 0.92
DecryptFunction · 0.92
clearMasterKeyForTestFunction · 0.85
encryptConfigForSaveFunction · 0.85

Tested by

no test coverage detected