Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-workhorse
Commits
3ab95e20
Commit
3ab95e20
authored
Oct 11, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove test-only local git mode
parent
77986088
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
3 additions
and
228 deletions
+3
-228
gitaly_test.go
gitaly_test.go
+0
-72
internal/git/git-http.go
internal/git/git-http.go
+0
-5
internal/git/git-http_test.go
internal/git/git-http_test.go
+0
-9
internal/git/info-refs.go
internal/git/info-refs.go
+1
-35
internal/git/pktline.go
internal/git/pktline.go
+0
-10
internal/git/upload-pack.go
internal/git/upload-pack.go
+2
-31
main_test.go
main_test.go
+0
-66
No files found.
gitaly_test.go
View file @
3ab95e20
...
@@ -327,78 +327,6 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) {
...
@@ -327,78 +327,6 @@ func TestPostUploadPackProxiedToGitalyInterrupted(t *testing.T) {
}
}
}
}
func
TestGetInfoRefsHandledLocallyDueToEmptyGitalySocketPath
(
t
*
testing
.
T
)
{
gitalyServer
,
_
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
apiResponse
:=
gitOkBody
(
t
)
apiResponse
.
GitalyServer
.
Address
=
""
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
resource
:=
"/gitlab-org/gitlab-test.git/info/refs?service=git-upload-pack"
resp
,
body
:=
httpGet
(
t
,
ws
.
URL
+
resource
,
nil
)
assert
.
Equal
(
t
,
200
,
resp
.
StatusCode
,
"GET %q"
,
resource
)
assert
.
NotContains
(
t
,
string
(
testhelper
.
GitalyInfoRefsResponseMock
),
body
,
"GET %q: should not have been proxied to Gitaly"
,
resource
)
testhelper
.
AssertResponseHeader
(
t
,
resp
,
"Content-Type"
,
"application/x-git-upload-pack-advertisement"
)
}
func
TestPostReceivePackHandledLocallyDueToEmptyGitalySocketPath
(
t
*
testing
.
T
)
{
gitalyServer
,
_
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
apiResponse
:=
gitOkBody
(
t
)
apiResponse
.
GitalyServer
.
Address
=
""
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
resource
:=
"/gitlab-org/gitlab-test.git/git-receive-pack"
payload
:=
[]
byte
(
"This payload should not reach Gitaly"
)
resp
,
body
:=
httpPost
(
t
,
ws
.
URL
+
resource
,
map
[
string
]
string
{
"Content-type"
:
"application/x-git-receive-pack-request"
},
payload
,
)
assert
.
Equal
(
t
,
200
,
resp
.
StatusCode
,
"POST %q: status code"
,
resource
)
assert
.
NotContains
(
t
,
payload
,
body
,
"POST %q: request should not have been proxied to Gitaly"
,
resource
)
testhelper
.
AssertResponseHeader
(
t
,
resp
,
"Content-Type"
,
"application/x-git-receive-pack-result"
)
}
func
TestPostUploadPackHandledLocallyDueToEmptyGitalySocketPath
(
t
*
testing
.
T
)
{
gitalyServer
,
_
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
apiResponse
:=
gitOkBody
(
t
)
apiResponse
.
GitalyServer
.
Address
=
""
ts
:=
testAuthServer
(
nil
,
200
,
apiResponse
)
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
resource
:=
"/gitlab-org/gitlab-test.git/git-upload-pack"
payload
:=
[]
byte
(
"This payload should not reach Gitaly"
)
resp
,
body
:=
httpPost
(
t
,
ws
.
URL
+
resource
,
map
[
string
]
string
{
"Content-type"
:
"application/x-git-upload-pack-request"
},
payload
,
)
assert
.
Equal
(
t
,
200
,
resp
.
StatusCode
,
"POST %q: status code"
,
resource
)
assert
.
NotContains
(
t
,
payload
,
body
,
"POST %q: request should not have been proxied to Gitaly"
,
resource
)
testhelper
.
AssertResponseHeader
(
t
,
resp
,
"Content-Type"
,
"application/x-git-upload-pack-result"
)
}
func
TestGetBlobProxiedToGitalySuccessfully
(
t
*
testing
.
T
)
{
func
TestGetBlobProxiedToGitalySuccessfully
(
t
*
testing
.
T
)
{
gitalyServer
,
socketPath
:=
startGitalyServer
(
t
,
codes
.
OK
)
gitalyServer
,
socketPath
:=
startGitalyServer
(
t
,
codes
.
OK
)
defer
gitalyServer
.
Stop
()
defer
gitalyServer
.
Stop
()
...
...
internal/git/git-http.go
View file @
3ab95e20
...
@@ -95,11 +95,6 @@ func getService(r *http.Request) string {
...
@@ -95,11 +95,6 @@ func getService(r *http.Request) string {
return
filepath
.
Base
(
r
.
URL
.
Path
)
return
filepath
.
Base
(
r
.
URL
.
Path
)
}
}
func
isExitError
(
err
error
)
bool
{
_
,
ok
:=
err
.
(
*
exec
.
ExitError
)
return
ok
}
func
subCommand
(
rpc
string
)
string
{
func
subCommand
(
rpc
string
)
string
{
return
strings
.
TrimPrefix
(
rpc
,
"git-"
)
return
strings
.
TrimPrefix
(
rpc
,
"git-"
)
}
}
...
...
internal/git/git-http_test.go
View file @
3ab95e20
...
@@ -31,20 +31,11 @@ func createTestPayload() []byte {
...
@@ -31,20 +31,11 @@ func createTestPayload() []byte {
return
bytes
.
Repeat
([]
byte
{
'0'
},
expectedBytes
)
return
bytes
.
Repeat
([]
byte
{
'0'
},
expectedBytes
)
}
}
func
TestHandleUploadPack
(
t
*
testing
.
T
)
{
testHandlePostRpc
(
t
,
"git-upload-pack"
,
handleUploadPack
)
}
func
TestHandleReceivePack
(
t
*
testing
.
T
)
{
func
TestHandleReceivePack
(
t
*
testing
.
T
)
{
testHandlePostRpc
(
t
,
"git-receive-pack"
,
handleReceivePack
)
testHandlePostRpc
(
t
,
"git-receive-pack"
,
handleReceivePack
)
}
}
func
testHandlePostRpc
(
t
*
testing
.
T
,
action
string
,
handler
func
(
*
HttpResponseWriter
,
*
http
.
Request
,
*
api
.
Response
)
error
)
{
func
testHandlePostRpc
(
t
*
testing
.
T
,
action
string
,
handler
func
(
*
HttpResponseWriter
,
*
http
.
Request
,
*
api
.
Response
)
error
)
{
defer
func
(
oldTesting
bool
)
{
Testing
=
oldTesting
}(
Testing
)
Testing
=
true
execCommand
=
fakeExecCommand
execCommand
=
fakeExecCommand
defer
func
()
{
execCommand
=
exec
.
Command
}()
defer
func
()
{
execCommand
=
exec
.
Command
}()
...
...
internal/git/info-refs.go
View file @
3ab95e20
...
@@ -11,11 +11,6 @@ import (
...
@@ -11,11 +11,6 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
)
var
(
// Testing is only set during workhorse testing.
Testing
=
false
)
func
GetInfoRefsHandler
(
a
*
api
.
API
)
http
.
Handler
{
func
GetInfoRefsHandler
(
a
*
api
.
API
)
http
.
Handler
{
return
repoPreAuthorizeHandler
(
a
,
handleGetInfoRefs
)
return
repoPreAuthorizeHandler
(
a
,
handleGetInfoRefs
)
}
}
...
@@ -37,42 +32,13 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
...
@@ -37,42 +32,13 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
var
err
error
err
:=
handleGetInfoRefsWithGitaly
(
r
.
Context
(),
w
,
a
,
rpc
,
gitProtocol
)
if
a
.
GitalyServer
.
Address
==
""
&&
Testing
{
err
=
handleGetInfoRefsLocalTesting
(
w
,
a
,
rpc
)
}
else
{
err
=
handleGetInfoRefsWithGitaly
(
r
.
Context
(),
w
,
a
,
rpc
,
gitProtocol
)
}
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: %v"
,
err
))
}
}
}
}
// This code is not used in production. It is left over from before
// Gitaly. We left it here to allow local workhorse tests to keep working
// until we are done migrating Git HTTP to Gitaly.
func
handleGetInfoRefsLocalTesting
(
w
http
.
ResponseWriter
,
a
*
api
.
Response
,
rpc
string
)
error
{
if
err
:=
pktLine
(
w
,
fmt
.
Sprintf
(
"# service=%s
\n
"
,
rpc
));
err
!=
nil
{
return
fmt
.
Errorf
(
"pktLine: %v"
,
err
)
}
if
err
:=
pktFlush
(
w
);
err
!=
nil
{
return
fmt
.
Errorf
(
"pktFlush: %v"
,
err
)
}
cmd
,
err
:=
startGitCommand
(
a
,
nil
,
w
,
rpc
,
"--advertise-refs"
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"startGitCommand: %v"
,
err
)
}
defer
helper
.
CleanUpProcessGroup
(
cmd
)
// Ensure brute force subprocess clean-up
if
err
:=
cmd
.
Wait
();
err
!=
nil
{
return
fmt
.
Errorf
(
"wait for %v: %v"
,
cmd
.
Args
,
err
)
}
return
nil
}
func
handleGetInfoRefsWithGitaly
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
a
*
api
.
Response
,
rpc
string
,
gitProtocol
string
)
error
{
func
handleGetInfoRefsWithGitaly
(
ctx
context
.
Context
,
w
http
.
ResponseWriter
,
a
*
api
.
Response
,
rpc
string
,
gitProtocol
string
)
error
{
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
smarthttp
,
err
:=
gitaly
.
NewSmartHTTPClient
(
a
.
GitalyServer
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
internal/git/pktline.go
View file @
3ab95e20
...
@@ -8,16 +8,6 @@ import (
...
@@ -8,16 +8,6 @@ import (
"strconv"
"strconv"
)
)
func
pktLine
(
w
io
.
Writer
,
s
string
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%04x%s"
,
len
(
s
)
+
4
,
s
)
return
err
}
func
pktFlush
(
w
io
.
Writer
)
error
{
_
,
err
:=
fmt
.
Fprint
(
w
,
"0000"
)
return
err
}
func
scanDeepen
(
body
io
.
Reader
)
bool
{
func
scanDeepen
(
body
io
.
Reader
)
bool
{
scanner
:=
bufio
.
NewScanner
(
body
)
scanner
:=
bufio
.
NewScanner
(
body
)
scanner
.
Split
(
pktLineSplitter
)
scanner
.
Split
(
pktLineSplitter
)
...
...
internal/git/upload-pack.go
View file @
3ab95e20
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
"os"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
...
@@ -28,37 +27,9 @@ func handleUploadPack(w *HttpResponseWriter, r *http.Request, a *api.Response) e
...
@@ -28,37 +27,9 @@ func handleUploadPack(w *HttpResponseWriter, r *http.Request, a *api.Response) e
action
:=
getService
(
r
)
action
:=
getService
(
r
)
writePostRPCHeader
(
w
,
action
)
writePostRPCHeader
(
w
,
action
)
if
Testing
&&
a
.
GitalyServer
.
Address
==
""
{
// This code path is no longer reachable in GitLab 10.0
err
=
handleUploadPackLocally
(
a
,
r
,
buffer
,
w
,
action
)
}
else
{
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
gitProtocol
:=
r
.
Header
.
Get
(
"Git-Protocol"
)
err
=
handleUploadPackWithGitaly
(
r
.
Context
(),
a
,
buffer
,
w
,
gitProtocol
)
return
handleUploadPackWithGitaly
(
r
.
Context
(),
a
,
buffer
,
w
,
gitProtocol
)
}
return
err
}
func
handleUploadPackLocally
(
a
*
api
.
Response
,
r
*
http
.
Request
,
stdin
*
os
.
File
,
stdout
io
.
Writer
,
action
string
)
error
{
isShallowClone
:=
scanDeepen
(
stdin
)
if
_
,
err
:=
stdin
.
Seek
(
0
,
0
);
err
!=
nil
{
return
fmt
.
Errorf
(
"seek tempfile: %v"
,
err
)
}
cmd
,
err
:=
startGitCommand
(
a
,
stdin
,
stdout
,
action
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"startGitCommand: %v"
,
err
)
}
defer
helper
.
CleanUpProcessGroup
(
cmd
)
if
err
:=
cmd
.
Wait
();
err
!=
nil
&&
!
(
isExitError
(
err
)
&&
isShallowClone
)
{
helper
.
LogError
(
r
,
fmt
.
Errorf
(
"wait for %v: %v"
,
cmd
.
Args
,
err
))
// Return nil because the response body has been written to already.
return
nil
}
return
nil
}
}
func
handleUploadPackWithGitaly
(
ctx
context
.
Context
,
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
,
gitProtocol
string
)
error
{
func
handleUploadPackWithGitaly
(
ctx
context
.
Context
,
a
*
api
.
Response
,
clientRequest
io
.
Reader
,
clientResponse
io
.
Writer
,
gitProtocol
string
)
error
{
...
...
main_test.go
View file @
3ab95e20
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/config"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/config"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/git"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/testhelper"
...
@@ -41,8 +40,6 @@ var checkoutDir = path.Join(scratchDir, "test")
...
@@ -41,8 +40,6 @@ var checkoutDir = path.Join(scratchDir, "test")
var
cacheDir
=
path
.
Join
(
scratchDir
,
"cache"
)
var
cacheDir
=
path
.
Join
(
scratchDir
,
"cache"
)
func
TestMain
(
m
*
testing
.
M
)
{
func
TestMain
(
m
*
testing
.
M
)
{
git
.
Testing
=
true
if
_
,
err
:=
os
.
Stat
(
path
.
Join
(
testRepoRoot
,
testRepo
));
os
.
IsNotExist
(
err
)
{
if
_
,
err
:=
os
.
Stat
(
path
.
Join
(
testRepoRoot
,
testRepo
));
os
.
IsNotExist
(
err
)
{
log
.
Fatal
(
"cannot find test repository. Please run 'make prepare-tests'"
)
log
.
Fatal
(
"cannot find test repository. Please run 'make prepare-tests'"
)
}
}
...
@@ -56,46 +53,6 @@ func TestMain(m *testing.M) {
...
@@ -56,46 +53,6 @@ func TestMain(m *testing.M) {
os
.
Exit
(
m
.
Run
())
os
.
Exit
(
m
.
Run
())
}
}
func
TestAllowedClone
(
t
*
testing
.
T
)
{
// Prepare clone directory
require
.
NoError
(
t
,
os
.
RemoveAll
(
scratchDir
))
// Prepare test server and backend
ts
:=
testAuthServer
(
nil
,
200
,
gitOkBody
(
t
))
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
// Do the git clone
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
fmt
.
Sprintf
(
"%s/%s"
,
ws
.
URL
,
testRepo
),
checkoutDir
)
runOrFail
(
t
,
cloneCmd
)
// We may have cloned an 'empty' repository, 'git log' will fail in it
logCmd
:=
exec
.
Command
(
"git"
,
"log"
,
"-1"
,
"--oneline"
)
logCmd
.
Dir
=
checkoutDir
runOrFail
(
t
,
logCmd
)
}
func
TestAllowedShallowClone
(
t
*
testing
.
T
)
{
// Prepare clone directory
require
.
NoError
(
t
,
os
.
RemoveAll
(
scratchDir
))
// Prepare test server and backend
ts
:=
testAuthServer
(
nil
,
200
,
gitOkBody
(
t
))
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
// Shallow git clone (depth 1)
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
"--depth"
,
"1"
,
fmt
.
Sprintf
(
"%s/%s"
,
ws
.
URL
,
testRepo
),
checkoutDir
)
runOrFail
(
t
,
cloneCmd
)
// We may have cloned an 'empty' repository, 'git log' will fail in it
logCmd
:=
exec
.
Command
(
"git"
,
"log"
,
"-1"
,
"--oneline"
)
logCmd
.
Dir
=
checkoutDir
runOrFail
(
t
,
logCmd
)
}
func
TestDeniedClone
(
t
*
testing
.
T
)
{
func
TestDeniedClone
(
t
*
testing
.
T
)
{
// Prepare clone directory
// Prepare clone directory
require
.
NoError
(
t
,
os
.
RemoveAll
(
scratchDir
))
require
.
NoError
(
t
,
os
.
RemoveAll
(
scratchDir
))
...
@@ -113,24 +70,7 @@ func TestDeniedClone(t *testing.T) {
...
@@ -113,24 +70,7 @@ func TestDeniedClone(t *testing.T) {
assert
.
Error
(
t
,
err
,
"git clone should have failed"
)
assert
.
Error
(
t
,
err
,
"git clone should have failed"
)
}
}
func
TestAllowedPush
(
t
*
testing
.
T
)
{
preparePushRepo
(
t
)
// Prepare the test server and backend
ts
:=
testAuthServer
(
nil
,
200
,
gitOkBody
(
t
))
defer
ts
.
Close
()
ws
:=
startWorkhorseServer
(
ts
.
URL
)
defer
ws
.
Close
()
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
fmt
.
Sprintf
(
"%s/%s"
,
ws
.
URL
,
testRepo
),
fmt
.
Sprintf
(
"master:%s"
,
newBranch
()))
pushCmd
.
Dir
=
checkoutDir
runOrFail
(
t
,
pushCmd
)
}
func
TestDeniedPush
(
t
*
testing
.
T
)
{
func
TestDeniedPush
(
t
*
testing
.
T
)
{
preparePushRepo
(
t
)
// Prepare the test server and backend
// Prepare the test server and backend
ts
:=
testAuthServer
(
nil
,
403
,
"Access denied"
)
ts
:=
testAuthServer
(
nil
,
403
,
"Access denied"
)
defer
ts
.
Close
()
defer
ts
.
Close
()
...
@@ -573,12 +513,6 @@ func prepareDownloadDir(t *testing.T) {
...
@@ -573,12 +513,6 @@ func prepareDownloadDir(t *testing.T) {
require
.
NoError
(
t
,
os
.
MkdirAll
(
scratchDir
,
0755
))
require
.
NoError
(
t
,
os
.
MkdirAll
(
scratchDir
,
0755
))
}
}
func
preparePushRepo
(
t
*
testing
.
T
)
{
require
.
NoError
(
t
,
os
.
RemoveAll
(
scratchDir
))
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
path
.
Join
(
testRepoRoot
,
testRepo
),
checkoutDir
)
runOrFail
(
t
,
cloneCmd
)
}
func
newBranch
()
string
{
func
newBranch
()
string
{
return
fmt
.
Sprintf
(
"branch-%d"
,
time
.
Now
()
.
UnixNano
())
return
fmt
.
Sprintf
(
"branch-%d"
,
time
.
Now
()
.
UnixNano
())
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment