Skip to content

Commit

Permalink
Adjust useDatabricksOAuthInAzure behavior (#225)
Browse files Browse the repository at this point in the history
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
  • Loading branch information
kravets-levko authored Feb 5, 2024
1 parent 86f3888 commit 3953e5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
20 changes: 10 additions & 10 deletions lib/connection/auth/DatabricksOAuth/OAuthManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,19 @@ export default abstract class OAuthManager {
}

if (options.useDatabricksOAuthInAzure) {
const domains = ['.azuredatabricks.net'];
const isSupportedDomain = domains.some((domain) => host.endsWith(domain));
if (isSupportedDomain) {
const azureDomains = ['.azuredatabricks.net'];
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
if (isAzureDomain) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new DatabricksOAuthManager(options);
}
}

const azureDomains = ['.azuredatabricks.net', '.databricks.azure.us', '.databricks.azure.cn'];
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
if (isAzureDomain) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new AzureOAuthManager(options);
} else {
const azureDomains = ['.azuredatabricks.net', '.databricks.azure.us', '.databricks.azure.cn'];
const isAzureDomain = azureDomains.some((domain) => host.endsWith(domain));
if (isAzureDomain) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return new AzureOAuthManager(options);
}
}

throw new Error(`OAuth is not supported for ${options.host}`);
Expand Down
20 changes: 11 additions & 9 deletions tests/unit/DBSQLClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ describe('DBSQLClient.initAuthProvider', () => {
it('should use Databricks InHouse OAuth method (Azure)', () => {
const client = new DBSQLClient();

// When `useDatabricksOAuthInAzure = true`, it should use Databricks OAuth method
// only for supported Azure hosts, and fail for others

case1: {
const provider = client.initAuthProvider({
authType: 'databricks-oauth',
Expand All @@ -392,15 +395,14 @@ describe('DBSQLClient.initAuthProvider', () => {
}

case2: {
const provider = client.initAuthProvider({
authType: 'databricks-oauth',
// host is used when creating OAuth manager, so make it look like a real Azure instance
host: 'example.databricks.azure.us',
useDatabricksOAuthInAzure: true,
});

expect(provider).to.be.instanceOf(DatabricksOAuth);
expect(provider.manager).to.be.instanceOf(AzureOAuthManager);
expect(() => {
const provider = client.initAuthProvider({
authType: 'databricks-oauth',
// host is used when creating OAuth manager, so make it look like a real Azure instance
host: 'example.databricks.azure.us',
useDatabricksOAuthInAzure: true,
});
}).to.throw();
}
});

Expand Down

0 comments on commit 3953e5d

Please sign in to comment.