2019-09-06 17:14:03 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package contact_test
|
|
|
|
|
|
|
|
import (
|
2019-09-10 17:05:07 +01:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
|
|
|
"net"
|
2019-09-06 17:14:03 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/rpc/rpcpeer"
|
|
|
|
"storj.io/common/testcontext"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-09-06 17:14:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSatelliteContactEndpoint(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2020-05-20 14:40:25 +01:00
|
|
|
nodeInfo := planet.StorageNodes[0].Contact.Service.Local()
|
2019-09-10 17:05:07 +01:00
|
|
|
ident := planet.StorageNodes[0].Identity
|
2019-09-06 17:14:03 +01:00
|
|
|
|
2019-09-19 05:46:39 +01:00
|
|
|
peer := rpcpeer.Peer{
|
2019-09-10 17:05:07 +01:00
|
|
|
Addr: &net.TCPAddr{
|
2020-05-20 14:40:25 +01:00
|
|
|
IP: net.ParseIP(nodeInfo.Address),
|
2019-09-10 17:05:07 +01:00
|
|
|
Port: 5,
|
|
|
|
},
|
2019-09-19 05:46:39 +01:00
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
2019-09-10 17:05:07 +01:00
|
|
|
},
|
|
|
|
}
|
2019-09-19 05:46:39 +01:00
|
|
|
peerCtx := rpcpeer.NewContext(ctx, &peer)
|
2019-09-14 01:37:32 +01:00
|
|
|
resp, err := planet.Satellites[0].Contact.Endpoint.CheckIn(peerCtx, &pb.CheckInRequest{
|
2020-05-20 14:40:25 +01:00
|
|
|
Address: nodeInfo.Address,
|
|
|
|
Version: &nodeInfo.Version,
|
|
|
|
Capacity: &nodeInfo.Capacity,
|
|
|
|
Operator: &nodeInfo.Operator,
|
2019-09-06 17:14:03 +01:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2019-09-10 17:05:07 +01:00
|
|
|
require.NotNil(t, resp)
|
2019-09-12 17:33:04 +01:00
|
|
|
|
2020-05-20 14:40:25 +01:00
|
|
|
peerID, err := planet.Satellites[0].DB.PeerIdentities().Get(ctx, nodeInfo.ID)
|
2019-09-12 17:33:04 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, ident.PeerIdentity(), peerID)
|
2019-09-06 17:14:03 +01:00
|
|
|
})
|
|
|
|
}
|