Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
e8972c11
Commit
e8972c11
authored
May 22, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify error messages
And refactor to self-document a little better.
parent
23d37382
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
lib/gitlab/git_access.rb
lib/gitlab/git_access.rb
+26
-8
spec/lib/gitlab/git_access_spec.rb
spec/lib/gitlab/git_access_spec.rb
+2
-2
spec/requests/git_http_spec.rb
spec/requests/git_http_spec.rb
+3
-3
No files found.
lib/gitlab/git_access.rb
View file @
e8972c11
...
@@ -14,8 +14,8 @@ module Gitlab
...
@@ -14,8 +14,8 @@ module Gitlab
project_not_found:
'The project you were looking for could not be found.'
,
project_not_found:
'The project you were looking for could not be found.'
,
account_blocked:
'Your account has been blocked.'
,
account_blocked:
'Your account has been blocked.'
,
command_not_allowed:
"The command you're trying to execute is not allowed."
,
command_not_allowed:
"The command you're trying to execute is not allowed."
,
upload_pack_disabled_
in_config:
'The command "git-upload-pack"
is not allowed.'
,
upload_pack_disabled_
over_http:
'Pulling over HTTP
is not allowed.'
,
receive_pack_disabled_
in_config:
'The command "git-receive-pack"
is not allowed.'
receive_pack_disabled_
over_http:
'Pushing over HTTP
is not allowed.'
}.
freeze
}.
freeze
DOWNLOAD_COMMANDS
=
%w{ git-upload-pack git-upload-archive }
.
freeze
DOWNLOAD_COMMANDS
=
%w{ git-upload-pack git-upload-archive }
.
freeze
...
@@ -94,13 +94,23 @@ module Gitlab
...
@@ -94,13 +94,23 @@ module Gitlab
end
end
def
check_command_disabled!
(
cmd
)
def
check_command_disabled!
(
cmd
)
if
http?
if
upload_pack?
(
cmd
)
if
upload_pack?
(
cmd
)
&&
!
Gitlab
.
config
.
gitlab_shell
.
upload_pack
check_upload_pack_disabled!
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:upload_pack_disabled_in_config
]
elsif
receive_pack?
(
cmd
)
elsif
receive_pack?
(
cmd
)
&&
!
Gitlab
.
config
.
gitlab_shell
.
receive_pack
check_receive_pack_disabled!
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:receive_pack_disabled_in_config
]
end
end
end
end
def
check_upload_pack_disabled!
if
http?
&&
upload_pack_disabled_over_http?
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:upload_pack_disabled_over_http
]
end
end
def
check_receive_pack_disabled!
if
http?
&&
receive_pack_disabled_over_http?
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:receive_pack_disabled_over_http
]
end
end
end
def
check_command_existence!
(
cmd
)
def
check_command_existence!
(
cmd
)
...
@@ -215,6 +225,14 @@ module Gitlab
...
@@ -215,6 +225,14 @@ module Gitlab
command
==
'git-receive-pack'
command
==
'git-receive-pack'
end
end
def
upload_pack_disabled_over_http?
!
Gitlab
.
config
.
gitlab_shell
.
upload_pack
end
def
receive_pack_disabled_over_http?
!
Gitlab
.
config
.
gitlab_shell
.
receive_pack
end
protected
protected
def
user
def
user
...
...
spec/lib/gitlab/git_access_spec.rb
View file @
e8972c11
...
@@ -170,7 +170,7 @@ describe Gitlab::GitAccess, lib: true do
...
@@ -170,7 +170,7 @@ describe Gitlab::GitAccess, lib: true do
end
end
context
'when calling git-upload-pack'
do
context
'when calling git-upload-pack'
do
it
{
expect
{
pull_access_check
}.
to
raise_unauthorized
(
'
The command "git-upload-pack"
is not allowed.'
)
}
it
{
expect
{
pull_access_check
}.
to
raise_unauthorized
(
'
Pulling over HTTP
is not allowed.'
)
}
end
end
context
'when calling git-receive-pack'
do
context
'when calling git-receive-pack'
do
...
@@ -184,7 +184,7 @@ describe Gitlab::GitAccess, lib: true do
...
@@ -184,7 +184,7 @@ describe Gitlab::GitAccess, lib: true do
end
end
context
'when calling git-receive-pack'
do
context
'when calling git-receive-pack'
do
it
{
expect
{
push_access_check
}.
to
raise_unauthorized
(
'
The command "git-receive-pack"
is not allowed.'
)
}
it
{
expect
{
push_access_check
}.
to
raise_unauthorized
(
'
Pushing over HTTP
is not allowed.'
)
}
end
end
context
'when calling git-upload-pack'
do
context
'when calling git-upload-pack'
do
...
...
spec/requests/git_http_spec.rb
View file @
e8972c11
...
@@ -254,7 +254,7 @@ describe 'Git HTTP requests', lib: true do
...
@@ -254,7 +254,7 @@ describe 'Git HTTP requests', lib: true do
it
'rejects pushes with 403 Forbidden'
do
it
'rejects pushes with 403 Forbidden'
do
upload
(
path
,
env
)
do
|
response
|
upload
(
path
,
env
)
do
|
response
|
expect
(
response
).
to
have_http_status
(
:forbidden
)
expect
(
response
).
to
have_http_status
(
:forbidden
)
expect
(
response
.
body
).
to
eq
(
git_access_error
(
:receive_pack_disabled_
in_config
))
expect
(
response
.
body
).
to
eq
(
git_access_error
(
:receive_pack_disabled_
over_http
))
end
end
end
end
end
end
...
@@ -265,7 +265,7 @@ describe 'Git HTTP requests', lib: true do
...
@@ -265,7 +265,7 @@ describe 'Git HTTP requests', lib: true do
download
(
path
,
env
)
do
|
response
|
download
(
path
,
env
)
do
|
response
|
expect
(
response
).
to
have_http_status
(
:forbidden
)
expect
(
response
).
to
have_http_status
(
:forbidden
)
expect
(
response
.
body
).
to
eq
(
git_access_error
(
:upload_pack_disabled_
in_config
))
expect
(
response
.
body
).
to
eq
(
git_access_error
(
:upload_pack_disabled_
over_http
))
end
end
end
end
end
end
...
...
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