Skip to content

Commit b2016b7

Browse files
committed
fix(kernel): reject conflicting static token auth
1 parent f26244c commit b2016b7

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/kernel/KernelAuth.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,9 @@ export function buildKernelConnectionOptions(options: ConnectionOptions): Kernel
640640
}
641641

642642
if (authType === 'static-token') {
643-
const { staticToken, enableTokenFederation, federationClientId } = options as {
643+
const { staticToken, token, enableTokenFederation, federationClientId } = options as {
644644
staticToken?: string;
645+
token?: string;
645646
enableTokenFederation?: boolean;
646647
federationClientId?: string;
647648
};
@@ -650,6 +651,12 @@ export function buildKernelConnectionOptions(options: ConnectionOptions): Kernel
650651
"kernel backend: a non-empty token must be supplied via `staticToken` when using `authType: 'static-token'`.",
651652
);
652653
}
654+
if (token !== undefined || oauth.oauthClientId !== undefined || oauth.oauthClientSecret !== undefined) {
655+
throw new HiveDriverError(
656+
'kernel backend: cannot supply `staticToken` alongside `token` or ' +
657+
'`oauthClientId`/`oauthClientSecret` on the same connection. Pick one auth mode.',
658+
);
659+
}
653660
return {
654661
...base,
655662
authMode: 'Pat',

tests/unit/kernel/auth-static-token.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { expect } from 'chai';
1616
import expectNativeConnectionOptions from './_helpers/nativeOptions';
1717
import { buildKernelConnectionOptions } from '../../../lib/kernel/KernelAuth';
1818
import AuthenticationError from '../../../lib/errors/AuthenticationError';
19+
import HiveDriverError from '../../../lib/errors/HiveDriverError';
1920

2021
describe('KernelAuth — static-token auth options builder', () => {
2122
it('maps a static token to the native bearer-token mode', () => {
@@ -88,4 +89,22 @@ describe('KernelAuth — static-token auth options builder', () => {
8889
).to.throw(AuthenticationError, /non-empty token.*`staticToken`/);
8990
}
9091
});
92+
93+
it('rejects conflicting token and OAuth credentials', () => {
94+
for (const conflicting of [
95+
{ token: 'dapi-pat' },
96+
{ oauthClientId: 'oauth-client' },
97+
{ oauthClientSecret: 'oauth-secret' },
98+
]) {
99+
expect(() =>
100+
buildKernelConnectionOptions({
101+
host: 'example.cloud.databricks.com',
102+
path: '/sql/1.0/warehouses/abc',
103+
authType: 'static-token',
104+
staticToken: 'header.payload.signature',
105+
...conflicting,
106+
} as any),
107+
).to.throw(HiveDriverError, /cannot supply `staticToken` alongside/);
108+
}
109+
});
91110
});

0 commit comments

Comments
 (0)