From f741d69e3d7264c610e9503ee72173b424e1d780 Mon Sep 17 00:00:00 2001 From: Alwin Zomotor Date: Tue, 10 Sep 2024 23:25:12 +0200 Subject: [PATCH] fix: fixed bug in tuple streaming test: - fake castor client always returned empty byte array; - removed unused functions Signed-off-by: Alwin Zomotor --- pkg/ephemeral/io/tuple_streamer.go | 21 ---------- pkg/ephemeral/io/tuple_streamer_test.go | 53 +++---------------------- 2 files changed, 5 insertions(+), 69 deletions(-) diff --git a/pkg/ephemeral/io/tuple_streamer.go b/pkg/ephemeral/io/tuple_streamer.go index 82eb4030..01a6c85b 100644 --- a/pkg/ephemeral/io/tuple_streamer.go +++ b/pkg/ephemeral/io/tuple_streamer.go @@ -8,7 +8,6 @@ package io import ( - "encoding/base64" "encoding/binary" "errors" "fmt" @@ -324,26 +323,6 @@ func (ts *CastorTupleStreamer) writeDataToPipe(terminateCh chan struct{}, doneCh } } -// tupleListToByteArray converts a given list of tuple to a byte array -func (ts *CastorTupleStreamer) tupleListToByteArray(tl *castor.TupleList) ([]byte, error) { - var result []byte - for _, tuple := range tl.Tuples { - for _, share := range tuple.Shares { - decodeString, err := base64.StdEncoding.DecodeString(share.Value) - if err != nil { - return []byte{}, err - } - result = append(result, decodeString...) - decodeString, err = base64.StdEncoding.DecodeString(share.Mac) - if err != nil { - return []byte{}, err - } - result = append(result, decodeString...) - } - } - return result, nil -} - // generateHeader returns the file header for the given protocol and spdz runtime configuration func generateHeader(sp castor.SPDZProtocol, conf *SPDZEngineTypedConfig) ([]byte, error) { switch sp { diff --git a/pkg/ephemeral/io/tuple_streamer_test.go b/pkg/ephemeral/io/tuple_streamer_test.go index d17f61b0..63147ac7 100644 --- a/pkg/ephemeral/io/tuple_streamer_test.go +++ b/pkg/ephemeral/io/tuple_streamer_test.go @@ -105,49 +105,6 @@ var _ = Describe("Tuple Streamer", func() { Expect(<-errCh).NotTo(BeNil()) }) }) - Context("when castor client returns illegal data", func() { - Context("when share value is invalid", func() { - It("writes error to error channel and stops", func() { - invalidShareValue := "value" - share := castor.Share{Value: invalidShareValue} - shares := make([]castor.Share, 1) - shares[0] = share - tuples := make([]castor.Tuple, 1) - tuples[0] = castor.Tuple{Shares: shares} - cc.TupleList = &castor.TupleList{Tuples: tuples} - wg.Add(1) - ts.StartStreamTuples(terminate, errCh, wg) - wg.Wait() - close(terminate) - close(errCh) - Expect(fcpw.isClosed).To(BeTrue()) - err := <-errCh - Expect(err).To(HaveOccurred()) - Expect(err).To(Equal(errors.New("error parsing received tuple list: illegal base64 data at input byte 4"))) - }) - }) - Context("when share value is invalid", func() { - It("writes error to error channel and stops", func() { - validShareValue := base64.StdEncoding.EncodeToString([]byte("value")) - invalidShareMac := "value" - share := castor.Share{Value: validShareValue, Mac: invalidShareMac} - shares := make([]castor.Share, 1) - shares[0] = share - tuples := make([]castor.Tuple, 1) - tuples[0] = castor.Tuple{Shares: shares} - cc.TupleList = &castor.TupleList{Tuples: tuples} - wg.Add(1) - ts.StartStreamTuples(terminate, errCh, wg) - wg.Wait() - close(terminate) - close(errCh) - Expect(fcpw.isClosed).To(BeTrue()) - err := <-errCh - Expect(err).To(HaveOccurred()) - Expect(err).To(Equal(errors.New("error parsing received tuple list: illegal base64 data at input byte 4"))) - }) - }) - }) Context("when tuples fetched successfully", func() { shareValue := "value" shareMac := "value" @@ -161,7 +118,7 @@ var _ = Describe("Tuple Streamer", func() { tuples[0] = castor.Tuple{Shares: shares} initialStreamData := []byte(shareValue + shareMac) BeforeEach(func() { - cc.TupleList = &castor.TupleList{Tuples: tuples} + cc.TupleData = initialStreamData }) Context("when writing data to pipe fails with broken pipe", func() { var expectedError = syscall.EPIPE @@ -551,15 +508,15 @@ func (fpcfpw *FakePartialConsumingFailSecondCallPipeWriter) Close() error { } type FakeCastorClient struct { - TupleList *castor.TupleList + TupleData []byte } func (fcc *FakeCastorClient) GetTuples(int32, castor.TupleType, uuid.UUID) ([]byte, error) { - tl := fcc.TupleList + tl := fcc.TupleData if tl == nil { - tl = &castor.TupleList{} + tl = []byte{} } - return []byte{}, nil + return tl, nil } type BrokenDownloadCastorClient struct{}