(t *testing.T)
| 436 | } |
| 437 | |
| 438 | func TestDecryptConfig_WrongKey(t *testing.T) { |
| 439 | // Set master key to "testpassword123" |
| 440 | os.Setenv("TRYSSH_MASTER_KEY", "testpassword123") |
| 441 | defer os.Unsetenv("TRYSSH_MASTER_KEY") |
| 442 | clearMasterKeyForTest() |
| 443 | |
| 444 | // Encrypt with a DIFFERENT key derived from "otherpassword123" |
| 445 | // We need to get a key for "otherpassword123" without messing up env var |
| 446 | os.Setenv("TRYSSH_MASTER_KEY", "otherpassword123") |
| 447 | clearMasterKeyForTest() |
| 448 | otherKey, err := utils.GetMasterKey() |
| 449 | require.NoError(t, err) |
| 450 | |
| 451 | encPass, encErr := utils.Encrypt("mysecret", otherKey) |
| 452 | require.NoError(t, encErr) |
| 453 | |
| 454 | // Now switch back to the "correct" master key |
| 455 | os.Setenv("TRYSSH_MASTER_KEY", "testpassword123") |
| 456 | clearMasterKeyForTest() |
| 457 | |
| 458 | conf := &MainConfig{} |
| 459 | conf.Main.Passwords = []string{encPass} |
| 460 | |
| 461 | decErr := decryptConfig(conf) |
| 462 | assert.Error(t, decErr) |
| 463 | assert.Contains(t, decErr.Error(), "decrypt") |
| 464 | } |
| 465 | |
| 466 | func TestDecryptConfig_NoMasterKey(t *testing.T) { |
| 467 | os.Unsetenv("TRYSSH_MASTER_KEY") |
nothing calls this directly
no test coverage detected