Skip to content

Commit 07c74d8

Browse files
committed
refactor(cubesql): Use correct naming for checkSqlAuth
1 parent e1a1f02 commit 07c74d8

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

packages/cubejs-api-gateway/src/sql-server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ export class SQLServer {
107107
this.sqlInterfaceInstance = await registerInterface({
108108
gatewayPort: this.gatewayPort,
109109
pgPort: options.pgSqlPort,
110-
checkAuth: async ({ request, user, password }) => {
110+
checkSqlAuth: async ({ request, user, password }) => {
111111
const { password: returnedPassword, superuser, securityContext, skipPasswordCheck } = await checkSqlAuth(request, user, password);
112112

113-
// Strip securityContext to improve speed deserialization
114113
return {
115114
password: returnedPassword,
116115
superuser: superuser || false,

packages/cubejs-backend-native/js/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface CanSwitchUserPayload {
8888

8989
export type SQLInterfaceOptions = {
9090
pgPort?: number,
91-
checkAuth: (payload: CheckAuthPayload) => CheckAuthResponse | Promise<CheckAuthResponse>,
91+
checkSqlAuth: (payload: CheckAuthPayload) => CheckAuthResponse | Promise<CheckAuthResponse>,
9292
load: (payload: LoadPayload) => unknown | Promise<unknown>,
9393
sql: (payload: SqlPayload) => unknown | Promise<unknown>,
9494
meta: (payload: MetaPayload) => unknown | Promise<unknown>,
@@ -347,8 +347,8 @@ export const registerInterface = async (options: SQLInterfaceOptions): Promise<S
347347
throw new Error('Argument options must be an object');
348348
}
349349

350-
if (typeof options.checkAuth !== 'function') {
351-
throw new Error('options.checkAuth must be a function');
350+
if (typeof options.checkSqlAuth !== 'function') {
351+
throw new Error('options.checkSqlAuth must be a function');
352352
}
353353

354354
if (typeof options.load !== 'function') {
@@ -378,7 +378,7 @@ export const registerInterface = async (options: SQLInterfaceOptions): Promise<S
378378
const native = loadNative();
379379
return native.registerInterface({
380380
...options,
381-
checkAuth: wrapNativeFunctionWithChannelCallback(options.checkAuth),
381+
checkSqlAuth: wrapNativeFunctionWithChannelCallback(options.checkSqlAuth),
382382
load: wrapNativeFunctionWithChannelCallback(options.load),
383383
sql: wrapNativeFunctionWithChannelCallback(options.sql),
384384
meta: wrapNativeFunctionWithChannelCallback(options.meta),

packages/cubejs-backend-native/test/sql.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function interfaceMethods() {
103103
dataSourceToSqlGenerator: {},
104104
};
105105
}),
106-
checkAuth: jest.fn(async ({ request, user }) => {
107-
console.log('[js] checkAuth', {
106+
checkSqlAuth: jest.fn(async ({ request, user }) => {
107+
console.log('[js] checkSqlAuth', {
108108
request,
109109
user,
110110
});
@@ -146,7 +146,7 @@ describe('SQLInterface', () => {
146146

147147
it('SHOW FULL TABLES FROM `db`', async () => {
148148
const methods = interfaceMethods();
149-
const { checkAuth, meta } = methods;
149+
const { checkSqlAuth, meta } = methods;
150150

151151
const instance = await native.registerInterface({
152152
pgPort: 5555,
@@ -178,9 +178,9 @@ describe('SQLInterface', () => {
178178
);
179179
}
180180

181-
console.log(checkAuth.mock.calls);
182-
expect(checkAuth.mock.calls.length).toEqual(1);
183-
expect(checkAuth.mock.calls[0][0]).toEqual({
181+
console.log(checkSqlAuth.mock.calls);
182+
expect(checkSqlAuth.mock.calls.length).toEqual(1);
183+
expect(checkSqlAuth.mock.calls[0][0]).toEqual({
184184
request: {
185185
id: expect.any(String),
186186
meta: null,
@@ -195,19 +195,19 @@ describe('SQLInterface', () => {
195195
user: 'random user',
196196
password: undefined,
197197
});
198-
checkAuth.mockClear();
198+
checkSqlAuth.mockClear();
199199

200200
await testConnectionFailed({
201201
user: 'allowed_user',
202202
password: undefined,
203203
});
204-
checkAuth.mockClear();
204+
checkSqlAuth.mockClear();
205205

206206
await testConnectionFailed({
207207
user: 'allowed_user',
208208
password: 'wrong_password',
209209
});
210-
checkAuth.mockClear();
210+
checkSqlAuth.mockClear();
211211

212212
const connection = new Client({
213213
host: '127.0.0.1',
@@ -236,8 +236,8 @@ describe('SQLInterface', () => {
236236
]);
237237
}
238238

239-
expect(checkAuth.mock.calls.length).toEqual(1);
240-
expect(checkAuth.mock.calls[0][0]).toEqual({
239+
expect(checkSqlAuth.mock.calls.length).toEqual(1);
240+
expect(checkSqlAuth.mock.calls[0][0]).toEqual({
241241
request: {
242242
id: expect.any(String),
243243
meta: null,

0 commit comments

Comments
 (0)