|
| 1 | +import { assert } from 'chai'; |
| 2 | + |
| 3 | +import { upgradeLegacyIntegrationConfig } from './legacyIntegrationConfigUtils'; |
| 4 | +import { |
| 5 | + LegacyBigQueryIntegrationConfig, |
| 6 | + LegacyIntegrationType, |
| 7 | + LegacyPostgresIntegrationConfig, |
| 8 | + LegacySnowflakeIntegrationConfig, |
| 9 | + SnowflakeAuthMethods |
| 10 | +} from './integrationTypes'; |
| 11 | + |
| 12 | +suite('upgradeLegacyIntegrationConfig', () => { |
| 13 | + suite('PostgreSQL', () => { |
| 14 | + test('Upgrades valid PostgreSQL config with all fields', async () => { |
| 15 | + const legacyConfig: LegacyPostgresIntegrationConfig = { |
| 16 | + id: 'postgres-1', |
| 17 | + name: 'My Postgres', |
| 18 | + type: LegacyIntegrationType.Postgres, |
| 19 | + host: 'localhost', |
| 20 | + port: 5432, |
| 21 | + database: 'testdb', |
| 22 | + username: 'testuser', |
| 23 | + password: 'testpass', |
| 24 | + ssl: true |
| 25 | + }; |
| 26 | + |
| 27 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 28 | + |
| 29 | + assert.ok(result); |
| 30 | + assert.strictEqual(result.id, 'postgres-1'); |
| 31 | + assert.strictEqual(result.name, 'My Postgres'); |
| 32 | + assert.strictEqual(result.type, 'pgsql'); |
| 33 | + assert.strictEqual(result.metadata.host, 'localhost'); |
| 34 | + assert.strictEqual(result.metadata.port, '5432'); |
| 35 | + assert.strictEqual(result.metadata.database, 'testdb'); |
| 36 | + assert.strictEqual(result.metadata.user, 'testuser'); |
| 37 | + assert.strictEqual(result.metadata.password, 'testpass'); |
| 38 | + assert.strictEqual(result.metadata.sslEnabled, true); |
| 39 | + }); |
| 40 | + |
| 41 | + test('Upgrades PostgreSQL config without SSL (defaults to false)', async () => { |
| 42 | + const legacyConfig: LegacyPostgresIntegrationConfig = { |
| 43 | + id: 'postgres-2', |
| 44 | + name: 'My Postgres No SSL', |
| 45 | + type: LegacyIntegrationType.Postgres, |
| 46 | + host: 'localhost', |
| 47 | + port: 5432, |
| 48 | + database: 'testdb', |
| 49 | + username: 'testuser', |
| 50 | + password: 'testpass', |
| 51 | + ssl: false |
| 52 | + }; |
| 53 | + |
| 54 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 55 | + |
| 56 | + assert.ok(result); |
| 57 | + assert.strictEqual(result.metadata.sslEnabled, false); |
| 58 | + }); |
| 59 | + |
| 60 | + test('Converts port number to string', async () => { |
| 61 | + const legacyConfig: LegacyPostgresIntegrationConfig = { |
| 62 | + id: 'postgres-3', |
| 63 | + name: 'My Postgres', |
| 64 | + type: LegacyIntegrationType.Postgres, |
| 65 | + host: 'localhost', |
| 66 | + port: 5433, |
| 67 | + database: 'testdb', |
| 68 | + username: 'testuser', |
| 69 | + password: 'testpass' |
| 70 | + }; |
| 71 | + |
| 72 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 73 | + |
| 74 | + assert.ok(result); |
| 75 | + assert.strictEqual(result.metadata.port, '5433'); |
| 76 | + assert.strictEqual(typeof result.metadata.port, 'string'); |
| 77 | + }); |
| 78 | + |
| 79 | + test('Returns null for PostgreSQL config with missing required fields', async () => { |
| 80 | + const legacyConfig = { |
| 81 | + id: 'postgres-invalid', |
| 82 | + name: 'Invalid Postgres', |
| 83 | + type: LegacyIntegrationType.Postgres, |
| 84 | + host: 'localhost' |
| 85 | + // Missing port, database, username, password |
| 86 | + } as LegacyPostgresIntegrationConfig; |
| 87 | + |
| 88 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 89 | + |
| 90 | + assert.strictEqual(result, null); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + suite('BigQuery', () => { |
| 95 | + test('Upgrades valid BigQuery config', async () => { |
| 96 | + const credentials = JSON.stringify({ |
| 97 | + type: 'service_account', |
| 98 | + project_id: 'my-project', |
| 99 | + private_key_id: 'key123', |
| 100 | + private_key: '-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----\n', |
| 101 | + client_email: 'test@my-project.iam.gserviceaccount.com', |
| 102 | + client_id: '123456789', |
| 103 | + auth_uri: 'https://accounts.google.com/o/oauth2/auth', |
| 104 | + token_uri: 'https://oauth2.googleapis.com/token', |
| 105 | + auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs', |
| 106 | + client_x509_cert_url: |
| 107 | + 'https://www.googleapis.com/robot/v1/metadata/x509/test%40my-project.iam.gserviceaccount.com' |
| 108 | + }); |
| 109 | + |
| 110 | + const legacyConfig: LegacyBigQueryIntegrationConfig = { |
| 111 | + id: 'bigquery-1', |
| 112 | + name: 'My BigQuery', |
| 113 | + type: LegacyIntegrationType.BigQuery, |
| 114 | + projectId: 'my-project', |
| 115 | + credentials |
| 116 | + }; |
| 117 | + |
| 118 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 119 | + |
| 120 | + assert.ok(result); |
| 121 | + assert.strictEqual(result.id, 'bigquery-1'); |
| 122 | + assert.strictEqual(result.name, 'My BigQuery'); |
| 123 | + assert.strictEqual(result.type, 'big-query'); |
| 124 | + assert.strictEqual(result.metadata.authMethod, 'service-account'); |
| 125 | + assert.strictEqual(result.metadata.service_account, credentials); |
| 126 | + }); |
| 127 | + |
| 128 | + test('Returns null for BigQuery config with missing credentials', async () => { |
| 129 | + const legacyConfig = { |
| 130 | + id: 'bigquery-invalid-2', |
| 131 | + name: 'Invalid BigQuery', |
| 132 | + type: LegacyIntegrationType.BigQuery, |
| 133 | + projectId: 'my-project' |
| 134 | + } as LegacyBigQueryIntegrationConfig; |
| 135 | + |
| 136 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 137 | + |
| 138 | + assert.strictEqual(result, null); |
| 139 | + }); |
| 140 | + }); |
| 141 | + |
| 142 | + suite('Snowflake - PASSWORD auth', () => { |
| 143 | + test('Upgrades valid Snowflake config with PASSWORD auth', async () => { |
| 144 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 145 | + id: 'snowflake-1', |
| 146 | + name: 'My Snowflake', |
| 147 | + type: LegacyIntegrationType.Snowflake, |
| 148 | + authMethod: SnowflakeAuthMethods.PASSWORD, |
| 149 | + account: 'myaccount', |
| 150 | + warehouse: 'mywarehouse', |
| 151 | + database: 'mydb', |
| 152 | + role: 'myrole', |
| 153 | + username: 'myuser', |
| 154 | + password: 'mypass' |
| 155 | + }; |
| 156 | + |
| 157 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 158 | + |
| 159 | + assert.ok(result); |
| 160 | + assert.strictEqual(result.id, 'snowflake-1'); |
| 161 | + assert.strictEqual(result.name, 'My Snowflake'); |
| 162 | + assert.strictEqual(result.type, 'snowflake'); |
| 163 | + // The authMethod is converted to the database-integrations format (lowercase/kebab-case) |
| 164 | + assert.ok(result.metadata.authMethod); |
| 165 | + assert.strictEqual(result.metadata.accountName, 'myaccount'); |
| 166 | + assert.strictEqual(result.metadata.warehouse, 'mywarehouse'); |
| 167 | + assert.strictEqual(result.metadata.database, 'mydb'); |
| 168 | + assert.strictEqual(result.metadata.role, 'myrole'); |
| 169 | + assert.strictEqual(result.metadata.username, 'myuser'); |
| 170 | + assert.strictEqual(result.metadata.password, 'mypass'); |
| 171 | + }); |
| 172 | + |
| 173 | + test('Upgrades Snowflake config with PASSWORD auth and minimal fields', async () => { |
| 174 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 175 | + id: 'snowflake-2', |
| 176 | + name: 'My Snowflake Minimal', |
| 177 | + type: LegacyIntegrationType.Snowflake, |
| 178 | + authMethod: SnowflakeAuthMethods.PASSWORD, |
| 179 | + account: 'myaccount', |
| 180 | + username: 'myuser', |
| 181 | + password: 'mypass' |
| 182 | + }; |
| 183 | + |
| 184 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 185 | + |
| 186 | + assert.ok(result); |
| 187 | + assert.ok(result.metadata.authMethod); |
| 188 | + assert.strictEqual(result.metadata.accountName, 'myaccount'); |
| 189 | + assert.strictEqual(result.metadata.username, 'myuser'); |
| 190 | + assert.strictEqual(result.metadata.password, 'mypass'); |
| 191 | + }); |
| 192 | + |
| 193 | + test('Returns null for Snowflake PASSWORD config with missing required fields', async () => { |
| 194 | + const legacyConfig = { |
| 195 | + id: 'snowflake-invalid', |
| 196 | + name: 'Invalid Snowflake', |
| 197 | + type: LegacyIntegrationType.Snowflake, |
| 198 | + authMethod: SnowflakeAuthMethods.PASSWORD, |
| 199 | + account: 'myaccount' |
| 200 | + // Missing username and password |
| 201 | + } as LegacySnowflakeIntegrationConfig; |
| 202 | + |
| 203 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 204 | + |
| 205 | + assert.strictEqual(result, null); |
| 206 | + }); |
| 207 | + }); |
| 208 | + |
| 209 | + suite('Snowflake - SERVICE_ACCOUNT_KEY_PAIR auth', () => { |
| 210 | + test('Upgrades valid Snowflake config with SERVICE_ACCOUNT_KEY_PAIR auth', async () => { |
| 211 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 212 | + id: 'snowflake-keypair-1', |
| 213 | + name: 'My Snowflake KeyPair', |
| 214 | + type: LegacyIntegrationType.Snowflake, |
| 215 | + authMethod: SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR, |
| 216 | + account: 'myaccount', |
| 217 | + warehouse: 'mywarehouse', |
| 218 | + database: 'mydb', |
| 219 | + role: 'myrole', |
| 220 | + username: 'myuser', |
| 221 | + privateKey: '-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----\n', |
| 222 | + privateKeyPassphrase: 'passphrase' |
| 223 | + }; |
| 224 | + |
| 225 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 226 | + |
| 227 | + assert.ok(result); |
| 228 | + assert.strictEqual(result.id, 'snowflake-keypair-1'); |
| 229 | + assert.strictEqual(result.name, 'My Snowflake KeyPair'); |
| 230 | + assert.strictEqual(result.type, 'snowflake'); |
| 231 | + assert.ok(result.metadata.authMethod); |
| 232 | + assert.strictEqual(result.metadata.accountName, 'myaccount'); |
| 233 | + assert.strictEqual(result.metadata.username, 'myuser'); |
| 234 | + assert.strictEqual( |
| 235 | + result.metadata.privateKey, |
| 236 | + '-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----\n' |
| 237 | + ); |
| 238 | + assert.strictEqual(result.metadata.privateKeyPassphrase, 'passphrase'); |
| 239 | + }); |
| 240 | + |
| 241 | + test('Upgrades Snowflake SERVICE_ACCOUNT_KEY_PAIR config without passphrase', async () => { |
| 242 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 243 | + id: 'snowflake-keypair-2', |
| 244 | + name: 'My Snowflake KeyPair No Passphrase', |
| 245 | + type: LegacyIntegrationType.Snowflake, |
| 246 | + authMethod: SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR, |
| 247 | + account: 'myaccount', |
| 248 | + username: 'myuser', |
| 249 | + privateKey: '-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----\n' |
| 250 | + }; |
| 251 | + |
| 252 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 253 | + |
| 254 | + assert.ok(result); |
| 255 | + assert.ok(result.metadata.authMethod); |
| 256 | + }); |
| 257 | + |
| 258 | + test('Returns null for Snowflake SERVICE_ACCOUNT_KEY_PAIR config with missing private key', async () => { |
| 259 | + const legacyConfig = { |
| 260 | + id: 'snowflake-keypair-invalid', |
| 261 | + name: 'Invalid Snowflake KeyPair', |
| 262 | + type: LegacyIntegrationType.Snowflake, |
| 263 | + authMethod: SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR, |
| 264 | + account: 'myaccount', |
| 265 | + username: 'myuser' |
| 266 | + // Missing privateKey |
| 267 | + } as LegacySnowflakeIntegrationConfig; |
| 268 | + |
| 269 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 270 | + |
| 271 | + assert.strictEqual(result, null); |
| 272 | + }); |
| 273 | + }); |
| 274 | + |
| 275 | + suite('Snowflake - Unsupported auth methods', () => { |
| 276 | + test('Returns null for Snowflake config with OKTA auth', async () => { |
| 277 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 278 | + id: 'snowflake-okta', |
| 279 | + name: 'Snowflake OKTA', |
| 280 | + type: LegacyIntegrationType.Snowflake, |
| 281 | + authMethod: SnowflakeAuthMethods.OKTA, |
| 282 | + account: 'myaccount', |
| 283 | + oktaUrl: 'https://mycompany.okta.com' |
| 284 | + }; |
| 285 | + |
| 286 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 287 | + |
| 288 | + assert.strictEqual(result, null); |
| 289 | + }); |
| 290 | + |
| 291 | + test('Returns null for Snowflake config with NATIVE_SNOWFLAKE auth', async () => { |
| 292 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 293 | + id: 'snowflake-native', |
| 294 | + name: 'Snowflake Native', |
| 295 | + type: LegacyIntegrationType.Snowflake, |
| 296 | + authMethod: SnowflakeAuthMethods.NATIVE_SNOWFLAKE, |
| 297 | + account: 'myaccount' |
| 298 | + }; |
| 299 | + |
| 300 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 301 | + |
| 302 | + assert.strictEqual(result, null); |
| 303 | + }); |
| 304 | + |
| 305 | + test('Returns null for Snowflake config with AZURE_AD auth', async () => { |
| 306 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 307 | + id: 'snowflake-azure', |
| 308 | + name: 'Snowflake Azure AD', |
| 309 | + type: LegacyIntegrationType.Snowflake, |
| 310 | + authMethod: SnowflakeAuthMethods.AZURE_AD, |
| 311 | + account: 'myaccount', |
| 312 | + tenantId: 'my-tenant-id' |
| 313 | + }; |
| 314 | + |
| 315 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 316 | + |
| 317 | + assert.strictEqual(result, null); |
| 318 | + }); |
| 319 | + |
| 320 | + test('Returns null for Snowflake config with KEY_PAIR auth', async () => { |
| 321 | + const legacyConfig: LegacySnowflakeIntegrationConfig = { |
| 322 | + id: 'snowflake-keypair', |
| 323 | + name: 'Snowflake KeyPair', |
| 324 | + type: LegacyIntegrationType.Snowflake, |
| 325 | + authMethod: SnowflakeAuthMethods.KEY_PAIR, |
| 326 | + account: 'myaccount' |
| 327 | + }; |
| 328 | + |
| 329 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 330 | + |
| 331 | + assert.strictEqual(result, null); |
| 332 | + }); |
| 333 | + }); |
| 334 | + |
| 335 | + suite('Unknown integration types', () => { |
| 336 | + test('Returns null for unknown integration type', async () => { |
| 337 | + const legacyConfig = { |
| 338 | + id: 'unknown-1', |
| 339 | + name: 'Unknown Integration', |
| 340 | + type: 'unknown-type' |
| 341 | + } as any; |
| 342 | + |
| 343 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 344 | + |
| 345 | + assert.strictEqual(result, null); |
| 346 | + }); |
| 347 | + |
| 348 | + test('Returns null for DuckDB integration type', async () => { |
| 349 | + const legacyConfig = { |
| 350 | + id: 'duckdb-1', |
| 351 | + name: 'DuckDB', |
| 352 | + type: LegacyIntegrationType.DuckDB |
| 353 | + } as any; |
| 354 | + |
| 355 | + const result = await upgradeLegacyIntegrationConfig(legacyConfig); |
| 356 | + |
| 357 | + assert.strictEqual(result, null); |
| 358 | + }); |
| 359 | + }); |
| 360 | +}); |
0 commit comments