Skip to content

Commit

Permalink
fix: crash in CreateChunkedBlob with invalid param (#288)
Browse files Browse the repository at this point in the history
Fix a crash bug when an invalid parameter was passed to CreateChunkedBlob.
  • Loading branch information
yuryu authored Aug 24, 2021
1 parent 57435e7 commit 908e78c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/app/server/open_saves.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (s *openSavesServer) CreateChunkedBlob(ctx context.Context, req *pb.CreateC
b := blobref.NewChunkedBlobRef(req.GetStoreKey(), req.GetRecordKey())
b, err := s.metaDB.InsertBlobRef(ctx, b)
if err != nil {
log.Errorf("CreateChunkedBlob failed for record (%v), blob key (%v): %v", b.RecordKey, b.Key, err)
log.Errorf("CreateChunkedBlob failed for store (%v), record (%v): %v", req.GetStoreKey(), req.GetRecordKey(), err)
return nil, err
}
return &pb.CreateChunkedBlobResponse{
Expand Down
17 changes: 17 additions & 0 deletions internal/app/server/open_saves_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/api/iterator"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down Expand Up @@ -855,3 +857,18 @@ func TestOpenSaves_QueryRecords_Tags(t *testing.T) {

assert.Contains(t, resp.Records[0].Tags, "hello")
}

func TestOpenSaves_CreateChunkedBlobNonExistent(t *testing.T) {
ctx := context.Background()
_, listener := getOpenSavesServer(ctx, t, "gcp")
_, client := getTestClient(ctx, t, listener)

// Non-existent record should fail with codes.FailedPrecondition
res, err := client.CreateChunkedBlob(ctx, &pb.CreateChunkedBlobRequest{
StoreKey: uuid.NewString(),
RecordKey: uuid.NewString(),
ChunkSize: 0,
})
assert.Nil(t, res)
assert.Equal(t, codes.FailedPrecondition, status.Code(err))
}

0 comments on commit 908e78c

Please sign in to comment.