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-09-10 17:05:07 +01:00
|
|
|
"google.golang.org/grpc/credentials"
|
|
|
|
"google.golang.org/grpc/peer"
|
2019-09-06 17:14:03 +01:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
|
|
|
nodeDossier := planet.StorageNodes[0].Local()
|
2019-09-10 17:05:07 +01:00
|
|
|
ident := planet.StorageNodes[0].Identity
|
2019-09-06 17:14:03 +01:00
|
|
|
|
2019-09-10 17:05:07 +01:00
|
|
|
grpcPeer := peer.Peer{
|
|
|
|
Addr: &net.TCPAddr{
|
|
|
|
IP: net.ParseIP(nodeDossier.Address.GetAddress()),
|
|
|
|
Port: 5,
|
|
|
|
},
|
|
|
|
AuthInfo: credentials.TLSInfo{
|
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
peerCtx := peer.NewContext(ctx, &grpcPeer)
|
2019-09-14 01:37:32 +01:00
|
|
|
resp, err := planet.Satellites[0].Contact.Endpoint.CheckIn(peerCtx, &pb.CheckInRequest{
|
|
|
|
Address: nodeDossier.Address.GetAddress(),
|
|
|
|
Version: nodeDossier.Version.GetVersion(),
|
2019-09-06 17:14:03 +01:00
|
|
|
Capacity: &nodeDossier.Capacity,
|
|
|
|
Operator: &nodeDossier.Operator,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2019-09-10 17:05:07 +01:00
|
|
|
require.NotNil(t, resp)
|
2019-09-12 17:33:04 +01:00
|
|
|
|
|
|
|
peerID, err := planet.Satellites[0].DB.PeerIdentities().Get(ctx, nodeDossier.Id)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, ident.PeerIdentity(), peerID)
|
2019-09-06 17:14:03 +01:00
|
|
|
})
|
|
|
|
}
|