Skip to content
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
10 changes: 9 additions & 1 deletion lib/DBSQLSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import InfoValue from './dto/InfoValue';
import CloseableCollection from './utils/CloseableCollection';
import { LogLevel } from './contracts/IDBSQLLogger';
import HiveDriverError from './errors/HiveDriverError';
import ParameterError from './errors/ParameterError';
import StagingError from './errors/StagingError';
import IClientContext from './contracts/IClientContext';
import ISessionBackend from './contracts/ISessionBackend';
Expand Down Expand Up @@ -293,7 +294,14 @@ export default class DBSQLSession implements IDBSQLSession {
* @returns DBSQLOperation
*/
public async getFunctions(request: FunctionsRequest): Promise<IOperation> {
return this.wrapOperation(await this.runBackend(() => this.backend.getFunctions(request)));
return this.wrapOperation(
await this.runBackend(() => {
if (typeof request?.functionName !== 'string') {
throw new ParameterError('functionName must be a string');
}
return this.backend.getFunctions(request);
}),
);
}

public async getPrimaryKeys(request: PrimaryKeysRequest): Promise<IOperation> {
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/DBSQLSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import DBSQLSession, { numberToInt64 } from '../../lib/DBSQLSession';
import InfoValue from '../../lib/dto/InfoValue';
import Status from '../../lib/dto/Status';
import DBSQLOperation from '../../lib/DBSQLOperation';
import ISessionBackend from '../../lib/contracts/ISessionBackend';
import ParameterError from '../../lib/errors/ParameterError';
import { TSessionHandle, TProtocolVersion } from '../../thrift/TCLIService_types';
import ClientContextStub from './.stubs/ClientContextStub';
import { createSessionForTest } from './.stubs/createSessionForTest';
Expand Down Expand Up @@ -450,6 +452,28 @@ describe('DBSQLSession', () => {
});

describe('getFunctions', () => {
it('rejects a missing or non-string functionName before calling the backend', async () => {
const getFunctions = sinon.stub();
const session = new DBSQLSession({
backend: { id: 'test', getFunctions } as unknown as ISessionBackend,
context: new ClientContextStub(),
});
const invalidRequests = [undefined, null, {}, { functionName: null }, { functionName: 123 }];

await Promise.all(
invalidRequests.map(async (request) => {
try {
await session.getFunctions(request as unknown as Parameters<DBSQLSession['getFunctions']>[0]);
expect.fail('Expected getFunctions to reject an invalid functionName');
} catch (error) {
expect(error).instanceOf(ParameterError);
expect((error as Error).message).equal('functionName must be a string');
}
}),
);
expect(getFunctions.called).false;
});

it('should run operation', async () => {
const session = createSessionForTest({ handle: sessionHandleStub, context: new ClientContextStub() });
const result = await session.getFunctions({
Expand All @@ -460,6 +484,12 @@ describe('DBSQLSession', () => {
expect(result).instanceOf(DBSQLOperation);
});

it('accepts an empty functionName string', async () => {
const session = createSessionForTest({ handle: sessionHandleStub, context: new ClientContextStub() });
const result = await session.getFunctions({ functionName: '' });
expect(result).instanceOf(DBSQLOperation);
});

it('should use direct results', async () => {
const session = createSessionForTest({ handle: sessionHandleStub, context: new ClientContextStub() });
const result = await session.getFunctions({
Expand Down
Loading