(t *testing.T)
| 381 | } |
| 382 | |
| 383 | func 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 | |
| 416 | func TestDecryptConfig_WithEncryptedData(t *testing.T) { |
| 417 | os.Setenv("TRYSSH_MASTER_KEY", "testpassword123") |
nothing calls this directly
no test coverage detected