@@ -2,10 +2,12 @@ package envbuilder_test
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"io"
6
7
"net/http/httptest"
7
8
"net/url"
8
9
"os"
10
+ "regexp"
9
11
"testing"
10
12
"time"
11
13
@@ -45,46 +47,29 @@ func TestCloneRepo(t *testing.T) {
45
47
expectClone : true ,
46
48
},
47
49
{
48
- name : "invalid auth" ,
50
+ name : "auth but no creds " ,
49
51
srvUsername : "user" ,
50
52
srvPassword : "password" ,
51
53
expectClone : false ,
52
54
expectError : "authentication required" ,
53
55
},
54
56
{
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" ,
65
58
srvUsername : "user" ,
66
59
srvPassword : "password" ,
67
- username : "" ,
68
- password : "password " ,
60
+ username : "notuser " ,
61
+ password : "notpassword " ,
69
62
expectClone : false ,
70
63
expectError : "authentication required" ,
71
64
},
72
65
{
73
- name : "user only " ,
74
- srvUsername : "user " ,
66
+ name : "tokenish username " ,
67
+ srvUsername : "tokentokentoken " ,
75
68
srvPassword : "" ,
76
- username : "user " ,
69
+ username : "tokentokentoken " ,
77
70
password : "" ,
78
71
expectClone : true ,
79
72
},
80
- {
81
- name : "password only" ,
82
- srvUsername : "" ,
83
- srvPassword : "password" ,
84
- username : "" ,
85
- password : "password" ,
86
- expectClone : true ,
87
- },
88
73
} {
89
74
tc := tc
90
75
t .Run (tc .name , func (t * testing.T ) {
@@ -131,7 +116,8 @@ func TestCloneRepo(t *testing.T) {
131
116
readme := mustRead (t , clientFS , "/workspace/README.md" )
132
117
require .Equal (t , "Hello, world!" , readme )
133
118
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 )
135
121
})
136
122
137
123
// In-URL-style auth e.g. http://user:password@host:port
@@ -159,8 +145,8 @@ func TestCloneRepo(t *testing.T) {
159
145
readme := mustRead (t , clientFS , "/workspace/README.md" )
160
146
require .Equal (t , "Hello, world!" , readme )
161
147
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 )
164
150
})
165
151
})
166
152
}
0 commit comments