Skip to content

Commit

Permalink
fix: canonicalized hostname should not contain glob pattern (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjake authored May 8, 2024
1 parent dbeaa19 commit 5c68841
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/ssh-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ export default class SSHConfig extends Array<Line> {
}
}

if (canonicalDomains.length > 0 && canonicalizeHostName) {
if (canonicalDomains.length > 0 && canonicalizeHostName && context.params.Host === context.params.OriginalHost) {
for (const domain of canonicalDomains) {
const host = `${line.value}.${domain}`
const { status } = spawnSync('nslookup', [host])
if (status === 0) {
const host = `${context.params.OriginalHost}.${domain}`
const { status, stderr } = spawnSync('nslookup', [host])
if (status === 0 && !/can't find/.test(stderr.toString())) {
context.params.Host = host
setProperty('Host', host)
doPass()
Expand Down
21 changes: 19 additions & 2 deletions test/unit/ssh-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ describe('SSHConfig', function() {
it('.compute By Host with canonical domains', async () => {
const config = SSHConfig.parse(`
Host www.cyj.me
ServerAliveInterval 60
ServerAliveCountMax 2
ServerAliveInterval 60
ServerAliveCountMax 2
Host www
User matthew
Expand All @@ -110,6 +110,23 @@ describe('SSHConfig', function() {
assert.equal(result.ServerAliveCountMax, '2')
})

it('.compute By Host with canonical domains', async () => {
const config = SSHConfig.parse(`
Host www.example.net
ServerAliveInterval 60
ServerAliveCountMax 2
Host *
User matthew
CanonicalizeHostName yes
CanonicalDomains example.net example.com
`)

const result = config.compute('www')
assert.ok(result)
assert.equal(result.ServerAliveCountMax, '2')
})

it('.compute by Match host', async function() {
const config = SSHConfig.parse(`
Match host tahoe1
Expand Down

0 comments on commit 5c68841

Please sign in to comment.