Skip to content

Commit f53b654

Browse files
committed
Adjust useDatabricksOAuthInAzure behavior
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
1 parent f3c53a5 commit f53b654

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
@@ -198,19 +198,19 @@ export default abstract class OAuthManager {
198198
}
199199

200200
if (options.useDatabricksOAuthInAzure) {
201-
const domains = ['.azuredatabricks.net'];
202-
const isSupportedDomain = domains.some((domain) => host.endsWith(domain));
203-
if (isSupportedDomain) {
201+
const azureDomains = ['.azuredatabricks.net'];
202+
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
203+
if (isAzureDomain) {
204204
// eslint-disable-next-line @typescript-eslint/no-use-before-define
205205
return new DatabricksOAuthManager(options);
206206
}
207-
}
208-
209-
const azureDomains = ['.azuredatabricks.net', '.databricks.azure.us', '.databricks.azure.cn'];
210-
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
211-
if (isAzureDomain) {
212-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
213-
return new AzureOAuthManager(options);
207+
} else {
208+
const azureDomains = ['.azuredatabricks.net', '.databricks.azure.us', '.databricks.azure.cn'];
209+
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
210+
if (isAzureDomain) {
211+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
212+
return new AzureOAuthManager(options);
213+
}
214214
}
215215

216216
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
@@ -366,6 +366,9 @@ describe('DBSQLClient.initAuthProvider', () => {
366366
it('should use Databricks InHouse OAuth method (Azure)', () => {
367367
const client = new DBSQLClient();
368368

369+
// When `useDatabricksOAuthInAzure = true`, it should use Databricks OAuth method
370+
// only for supported Azure hosts, and fail for others
371+
369372
case1: {
370373
const provider = client.initAuthProvider({
371374
authType: 'databricks-oauth',
@@ -379,15 +382,14 @@ describe('DBSQLClient.initAuthProvider', () => {
379382
}
380383

381384
case2: {
382-
const provider = client.initAuthProvider({
383-
authType: 'databricks-oauth',
384-
// host is used when creating OAuth manager, so make it look like a real Azure instance
385-
host: 'example.databricks.azure.us',
386-
useDatabricksOAuthInAzure: true,
387-
});
388-
389-
expect(provider).to.be.instanceOf(DatabricksOAuth);
390-
expect(provider.manager).to.be.instanceOf(AzureOAuthManager);
385+
expect(() => {
386+
const provider = client.initAuthProvider({
387+
authType: 'databricks-oauth',
388+
// host is used when creating OAuth manager, so make it look like a real Azure instance
389+
host: 'example.databricks.azure.us',
390+
useDatabricksOAuthInAzure: true,
391+
});
392+
}).to.throw();
391393
}
392394
});
393395

0 commit comments

Comments
 (0)