Skip to content

Commit

Permalink
feat: handle outdated client protocol version (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
lechnerc77 authored Sep 4, 2023
1 parent 8bb76b7 commit dde1517
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/btpcli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
HeaderCLIBackendStatus string = "X-Cpcli-Backend-Status"
HeaderCLIBackendMessage string = "X-Cpcli-Backend-Message"
HeaderCLIBackendMediaType string = "X-Cpcli-Backend-Mediatype"
HeaderCLIClientUpdate string = "X-Cpcli-Client-Update"
HeaderCLIServerMessage string = "X-Cpcli-Server-Message"
)

const cliTargetProtocolVersion string = "v2.38.0"
Expand Down Expand Up @@ -157,10 +159,11 @@ func (v2 *v2Client) Login(ctx context.Context, loginReq *LoginRequest) (*LoginRe

var loginResponse LoginResponse
err = v2.parseResponse(ctx, res, &loginResponse, http.StatusOK, map[int]string{
http.StatusUnauthorized: "Login failed. Check your credentials.",
http.StatusForbidden: fmt.Sprintf("You cannot access global account '%s'. Make sure you have at least read access to the global account, a directory, or a subaccount.", loginReq.GlobalAccountSubdomain),
http.StatusNotFound: fmt.Sprintf("Global account '%s' not found. Try again and make sure to provide the global account's subdomain.", loginReq.GlobalAccountSubdomain),
http.StatusGatewayTimeout: "Login timed out. Please try again later.",
http.StatusUnauthorized: "Login failed. Check your credentials.",
http.StatusForbidden: fmt.Sprintf("You cannot access global account '%s'. Make sure you have at least read access to the global account, a directory, or a subaccount.", loginReq.GlobalAccountSubdomain),
http.StatusNotFound: fmt.Sprintf("Global account '%s' not found. Try again and make sure to provide the global account's subdomain.", loginReq.GlobalAccountSubdomain),
http.StatusPreconditionFailed: "Login failed due to outdated provider version. Update to the latest version of the provider.",
http.StatusGatewayTimeout: "Login timed out. Please try again later.",
})

if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions internal/btpcli/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ func TestV2Client_Login(t *testing.T) {
expectErrorMsg: "Global account 'subdomain' not found. Try again and make sure to provide the global account's subdomain. [Status: 404; Correlation ID: fake-correlation-id]",
},
},
{
description: "error path - outdated protocol version [412]",
loginRequest: NewLoginRequest("subdomain", "john.doe", "pass"),
simulation: v2SimulationConfig{
srvReturnStatus: http.StatusPreconditionFailed,
expectErrorMsg: "Login failed due to outdated provider version. Update to the latest version of the provider. [Status: 412; Correlation ID: fake-correlation-id]",
},
},
{
description: "error path - login request times out [504]]",
loginRequest: NewLoginRequest("subdomain", "john.doe", "pass"),
Expand Down

0 comments on commit dde1517

Please sign in to comment.