Skip to content

Commit c4b661d

Browse files
author
Paulo Gomes
committed
git: Update proxy tests
Signed-off-by: Paulo Gomes <[email protected]>
1 parent 6ed7f39 commit c4b661d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/git/strategy/proxy/strategy_proxy_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestCheckoutStrategyForImplementation_Proxied(t *testing.T) {
8080
gitImpl: gogit.Implementation,
8181
url: "http://example.com/bar/test-reponame",
8282
branch: "main",
83-
setupGitProxy: func(g *WithT, proxy *goproxy.ProxyHttpServer, proxyGotRequest *bool) (*git.AuthOptions, cleanupFunc) {
83+
setupGitProxy: func(g *WithT, proxy *goproxy.ProxyHttpServer, proxiedRequests *int32) (*git.AuthOptions, cleanupFunc) {
8484
// Create the git server.
8585
gitServer, err := gittestserver.NewTempGitServer()
8686
g.Expect(err).ToNot(HaveOccurred())
@@ -103,7 +103,7 @@ func TestCheckoutStrategyForImplementation_Proxied(t *testing.T) {
103103
var proxyHandler goproxy.FuncReqHandler = func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
104104
userAgent := req.Header.Get("User-Agent")
105105
if strings.Contains(req.Host, "example.com") && strings.Contains(userAgent, "git") {
106-
*proxyGotRequest = true
106+
atomic.AddInt32(proxiedRequests, 1)
107107
req.Host = u.Host
108108
req.URL.Host = req.Host
109109
return req, nil
@@ -131,13 +131,13 @@ func TestCheckoutStrategyForImplementation_Proxied(t *testing.T) {
131131
gitImpl: gogit.Implementation,
132132
url: "https://github.com/git-fixtures/basic",
133133
branch: "master",
134-
setupGitProxy: func(g *WithT, proxy *goproxy.ProxyHttpServer, proxyGotRequest *bool) (*git.AuthOptions, cleanupFunc) {
134+
setupGitProxy: func(g *WithT, proxy *goproxy.ProxyHttpServer, proxiedRequests *int32) (*git.AuthOptions, cleanupFunc) {
135135
var proxyHandler goproxy.FuncHttpsHandler = func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
136136
// We don't check for user agent as this handler is only going to process CONNECT requests, and because Go's net/http
137137
// is the one making such a request on behalf of go-git, adding a check for the go net/http user agent (Go-http-client)
138138
// would only allow false positives from any request originating from Go's net/http.
139139
if strings.Contains(host, "github.com") {
140-
*proxyGotRequest = true
140+
atomic.AddInt32(proxiedRequests, 1)
141141
return goproxy.OkConnect, host
142142
}
143143
// Reject if it isnt our request.
@@ -158,10 +158,10 @@ func TestCheckoutStrategyForImplementation_Proxied(t *testing.T) {
158158
gitImpl: gogit.Implementation,
159159
url: "https://192.0.2.1/bar/test-reponame",
160160
branch: "main",
161-
setupGitProxy: func(g *WithT, proxy *goproxy.ProxyHttpServer, proxyGotRequest *bool) (*git.AuthOptions, cleanupFunc) {
161+
setupGitProxy: func(g *WithT, proxy *goproxy.ProxyHttpServer, proxiedRequests *int32) (*git.AuthOptions, cleanupFunc) {
162162
var proxyHandler goproxy.FuncHttpsHandler = func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
163163
// We shouldn't hit the proxy so we just want to check for any interaction, then reject.
164-
*proxyGotRequest = true
164+
atomic.AddInt32(proxiedRequests, 1)
165165
return goproxy.RejectConnect, host
166166
}
167167
proxy.OnRequest().HandleConnect(proxyHandler)

0 commit comments

Comments
 (0)