Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: canonicalized hostname should not contain glob pattern #83

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading