Skip to content

Commit 3953e5d

Browse files
Adjust useDatabricksOAuthInAzure behavior (#225)
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
1 parent 86f3888 commit 3953e5d

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/connection/auth/DatabricksOAuth/OAuthManager.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,19 @@ export default abstract class OAuthManager {
205205
}
206206

207207
if (options.useDatabricksOAuthInAzure) {
208-
const domains = ['.azuredatabricks.net'];
209-
const isSupportedDomain = domains.some((domain) => host.endsWith(domain));
210-
if (isSupportedDomain) {
208+
const azureDomains = ['.azuredatabricks.net'];
209+
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
210+
if (isAzureDomain) {
211211
// eslint-disable-next-line @typescript-eslint/no-use-before-define
212212
return new DatabricksOAuthManager(options);
213213
}
214-
}
215-
216-
const azureDomains = ['.azuredatabricks.net', '.databricks.azure.us', '.databricks.azure.cn'];
217-
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
218-
if (isAzureDomain) {
219-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
220-
return new AzureOAuthManager(options);
214+
} else {
215+
const azureDomains = ['.azuredatabricks.net', '.databricks.azure.us', '.databricks.azure.cn'];
216+
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
217+
if (isAzureDomain) {
218+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
219+
return new AzureOAuthManager(options);
220+
}
221221
}
222222

223223
throw new Error(`OAuth is not supported for ${options.host}`);

tests/unit/DBSQLClient.test.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ describe('DBSQLClient.initAuthProvider', () => {
379379
it('should use Databricks InHouse OAuth method (Azure)', () => {
380380
const client = new DBSQLClient();
381381

382+
// When `useDatabricksOAuthInAzure = true`, it should use Databricks OAuth method
383+
// only for supported Azure hosts, and fail for others
384+
382385
case1: {
383386
const provider = client.initAuthProvider({
384387
authType: 'databricks-oauth',
@@ -392,15 +395,14 @@ describe('DBSQLClient.initAuthProvider', () => {
392395
}
393396

394397
case2: {
395-
const provider = client.initAuthProvider({
396-
authType: 'databricks-oauth',
397-
// host is used when creating OAuth manager, so make it look like a real Azure instance
398-
host: 'example.databricks.azure.us',
399-
useDatabricksOAuthInAzure: true,
400-
});
401-
402-
expect(provider).to.be.instanceOf(DatabricksOAuth);
403-
expect(provider.manager).to.be.instanceOf(AzureOAuthManager);
398+
expect(() => {
399+
const provider = client.initAuthProvider({
400+
authType: 'databricks-oauth',
401+
// host is used when creating OAuth manager, so make it look like a real Azure instance
402+
host: 'example.databricks.azure.us',
403+
useDatabricksOAuthInAzure: true,
404+
});
405+
}).to.throw();
404406
}
405407
});
406408

0 commit comments

Comments
 (0)