satellite/satellitedb: allow setting rate limit for a project to 0
If a user starts to abuse our system, we need the ability to manually disable their access Change-Id: Ia31964cedb830323da69c1153a84d610cf8310cd
This commit is contained in:
parent
211a630982
commit
445ebf86c0
@ -16,9 +16,11 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/common/errs2"
|
||||
"storj.io/common/macaroon"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/common/testrand"
|
||||
"storj.io/common/uuid"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
@ -566,3 +568,39 @@ func TestDeleteProjectWithUsagePreviousMonth(t *testing.T) {
|
||||
require.Equal(t, http.StatusConflict, response.StatusCode)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRateLimit_ProjectRateLimitZero(t *testing.T) {
|
||||
rateLimit := 2
|
||||
testplanet.Run(t, testplanet.Config{
|
||||
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1,
|
||||
Reconfigure: testplanet.Reconfigure{
|
||||
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
|
||||
config.Metainfo.RateLimiter.Rate = float64(rateLimit)
|
||||
// Make limit cache to refresh as quickly as possible
|
||||
// if it starts to become flaky, we can then add sleeps between
|
||||
// the cache update and the API calls
|
||||
config.Metainfo.RateLimiter.CacheExpiration = time.Millisecond
|
||||
},
|
||||
},
|
||||
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
||||
ul := planet.Uplinks[0]
|
||||
satellite := planet.Satellites[0]
|
||||
|
||||
projects, err := satellite.DB.Console().Projects().GetAll(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, projects, 1)
|
||||
|
||||
zeroRateLimit := 0
|
||||
err = satellite.DB.Console().Projects().UpdateRateLimit(ctx, projects[0].ID, zeroRateLimit)
|
||||
require.NoError(t, err)
|
||||
|
||||
var group errs2.Group
|
||||
for i := 0; i <= rateLimit; i++ {
|
||||
group.Go(func() error {
|
||||
return ul.CreateBucket(ctx, satellite, testrand.BucketName())
|
||||
})
|
||||
}
|
||||
groupErrs := group.Wait()
|
||||
require.Len(t, groupErrs, 3)
|
||||
})
|
||||
}
|
||||
|
@ -157,15 +157,14 @@ func (projects *projects) Update(ctx context.Context, project *console.Project)
|
||||
func (projects *projects) UpdateRateLimit(ctx context.Context, id uuid.UUID, newLimit int) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
rateLimit := &newLimit
|
||||
if newLimit == 0 {
|
||||
rateLimit = nil
|
||||
if newLimit < 0 {
|
||||
return Error.New("limit can't be set to negative value")
|
||||
}
|
||||
|
||||
_, err = projects.db.Update_Project_By_Id(ctx,
|
||||
dbx.Project_Id(id[:]),
|
||||
dbx.Project_Update_Fields{
|
||||
RateLimit: dbx.Project_RateLimit_Raw(rateLimit),
|
||||
RateLimit: dbx.Project_RateLimit(newLimit),
|
||||
})
|
||||
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user