aboutsummaryrefslogtreecommitdiff
path: root/ssh/keys_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ssh/keys_test.go')
-rw-r--r--ssh/keys_test.go37
1 files changed, 34 insertions, 3 deletions
diff --git a/ssh/keys_test.go b/ssh/keys_test.go
index a8e216e..365d93d 100644
--- a/ssh/keys_test.go
+++ b/ssh/keys_test.go
@@ -111,9 +111,9 @@ func TestKeySignVerify(t *testing.T) {
}
func TestKeySignWithAlgorithmVerify(t *testing.T) {
- for _, priv := range testSigners {
- if algorithmSigner, ok := priv.(AlgorithmSigner); !ok {
- t.Errorf("Signers constructed by ssh package should always implement the AlgorithmSigner interface: %T", priv)
+ for k, priv := range testSigners {
+ if algorithmSigner, ok := priv.(MultiAlgorithmSigner); !ok {
+ t.Errorf("Signers %q constructed by ssh package should always implement the MultiAlgorithmSigner interface: %T", k, priv)
} else {
pub := priv.PublicKey()
data := []byte("sign me")
@@ -684,3 +684,34 @@ func TestSKKeys(t *testing.T) {
}
}
}
+
+func TestNewSignerWithAlgos(t *testing.T) {
+ algorithSigner, ok := testSigners["rsa"].(AlgorithmSigner)
+ if !ok {
+ t.Fatal("rsa test signer does not implement the AlgorithmSigner interface")
+ }
+ _, err := NewSignerWithAlgorithms(algorithSigner, nil)
+ if err == nil {
+ t.Error("signer with algos created with no algorithms")
+ }
+
+ _, err = NewSignerWithAlgorithms(algorithSigner, []string{KeyAlgoED25519})
+ if err == nil {
+ t.Error("signer with algos created with invalid algorithms")
+ }
+
+ _, err = NewSignerWithAlgorithms(algorithSigner, []string{CertAlgoRSASHA256v01})
+ if err == nil {
+ t.Error("signer with algos created with certificate algorithms")
+ }
+
+ mas, err := NewSignerWithAlgorithms(algorithSigner, []string{KeyAlgoRSASHA256, KeyAlgoRSASHA512})
+ if err != nil {
+ t.Errorf("unable to create signer with valid algorithms: %v", err)
+ }
+
+ _, err = NewSignerWithAlgorithms(mas, []string{KeyAlgoRSA})
+ if err == nil {
+ t.Error("signer with algos created with restricted algorithms")
+ }
+}