From 9a7c4b365609d2d9655cfcf305a70838b548babc Mon Sep 17 00:00:00 2001 From: Acha Bill Date: Wed, 28 Feb 2024 21:21:28 +0100 Subject: [PATCH] fix: soc chunk from data --- .github/workflows/beekeeper.yml | 3 ++- pkg/api/chunk.go | 7 +++++++ pkg/soc/soc_test.go | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/.github/workflows/beekeeper.yml b/.github/workflows/beekeeper.yml index 437236925cd..17ec6c5a605 100644 --- a/.github/workflows/beekeeper.yml +++ b/.github/workflows/beekeeper.yml @@ -132,7 +132,8 @@ jobs: run: timeout ${TIMEOUT} bash -c 'until beekeeper check --cluster-name local-dns --checks=ci-full-connectivity; do echo "waiting for full connectivity..."; sleep .3; done' - name: Test redundancy id: redundancy - run: timeout ${TIMEOUT} bash -c 'until beekeeper check --cluster-name local-dns --checks ci-redundancy; do echo "waiting for redundancy..."; sleep .3; done' + #run: timeout ${TIMEOUT} bash -c 'until beekeeper check --cluster-name local-dns --checks ci-redundancy; do echo "waiting for redundancy..."; sleep .3; done' + run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks ci-redundancy - name: Collect debug artifacts if: failure() run: | diff --git a/pkg/api/chunk.go b/pkg/api/chunk.go index ced7b79a66a..c11037605b1 100644 --- a/pkg/api/chunk.go +++ b/pkg/api/chunk.go @@ -128,6 +128,13 @@ func (s *Service) chunkUploadHandler(w http.ResponseWriter, r *http.Request) { jsonhttp.InternalServerError(ow, "create chunk error") return } + + if !soc.Valid(chunk) { + logger.Debug("chunk upload: invalid soc chunk") + logger.Error(nil, "chunk upload: create chunk error") + jsonhttp.InternalServerError(ow, "create chunk error") + return + } } err = putter.Put(r.Context(), chunk) diff --git a/pkg/soc/soc_test.go b/pkg/soc/soc_test.go index e4f6fb4e199..105a7cdedde 100644 --- a/pkg/soc/soc_test.go +++ b/pkg/soc/soc_test.go @@ -47,6 +47,41 @@ func TestNew(t *testing.T) { } } +func TestReplica(t *testing.T) { + sig, err := hex.DecodeString("5acd384febc133b7b245e5ddc62d82d2cded9182d2716126cd8844509af65a053deb418208027f548e3e88343af6f84a8772fb3cebc0a1833a0ea7ec0c1348311b") + if err != nil { + t.Fatal(err) + } + + payload := []byte("foo") + ch, err := cac.New(payload) + if err != nil { + t.Fatal(err) + } + + id := make([]byte, swarm.HashSize) + s, err := soc.NewSigned(id, ch, swarm.ReplicasOwner, sig) + if err != nil { + t.Fatal(err) + } + + ch, err = s.Chunk() + if err != nil { + t.Fatal(err) + } + sch, err := soc.FromChunk(swarm.NewChunk(swarm.EmptyAddress, ch.Data())) + if err != nil { + t.Fatal(err) + } + ch, err = sch.Chunk() + if err != nil { + t.Fatal(err) + } + if !soc.Valid(ch) { + t.Fatal("invalid soc chunk") + } +} + func TestNewSigned(t *testing.T) { t.Parallel()