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
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-ce
Commits
b5018ac5
Commit
b5018ac5
authored
Jun 09, 2016
by
Fatih Acet
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into award-emoji-fixes
parents
d866faf2
3803b380
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
18 deletions
+99
-18
config/routes.rb
config/routes.rb
+17
-17
spec/requests/git_http_spec.rb
spec/requests/git_http_spec.rb
+82
-1
No files found.
config/routes.rb
View file @
b5018ac5
...
@@ -442,22 +442,6 @@ Rails.application.routes.draw do
...
@@ -442,22 +442,6 @@ Rails.application.routes.draw do
resources
(
:projects
,
constraints:
{
id:
/[a-zA-Z.0-9_\-]+(?<!\.atom)/
},
except:
resources
(
:projects
,
constraints:
{
id:
/[a-zA-Z.0-9_\-]+(?<!\.atom)/
},
except:
[
:new
,
:create
,
:index
],
path:
"/"
)
do
[
:new
,
:create
,
:index
],
path:
"/"
)
do
# Allow /info/refs, /info/refs?service=git-upload-pack, and
# /info/refs?service=git-receive-pack, but nothing else.
#
git_http_handshake
=
lambda
do
|
request
|
request
.
query_string
.
blank?
||
request
.
query_string
.
match
(
/\Aservice=git-(upload|receive)-pack\z/
)
end
ref_redirect
=
redirect
do
|
params
,
request
|
path
=
"
#{
params
[
:namespace_id
]
}
/
#{
params
[
:project_id
]
}
.git/info/refs"
path
<<
"?
#{
request
.
query_string
}
"
unless
request
.
query_string
.
blank?
path
end
get
'/info/refs'
,
constraints:
git_http_handshake
,
to:
ref_redirect
member
do
member
do
put
:transfer
put
:transfer
delete
:remove_fork
delete
:remove_fork
...
@@ -472,12 +456,28 @@ Rails.application.routes.draw do
...
@@ -472,12 +456,28 @@ Rails.application.routes.draw do
scope
module: :projects
do
scope
module: :projects
do
# Git HTTP clients ('git clone' etc.)
# Git HTTP clients ('git clone' etc.)
scope
constraints:
{
format:
/(git|wiki\.git)/
}
do
scope
constraints:
{
id:
/.+\.git/
,
format:
nil
}
do
get
'/info/refs'
,
to:
'git_http#info_refs'
get
'/info/refs'
,
to:
'git_http#info_refs'
post
'/git-upload-pack'
,
to:
'git_http#git_upload_pack'
post
'/git-upload-pack'
,
to:
'git_http#git_upload_pack'
post
'/git-receive-pack'
,
to:
'git_http#git_receive_pack'
post
'/git-receive-pack'
,
to:
'git_http#git_receive_pack'
end
end
# Allow /info/refs, /info/refs?service=git-upload-pack, and
# /info/refs?service=git-receive-pack, but nothing else.
#
git_http_handshake
=
lambda
do
|
request
|
request
.
query_string
.
blank?
||
request
.
query_string
.
match
(
/\Aservice=git-(upload|receive)-pack\z/
)
end
ref_redirect
=
redirect
do
|
params
,
request
|
path
=
"
#{
params
[
:namespace_id
]
}
/
#{
params
[
:project_id
]
}
.git/info/refs"
path
<<
"?
#{
request
.
query_string
}
"
unless
request
.
query_string
.
blank?
path
end
get
'/info/refs'
,
constraints:
git_http_handshake
,
to:
ref_redirect
# Blob routes:
# Blob routes:
get
'/new/*id'
,
to:
'blob#new'
,
constraints:
{
id:
/.+/
},
as:
'new_blob'
get
'/new/*id'
,
to:
'blob#new'
,
constraints:
{
id:
/.+/
},
as:
'new_blob'
post
'/create/*id'
,
to:
'blob#create'
,
constraints:
{
id:
/.+/
},
as:
'create_blob'
post
'/create/*id'
,
to:
'blob#create'
,
constraints:
{
id:
/.+/
},
as:
'create_blob'
...
...
spec/requests/git_http_spec.rb
View file @
b5018ac5
...
@@ -2,7 +2,7 @@ require "spec_helper"
...
@@ -2,7 +2,7 @@ require "spec_helper"
describe
'Git HTTP requests'
,
lib:
true
do
describe
'Git HTTP requests'
,
lib:
true
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
,
path:
'project.git-project'
)
}
it
"gives WWW-Authenticate hints"
do
it
"gives WWW-Authenticate hints"
do
clone_get
(
'doesnt/exist.git'
)
clone_get
(
'doesnt/exist.git'
)
...
@@ -268,6 +268,87 @@ describe 'Git HTTP requests', lib: true do
...
@@ -268,6 +268,87 @@ describe 'Git HTTP requests', lib: true do
end
end
end
end
context
"when the project path doesn't end in .git"
do
context
"GET info/refs"
do
let
(
:path
)
{
"/
#{
project
.
path_with_namespace
}
/info/refs"
}
context
"when no params are added"
do
before
{
get
path
}
it
"redirects to the .git suffix version"
do
expect
(
response
).
to
redirect_to
(
"/
#{
project
.
path_with_namespace
}
.git/info/refs"
)
end
end
context
"when the upload-pack service is requested"
do
let
(
:params
)
{
{
service:
'git-upload-pack'
}
}
before
{
get
path
,
params
}
it
"redirects to the .git suffix version"
do
expect
(
response
).
to
redirect_to
(
"/
#{
project
.
path_with_namespace
}
.git/info/refs?service=
#{
params
[
:service
]
}
"
)
end
end
context
"when the receive-pack service is requested"
do
let
(
:params
)
{
{
service:
'git-receive-pack'
}
}
before
{
get
path
,
params
}
it
"redirects to the .git suffix version"
do
expect
(
response
).
to
redirect_to
(
"/
#{
project
.
path_with_namespace
}
.git/info/refs?service=
#{
params
[
:service
]
}
"
)
end
end
context
"when the params are anything else"
do
let
(
:params
)
{
{
service:
'git-implode-pack'
}
}
before
{
get
path
,
params
}
it
"redirects to the sign-in page"
do
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
context
"POST git-upload-pack"
do
it
"fails to find a route"
do
expect
{
clone_post
(
project
.
path_with_namespace
)
}.
to
raise_error
(
ActionController
::
RoutingError
)
end
end
context
"POST git-receive-pack"
do
it
"failes to find a route"
do
expect
{
push_post
(
project
.
path_with_namespace
)
}.
to
raise_error
(
ActionController
::
RoutingError
)
end
end
end
context
"retrieving an info/refs file"
do
before
{
project
.
update_attribute
(
:visibility_level
,
Project
::
PUBLIC
)
}
context
"when the file exists"
do
before
do
# Provide a dummy file in its place
allow_any_instance_of
(
Repository
).
to
receive
(
:blob_at
).
and_call_original
allow_any_instance_of
(
Repository
).
to
receive
(
:blob_at
).
with
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
,
'info/refs'
)
do
Gitlab
::
Git
::
Blob
.
find
(
project
.
repository
,
'master'
,
'.gitignore'
)
end
get
"/
#{
project
.
path_with_namespace
}
/blob/master/info/refs"
end
it
"returns the file"
do
expect
(
response
.
status
).
to
eq
(
200
)
end
end
context
"when the file exists"
do
before
{
get
"/
#{
project
.
path_with_namespace
}
/blob/master/info/refs"
}
it
"returns not found"
do
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
def
clone_get
(
project
,
options
=
{})
def
clone_get
(
project
,
options
=
{})
get
"/
#{
project
}
/info/refs"
,
{
service:
'git-upload-pack'
},
auth_env
(
*
options
.
values_at
(
:user
,
:password
))
get
"/
#{
project
}
/info/refs"
,
{
service:
'git-upload-pack'
},
auth_env
(
*
options
.
values_at
(
:user
,
:password
))
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