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

Function TestGetMasterKey_InteractivePromptError

pkg/utils/crypto_test.go:284–301  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

282}
283
284func TestGetMasterKey_InteractivePromptError(t *testing.T) {
285 // When no env var is set and stdin is not a terminal (as in tests),
286 // term.ReadPassword will fail, triggering the error path.
287 ClearMasterKey()
288 os.Unsetenv(keyEnvVar)
289
290 key, err := GetMasterKey()
291 // In test environments, stdin is a pipe so term.ReadPassword should fail.
292 // If for some reason it doesn't (e.g., very unusual test runner),
293 // the key should still be usable.
294 if err != nil {
295 assert.Error(t, err)
296 assert.Nil(t, key)
297 assert.Contains(t, err.Error(), "failed to read master password")
298 }
299
300 ClearMasterKey()
301}
302
303func TestGetMasterKey_AlreadyCached(t *testing.T) {
304 // Test the early return when masterKey is already cached.

Callers

nothing calls this directly

Calls 2

ClearMasterKeyFunction · 0.85
GetMasterKeyFunction · 0.85

Tested by

no test coverage detected