Skip to content

Commit 52fa5b4

Browse files
committed
address PR comments
1 parent afa49ab commit 52fa5b4

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

envbuilder.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,8 @@ func Run(ctx context.Context, options Options) error {
361361
}
362362

363363
if options.GitUsername != "" || options.GitPassword != "" {
364-
// Previously, we had been placing credentials in the URL
365-
// as well as setting githttp.BasicAuth.
366-
// This was removed as it would leak the credentials used
367-
// to clone the repo into the resulting workspace.
368-
// Users may still hard-code credentials directly into the
369-
// git URL themselves, if required.
370-
364+
// NOTE: we previously inserted the credentials into the repo URL.
365+
// This was removed in https://github.com/coder/envbuilder/pull/141
371366
cloneOpts.RepoAuth = &githttp.BasicAuth{
372367
Username: options.GitUsername,
373368
Password: options.GitPassword,

git_test.go

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package envbuilder_test
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"net/http/httptest"
78
"net/url"
89
"os"
10+
"regexp"
911
"testing"
1012
"time"
1113

@@ -45,46 +47,29 @@ func TestCloneRepo(t *testing.T) {
4547
expectClone: true,
4648
},
4749
{
48-
name: "invalid auth",
50+
name: "auth but no creds",
4951
srvUsername: "user",
5052
srvPassword: "password",
5153
expectClone: false,
5254
expectError: "authentication required",
5355
},
5456
{
55-
name: "invalid auth password",
56-
srvUsername: "user",
57-
srvPassword: "password",
58-
username: "user",
59-
password: "",
60-
expectClone: false,
61-
expectError: "authentication required",
62-
},
63-
{
64-
name: "invalid auth user",
57+
name: "invalid auth",
6558
srvUsername: "user",
6659
srvPassword: "password",
67-
username: "",
68-
password: "password",
60+
username: "notuser",
61+
password: "notpassword",
6962
expectClone: false,
7063
expectError: "authentication required",
7164
},
7265
{
73-
name: "user only",
74-
srvUsername: "user",
66+
name: "tokenish username",
67+
srvUsername: "tokentokentoken",
7568
srvPassword: "",
76-
username: "user",
69+
username: "tokentokentoken",
7770
password: "",
7871
expectClone: true,
7972
},
80-
{
81-
name: "password only",
82-
srvUsername: "",
83-
srvPassword: "password",
84-
username: "",
85-
password: "password",
86-
expectClone: true,
87-
},
8873
} {
8974
tc := tc
9075
t.Run(tc.name, func(t *testing.T) {
@@ -131,7 +116,8 @@ func TestCloneRepo(t *testing.T) {
131116
readme := mustRead(t, clientFS, "/workspace/README.md")
132117
require.Equal(t, "Hello, world!", readme)
133118
gitConfig := mustRead(t, clientFS, "/workspace/.git/config")
134-
require.Contains(t, gitConfig, srvURL)
119+
// Ensure we do not modify the git URL that folks pass in.
120+
require.Regexp(t, fmt.Sprintf(`(?m)^\s+url\s+=\s+%s\s*$`, regexp.QuoteMeta(srvURL)), gitConfig)
135121
})
136122

137123
// In-URL-style auth e.g. http://user:password@host:port
@@ -159,8 +145,8 @@ func TestCloneRepo(t *testing.T) {
159145
readme := mustRead(t, clientFS, "/workspace/README.md")
160146
require.Equal(t, "Hello, world!", readme)
161147
gitConfig := mustRead(t, clientFS, "/workspace/.git/config")
162-
// We do not modify the git URL that folks pass in.
163-
require.Contains(t, gitConfig, authURL.String())
148+
// Ensure we do not modify the git URL that folks pass in.
149+
require.Regexp(t, fmt.Sprintf(`(?m)^\s+url\s+=\s+%s\s*$`, regexp.QuoteMeta(authURL.String())), gitConfig)
164150
})
165151
})
166152
}

gittest/gittest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func WriteFile(t *testing.T, fs billy.Filesystem, path, content string) {
122122
func BasicAuthMW(username, password string) func(http.Handler) http.Handler {
123123
return func(next http.Handler) http.Handler {
124124
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
125-
if username != "" && password != "" {
125+
if username != "" || password != "" {
126126
authUser, authPass, ok := r.BasicAuth()
127127
if !ok || username != authUser || password != authPass {
128128
w.WriteHeader(http.StatusUnauthorized)

0 commit comments

Comments
 (0)