github.com/status-im/status-go@v1.1.0/server/servertest/servertest.go (about) 1 // Package servertest provides utilities for server testing. 2 package servertest 3 4 import ( 5 "crypto/ecdsa" 6 "crypto/elliptic" 7 "encoding/asn1" 8 "math/big" 9 "testing" 10 "time" 11 12 "github.com/btcsuite/btcutil/base58" 13 "github.com/stretchr/testify/require" 14 "go.uber.org/zap" 15 16 "github.com/status-im/status-go/logutils" 17 ) 18 19 const ( 20 X = "7744735542292224619198421067303535767629647588258222392379329927711683109548" 21 Y = "6855516769916529066379811647277920115118980625614889267697023742462401590771" 22 D = "38564357061962143106230288374146033267100509055924181407058066820384455255240" 23 AES = "BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6" 24 DB58 = "6jpbvo2ucrtrnpXXF4DQYuysh697isH9ppd2aT8uSRDh" 25 SN = "91849736469742262272885892667727604096707836853856473239722372976236128900962" 26 CertTime = "eQUriVtGtkWhPJFeLZjF" 27 ) 28 29 type TestKeyComponents struct { 30 X *big.Int 31 Y *big.Int 32 D *big.Int 33 AES []byte 34 DBytes []byte 35 PK *ecdsa.PrivateKey 36 } 37 38 func (tk *TestKeyComponents) SetupKeyComponents(t *testing.T) { 39 var ok bool 40 41 tk.X, ok = new(big.Int).SetString(X, 10) 42 require.True(t, ok) 43 44 tk.Y, ok = new(big.Int).SetString(Y, 10) 45 require.True(t, ok) 46 47 tk.D, ok = new(big.Int).SetString(D, 10) 48 require.True(t, ok) 49 50 tk.AES = base58.Decode(AES) 51 require.Len(t, tk.AES, 32) 52 53 tk.DBytes = base58.Decode(DB58) 54 require.Exactly(t, tk.D.Bytes(), tk.DBytes) 55 56 tk.PK = &ecdsa.PrivateKey{ 57 PublicKey: ecdsa.PublicKey{ 58 Curve: elliptic.P256(), 59 X: tk.X, 60 Y: tk.Y, 61 }, 62 D: tk.D, 63 } 64 } 65 66 type TestCertComponents struct { 67 NotBefore, NotAfter time.Time 68 SN *big.Int 69 } 70 71 func (tcc *TestCertComponents) SetupCertComponents(t *testing.T) { 72 var ok bool 73 74 tcc.SN, ok = new(big.Int).SetString(SN, 10) 75 require.True(t, ok) 76 77 _, err := asn1.Unmarshal(base58.Decode(CertTime), &tcc.NotBefore) 78 require.NoError(t, err) 79 80 tcc.NotAfter = tcc.NotBefore.Add(time.Hour) 81 } 82 83 type TestLoggerComponents struct { 84 Logger *zap.Logger 85 } 86 87 func (tlc *TestLoggerComponents) SetupLoggerComponents() { 88 tlc.Logger = logutils.ZapLogger() 89 }