Skip to content

Commit

Permalink
Fix old proto compatibility (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyech authored Aug 18, 2023
1 parent 815a746 commit 35e4ba0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/transports/anypb_nourl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transports

import (
"fmt"
"strings"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
Expand All @@ -17,6 +18,8 @@ func UnmarshalAnypbTo(src *anypb.Any, dst protoreflect.ProtoMessage) error {
return fmt.Errorf("error reading src type: %v", err)
}

src.TypeUrl = strings.ReplaceAll(src.TypeUrl, "tapdance.", "proto.")

if src.TypeUrl != "" && src.TypeUrl != expected.TypeUrl {
return fmt.Errorf("incorrect non-empty TypeUrl: %v != %v", src.TypeUrl, expected.TypeUrl)
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/transports/anypb_nourl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transports_test

import (
"crypto/rand"
"strings"
"testing"

"github.com/refraction-networking/conjure/pkg/transports"
Expand Down Expand Up @@ -55,3 +56,16 @@ func TestGarbage(t *testing.T) {
err = proto.Unmarshal(garbagebytes, dstAnypb)
require.NotNil(t, err)
}

func TestOldProto(t *testing.T) {
src, err := anypb.New(&pb.GenericTransportParams{RandomizeDstPort: proto.Bool(true)})
require.Nil(t, err)

src.TypeUrl = strings.ReplaceAll(src.TypeUrl, "proto.", "tapdance.")

dst := &pb.GenericTransportParams{}
err = transports.UnmarshalAnypbTo(src, dst)
require.Nil(t, err)

require.True(t, dst.GetRandomizeDstPort())
}

0 comments on commit 35e4ba0

Please sign in to comment.