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
1c282165
Commit
1c282165
authored
Aug 01, 2015
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'denied push' test
parent
83525e7f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
10 deletions
+37
-10
main_test.go
main_test.go
+37
-10
No files found.
main_test.go
View file @
1c282165
...
@@ -77,16 +77,7 @@ func TestDeniedClone(t *testing.T) {
...
@@ -77,16 +77,7 @@ func TestDeniedClone(t *testing.T) {
}
}
func
TestAllowedPush
(
t
*
testing
.
T
)
{
func
TestAllowedPush
(
t
*
testing
.
T
)
{
// Prepare the repo to push from
branch
:=
preparePushRepo
(
t
)
if
err
:=
os
.
RemoveAll
(
scratchDir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
path
.
Join
(
testRepoRoot
,
testRepo
),
checkoutDir
)
runOrFail
(
t
,
cloneCmd
)
branch
:=
fmt
.
Sprintf
(
"branch-%d"
,
time
.
Now
()
.
UnixNano
())
branchCmd
:=
exec
.
Command
(
"git"
,
"branch"
,
branch
)
branchCmd
.
Dir
=
checkoutDir
runOrFail
(
t
,
branchCmd
)
// Prepare the test server and backend
// Prepare the test server and backend
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
ts
:=
testAuthServer
(
200
,
`{"GL_ID":"user-123"}`
)
...
@@ -106,6 +97,42 @@ func TestAllowedPush(t *testing.T) {
...
@@ -106,6 +97,42 @@ func TestAllowedPush(t *testing.T) {
runOrFail
(
t
,
pushCmd
)
runOrFail
(
t
,
pushCmd
)
}
}
func
TestDeniedPush
(
t
*
testing
.
T
)
{
branch
:=
preparePushRepo
(
t
)
// Prepare the test server and backend
ts
:=
testAuthServer
(
403
,
"Access denied"
)
defer
ts
.
Close
()
cmd
,
err
:=
startServer
(
ts
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
cleanUpProcessGroup
(
cmd
)
if
err
:=
waitServer
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Perform the git push
pushCmd
:=
exec
.
Command
(
"git"
,
"push"
,
remote
,
branch
)
pushCmd
.
Dir
=
checkoutDir
if
err
:=
pushCmd
.
Run
();
err
==
nil
{
t
.
Fatal
(
"git push should have failed"
)
}
}
func
preparePushRepo
(
t
*
testing
.
T
)
string
{
if
err
:=
os
.
RemoveAll
(
scratchDir
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
cloneCmd
:=
exec
.
Command
(
"git"
,
"clone"
,
path
.
Join
(
testRepoRoot
,
testRepo
),
checkoutDir
)
runOrFail
(
t
,
cloneCmd
)
branch
:=
fmt
.
Sprintf
(
"branch-%d"
,
time
.
Now
()
.
UnixNano
())
branchCmd
:=
exec
.
Command
(
"git"
,
"branch"
,
branch
)
branchCmd
.
Dir
=
checkoutDir
runOrFail
(
t
,
branchCmd
)
return
branch
}
func
testAuthServer
(
code
int
,
body
string
)
*
httptest
.
Server
{
func
testAuthServer
(
code
int
,
body
string
)
*
httptest
.
Server
{
return
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
code
)
w
.
WriteHeader
(
code
)
...
...
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