2019-06-07 13:38:41 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package audit_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/pkcrypto"
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
2020-03-11 21:11:46 +00:00
|
|
|
"storj.io/common/testrand"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-07-28 06:55:36 +01:00
|
|
|
"storj.io/storj/satellite/audit"
|
2019-06-07 13:38:41 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestReportPendingAudits(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
audits.Worker.Loop.Pause()
|
2019-06-07 13:38:41 +01:00
|
|
|
|
|
|
|
nodeID := planet.StorageNodes[0].ID()
|
|
|
|
|
|
|
|
pending := audit.PendingAudit{
|
|
|
|
NodeID: nodeID,
|
|
|
|
PieceID: storj.NewPieceID(),
|
|
|
|
StripeIndex: 1,
|
|
|
|
ShareSize: 1 * memory.KiB.Int32(),
|
|
|
|
ExpectedShareHash: pkcrypto.SHA256Hash([]byte("test")),
|
|
|
|
}
|
|
|
|
|
|
|
|
report := audit.Report{PendingAudits: []*audit.PendingAudit{&pending}}
|
2019-09-11 23:37:01 +01:00
|
|
|
overlay := satellite.Overlay.Service
|
|
|
|
containment := satellite.DB.Containment()
|
2019-06-07 13:38:41 +01:00
|
|
|
|
2019-10-16 12:48:05 +01:00
|
|
|
failed, err := audits.Reporter.RecordAudits(ctx, report, "")
|
2019-06-07 13:38:41 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Zero(t, failed)
|
|
|
|
|
|
|
|
node, err := overlay.Get(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, node.Contained)
|
|
|
|
|
|
|
|
pa, err := containment.Get(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, pending, *pa)
|
|
|
|
})
|
|
|
|
}
|
2019-06-21 16:10:03 +01:00
|
|
|
|
|
|
|
func TestRecordAuditsAtLeastOnce(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
2019-09-11 23:37:01 +01:00
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
audits.Worker.Loop.Pause()
|
2019-06-21 16:10:03 +01:00
|
|
|
|
|
|
|
nodeID := planet.StorageNodes[0].ID()
|
|
|
|
|
|
|
|
report := audit.Report{Successes: []storj.NodeID{nodeID}}
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
// expect RecordAudits to try recording at least once (maxRetries is set to 0)
|
2019-10-16 12:48:05 +01:00
|
|
|
failed, err := audits.Reporter.RecordAudits(ctx, report, "")
|
2019-06-21 16:10:03 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, failed)
|
|
|
|
|
2019-09-11 23:37:01 +01:00
|
|
|
overlay := satellite.Overlay.Service
|
2019-06-21 16:10:03 +01:00
|
|
|
node, err := overlay.Get(ctx, nodeID)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, 1, node.Reputation.AuditCount)
|
|
|
|
})
|
|
|
|
}
|
2020-03-11 21:11:46 +00:00
|
|
|
|
|
|
|
// TestRecordAuditsCorrectOutcome ensures that audit successes, failures, and unknown audits result in the correct disqualification/suspension state.
|
|
|
|
func TestRecordAuditsCorrectOutcome(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 5, UplinkCount: 0,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
audits := satellite.Audit
|
|
|
|
audits.Worker.Loop.Pause()
|
|
|
|
|
|
|
|
goodNode := planet.StorageNodes[0].ID()
|
|
|
|
dqNode := planet.StorageNodes[1].ID()
|
|
|
|
suspendedNode := planet.StorageNodes[2].ID()
|
|
|
|
pendingNode := planet.StorageNodes[3].ID()
|
|
|
|
offlineNode := planet.StorageNodes[4].ID()
|
|
|
|
|
|
|
|
report := audit.Report{
|
|
|
|
Successes: []storj.NodeID{goodNode},
|
|
|
|
Fails: []storj.NodeID{dqNode},
|
|
|
|
Unknown: []storj.NodeID{suspendedNode},
|
|
|
|
PendingAudits: []*audit.PendingAudit{
|
|
|
|
{
|
|
|
|
NodeID: pendingNode,
|
|
|
|
PieceID: testrand.PieceID(),
|
|
|
|
StripeIndex: 0,
|
|
|
|
ShareSize: 10,
|
|
|
|
ExpectedShareHash: []byte{},
|
|
|
|
ReverifyCount: 0,
|
|
|
|
Path: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Offlines: []storj.NodeID{offlineNode},
|
|
|
|
}
|
|
|
|
|
|
|
|
failed, err := audits.Reporter.RecordAudits(ctx, report, "")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, failed)
|
|
|
|
|
|
|
|
overlay := satellite.Overlay.Service
|
|
|
|
node, err := overlay.Get(ctx, goodNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, node.Disqualified)
|
|
|
|
require.Nil(t, node.Suspended)
|
|
|
|
|
|
|
|
node, err = overlay.Get(ctx, dqNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, node.Disqualified)
|
|
|
|
require.Nil(t, node.Suspended)
|
|
|
|
|
|
|
|
node, err = overlay.Get(ctx, suspendedNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, node.Disqualified)
|
|
|
|
require.NotNil(t, node.Suspended)
|
|
|
|
|
|
|
|
node, err = overlay.Get(ctx, pendingNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, node.Disqualified)
|
|
|
|
require.Nil(t, node.Suspended)
|
|
|
|
|
|
|
|
node, err = overlay.Get(ctx, offlineNode)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, node.Disqualified)
|
|
|
|
require.Nil(t, node.Suspended)
|
|
|
|
})
|
|
|
|
}
|