Skip to content

Commit bde153e

Browse files
committed
add test for keygen
1 parent e1bba9c commit bde153e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

modules/ssh/ssh_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ssh_test
2+
3+
import (
4+
"crypto/x509"
5+
"encoding/pem"
6+
"io"
7+
"os"
8+
"testing"
9+
10+
"code.gitea.io/gitea/modules/ssh"
11+
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
func TestGenKeyPair(t *testing.T) {
16+
path := t.TempDir() + "/gitea.rsa"
17+
ssh.GenKeyPair(path)
18+
19+
file, err := os.Open(path)
20+
require.NoError(t, err)
21+
22+
bytes, err := io.ReadAll(file)
23+
require.NoError(t, err)
24+
25+
block, _ := pem.Decode(bytes)
26+
require.NotNil(t, block)
27+
assert.Equal(t, "RSA PRIVATE KEY", block.Type)
28+
29+
privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
30+
require.NoError(t, err)
31+
assert.NotNil(t, privateKey)
32+
}

0 commit comments

Comments
 (0)