Skip to content

Commit

Permalink
Add validation for preview account API paths (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong authored Nov 25, 2022
1 parent 3b85923 commit 4a7ca53
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *DatabricksClient) isAccountsClient() bool {
}

func (c *DatabricksClient) commonErrorClarity(resp *http.Response) *APIError {
isAccountsAPI := strings.HasPrefix(resp.Request.URL.Path, "/api/2.0/accounts")
isAccountsAPI := strings.HasPrefix(resp.Request.URL.Path, "/api/2.0/accounts") || strings.HasPrefix(resp.Request.URL.Path, "/api/2.0/preview/accounts")
isAccountsClient := c.isAccountsClient()
isTesting := strings.HasPrefix(resp.Request.URL.Host, "127.0.0.1")
if !isTesting && isAccountsClient && !isAccountsAPI {
Expand Down
22 changes: 22 additions & 0 deletions common/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ func TestCommonErrorFromWorkspaceClientToE2(t *testing.T) {
assert.Nil(t, workspaceAPIFromWorkspaceClient)
}

func TestCommonErrorFromWorkspaceClientToAccountSCIM(t *testing.T) {
ws := DatabricksClient{
Host: "https://qwerty.cloud.databricks.com/",
}
accountsAPIForWorkspaceClient := ws.commonErrorClarity(&http.Response{
Request: httptest.NewRequest(
"GET", "https://accounts.cloud.databricks.com/api/2.0/preview/accounts/a/scim/v2/Groups",
nil),
})
require.Error(t, accountsAPIForWorkspaceClient)
assert.True(t, strings.HasPrefix(accountsAPIForWorkspaceClient.Error(),
"Accounts API (/api/2.0/preview/accounts/a/scim/v2/Groups) requires you to set accounts.cloud.databricks.com"),
"Actual message: %s", accountsAPIForWorkspaceClient.Error())

workspaceAPIFromWorkspaceClient := ws.commonErrorClarity(&http.Response{
Request: httptest.NewRequest(
"GET", "https://qwerty.cloud.databricks.com/api/2.0/clusters/list",
nil),
})
assert.Nil(t, workspaceAPIFromWorkspaceClient)
}

func TestCommonErrorFromE2ClientToWorkspace(t *testing.T) {
ws := DatabricksClient{
Host: "accounts.cloud.databricks.com",
Expand Down

0 comments on commit 4a7ca53

Please sign in to comment.