Skip to content

Commit

Permalink
[REGRESSION] Prepend slash to path if needed (#91)
Browse files Browse the repository at this point in the history
Prepend slash to path if needed

Signed-off-by: Levko Kravets <[email protected]>

Signed-off-by: Levko Kravets <[email protected]>
  • Loading branch information
kravets-levko authored Nov 8, 2022
1 parent cc2cb62 commit e57e017
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import PlainHttpAuthentication from './connection/auth/PlainHttpAuthentication';
import IDBSQLLogger, { LogLevel } from './contracts/IDBSQLLogger';
import DBSQLLogger from './DBSQLLogger';

function prependSlash(str: string): string {
if (str.length > 0 && str.charAt(0) !== '/') {
return `/${str}`;
}
return str;
}

function getInitialNamespaceOptions(catalogName?: string, schemaName?: string) {
if (!catalogName && !schemaName) {
return {};
Expand Down Expand Up @@ -61,11 +68,12 @@ export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
}

private getConnectionOptions(options: ConnectionOptions): IConnectionOptions {
const { host, port, token, clientId, ...otherOptions } = options;
const { host, port, path, token, clientId, ...otherOptions } = options;
return {
host,
port: port || 443,
options: {
path: prependSlash(path),
https: true,
...otherOptions,
},
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/DBSQLClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@ describe('DBSQLClient.connect', () => {
token: 'dapi********************************',
};

it('should prepend "/" to path if it is missing', async () => {
const client = new DBSQLClient();
client.thrift = {
createClient() {},
};
const connectionProvider = ConnectionProviderMock();

const path = 'example/path';

client.connectionProvider = connectionProvider;
await client.connect({
...options,
path,
});

expect(connectionProvider.options.options.path).to.equal(`/${path}`);
});

it('should not prepend "/" to path if it is already available', async () => {
const client = new DBSQLClient();
client.thrift = {
createClient() {},
};
const connectionProvider = ConnectionProviderMock();

const path = '/example/path';

client.connectionProvider = connectionProvider;
await client.connect({
...options,
path,
});

expect(connectionProvider.options.options.path).to.equal(path);
});

it('should set nosasl authenticator by default', async () => {
const client = new DBSQLClient();
const connectionProvider = ConnectionProviderMock();
Expand Down

0 comments on commit e57e017

Please sign in to comment.