go-http-peering/client/client_test.go

45 lines
824 B
Go
Raw Permalink Normal View History

2019-02-22 17:35:49 +01:00
package client
import (
"crypto/rand"
"crypto/rsa"
"testing"
peeringCrypto "forge.cadoles.com/wpetit/go-http-peering/crypto"
peering "forge.cadoles.com/wpetit/go-http-peering"
)
func TestClientPeerID(t *testing.T) {
serverPK := mustGeneratePrivateKey()
peerID := peering.NewPeerID()
serverToken, err := peeringCrypto.CreateServerToken(serverPK, "test", peerID)
if err != nil {
t.Fatal(err)
}
client := New(
WithServerToken(serverToken),
)
clientPeerID, err := client.PeerID(&serverPK.PublicKey)
if err != nil {
t.Fatal(err)
}
if g, e := clientPeerID, peerID; g != e {
t.Errorf("client.PeerID(): got '%v', expected '%v'", g, e)
}
}
func mustGeneratePrivateKey() *rsa.PrivateKey {
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
panic(err)
}
return privateKey
}