Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust useDatabricksOAuthInAzure behavior #225

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading