added test for CA generation + use SeedSize constant

Previously, I just hard coded 256 as the key length that seeds the key
generation since it worked. Now, it uses ed25519.SeedSize (32) instead.
This commit is contained in:
miampf 2025-01-09 17:24:32 +01:00
parent 0be301fa3a
commit bee3f6c159
No known key found for this signature in database
GPG key ID: EF039364B5B6886C
3 changed files with 38 additions and 2 deletions

View file

@ -7,6 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only
package crypto
import (
"crypto/ed25519"
"crypto/x509"
"testing"
@ -121,6 +122,39 @@ func TestGenerateRandomBytes(t *testing.T) {
assert.Len(n3, 16)
}
func TestGenerateEmergencySSHCAKey(t *testing.T) {
nullKey := make([]byte, ed25519.SeedSize)
for i := range nullKey {
nullKey[i] = 0x0
}
testCases := map[string]struct {
key []byte
wantErr bool
}{
"invalid key": {
key: make([]byte, 0),
wantErr: true,
},
"valid key": {
key: nullKey,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
_, err := GenerateEmergencySSHCAKey(tc.key)
if tc.wantErr {
assert.NotNil(err)
} else {
assert.Nil(err)
}
})
}
}
func TestPemToX509Cert(t *testing.T) {
testCases := map[string]struct {
pemCert []byte