Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbcebbd4

Browse files
committed
move malformed block check earlier
1 parent572a938 commitbcebbd4

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

‎src/sshConfig.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,44 @@ Host coder-vscode.dev.coder.com--*
249249
})
250250
})
251251

252+
it("throws an error if there is a missing end block",async()=>{
253+
// The below config is missing an end block.
254+
// This is a malformed config and should throw an error.
255+
constexistentSSHConfig=`Host beforeconfig
256+
HostName before.config.tld
257+
User before
258+
259+
# --- START CODER VSCODE dev.coder.com ---
260+
Host coder-vscode.dev.coder.com--*
261+
ConnectTimeout 0
262+
LogLevel ERROR
263+
ProxyCommand some-command-here
264+
StrictHostKeyChecking no
265+
UserKnownHostsFile /dev/null
266+
267+
Host afterconfig
268+
HostName after.config.tld
269+
User after`
270+
271+
constsshConfig=newSSHConfig(sshFilePath,mockFileSystem)
272+
mockFileSystem.readFile.mockResolvedValueOnce(existentSSHConfig)
273+
awaitsshConfig.load()
274+
275+
// When we try to update the config, it should throw an error.
276+
awaitexpect(
277+
sshConfig.update("dev.coder.com",{
278+
Host:"coder-vscode.dev.coder.com--*",
279+
ProxyCommand:"some-command-here",
280+
ConnectTimeout:"0",
281+
StrictHostKeyChecking:"no",
282+
UserKnownHostsFile:"/dev/null",
283+
LogLevel:"ERROR",
284+
}),
285+
).rejects.toThrow(
286+
`Malformed config: Unterminated START CODER VSCODE dev.coder.com block: Each START block must have an END block.`,
287+
)
288+
})
289+
252290
it("throws an error if there is a mismatched start and end block count",async()=>{
253291
// The below config contains two start blocks and one end block.
254292
// This is a malformed config and should throw an error.

‎src/sshConfig.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,28 @@ export class SSHConfig {
126126
constraw=this.getRaw()
127127
conststartBlock=this.startBlockComment(label)
128128
constendBlock=this.endBlockComment(label)
129+
129130
conststartBlockCount=countSubstring(startBlock,raw)
130131
constendBlockCount=countSubstring(endBlock,raw)
131-
conststartBlockIndex=raw.indexOf(startBlock)
132-
constendBlockIndex=raw.indexOf(endBlock)
133-
consthasBlock=startBlockIndex>-1&&endBlockIndex>-1
134-
135-
if(!hasBlock){
136-
return
137-
}
138-
139132
if(startBlockCount!==endBlockCount){
140133
thrownewSSHConfigBadFormat(
141134
`Malformed config: Unterminated START CODER VSCODE${label ?label+" " :""}block: Each START block must have an END block.`,
142135
)
143136
}
137+
144138
if(startBlockCount>1||endBlockCount>1){
145139
thrownewSSHConfigBadFormat(
146140
`Malformed config: ssh config has${startBlockCount} START CODER VSCODE${label ?label+" " :""}sections, please remove all but one.`,
147141
)
148142
}
149143

144+
conststartBlockIndex=raw.indexOf(startBlock)
145+
constendBlockIndex=raw.indexOf(endBlock)
146+
consthasBlock=startBlockIndex>-1&&endBlockIndex>-1
147+
if(!hasBlock){
148+
return
149+
}
150+
150151
if(startBlockIndex===-1){
151152
thrownewSSHConfigBadFormat("Start block not found")
152153
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp