client: don't negotiate malformed responses

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-11-14 13:26:04 +01:00
parent bcc1db1ce5
commit a5c7f3f9c8
3 changed files with 13 additions and 0 deletions

View File

@@ -316,6 +316,12 @@ func (cli *Client) negotiateAPIVersion(pingVersion string) error {
return cerrdefs.ErrInvalidArgument.WithMessage(fmt.Sprintf("API version %s is not supported by this client: the minimum supported API version is %s", pingVersion, MinAPIVersion))
}
var err error
pingVersion, err = parseAPIVersion(pingVersion)
if err != nil {
return err
}
// if the client is not initialized with a version, start with the latest supported version
if cli.version == "" {
cli.version = MaxAPIVersion

View File

@@ -76,6 +76,7 @@ func TestPingSuccess(t *testing.T) {
assert.NilError(t, err)
assert.Check(t, is.Equal(true, ping.Experimental))
assert.Check(t, is.Equal("awesome", ping.APIVersion))
assert.Check(t, is.Equal(MaxAPIVersion, client.version))
assert.Check(t, is.Equal(SwarmStatus{NodeState: "active", ControlAvailable: true}, *ping.SwarmStatus))
}

View File

@@ -316,6 +316,12 @@ func (cli *Client) negotiateAPIVersion(pingVersion string) error {
return cerrdefs.ErrInvalidArgument.WithMessage(fmt.Sprintf("API version %s is not supported by this client: the minimum supported API version is %s", pingVersion, MinAPIVersion))
}
var err error
pingVersion, err = parseAPIVersion(pingVersion)
if err != nil {
return err
}
// if the client is not initialized with a version, start with the latest supported version
if cli.version == "" {
cli.version = MaxAPIVersion