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
Léo-Paul Géneau
gitlab-ce
Commits
7ea48bfb
Commit
7ea48bfb
authored
Nov 20, 2015
by
Kamil Trzcinski
Committed by
Marin Jankovski
Nov 20, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Part of tests done [ci skip]
parent
28113478
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
338 additions
and
104 deletions
+338
-104
lib/gitlab/lfs/response.rb
lib/gitlab/lfs/response.rb
+16
-11
spec/lib/gitlab/lfs/lfs_router_spec.rb
spec/lib/gitlab/lfs/lfs_router_spec.rb
+322
-93
No files found.
lib/gitlab/lfs/response.rb
View file @
7ea48bfb
...
@@ -42,7 +42,7 @@ module Gitlab
...
@@ -42,7 +42,7 @@ module Gitlab
when
"upload"
when
"upload"
render_batch_upload
(
request_body
)
render_batch_upload
(
request_body
)
else
else
render_
forbidden
render_
not_found
end
end
end
end
...
@@ -322,9 +322,8 @@ module Gitlab
...
@@ -322,9 +322,8 @@ module Gitlab
def
download_hypermedia_links
(
all_objects
,
existing_objects
)
def
download_hypermedia_links
(
all_objects
,
existing_objects
)
all_objects
.
each
do
|
object
|
all_objects
.
each
do
|
object
|
# generate links only for existing objects
# generate links only for existing objects
next
unless
existing_objects
.
include?
(
object
[
'oid'
])
if
existing_objects
.
include?
(
object
[
'oid'
])
object
[
'actions'
]
=
{
object
[
'_links'
]
=
{
'download'
=>
{
'download'
=>
{
'href'
=>
"
#{
@origin_project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
object
[
'oid'
]
}
"
,
'href'
=>
"
#{
@origin_project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
object
[
'oid'
]
}
"
,
'header'
=>
{
'header'
=>
{
...
@@ -332,6 +331,12 @@ module Gitlab
...
@@ -332,6 +331,12 @@ module Gitlab
}.
compact
}.
compact
}
}
}
}
else
object
[
'error'
]
=
{
'code'
=>
404
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
}
end
end
end
{
'objects'
=>
all_objects
}
{
'objects'
=>
all_objects
}
...
@@ -342,7 +347,7 @@ module Gitlab
...
@@ -342,7 +347,7 @@ module Gitlab
# generate links only for non-existing objects
# generate links only for non-existing objects
next
if
existing_objects
.
include?
(
object
[
'oid'
])
next
if
existing_objects
.
include?
(
object
[
'oid'
])
object
[
'
_link
s'
]
=
{
object
[
'
action
s'
]
=
{
'upload'
=>
{
'upload'
=>
{
'href'
=>
"
#{
@origin_project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
object
[
'oid'
]
}
/
#{
object
[
'size'
]
}
"
,
'href'
=>
"
#{
@origin_project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
object
[
'oid'
]
}
/
#{
object
[
'size'
]
}
"
,
'header'
=>
{
'header'
=>
{
...
...
spec/lib/gitlab/lfs/lfs_router_spec.rb
View file @
7ea48bfb
...
@@ -238,13 +238,225 @@ describe Gitlab::Lfs::Router do
...
@@ -238,13 +238,225 @@ describe Gitlab::Lfs::Router do
end
end
end
end
describe
'when
initiating pushing of the lfs objec
t'
do
describe
'when
handling lfs batch reques
t'
do
before
do
before
do
enable_lfs
enable_lfs
env
[
'REQUEST_METHOD'
]
=
'POST'
env
[
'REQUEST_METHOD'
]
=
'POST'
env
[
"PATH_INFO"
]
=
"
#{
project
.
repository
.
path_with_namespace
}
.git/info/lfs/objects/batch"
env
[
'PATH_INFO'
]
=
"
#{
project
.
repository
.
path_with_namespace
}
.git/info/lfs/objects/batch"
end
end
describe
'download'
do
describe
'when user is authenticated'
do
before
do
body
=
{
'objects'
=>
[{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
}],
'operation'
=>
'download'
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
describe
'when user has download access'
do
before
do
@auth
=
authorize
(
user
)
env
[
"HTTP_AUTHORIZATION"
]
=
@auth
project
.
team
<<
[
user
,
:reporter
]
end
context
'when downloading an lfs object that is assigned to our project'
do
before
do
project
.
lfs_objects
<<
lfs_object
end
it
'responds with status 200 and href to download'
do
response
=
lfs_router_auth
.
try_call
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
'objects'
=>
[{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
,
'actions'
=>
{
'download'
=>
{
'href'
=>
"
#{
project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'header'
=>
{
'Authorization'
=>
@auth
}
}
}
}])
end
end
context
'when downloading an lfs object that is assigned to other project'
do
before
do
public_project
.
lfs_objects
<<
lfs_object
end
it
'responds with status 200 and error message'
do
response
=
lfs_router_auth
.
try_call
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
'objects'
=>
[{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
,
'error'
=>
{
'code'
=>
404
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
}
}])
end
end
context
'when downloading a lfs object that does not exist'
do
before
do
body
=
{
'objects'
=>
[{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
}],
'operation'
=>
'download'
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
it
"responds with status 200 and error message"
do
response
=
lfs_router_auth
.
try_call
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
'objects'
=>
[{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
,
'error'
=>
{
'code'
=>
404
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
}
}])
end
end
context
'when downloading one new and one existing lfs object'
do
before
do
body
=
{
'objects'
=>
[
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
},
{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
}
],
'operation'
=>
'download'
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
project
.
lfs_objects
<<
lfs_object
end
it
"responds with status 200 with upload hypermedia link for the new object"
do
response
=
lfs_router_auth
.
try_call
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
'objects'
=>
[{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
,
'error'
=>
{
'code'
=>
404
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
}
},
{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
,
'actions'
=>
{
'download'
=>
{
'href'
=>
"
#{
project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'header'
=>
{
'Authorization'
=>
@auth
}
}
}
}])
end
end
end
context
'when user does is not member of the project'
do
before
do
@auth
=
authorize
(
user
)
env
[
"HTTP_AUTHORIZATION"
]
=
@auth
project
.
team
<<
[
user
,
:guest
]
end
it
'responds with 403'
do
expect
(
lfs_router_auth
.
try_call
.
first
).
to
eq
(
403
)
end
end
context
'when user does not have download access'
do
before
do
@auth
=
authorize
(
user
)
env
[
"HTTP_AUTHORIZATION"
]
=
@auth
project
.
team
<<
[
user
,
:guest
]
end
it
'responds with 403'
do
expect
(
lfs_router_auth
.
try_call
.
first
).
to
eq
(
403
)
end
end
end
context
'when user is not authenticated'
do
before
do
body
=
{
'objects'
=>
[{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
}],
'operation'
=>
'download'
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
describe
'is accessing public project'
do
before
do
public_project
.
lfs_objects
<<
lfs_object
end
it
'responds with status 200 and href to download'
do
response
=
lfs_router_public_noauth
.
try_call
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
'objects'
=>
[{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
,
'actions'
=>
{
'download'
=>
{
'href'
=>
"
#{
public_project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'header'
=>
{}
}
}
}])
end
end
describe
'is accessing non-public project'
do
before
do
project
.
lfs_objects
<<
lfs_object
end
it
'responds with authorization required'
do
expect
(
lfs_router_noauth
.
try_call
.
first
).
to
eq
(
401
)
end
end
end
end
describe
'upload'
do
describe
'when user is authenticated'
do
describe
'when user is authenticated'
do
before
do
before
do
body
=
{
'objects'
=>
[{
body
=
{
'objects'
=>
[{
...
@@ -378,6 +590,23 @@ describe Gitlab::Lfs::Router do
...
@@ -378,6 +590,23 @@ describe Gitlab::Lfs::Router do
end
end
end
end
describe
'unsupported'
do
before
do
body
=
{
'objects'
=>
[{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
}],
'operation'
=>
'other'
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
it
'responds with status 404'
do
expect
(
lfs_router_public_noauth
.
try_call
.
first
).
to
eq
(
404
)
end
end
end
describe
'when pushing a lfs object'
do
describe
'when pushing a lfs object'
do
before
do
before
do
enable_lfs
enable_lfs
...
...
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