-
Notifications
You must be signed in to change notification settings - Fork 251
/
Copy pathcerts_test.go
54 lines (42 loc) · 1.28 KB
/
certs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package server
import (
"net"
"testing"
"time"
"github.com/btcsuite/btcutil/base58"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/server/servertest"
)
func TestCerts(t *testing.T) {
suite.Run(t, new(CertsSuite))
}
type CertsSuite struct {
suite.Suite
servertest.TestKeyComponents
servertest.TestCertComponents
}
func (s *CertsSuite) SetupSuite() {
s.SetupKeyComponents(s.T())
s.SetupCertComponents(s.T())
}
func (s *CertsSuite) TestToECDSA() {
k := ToECDSA(base58.Decode(servertest.DB58))
s.Require().NotNil(k.PublicKey.X)
s.Require().NotNil(k.PublicKey.Y)
s.Require().Zero(k.PublicKey.X.Cmp(s.X))
s.Require().Zero(k.PublicKey.Y.Cmp(s.Y))
s.Require().Zero(k.D.Cmp(s.D))
b58 := base58.Encode(s.D.Bytes())
s.Require().Equal(servertest.DB58, b58)
}
func (s *CertsSuite) TestGenerateX509Cert() {
notBefore := time.Now()
notAfter := notBefore.Add(time.Hour)
c1 := GenerateX509Cert(s.SN, notBefore, notAfter, []net.IP{}, []string{Localhost})
s.Require().Exactly([]string{Localhost}, c1.DNSNames)
s.Require().Empty(c1.IPAddresses)
c2 := GenerateX509Cert(s.SN, notBefore, notAfter, []net.IP{LocalHostIP}, []string{})
s.Require().Len(c2.IPAddresses, 1)
s.Require().Equal(LocalHostIP.String(), c2.IPAddresses[0].String())
s.Require().Empty(c2.DNSNames)
}