(t *testing.T)
| 170 | } |
| 171 | |
| 172 | func 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 | |
| 229 | func TestConfigSSH_MissingDirectory(t *testing.T) { |
nothing calls this directly
no test coverage detected