From 4f2081acf60b72f4bfbe5d396c7722c705acf9e2 Mon Sep 17 00:00:00 2001 From: disheng Date: Fri, 3 Jan 2025 22:33:27 +0800 Subject: [PATCH] Modified ibisAdaptor test for MySQL --- .../server/adaptors/tests/ibisAdaptor.test.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts b/wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts index 4c4a7b3de..0e4f51d24 100644 --- a/wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts +++ b/wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts @@ -6,7 +6,7 @@ import { IbisQueryResponse, ValidationRules, } from '../ibisAdaptor'; -import { DataSourceName } from '../../types'; +import { DataSourceName, SSLMode } from '../../types'; import { Manifest } from '../../mdl/type'; import { BIG_QUERY_CONNECTION_INFO, @@ -45,6 +45,8 @@ describe('IbisAdaptor', () => { database: 'my-database', user: 'my-user', password: 'my-password', + sslMode: SSLMode.VERIFY_CA, + sslCA: 'encrypted-certificate-string', }; const mockPostgresConnectionInfo: POSTGRES_CONNECTION_INFO = { @@ -176,17 +178,28 @@ describe('IbisAdaptor', () => { mockedAxios.post.mockResolvedValue(mockResponse); // mock decrypt method in Encryptor to return the same password mockedEncryptor.prototype.decrypt.mockReturnValue( - JSON.stringify({ password: mockMySQLConnectionInfo.password }), + JSON.stringify({ + password: mockMySQLConnectionInfo.password, + ...(mockMySQLConnectionInfo.sslCA && { sslCA: mockMySQLConnectionInfo.sslCA }) + }), ); const result = await ibisAdaptor.getConstraints( DataSourceName.MYSQL, mockMySQLConnectionInfo, ); - const expectConnectionInfo = Object.entries(mockMySQLConnectionInfo).reduce( - (acc, [key, value]) => ((acc[snakeCase(key)] = value), acc), - {}, - ); + const expectConnectionInfo = Object.entries( + mockMySQLConnectionInfo, + ).reduce((acc, [key, value]) => { + if (key === 'sslCA') { + acc['sslCA'] = Buffer + .from(mockMySQLConnectionInfo.sslCA) + .toString('base64'); + } else { + acc[key] = value; + } + return acc; + }, {}); expect(result).toEqual([]); expect(mockedAxios.post).toHaveBeenCalledWith(