X Tutup
Skip to content
Draft
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
18 changes: 12 additions & 6 deletions cli/gitauth/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ func OverrideVSCodeConfigs(fs afero.Fs) error {
return err
}
mutate := func(m map[string]interface{}) {
// This prevents VS Code from overriding GIT_ASKPASS, which
// we use to automatically authenticate Git providers.
m["git.useIntegratedAskPass"] = false
// This prevents VS Code from using it's own GitHub authentication
// which would circumvent cloning with Coder-configured providers.
m["github.gitAuthentication"] = false
// These defaults prevent VS Code from overriding
// GIT_ASKPASS and using its own GitHub authentication,
// which would circumvent cloning with Coder-configured
// providers. We only set them if they are not already
// present so that template authors can override them
// via module settings (e.g. the vscode-web module).
if _, ok := m["git.useIntegratedAskPass"]; !ok {
m["git.useIntegratedAskPass"] = false
}
if _, ok := m["github.gitAuthentication"]; !ok {
m["github.gitAuthentication"] = false
}
}

for _, configPath := range []string{
Expand Down
27 changes: 27 additions & 0 deletions cli/gitauth/vscode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,31 @@ func TestOverrideVSCodeConfigs(t *testing.T) {
require.Equal(t, "something", mapping["hotdogs"])
}
})
t.Run("NoOverwrite", func(t *testing.T) {
t.Parallel()
fs := afero.NewMemMapFs()
mapping := map[string]interface{}{
"git.useIntegratedAskPass": true,
"github.gitAuthentication": true,
"other.setting": "preserved",
}
data, err := json.Marshal(mapping)
require.NoError(t, err)
for _, configPath := range configPaths {
err = afero.WriteFile(fs, configPath, data, 0o600)
require.NoError(t, err)
}
err = gitauth.OverrideVSCodeConfigs(fs)
require.NoError(t, err)
for _, configPath := range configPaths {
data, err := afero.ReadFile(fs, configPath)
require.NoError(t, err)
mapping := map[string]interface{}{}
err = json.Unmarshal(data, &mapping)
require.NoError(t, err)
require.Equal(t, true, mapping["git.useIntegratedAskPass"])
require.Equal(t, true, mapping["github.gitAuthentication"])
require.Equal(t, "preserved", mapping["other.setting"])
}
})
}
Loading
X Tutup