2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-05 14:03:23 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-25 23:06:38 +00:00
|
|
|
package bwagreement_test
|
2018-12-05 14:03:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-12-07 12:11:35 +00:00
|
|
|
"crypto/ecdsa"
|
2019-01-25 18:05:21 +00:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
|
|
|
"net"
|
2018-12-05 14:03:23 +00:00
|
|
|
"testing"
|
2019-01-15 04:44:56 +00:00
|
|
|
"time"
|
2018-12-05 14:03:23 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
"github.com/gtank/cryptopasta"
|
2018-12-05 14:03:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-12-07 12:11:35 +00:00
|
|
|
"go.uber.org/zap"
|
2019-01-25 18:05:21 +00:00
|
|
|
"google.golang.org/grpc/credentials"
|
|
|
|
"google.golang.org/grpc/peer"
|
2018-12-07 12:11:35 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2019-01-02 17:39:17 +00:00
|
|
|
"storj.io/storj/internal/testidentity"
|
2019-01-25 18:05:21 +00:00
|
|
|
"storj.io/storj/pkg/auth"
|
2018-12-07 12:11:35 +00:00
|
|
|
"storj.io/storj/pkg/bwagreement"
|
2019-01-25 23:06:38 +00:00
|
|
|
"storj.io/storj/pkg/bwagreement/testbwagreement"
|
2019-01-25 18:05:21 +00:00
|
|
|
"storj.io/storj/pkg/identity"
|
2018-12-05 14:03:23 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2019-01-25 18:05:21 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
2018-12-27 09:56:25 +00:00
|
|
|
"storj.io/storj/satellite"
|
2018-12-10 14:50:12 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
2018-12-05 14:03:23 +00:00
|
|
|
)
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
func TestBandwidthAgreement(t *testing.T) {
|
2018-12-27 09:56:25 +00:00
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
2018-12-07 12:11:35 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
testDatabase(ctx, t, db.BandwidthAgreement())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
func getPeerContext(ctx context.Context, t *testing.T) (context.Context, storj.NodeID) {
|
|
|
|
ident, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
if !assert.NoError(t, err) || !assert.NotNil(t, ident) {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
grpcPeer := &peer.Peer{
|
|
|
|
Addr: &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 5},
|
|
|
|
AuthInfo: credentials.TLSInfo{
|
|
|
|
State: tls.ConnectionState{
|
|
|
|
PeerCertificates: []*x509.Certificate{ident.Leaf, ident.CA},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
nodeID, err := identity.NodeIDFromKey(ident.CA.PublicKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
return peer.NewContext(ctx, grpcPeer), nodeID
|
|
|
|
}
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
func testDatabase(ctx context.Context, t *testing.T, bwdb bwagreement.DB) {
|
2019-01-25 18:05:21 +00:00
|
|
|
upID, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
satID, err := testidentity.NewTestIdentity(ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
satellite := bwagreement.NewServer(bwdb, zap.NewNop(), satID.ID)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
{ // TestSameSerialNumberBandwidthAgreements
|
2019-01-25 23:06:38 +00:00
|
|
|
pbaFile1, err := testbwagreement.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satID, upID, time.Hour)
|
2019-01-07 15:19:05 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-01-25 23:06:38 +00:00
|
|
|
rbaNode1, err := testbwagreement.GenerateRenterBandwidthAllocation(pbaFile1, storageNode1, upID, 666)
|
2019-01-07 15:19:05 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN2, storageNode2 := getPeerContext(ctx, t)
|
2019-01-25 23:06:38 +00:00
|
|
|
rbaNode2, err := testbwagreement.GenerateRenterBandwidthAllocation(pbaFile1, storageNode2, upID, 666)
|
2019-01-07 15:19:05 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
/* More than one storage node can submit bwagreements with the same serial number.
|
|
|
|
Uplink would like to download a file from 2 storage nodes.
|
|
|
|
Uplink requests a PayerBandwidthAllocation from the satellite. One serial number for all storage nodes.
|
|
|
|
Uplink signes 2 RenterBandwidthAllocation for both storage node. */
|
|
|
|
{
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rbaNode1)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err = satellite.BandwidthAgreements(ctxSN2, rbaNode2)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
|
|
|
}
|
2019-01-07 15:19:05 +00:00
|
|
|
|
|
|
|
/* Storage node can submit a second bwagreement with a different sequence value.
|
|
|
|
Uplink downloads another file. New PayerBandwidthAllocation with a new sequence. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-25 23:06:38 +00:00
|
|
|
pbaFile2, err := testbwagreement.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satID, upID, time.Hour)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 23:06:38 +00:00
|
|
|
rbaNode1, err := testbwagreement.GenerateRenterBandwidthAllocation(pbaFile2, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rbaNode1)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
|
|
|
}
|
2019-01-07 15:19:05 +00:00
|
|
|
|
|
|
|
/* Storage nodes can't submit a second bwagreement with the same sequence. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-25 23:06:38 +00:00
|
|
|
rbaNode1, err := testbwagreement.GenerateRenterBandwidthAllocation(pbaFile1, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rbaNode1)
|
|
|
|
assert.True(t, auth.Serial.Has(err))
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
2019-01-07 15:19:05 +00:00
|
|
|
|
|
|
|
/* Storage nodes can't submit the same bwagreement twice.
|
|
|
|
This test is kind of duplicate cause it will most likely trigger the same sequence error.
|
|
|
|
For safety we will try it anyway to make sure nothing strange will happen */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN2, rbaNode2)
|
|
|
|
assert.True(t, auth.Serial.Has(err))
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // TestExpiredBandwidthAgreements
|
2019-01-25 23:06:38 +00:00
|
|
|
{ // storage nodes can submit a bwagreement that will expire in 30 seconds
|
|
|
|
pba, err := testbwagreement.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satID, upID, 30*time.Second)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-01-25 23:06:38 +00:00
|
|
|
rba, err := testbwagreement.GenerateRenterBandwidthAllocation(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // storage nodes can't submit a bwagreement that expires right now
|
2019-01-25 23:06:38 +00:00
|
|
|
pba, err := testbwagreement.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satID, upID, 0*time.Second)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-01-25 23:06:38 +00:00
|
|
|
rba, err := testbwagreement.GenerateRenterBandwidthAllocation(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // storage nodes can't submit a bwagreement that expires yesterday
|
2019-01-25 23:06:38 +00:00
|
|
|
pba, err := testbwagreement.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satID, upID, -23*time.Hour-55*time.Second)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-01-25 23:06:38 +00:00
|
|
|
rba, err := testbwagreement.GenerateRenterBandwidthAllocation(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // TestManipulatedBandwidthAgreements
|
2019-01-25 23:06:38 +00:00
|
|
|
pba, err := testbwagreement.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satID, upID, time.Hour)
|
2019-01-25 18:05:21 +00:00
|
|
|
if !assert.NoError(t, err) {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-12-07 12:11:35 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
2019-01-25 23:06:38 +00:00
|
|
|
rba, err := testbwagreement.GenerateRenterBandwidthAllocation(pba, storageNode1, upID, 666)
|
2018-12-10 14:50:12 +00:00
|
|
|
assert.NoError(t, err)
|
2018-12-07 12:11:35 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
// Unmarschal Renter and Payer bwagreements
|
|
|
|
rbaData := &pb.RenterBandwidthAllocation_Data{}
|
|
|
|
err = proto.Unmarshal(rba.GetData(), rbaData)
|
2018-12-10 14:50:12 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-10 18:30:55 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
pbaData := &pb.PayerBandwidthAllocation_Data{}
|
|
|
|
err = proto.Unmarshal(pba.GetData(), pbaData)
|
2019-01-10 18:30:55 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
// Storage node manipulates the bwagreement
|
|
|
|
rbaData.Total = 1337
|
|
|
|
|
|
|
|
// Marschal the manipulated bwagreement
|
|
|
|
maniprba, err := proto.Marshal(rbaData)
|
2019-01-10 18:30:55 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
// Generate a new keypair for self signing bwagreements
|
2019-01-25 18:05:21 +00:00
|
|
|
manipID, err := testidentity.NewTestIdentity(ctx)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-25 18:05:21 +00:00
|
|
|
manipCerts := manipID.ChainRaw() //todo: do we need RestChain?
|
|
|
|
manipPrivKey, ok := manipID.Key.(*ecdsa.PrivateKey)
|
|
|
|
assert.True(t, ok)
|
2019-01-10 18:30:55 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
/* Storage node can't manipulate the bwagreement size (or any other field)
|
2019-01-25 18:05:21 +00:00
|
|
|
Satellite will verify Renter's Signature. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
|
|
|
// Using uplink signature
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := callBWA(ctxSN1, satellite, rba.GetSignature(), maniprba, rba.GetCerts())
|
|
|
|
assert.True(t, auth.Verify.Has(err) && pb.Renter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Storage node can't sign the manipulated bwagreement
|
2019-01-25 18:05:21 +00:00
|
|
|
Satellite will verify Renter's Signature. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
|
|
|
manipSignature, err := cryptopasta.Sign(maniprba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Using self created signature
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := callBWA(ctxSN1, satellite, manipSignature, maniprba, rba.GetCerts())
|
|
|
|
assert.True(t, auth.Verify.Has(err) && pb.Renter.Has(err), err.Error())
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
2019-01-15 04:44:56 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
/* Storage node can't replace uplink Certs
|
|
|
|
Satellite will check uplink Certs against uplinkeId. */
|
|
|
|
{
|
|
|
|
manipSignature, err := cryptopasta.Sign(maniprba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Using self created signature + public key
|
|
|
|
reply, err := callBWA(ctxSN1, satellite, manipSignature, maniprba, manipCerts)
|
|
|
|
assert.True(t, auth.Signer.Has(err) && pb.Renter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
/* Storage node can't replace uplink NodeId
|
|
|
|
Satellite will verify the Payer's Signature. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-25 18:05:21 +00:00
|
|
|
// Overwrite the uplinkId with our own keypair
|
|
|
|
pbaData.UplinkId = manipID.ID
|
2019-01-15 04:44:56 +00:00
|
|
|
|
|
|
|
manippba, err := proto.Marshal(pbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
// Overwrite the uplink public key with our own keypair
|
2019-01-15 04:44:56 +00:00
|
|
|
rbaData.PayerAllocation = &pb.PayerBandwidthAllocation{
|
|
|
|
Signature: pba.GetSignature(),
|
|
|
|
Data: manippba,
|
2019-01-25 18:05:21 +00:00
|
|
|
Certs: pba.GetCerts(),
|
2019-01-15 04:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
maniprba, err := proto.Marshal(rbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
manipSignature, err := cryptopasta.Sign(maniprba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Using self created signature + public key
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := callBWA(ctxSN1, satellite, manipSignature, maniprba, manipCerts)
|
|
|
|
assert.True(t, auth.Verify.Has(err) && pb.Payer.Has(err), err.Error())
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Storage node can't self sign the PayerBandwidthAllocation.
|
|
|
|
Satellite will verify the Payer's Signature. */
|
|
|
|
{
|
|
|
|
// Overwrite the uplinkId with our own keypair
|
|
|
|
pbaData.UplinkId = manipID.ID
|
|
|
|
|
|
|
|
manippba, err := proto.Marshal(pbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
manipSignature, err := cryptopasta.Sign(manippba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
rbaData.PayerAllocation = &pb.PayerBandwidthAllocation{
|
2019-01-15 04:44:56 +00:00
|
|
|
Signature: manipSignature,
|
2019-01-25 18:05:21 +00:00
|
|
|
Data: manippba,
|
|
|
|
Certs: pba.GetCerts(),
|
|
|
|
}
|
2019-01-15 04:44:56 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
maniprba, err := proto.Marshal(rbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
manipSignature, err = cryptopasta.Sign(maniprba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Using self created Payer and Renter bwagreement signatures
|
|
|
|
reply, err := callBWA(ctxSN1, satellite, manipSignature, maniprba, manipCerts)
|
|
|
|
assert.True(t, auth.Verify.Has(err) && pb.Payer.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
/* Storage node can't replace the satellite Certs.
|
|
|
|
Satellite will check satellite certs against satelliteId. */
|
2019-01-15 04:44:56 +00:00
|
|
|
{
|
2019-01-25 18:05:21 +00:00
|
|
|
// Overwrite the uplinkId with our own keypair
|
|
|
|
pbaData.UplinkId = manipID.ID
|
2019-01-15 04:44:56 +00:00
|
|
|
|
|
|
|
manippba, err := proto.Marshal(pbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
manipSignature, err := cryptopasta.Sign(manippba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
rbaData.PayerAllocation = &pb.PayerBandwidthAllocation{
|
|
|
|
Signature: manipSignature,
|
|
|
|
Data: manippba,
|
2019-01-25 18:05:21 +00:00
|
|
|
Certs: manipCerts,
|
2019-01-15 04:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
maniprba, err := proto.Marshal(rbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
manipSignature, err = cryptopasta.Sign(maniprba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Using self created Payer and Renter bwagreement signatures
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := callBWA(ctxSN1, satellite, manipSignature, maniprba, manipCerts)
|
|
|
|
assert.True(t, auth.Signer.Has(err) && pb.Payer.Has(err), err.Error())
|
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Storage node can't replace the satellite.
|
|
|
|
Satellite will verify the Satellite Id. */
|
|
|
|
{
|
|
|
|
// Overwrite the uplinkId and satelliteID with our own keypair
|
|
|
|
pbaData.UplinkId = manipID.ID
|
|
|
|
pbaData.SatelliteId = manipID.ID
|
|
|
|
|
|
|
|
manippba, err := proto.Marshal(pbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
manipSignature, err := cryptopasta.Sign(manippba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
rbaData.PayerAllocation = &pb.PayerBandwidthAllocation{
|
2019-01-15 04:44:56 +00:00
|
|
|
Signature: manipSignature,
|
2019-01-25 18:05:21 +00:00
|
|
|
Data: manippba,
|
|
|
|
Certs: manipCerts,
|
|
|
|
}
|
2019-01-15 04:44:56 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
maniprba, err := proto.Marshal(rbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
manipSignature, err = cryptopasta.Sign(maniprba, manipPrivKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Using self created Payer and Renter bwagreement signatures
|
|
|
|
reply, err := callBWA(ctxSN1, satellite, manipSignature, maniprba, manipCerts)
|
|
|
|
assert.True(t, pb.Payer.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ //TestInvalidBandwidthAgreements
|
2019-01-25 18:05:21 +00:00
|
|
|
ctxSN1, storageNode1 := getPeerContext(ctx, t)
|
|
|
|
ctxSN2, storageNode2 := getPeerContext(ctx, t)
|
2019-01-25 23:06:38 +00:00
|
|
|
pba, err := testbwagreement.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satID, upID, time.Hour)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
{ // Storage node sends an corrupted signuature to force a satellite crash
|
2019-01-25 23:06:38 +00:00
|
|
|
rba, err := testbwagreement.GenerateRenterBandwidthAllocation(pba, storageNode1, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
rba.Signature = []byte("invalid")
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := satellite.BandwidthAgreements(ctxSN1, rba)
|
|
|
|
assert.True(t, auth.SigLen.Has(err) && pb.Renter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
2019-01-11 03:31:47 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
{ // Storage node sends an corrupted uplink Certs to force a crash
|
2019-01-25 23:06:38 +00:00
|
|
|
rba, err := testbwagreement.GenerateRenterBandwidthAllocation(pba, storageNode2, upID, 666)
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.NoError(t, err)
|
2019-01-11 03:31:47 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
rbaData := &pb.RenterBandwidthAllocation_Data{}
|
|
|
|
err = proto.Unmarshal(rba.GetData(), rbaData)
|
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
pbaData := &pb.PayerBandwidthAllocation_Data{}
|
|
|
|
err = proto.Unmarshal(pba.GetData(), pbaData)
|
|
|
|
assert.NoError(t, err)
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
pba.Certs = nil
|
2019-01-07 15:19:05 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
invalidpba, err := proto.Marshal(pbaData)
|
|
|
|
assert.NoError(t, err)
|
2019-01-11 03:31:47 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
rbaData.PayerAllocation = &pb.PayerBandwidthAllocation{
|
|
|
|
Signature: pba.GetSignature(),
|
|
|
|
Data: invalidpba,
|
2019-01-25 18:05:21 +00:00
|
|
|
Certs: pba.GetCerts(),
|
2019-01-15 04:44:56 +00:00
|
|
|
}
|
2019-01-11 03:31:47 +00:00
|
|
|
|
2019-01-15 04:44:56 +00:00
|
|
|
invalidrba, err := proto.Marshal(rbaData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
reply, err := callBWA(ctxSN2, satellite, rba.GetSignature(), invalidrba, rba.GetCerts())
|
|
|
|
assert.True(t, auth.Verify.Has(err) && pb.Renter.Has(err), err.Error())
|
2019-01-15 04:44:56 +00:00
|
|
|
assert.Equal(t, pb.AgreementsSummary_REJECTED, reply.Status)
|
|
|
|
}
|
|
|
|
}
|
2018-12-07 12:11:35 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 18:05:21 +00:00
|
|
|
func callBWA(ctx context.Context, sat *bwagreement.Server, signature, data []byte, certs [][]byte) (*pb.AgreementsSummary, error) {
|
|
|
|
rba := &pb.RenterBandwidthAllocation{Signature: signature, Data: data, Certs: certs}
|
|
|
|
return sat.BandwidthAgreements(ctx, rba)
|
2018-12-05 14:03:23 +00:00
|
|
|
}
|