diff options
Diffstat (limited to 'ssh/keys_test.go')
| -rw-r--r-- | ssh/keys_test.go | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/ssh/keys_test.go b/ssh/keys_test.go index a1165ec..ed5bb1a 100644 --- a/ssh/keys_test.go +++ b/ssh/keys_test.go @@ -272,18 +272,18 @@ func TestParseEncryptedPrivateKeysWithPassphrase(t *testing.T) { } func TestParseEncryptedPrivateKeysWithUnsupportedCiphers(t *testing.T) { - for _, tt := range testdata.UnsupportedCipherData { - t.Run(tt.Name, func(t *testing.T){ - _, err := ParsePrivateKeyWithPassphrase(tt.PEMBytes, []byte(tt.EncryptionKey)) - if err == nil { - t.Fatalf("expected 'unknown cipher' error for %q, got nil", tt.Name) - // If this cipher is now supported, remove it from testdata.UnsupportedCipherData - } - if !strings.Contains(err.Error(), "unknown cipher") { - t.Errorf("wanted 'unknown cipher' error, got %v", err.Error()) - } - }) - } + for _, tt := range testdata.UnsupportedCipherData { + t.Run(tt.Name, func(t *testing.T) { + _, err := ParsePrivateKeyWithPassphrase(tt.PEMBytes, []byte(tt.EncryptionKey)) + if err == nil { + t.Fatalf("expected 'unknown cipher' error for %q, got nil", tt.Name) + // If this cipher is now supported, remove it from testdata.UnsupportedCipherData + } + if !strings.Contains(err.Error(), "unknown cipher") { + t.Errorf("wanted 'unknown cipher' error, got %v", err.Error()) + } + }) + } } func TestParseEncryptedPrivateKeysWithIncorrectPassphrase(t *testing.T) { @@ -863,3 +863,20 @@ cLYUOHfQDw== t.Fatal("parsing an SSH certificate using another certificate as signature key succeeded; expected failure") } } + +func TestPassphraseMissingErrorIs(t *testing.T) { + var ( + errPassMissing = &PassphraseMissingError{} + + err error + ) + + _, err = ParseRawPrivateKey(testdata.PEMEncryptedKeys[0].PEMBytes) + if err == nil { + t.Fatalf(`got error nil, want %T`, errPassMissing) + } + + if !errors.Is(err, errPassMissing) { + t.Fatalf(`got error %T, want %T `, err, errPassMissing) + } +} |
