From e6a5801155325959c57c9779e2f66e8594bec86c Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 15 Aug 2021 18:16:17 +0200 Subject: [PATCH 1/3] rest: Fix test backend url The rest config normally uses prepareURL to sanitize URLs and ensures that the URL ends with a slash. However, the test used an URL without a trailing slash, which after the rest server changes causes test failures. --- internal/backend/rest/rest_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/backend/rest/rest_test.go b/internal/backend/rest/rest_test.go index 3f6859626..45aeabb99 100644 --- a/internal/backend/rest/rest_test.go +++ b/internal/backend/rest/rest_test.go @@ -50,7 +50,7 @@ func runRESTServer(ctx context.Context, t testing.TB, dir string) (*url.URL, fun return nil, nil } - url, err := url.Parse("http://localhost:8000/restic-test") + url, err := url.Parse("http://localhost:8000/restic-test/") if err != nil { t.Fatal(err) } From 574c83e47f47fb52cf7c2f2c31ab0cbfef949d9f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 15 Aug 2021 18:19:43 +0200 Subject: [PATCH 2/3] rest: Fix test to use paths which are the sha256 sum of the data --- internal/backend/test/tests.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/backend/test/tests.go b/internal/backend/test/tests.go index 05a41c616..8e1f78ca6 100644 --- a/internal/backend/test/tests.go +++ b/internal/backend/test/tests.go @@ -13,6 +13,7 @@ import ( "testing" "time" + "github.com/minio/sha256-simd" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" @@ -484,12 +485,11 @@ func (s *Suite) TestSave(t *testing.T) { for i := 0; i < saveTests; i++ { length := rand.Intn(1<<23) + 200000 data := test.Random(23, length) - // use the first 32 byte as the ID - copy(id[:], data) + id = sha256.Sum256(data) h := restic.Handle{ Type: restic.PackFile, - Name: fmt.Sprintf("%s-%d", id, i), + Name: id.String(), } err := b.Save(context.TODO(), h, restic.NewByteReader(data, b.Hasher())) test.OK(t, err) @@ -529,7 +529,7 @@ func (s *Suite) TestSave(t *testing.T) { length := rand.Intn(1<<23) + 200000 data := test.Random(23, length) - copy(id[:], data) + id = sha256.Sum256(data) if _, err = tmpfile.Write(data); err != nil { t.Fatal(err) From 68370feeee702353c5b5069cd7d0e77945974333 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 15 Aug 2021 18:24:16 +0200 Subject: [PATCH 3/3] backends: Remove TestSaveFilenames test Filenames are expected to match the sha256 sum of the file content. This rule is now enforced by the rest server thus making this test useless. --- internal/backend/test/tests.go | 43 ---------------------------------- 1 file changed, 43 deletions(-) diff --git a/internal/backend/test/tests.go b/internal/backend/test/tests.go index 8e1f78ca6..bc89f737d 100644 --- a/internal/backend/test/tests.go +++ b/internal/backend/test/tests.go @@ -657,49 +657,6 @@ func (s *Suite) TestSaveWrongHash(t *testing.T) { } } -var filenameTests = []struct { - name string - data string -}{ - {"1dfc6bc0f06cb255889e9ea7860a5753e8eb9665c9a96627971171b444e3113e", "x"}, - {"f00b4r", "foobar"}, - { - "1dfc6bc0f06cb255889e9ea7860a5753e8eb9665c9a96627971171b444e3113e4bf8f2d9144cc5420a80f04a4880ad6155fc58903a4fb6457c476c43541dcaa6-5", - "foobar content of data blob", - }, -} - -// TestSaveFilenames tests saving data with various file names in the backend. -func (s *Suite) TestSaveFilenames(t *testing.T) { - b := s.open(t) - defer s.close(t, b) - - for i, test := range filenameTests { - h := restic.Handle{Name: test.name, Type: restic.PackFile} - err := b.Save(context.TODO(), h, restic.NewByteReader([]byte(test.data), b.Hasher())) - if err != nil { - t.Errorf("test %d failed: Save() returned %+v", i, err) - continue - } - - buf, err := backend.LoadAll(context.TODO(), nil, b, h) - if err != nil { - t.Errorf("test %d failed: Load() returned %+v", i, err) - continue - } - - if !bytes.Equal(buf, []byte(test.data)) { - t.Errorf("test %d: returned wrong bytes", i) - } - - err = b.Remove(context.TODO(), h) - if err != nil { - t.Errorf("test %d failed: Remove() returned %+v", i, err) - continue - } - } -} - var testStrings = []struct { id string data string