Skip to content

Commit

Permalink
fix: fixed bug in tuple streaming test:
Browse files Browse the repository at this point in the history
- fake castor client always returned empty byte array;
- removed unused functions

Signed-off-by: Alwin Zomotor <[email protected]>
  • Loading branch information
CRAlwin committed Sep 10, 2024
1 parent 9e8a846 commit f741d69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 69 deletions.
21 changes: 0 additions & 21 deletions pkg/ephemeral/io/tuple_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package io

import (
"encoding/base64"
"encoding/binary"
"errors"
"fmt"
Expand Down Expand Up @@ -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 {
Expand Down
53 changes: 5 additions & 48 deletions pkg/ephemeral/io/tuple_streamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit f741d69

Please sign in to comment.