Skip to content

Commit c4005d4

Browse files
committed
Fix api key validation tests
1 parent 76b3a6e commit c4005d4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

internal/tiger/api/client_util.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ func ValidateAPIKeyWithClient(client ClientWithResponsesInterface, projectID str
9494

9595
// Check the response status
9696
if resp.StatusCode() != 200 {
97+
if resp.StatusCode() == 404 {
98+
// Project not found, but API key is valid
99+
return nil
100+
}
97101
if resp.JSON4XX != nil {
98102
return resp.JSON4XX
99103
} else {
100-
return errors.New("unknown error")
104+
return errors.New("unexpected API response: 500")
101105
}
102106
} else {
103107
return nil

internal/tiger/api/client_util_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"testing"
77

8+
"github.com/timescale/tiger-cli/internal/tiger/util"
89
"go.uber.org/mock/gomock"
910

1011
"github.com/timescale/tiger-cli/internal/tiger/api"
@@ -46,9 +47,10 @@ func TestValidateAPIKeyWithClient(t *testing.T) {
4647
GetProjectsProjectIdServicesWithResponse(gomock.Any(), "00000000-0000-0000-0000-000000000000").
4748
Return(&api.GetProjectsProjectIdServicesResponse{
4849
HTTPResponse: &http.Response{StatusCode: 401},
50+
JSON4XX: &api.ClientError{Message: util.Ptr("Invalid or missing authentication credentials")},
4951
}, nil)
5052
},
51-
expectedError: "invalid API key: authentication failed",
53+
expectedError: "Invalid or missing authentication credentials",
5254
},
5355
{
5456
name: "invalid API key - 403 response",
@@ -57,9 +59,10 @@ func TestValidateAPIKeyWithClient(t *testing.T) {
5759
GetProjectsProjectIdServicesWithResponse(gomock.Any(), "00000000-0000-0000-0000-000000000000").
5860
Return(&api.GetProjectsProjectIdServicesResponse{
5961
HTTPResponse: &http.Response{StatusCode: 403},
62+
JSON4XX: &api.ClientError{Message: util.Ptr("Invalid or missing authentication credentials")},
6063
}, nil)
6164
},
62-
expectedError: "invalid API key: authentication failed",
65+
expectedError: "Invalid or missing authentication credentials",
6366
},
6467
{
6568
name: "unexpected response - 500",

0 commit comments

Comments
 (0)