Skip to content

Commit 734dae4

Browse files
committed
refactor throwing logic
1 parent 151b103 commit 734dae4

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

packages/core/src/shared/extensions/ssh.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ export async function startVscodeRemote(
155155
* @returns
156156
*/
157157
export async function getSshVersion(sshPath: string): Promise<string | undefined> {
158-
const result = await new ChildProcess(sshPath, ['-V']).run()
158+
const result = await new ChildProcess(sshPath, ['-V'], { collect: true }).run()
159159

160-
return parseSshVersion(result.stdout)
160+
return parseSshVersion(result.stdout == '' ? result.stderr : result.stdout)
161161
}
162162

163-
export async function assertSshVersionGte(sshPath: string, minVersion: string): Promise<void | never> {
163+
export async function ensureSshVersionGte(sshPath: string, minVersion: string): Promise<void | never> {
164164
const sshVersion = await getSshVersion(sshPath)
165165
if (sshVersion && semver.lt(sshVersion, minVersion)) {
166-
const msg = `SSH version ${sshVersion} is not supported, please upgrade to 7.6 or higher`
166+
const msg = `SSH version ${sshVersion} is not supported, please upgrade OpenSSH to ${minVersion} or higher`
167167
getLogger().error(msg)
168168
throw new Error(msg)
169169
}
@@ -179,5 +179,5 @@ function parseSshVersion(output: string): string | undefined {
179179
const major = parseInt(match[1], 10)
180180
const minor = parseInt(match[2], 10)
181181

182-
return `${major}.${minor}`
182+
return `${major}.${minor}.0`
183183
}

packages/core/src/shared/remoteSession.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { findSshPath, getVscodeCliPath } from './utilities/pathFind'
2222
import { IamClient } from './clients/iamClient'
2323
import { IAM } from 'aws-sdk'
2424
import { getIdeProperties } from './extensionUtilities'
25-
import { assertSshVersionGte } from './extensions/ssh'
25+
import { ensureSshVersionGte } from './extensions/ssh'
2626

2727
const policyAttachDelay = 5000
2828

@@ -103,7 +103,11 @@ export async function ensureDependencies(): Promise<Result<DependencyPaths, Canc
103103
if (tools.isOk()) {
104104
const sshPath = tools.unwrap().ssh
105105
// Pre 7.6 does not support accept-new as StrictHostKeyChecking
106-
assertSshVersionGte(sshPath, '7.6')
106+
try {
107+
await ensureSshVersionGte(sshPath, '7.6.0')
108+
} catch (e) {
109+
return Result.err(e as Error)
110+
}
107111
}
108112

109113
return tools

packages/core/src/test/shared/extensions/ssh.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import * as assert from 'assert'
66
import { ChildProcess } from '../../../shared/utilities/processUtils'
7-
import { assertSshVersionGte, getSshVersion, startSshAgent } from '../../../shared/extensions/ssh'
7+
import { ensureSshVersionGte, getSshVersion, startSshAgent } from '../../../shared/extensions/ssh'
88
import { createExecutableFile, createTestWorkspaceFolder } from '../../testUtil'
99
import { isWin } from '../../../shared/vscode/env'
1010
import path from 'path'
@@ -62,8 +62,8 @@ describe('SSH Versioning', function () {
6262
it('asserts version is above threshold', async function () {
6363
const sshPath = path.join(tempDir.uri.fsPath, `ssh3${isWin() ? '.cmd' : ''}`)
6464
await createExecutableFile(sshPath, `echo "'OpenSSH_9.7p1, LibreSSL 3.3.6'"`)
65-
assert.rejects(async () => await assertSshVersionGte('', '9.10'))
66-
assert.doesNotReject(async () => await assertSshVersionGte('', '9.7'))
67-
assert.doesNotReject(async () => await assertSshVersionGte('', '9.2'))
65+
assert.rejects(async () => await ensureSshVersionGte('', '9.10'))
66+
assert.doesNotReject(async () => await ensureSshVersionGte('', '9.7'))
67+
assert.doesNotReject(async () => await ensureSshVersionGte('', '9.2'))
6868
})
6969
})

0 commit comments

Comments
 (0)