mirror of
https://github.com/desktop/desktop
synced 2024-09-13 05:11:21 +00:00
Relax the SSH host prompt regex
This will support small changes in the prompt, like the lack of the `[fingerprint]` option, or when a key of different type is available for that host.
This commit is contained in:
parent
500ebc3800
commit
db65e5efba
|
@ -73,7 +73,7 @@ export async function getSSHEnvironment() {
|
|||
}
|
||||
|
||||
export function parseAddSSHHostPrompt(prompt: string) {
|
||||
const promptRegex = /^The authenticity of host '([^ ]+) \(([^\)]+)\)' can't be established.\n([^ ]+) key fingerprint is ([^.]+).\n(?:.*\n)*Are you sure you want to continue connecting \(yes\/no\/\[fingerprint\]\)\? $/
|
||||
const promptRegex = /^The authenticity of host '([^ ]+) \(([^\)]+)\)' can't be established[^.]*\.\n([^ ]+) key fingerprint is ([^.]+)\./
|
||||
|
||||
const matches = promptRegex.exec(prompt)
|
||||
if (matches === null || matches.length < 5) {
|
||||
|
|
|
@ -32,5 +32,37 @@ Are you sure you want to continue connecting (yes/no/[fingerprint])? `
|
|||
keyType: 'FAKE-TYPE',
|
||||
})
|
||||
})
|
||||
|
||||
it('extracts info from fake host key fingerprint when keys of different type are available', () => {
|
||||
const prompt = `The authenticity of host 'my-domain.com (1.2.3.4)' can't be established
|
||||
but keys of different type are already known for this host.
|
||||
FAKE-TYPE key fingerprint is ThisIsAFakeFingerprintForTestingPurposes.
|
||||
Are you sure you want to continue connecting (yes/no/[fingerprint])? `
|
||||
|
||||
const info = parseAddSSHHostPrompt(prompt)
|
||||
|
||||
expect(info).toEqual({
|
||||
host: 'my-domain.com',
|
||||
ip: '1.2.3.4',
|
||||
fingerprint: 'ThisIsAFakeFingerprintForTestingPurposes',
|
||||
keyType: 'FAKE-TYPE',
|
||||
})
|
||||
})
|
||||
|
||||
it('extract info when [fingerprint] option is not present', () => {
|
||||
const prompt = `The authenticity of host 'my-domain.com (1.2.3.4)' can't be established.
|
||||
FAKE-TYPE key fingerprint is ThisIsAFakeFingerprintForTestingPurposes.
|
||||
This key is not known by any other names.
|
||||
Are you sure you want to continue connecting (yes/no)? `
|
||||
|
||||
const info = parseAddSSHHostPrompt(prompt)
|
||||
|
||||
expect(info).toEqual({
|
||||
host: 'my-domain.com',
|
||||
ip: '1.2.3.4',
|
||||
fingerprint: 'ThisIsAFakeFingerprintForTestingPurposes',
|
||||
keyType: 'FAKE-TYPE',
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue