From 503983ce90c55eea57c6d9262dbcc2be90e72388 Mon Sep 17 00:00:00 2001 From: Vuong Nguyen Date: Fri, 25 Nov 2022 12:31:11 +0000 Subject: [PATCH] add validation for preview account API paths --- common/http.go | 2 +- common/http_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/common/http.go b/common/http.go index 7a30810734..02dc0e0fbd 100644 --- a/common/http.go +++ b/common/http.go @@ -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 { diff --git a/common/http_test.go b/common/http_test.go index d970904c46..95858e77cc 100644 --- a/common/http_test.go +++ b/common/http_test.go @@ -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",