Skip to content

Commit

Permalink
Do not show a warning about too new client version when server and cl…
Browse files Browse the repository at this point in the history
…ient are on the same major version
  • Loading branch information
gzdunek committed Nov 26, 2024
1 parent fc6829a commit 43c97bc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4257,8 +4257,17 @@ Future versions of tsh will fail when incompatible versions are detected.
versions.MinClient, versions.Client, versions.MinClient), nil
}

if !utils.MeetsMaxVersion(versions.Client, versions.Server) {
serverVersionWithWildcards, err := utils.MajorSemverWithWildcards(versions.Server)
clientMajorVersion, err := utils.MajorSemver(versions.Client)
if err != nil {
return "", trace.Wrap(err)
}
serverMajorVersion, err := utils.MajorSemver(versions.Server)
if err != nil {
return "", trace.Wrap(err)
}

if !utils.MeetsMaxVersion(clientMajorVersion, serverMajorVersion) {
serverVersionWithWildcards, err := utils.MajorSemverWithWildcards(serverMajorVersion)
if err != nil {
return "", trace.Wrap(err)
}
Expand Down
64 changes: 64 additions & 0 deletions lib/client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"testing"
"time"

"github.com/coreos/go-semver/semver"
"github.com/google/go-cmp/cmp"
"github.com/gravitational/trace"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1390,3 +1391,66 @@ func TestNonRetryableError(t *testing.T) {
assert.True(t, trace.IsAccessDenied(err))
assert.Equal(t, orgError, err.Unwrap())
}

func TestWarningsAboutClientVersion(t *testing.T) {
tests := []struct {
name string
clientVersion string
serverVersion string
expectedWarning string
}{
{
name: "client on a higher major version than server triggers a warning",
clientVersion: "17.0.0",
serverVersion: "16.0.0",
expectedWarning: `
WARNING
Detected potentially incompatible client and server versions.
Maximum client version supported by the server is 16.x.x but you are using 17.0.0.
Please downgrade tsh to 16.x.x or use the --skip-version-check flag to bypass this check.
Future versions of tsh will fail when incompatible versions are detected.
`,
},
{
name: "client on a too low major version compared to server triggers a warning",
clientVersion: "16.4.0",
serverVersion: "18.0.0",
expectedWarning: `
WARNING
Detected potentially incompatible client and server versions.
Minimum client version supported by the server is 17.0.0 but you are using 16.4.0.
Please upgrade tsh to 17.0.0 or newer or use the --skip-version-check flag to bypass this check.
Future versions of tsh will fail when incompatible versions are detected.
`,
},
{
name: "client on a higher minor version than server does not trigger a warning",
clientVersion: "17.1.0",
serverVersion: "17.0.0",
expectedWarning: "",
},
{
name: "client on a lower major version than server does not trigger a warning",
clientVersion: "17.0.0",
serverVersion: "18.0.0",
expectedWarning: "",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
minClientVersion, err := semver.NewVersion(test.serverVersion)
require.NoError(t, err)
minClientVersion.Major = minClientVersion.Major - 1
warning, err := getClientIncompatibilityWarning(versions{
MinClient: minClientVersion.String(),
Client: test.clientVersion,
Server: test.serverVersion,
})
require.NoError(t, err)
require.Equal(t, test.expectedWarning, warning)
})
}
}

0 comments on commit 43c97bc

Please sign in to comment.