MCPcopy Index your code
hub / github.com/coder/coder / TestConfigSSH_RejectsUnsafeServerConfig

Function TestConfigSSH_RejectsUnsafeServerConfig

cli/configssh_test.go:172–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

170}
171
172func TestConfigSSH_RejectsUnsafeServerConfig(t *testing.T) {
173 t.Parallel()
174
175 if runtime.GOOS == "windows" {
176 t.Skip("See coder/internal#117")
177 }
178
179 testCases := []struct {
180 name string
181 configSSH codersdk.SSHConfigResponse
182 wantErr string
183 }{
184 {
185 name: "HostnameSuffix",
186 configSSH: codersdk.SSHConfigResponse{HostnameSuffix: "coder\nHost *"},
187 wantErr: "workspace hostname suffix",
188 },
189 {
190 name: "HostnamePrefix",
191 configSSH: codersdk.SSHConfigResponse{HostnamePrefix: "coder.\nHost *"},
192 wantErr: "workspace hostname prefix",
193 },
194 {
195 name: "HostnameSuffixGlob",
196 configSSH: codersdk.SSHConfigResponse{HostnameSuffix: "*"},
197 wantErr: "glob",
198 },
199 }
200
201 for _, tc := range testCases {
202 t.Run(tc.name, func(t *testing.T) {
203 t.Parallel()
204
205 const existingConfig = "Host safe\n\tHostName safe.example.com\n"
206 client := coderdtest.New(t, &coderdtest.Options{
207 ConfigSSH: tc.configSSH,
208 })
209 _ = coderdtest.CreateFirstUser(t, client)
210
211 sshConfigPath := sshConfigFileName(t)
212 sshConfigFileCreate(t, sshConfigPath, strings.NewReader(existingConfig))
213
214 inv, root := clitest.New(t,
215 "config-ssh",
216 "--ssh-config-file", sshConfigPath,
217 "--yes",
218 )
219 clitest.SetupConfig(t, client, root)
220
221 err := inv.Run()
222 require.Error(t, err)
223 require.ErrorContains(t, err, tc.wantErr)
224 require.Equal(t, existingConfig, sshConfigFileRead(t, sshConfigPath))
225 })
226 }
227}
228
229func TestConfigSSH_MissingDirectory(t *testing.T) {

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
sshConfigFileNameFunction · 0.85
sshConfigFileCreateFunction · 0.85
sshConfigFileReadFunction · 0.85
SkipMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected