go-http-peering/client/client_test.go

45 lines
826 B
Go

package client
import (
"crypto/rand"
"crypto/rsa"
"testing"
peeringCrypto "forge.cadoles.com/Cadoles/go-http-peering/crypto"
peering "forge.cadoles.com/Cadoles/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
}