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

Function TestDecryptConfig_WrongKey

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

Source from the content-addressed store, hash-verified

436}
437
438func 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
466func TestDecryptConfig_NoMasterKey(t *testing.T) {
467 os.Unsetenv("TRYSSH_MASTER_KEY")

Callers

nothing calls this directly

Calls 4

GetMasterKeyFunction · 0.92
EncryptFunction · 0.92
clearMasterKeyForTestFunction · 0.85
decryptConfigFunction · 0.85

Tested by

no test coverage detected