2019-03-19 17:37:26 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package audit_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/memory"
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
"storj.io/storj/pkg/audit"
|
2019-05-13 23:43:24 +01:00
|
|
|
"storj.io/storj/uplink"
|
2019-03-19 17:37:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVerifierHappyPath(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2019-03-22 13:14:17 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1,
|
2019-03-19 17:37:26 +00:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
err := planet.Satellites[0].Audit.Service.Close()
|
2019-04-01 22:27:07 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:37:26 +00:00
|
|
|
|
2019-05-13 23:43:24 +01:00
|
|
|
ul := planet.Uplinks[0]
|
2019-03-22 13:14:17 +00:00
|
|
|
testData := make([]byte, 1*memory.MiB)
|
2019-03-19 17:37:26 +00:00
|
|
|
_, err = rand.Read(testData)
|
2019-04-01 22:27:07 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:37:26 +00:00
|
|
|
|
2019-05-13 23:43:24 +01:00
|
|
|
err = ul.UploadWithConfig(ctx, planet.Satellites[0], &uplink.RSConfig{
|
|
|
|
MinThreshold: 4,
|
|
|
|
RepairThreshold: 5,
|
|
|
|
SuccessThreshold: 6,
|
|
|
|
MaxThreshold: 6,
|
|
|
|
}, "testbucket", "test/path", testData)
|
2019-04-01 22:27:07 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:37:26 +00:00
|
|
|
|
2019-04-25 09:46:32 +01:00
|
|
|
metainfo := planet.Satellites[0].Metainfo.Service
|
2019-03-19 17:37:26 +00:00
|
|
|
overlay := planet.Satellites[0].Overlay.Service
|
2019-04-25 09:46:32 +01:00
|
|
|
cursor := audit.NewCursor(metainfo)
|
2019-03-19 17:37:26 +00:00
|
|
|
|
2019-05-01 19:59:30 +01:00
|
|
|
stripe, _, err := cursor.NextStripe(ctx)
|
2019-03-19 17:37:26 +00:00
|
|
|
require.NoError(t, err)
|
2019-04-25 16:43:26 +01:00
|
|
|
require.NotNil(t, stripe)
|
2019-03-19 17:37:26 +00:00
|
|
|
|
|
|
|
transport := planet.Satellites[0].Transport
|
2019-03-28 20:09:23 +00:00
|
|
|
orders := planet.Satellites[0].Orders.Service
|
2019-03-19 17:37:26 +00:00
|
|
|
minBytesPerSecond := 128 * memory.B
|
2019-03-28 20:09:23 +00:00
|
|
|
verifier := audit.NewVerifier(zap.L(), transport, overlay, orders, planet.Satellites[0].Identity, minBytesPerSecond)
|
2019-03-19 17:37:26 +00:00
|
|
|
require.NotNil(t, verifier)
|
|
|
|
|
|
|
|
// stop some storage nodes to ensure audit can deal with it
|
|
|
|
err = planet.StopPeer(planet.StorageNodes[0])
|
2019-04-01 22:27:07 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:37:26 +00:00
|
|
|
err = planet.StopPeer(planet.StorageNodes[1])
|
2019-04-01 22:27:07 +01:00
|
|
|
require.NoError(t, err)
|
2019-03-19 17:37:26 +00:00
|
|
|
|
2019-04-04 17:34:36 +01:00
|
|
|
// mark stopped nodes as offline in overlay cache
|
|
|
|
_, err = planet.Satellites[0].Overlay.Service.UpdateUptime(ctx, planet.StorageNodes[0].ID(), false)
|
2019-03-28 20:09:23 +00:00
|
|
|
require.NoError(t, err)
|
2019-04-04 17:34:36 +01:00
|
|
|
_, err = planet.Satellites[0].Overlay.Service.UpdateUptime(ctx, planet.StorageNodes[1].ID(), false)
|
2019-03-28 20:09:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-05-13 23:43:24 +01:00
|
|
|
verifiedNodes, err := verifier.Verify(ctx, stripe)
|
2019-04-01 22:27:07 +01:00
|
|
|
require.NoError(t, err)
|
2019-05-13 23:43:24 +01:00
|
|
|
|
|
|
|
require.Len(t, verifiedNodes.SuccessNodeIDs, 4)
|
|
|
|
require.Len(t, verifiedNodes.FailNodeIDs, 0)
|
2019-03-19 17:37:26 +00:00
|
|
|
})
|
|
|
|
}
|