Skip to content

Commit f80f622

Browse files
authored
fix(data-service): handle sshTunnelIdentityFile as array (#2539)
1 parent 76aa57d commit f80f622

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/data-service/src/legacy/legacy-connection-model.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,31 @@ describe('convertConnectionModelToInfo', function () {
232232
});
233233
});
234234

235+
it('converts ssh tunnel options (IDENTITY_FILE array)', async function () {
236+
const { connectionOptions } = await createAndConvertModel(
237+
'mongodb://localhost:27017',
238+
{
239+
sshTunnel: 'IDENTITY_FILE',
240+
sshTunnelHostname: 'jumphost',
241+
sshTunnelPort: 22,
242+
sshTunnelUsername: 'root',
243+
sshTunnelIdentityFile: ['myfile'],
244+
}
245+
);
246+
247+
expect(connectionOptions).to.deep.equal({
248+
connectionString:
249+
'mongodb://localhost:27017/' +
250+
'?readPreference=primary&directConnection=true&ssl=false',
251+
sshTunnel: {
252+
host: 'jumphost',
253+
port: 22,
254+
identityKeyFile: 'myfile',
255+
username: 'root',
256+
},
257+
});
258+
});
259+
235260
it('converts ssh tunnel options (IDENTITY_FILE) + passphrase', async function () {
236261
const { connectionOptions } = await createAndConvertModel(
237262
'mongodb://localhost:27017',

packages/data-service/src/legacy/legacy-connection-model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export interface LegacyConnectionModelProperties {
103103
sshTunnelBindToLocalPort?: number;
104104
sshTunnelUsername?: string;
105105
sshTunnelPassword?: string;
106-
sshTunnelIdentityFile?: string;
106+
sshTunnelIdentityFile?: string | string[];
107107
sshTunnelPassphrase?: string;
108108

109109
lastUsed?: Date;
@@ -283,7 +283,9 @@ function modelTunnelToConnectionOptions(
283283
}
284284

285285
if (model.sshTunnelIdentityFile !== undefined) {
286-
sshTunnel.identityKeyFile = model.sshTunnelIdentityFile;
286+
sshTunnel.identityKeyFile = Array.isArray(model.sshTunnelIdentityFile)
287+
? model.sshTunnelIdentityFile[0]
288+
: model.sshTunnelIdentityFile;
287289
}
288290

289291
if (model.sshTunnelPassphrase !== undefined) {

0 commit comments

Comments
 (0)