From 805850add9075ed71e67fab4ae87c8279ca9d3f5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 19 Aug 2020 14:36:43 -0700 Subject: [PATCH] derp: remove JSON struct tags in comments They don't work in comments. Added a test too to show that there's no change in behavior. (It does case insensitive matching on parse anyway) --- derp/derp_client.go | 4 ++-- derp/derp_server.go | 2 +- derp/derp_test.go | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/derp/derp_client.go b/derp/derp_client.go index 7291efbec..aca67fef6 100644 --- a/derp/derp_client.go +++ b/derp/derp_client.go @@ -129,13 +129,13 @@ func (c *Client) parseServerInfo(b []byte) (*serverInfo, error) { } type clientInfo struct { - Version int // `json:"version,omitempty"` + Version int `json:"version,omitempty"` // MeshKey optionally specifies a pre-shared key used by // trusted clients. It's required to subscribe to the // connection list & forward packets. It's empty for regular // users. - MeshKey string // `json:"meshKey,omitempty"` + MeshKey string `json:"meshKey,omitempty"` } func (c *Client) sendClientKey() error { diff --git a/derp/derp_server.go b/derp/derp_server.go index fbc9fa8df..7c6394e50 100644 --- a/derp/derp_server.go +++ b/derp/derp_server.go @@ -712,7 +712,7 @@ func (s *Server) sendServerKey(bw *bufio.Writer) error { } type serverInfo struct { - Version int // `json:"version,omitempty"` + Version int `json:"version,omitempty"` } func (s *Server) sendServerInfo(bw *bufio.Writer, clientKey key.Public) error { diff --git a/derp/derp_test.go b/derp/derp_test.go index 1ca32128d..d9e6580ff 100644 --- a/derp/derp_test.go +++ b/derp/derp_test.go @@ -8,6 +8,7 @@ import ( "bufio" "context" crand "crypto/rand" + "encoding/json" "errors" "expvar" "fmt" @@ -32,6 +33,22 @@ func newPrivateKey(tb testing.TB) (k key.Private) { return } +func TestClientInfoUnmarshal(t *testing.T) { + for i, in := range []string{ + `{"Version":5,"MeshKey":"abc"}`, + `{"version":5,"meshKey":"abc"}`, + } { + var got clientInfo + if err := json.Unmarshal([]byte(in), &got); err != nil { + t.Fatalf("[%d]: %v", i, err) + } + want := clientInfo{Version: 5, MeshKey: "abc"} + if got != want { + t.Errorf("[%d]: got %+v; want %+v", i, got, want) + } + } +} + func TestSendRecv(t *testing.T) { serverPrivateKey := newPrivateKey(t) s := NewServer(serverPrivateKey, t.Logf)