From 7dc696f82aba69e22688e47a73cdc9d007bd7e3b Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Thu, 19 Dec 2024 12:03:03 +0100 Subject: [PATCH] add TestDefaultSettingsUploadDownload --- internal/test/e2e/cluster.go | 11 +++--- internal/test/e2e/cluster_test.go | 60 +++++++++++++++++++++++++++++++ internal/test/e2e/host.go | 2 +- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/internal/test/e2e/cluster.go b/internal/test/e2e/cluster.go index 17dde4647..9564e046f 100644 --- a/internal/test/e2e/cluster.go +++ b/internal/test/e2e/cluster.go @@ -193,8 +193,9 @@ type testClusterOptions struct { hosts int logger *zap.Logger uploadPacking bool - skipSettingAutopilot bool skipRunningAutopilot bool + skipSettingAutopilot bool + skipUpdatingSettings bool walletKey *types.PrivateKey autopilotCfg *config.Autopilot @@ -474,9 +475,11 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster { } // Update the bus settings. - tt.OK(busClient.UpdateGougingSettings(ctx, test.GougingSettings)) - tt.OK(busClient.UpdateUploadSettings(ctx, us)) - tt.OK(busClient.UpdateS3Settings(ctx, s3)) + if !opts.skipUpdatingSettings { + tt.OK(busClient.UpdateGougingSettings(ctx, test.GougingSettings)) + tt.OK(busClient.UpdateUploadSettings(ctx, us)) + tt.OK(busClient.UpdateS3Settings(ctx, s3)) + } // Fund the bus. if funding { diff --git a/internal/test/e2e/cluster_test.go b/internal/test/e2e/cluster_test.go index b7cdac701..c1ca0245a 100644 --- a/internal/test/e2e/cluster_test.go +++ b/internal/test/e2e/cluster_test.go @@ -36,6 +36,7 @@ import ( "go.sia.tech/renterd/internal/test" "go.sia.tech/renterd/internal/utils" "go.sia.tech/renterd/object" + "go.sia.tech/renterd/stores/sql" "go.sia.tech/renterd/stores/sql/sqlite" "lukechampine.com/frand" ) @@ -3087,3 +3088,62 @@ func TestV1ToV2Transition(t *testing.T) { return nil }) } + +func TestDefaultSettingsUploadDownload(t *testing.T) { + // create a test cluster + apCfg := test.AutopilotConfig + apCfg.Contracts.Amount = uint64(api.DefaultRedundancySettingsTestnet.TotalShards) + cluster := newTestCluster(t, testClusterOptions{ + hosts: api.DefaultRedundancySettingsTestnet.TotalShards, + logger: newTestLogger(false), + skipUpdatingSettings: true, + autopilotConfig: &apCfg, + }) + defer cluster.Shutdown() + + b := cluster.Bus + w := cluster.Worker + tt := cluster.tt + + // sanity check settings + _, err := cluster.bs.GougingSettings(context.Background()) + tt.AssertIs(err, sql.ErrSettingNotFound) + _, err = cluster.bs.PinnedSettings(context.Background()) + tt.AssertIs(err, sql.ErrSettingNotFound) + _, err = cluster.bs.S3Settings(context.Background()) + tt.AssertIs(err, sql.ErrSettingNotFound) + _, err = cluster.bs.UploadSettings(context.Background()) + tt.AssertIs(err, sql.ErrSettingNotFound) + + // prepare a file + data := make([]byte, 128) + tt.OKAll(frand.Read(data)) + + // upload and download data the native way + path := "/regularFile" + tt.OKAll(w.UploadObject(context.Background(), bytes.NewReader(data), testBucket, path, api.UploadObjectOptions{})) + tt.OK(w.DownloadObject(context.Background(), bytes.NewBuffer(nil), testBucket, path, api.DownloadObjectOptions{})) + + // upload and download a multipart upload + multipartPath := "/multipartFile" + mpu, err := b.CreateMultipartUpload(context.Background(), testBucket, multipartPath, api.CreateMultipartOptions{}) + tt.OK(err) + offset := 0 + part, err := w.UploadMultipartUploadPart(context.Background(), bytes.NewReader(data), testBucket, multipartPath, mpu.UploadID, 1, api.UploadMultipartUploadPartOptions{EncryptionOffset: &offset}) + tt.OK(err) + tt.OKAll(b.CompleteMultipartUpload(context.Background(), testBucket, multipartPath, mpu.UploadID, []api.MultipartCompletedPart{ + { + PartNumber: 1, + ETag: part.ETag, + }, + }, api.CompleteMultipartOptions{})) + tt.OK(err) + tt.OK(w.DownloadObject(context.Background(), bytes.NewBuffer(nil), testBucket, multipartPath, api.DownloadObjectOptions{})) + + // upload and download via s3 to test the default s3 settings + s3Path := "/s3File" + _, err = cluster.S3.PutObject(testBucket, s3Path, bytes.NewReader(data), putObjectOptions{}) + if err == nil || !strings.Contains(err.Error(), "AccessDenied") { + t.Fatal("expected access denied error") + } +} diff --git a/internal/test/e2e/host.go b/internal/test/e2e/host.go index fc3d1194c..fe673fa46 100644 --- a/internal/test/e2e/host.go +++ b/internal/test/e2e/host.go @@ -76,7 +76,7 @@ var defaultHostSettings = settings.Settings{ IngressPrice: types.Siacoins(100).Div64(1e12), WindowSize: 5, - PriceTableValidity: 10 * time.Second, + PriceTableValidity: 5 * time.Minute, AccountExpiry: 30 * 24 * time.Hour, // 1 month MaxAccountBalance: types.Siacoins(10),