Skip to content

Commit

Permalink
backport of commit e0d834d
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed May 29, 2023
1 parent 19b308c commit 4a9c5bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client/fingerprint/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ func (f *ConsulFingerprint) grpc(scheme string) func(info agentconsul.Self) (str
return "", false
}

consulVersion, err := version.NewVersion(v)
consulVersion, err := version.NewVersion(strings.TrimSpace(v))
if err != nil {
f.logger.Warn("invalid Consul version", "version", v)
return "", false
}

Expand Down
17 changes: 17 additions & 0 deletions client/fingerprint/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ func TestConsulFingerprint_sku(t *testing.T) {
require.Equal(t, "ent", s)
})

t.Run("extra spaces", func(t *testing.T) {
v, ok := fp.sku(agentconsul.Self{
"Config": {"Version": " v1.9.5\n"},
})
require.True(t, ok)
require.Equal(t, "oss", v)
})

t.Run("missing", func(t *testing.T) {
_, ok := fp.sku(agentconsul.Self{
"Config": {},
Expand Down Expand Up @@ -368,6 +376,15 @@ func TestConsulFingerprint_grpc(t *testing.T) {
require.Equal(t, "8503", s)
})

t.Run("version with extra spaces", func(t *testing.T) {
s, ok := fp.grpc("https")(agentconsul.Self{
"Config": {"Version": " 1.14.0\n"},
"DebugConfig": {"GRPCTLSPort": 8503.0}, // JSON numbers are floats
})
require.True(t, ok)
require.Equal(t, "8503", s)
})

t.Run("grpc missing http", func(t *testing.T) {
_, ok := fp.grpc("http")(agentconsul.Self{
"DebugConfig": {},
Expand Down
2 changes: 1 addition & 1 deletion command/agent/consul/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func SKU(info Self) (string, bool) {
return "", ok
}

ver, vErr := version.NewVersion(v)
ver, vErr := version.NewVersion(strings.TrimSpace(v))
if vErr != nil {
return "", false
}
Expand Down

0 comments on commit 4a9c5bd

Please sign in to comment.