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
Kazuhiko Shiozaki
gitlab-ce
Commits
b8d8292b
Commit
b8d8292b
authored
Nov 20, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix upload tests, reformat code and make rubocop happy
parent
14d95b05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
122 deletions
+110
-122
lib/gitlab/lfs/response.rb
lib/gitlab/lfs/response.rb
+1
-2
spec/lib/gitlab/lfs/lfs_router_spec.rb
spec/lib/gitlab/lfs/lfs_router_spec.rb
+109
-120
No files found.
lib/gitlab/lfs/response.rb
View file @
b8d8292b
...
@@ -321,7 +321,6 @@ module Gitlab
...
@@ -321,7 +321,6 @@ 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
if
existing_objects
.
include?
(
object
[
'oid'
])
if
existing_objects
.
include?
(
object
[
'oid'
])
object
[
'actions'
]
=
{
object
[
'actions'
]
=
{
'download'
=>
{
'download'
=>
{
...
@@ -344,7 +343,7 @@ module Gitlab
...
@@ -344,7 +343,7 @@ module Gitlab
def
upload_hypermedia_links
(
all_objects
,
existing_objects
)
def
upload_hypermedia_links
(
all_objects
,
existing_objects
)
all_objects
.
each
do
|
object
|
all_objects
.
each
do
|
object
|
# generate
link
s only for non-existing objects
# generate
action
s only for non-existing objects
next
if
existing_objects
.
include?
(
object
[
'oid'
])
next
if
existing_objects
.
include?
(
object
[
'oid'
])
object
[
'actions'
]
=
{
object
[
'actions'
]
=
{
...
...
spec/lib/gitlab/lfs/lfs_router_spec.rb
View file @
b8d8292b
...
@@ -248,11 +248,11 @@ describe Gitlab::Lfs::Router do
...
@@ -248,11 +248,11 @@ describe Gitlab::Lfs::Router do
describe
'download'
do
describe
'download'
do
describe
'when user is authenticated'
do
describe
'when user is authenticated'
do
before
do
before
do
body
=
{
'o
bjects'
=>
[{
body
=
{
'o
peration'
=>
'download'
,
'oid'
=>
sample_oid
,
'objects'
=>
[
'size'
=>
sample_size
{
'oid'
=>
sample_oid
,
}],
'size'
=>
sample_size
'operation'
=>
'download'
}]
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
end
...
@@ -274,17 +274,16 @@ describe Gitlab::Lfs::Router do
...
@@ -274,17 +274,16 @@ describe Gitlab::Lfs::Router do
expect
(
response
.
first
).
to
eq
(
200
)
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
expect
(
response_body
).
to
eq
(
'objects'
=>
[
'objects'
=>
[{
{
'oid'
=>
sample_oid
,
'oid'
=>
sample_oid
,
'size'
=>
sample_size
,
'size'
=>
sample_size
,
'actions'
=>
{
'actions'
=>
{
'download'
=>
{
'download'
=>
{
'href'
=>
"
#{
project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'href'
=>
"
#{
project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'header'
=>
{
'Authorization'
=>
@auth
}
'header'
=>
{
'Authorization'
=>
@auth
}
}
}
}
}
}])
}])
end
end
end
end
...
@@ -298,26 +297,24 @@ describe Gitlab::Lfs::Router do
...
@@ -298,26 +297,24 @@ describe Gitlab::Lfs::Router do
expect
(
response
.
first
).
to
eq
(
200
)
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
expect
(
response_body
).
to
eq
(
'objects'
=>
[
'objects'
=>
[{
{
'oid'
=>
sample_oid
,
'oid'
=>
sample_oid
,
'size'
=>
sample_size
,
'size'
=>
sample_size
,
'error'
=>
{
'error'
=>
{
'code'
=>
404
,
'code'
=>
404
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
}
}
}])
}])
end
end
end
end
context
'when downloading a lfs object that does not exist'
do
context
'when downloading a lfs object that does not exist'
do
before
do
before
do
body
=
{
body
=
{
'operation'
=>
'download'
,
'objects'
=>
[{
'objects'
=>
[
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
'size'
=>
1575078
}],
}]
'operation'
=>
'download'
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
end
...
@@ -327,30 +324,28 @@ describe Gitlab::Lfs::Router do
...
@@ -327,30 +324,28 @@ describe Gitlab::Lfs::Router do
expect
(
response
.
first
).
to
eq
(
200
)
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
expect
(
response_body
).
to
eq
(
'objects'
=>
[
'objects'
=>
[{
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
,
'size'
=>
1575078
,
'error'
=>
{
'error'
=>
{
'code'
=>
404
,
'code'
=>
404
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
}
}
}])
}])
end
end
end
end
context
'when downloading one new and one existing lfs object'
do
context
'when downloading one new and one existing lfs object'
do
before
do
before
do
body
=
{
body
=
{
'operation'
=>
'download'
,
'objects'
=>
[
'objects'
=>
[
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
'size'
=>
1575078
},
},
{
'oid'
=>
sample_oid
,
{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
'size'
=>
sample_size
}
}
],
]
'operation'
=>
'download'
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
project
.
lfs_objects
<<
lfs_object
project
.
lfs_objects
<<
lfs_object
...
@@ -361,25 +356,23 @@ describe Gitlab::Lfs::Router do
...
@@ -361,25 +356,23 @@ describe Gitlab::Lfs::Router do
expect
(
response
.
first
).
to
eq
(
200
)
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
expect
(
response_body
).
to
eq
(
'objects'
=>
[
'objects'
=>
[{
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
,
'size'
=>
1575078
,
'error'
=>
{
'error'
=>
{
'code'
=>
404
,
'code'
=>
404
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
'message'
=>
"Object does not exist on the server or you don't have permissions to access it"
,
}
}
},
},
{
'oid'
=>
sample_oid
,
{
'size'
=>
sample_size
,
'oid'
=>
sample_oid
,
'actions'
=>
{
'size'
=>
sample_size
,
'download'
=>
{
'actions'
=>
{
'href'
=>
"
#{
project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'download'
=>
{
'header'
=>
{
'Authorization'
=>
@auth
}
'href'
=>
"
#{
project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
}
'header'
=>
{
'Authorization'
=>
@auth
}
}
}
}])
}
}])
end
end
end
end
end
end
...
@@ -411,11 +404,12 @@ describe Gitlab::Lfs::Router do
...
@@ -411,11 +404,12 @@ describe Gitlab::Lfs::Router do
context
'when user is not authenticated'
do
context
'when user is not authenticated'
do
before
do
before
do
body
=
{
'objects'
=>
[{
body
=
{
'operation'
=>
'download'
,
'oid'
=>
sample_oid
,
'objects'
=>
[
'size'
=>
sample_size
{
'oid'
=>
sample_oid
,
}],
'size'
=>
sample_size
'operation'
=>
'download'
}],
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
end
...
@@ -430,17 +424,16 @@ describe Gitlab::Lfs::Router do
...
@@ -430,17 +424,16 @@ describe Gitlab::Lfs::Router do
expect
(
response
.
first
).
to
eq
(
200
)
expect
(
response
.
first
).
to
eq
(
200
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
).
to
eq
(
expect
(
response_body
).
to
eq
(
'objects'
=>
[
'objects'
=>
[{
{
'oid'
=>
sample_oid
,
'oid'
=>
sample_oid
,
'size'
=>
sample_size
,
'size'
=>
sample_size
,
'actions'
=>
{
'actions'
=>
{
'download'
=>
{
'download'
=>
{
'href'
=>
"
#{
public_project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'href'
=>
"
#{
public_project
.
http_url_to_repo
}
/gitlab-lfs/objects/
#{
sample_oid
}
"
,
'header'
=>
{}
'header'
=>
{}
}
}
}
}
}])
}])
end
end
end
end
...
@@ -459,12 +452,12 @@ describe Gitlab::Lfs::Router do
...
@@ -459,12 +452,12 @@ describe Gitlab::Lfs::Router do
describe
'upload'
do
describe
'upload'
do
describe
'when user is authenticated'
do
describe
'when user is authenticated'
do
before
do
before
do
body
=
{
'o
bjects'
=>
[{
body
=
{
'o
peration'
=>
'upload'
,
'oid'
=>
sample_oid
,
'objects'
=>
[
'size'
=>
sample_size
{
'oid'
=>
sample_oid
,
}],
'size'
=>
sample_size
'operation'
=>
'upload'
}]
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
end
...
@@ -472,7 +465,7 @@ describe Gitlab::Lfs::Router do
...
@@ -472,7 +465,7 @@ describe Gitlab::Lfs::Router do
before
do
before
do
@auth
=
authorize
(
user
)
@auth
=
authorize
(
user
)
env
[
"HTTP_AUTHORIZATION"
]
=
@auth
env
[
"HTTP_AUTHORIZATION"
]
=
@auth
project
.
team
<<
[
user
,
:
mast
er
]
project
.
team
<<
[
user
,
:
develop
er
]
end
end
context
'when pushing an lfs object that already exists'
do
context
'when pushing an lfs object that already exists'
do
...
@@ -489,19 +482,19 @@ describe Gitlab::Lfs::Router do
...
@@ -489,19 +482,19 @@ describe Gitlab::Lfs::Router do
expect
(
response
[
'objects'
].
first
[
'size'
]).
to
eq
(
sample_size
)
expect
(
response
[
'objects'
].
first
[
'size'
]).
to
eq
(
sample_size
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
to_not
include
(
project
.
id
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
to_not
include
(
project
.
id
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
to
include
(
public_project
.
id
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
to
include
(
public_project
.
id
)
expect
(
response
[
'objects'
].
first
).
to
have_key
(
'_links'
)
expect
(
response
[
'objects'
].
first
[
'actions'
][
'upload'
][
'href'
]).
to
eq
(
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
path_with_namespace
}
.git/gitlab-lfs/objects/
#{
sample_oid
}
/
#{
sample_size
}
"
)
expect
(
response
[
'objects'
].
first
[
'actions'
][
'upload'
][
'header'
]).
to
eq
(
'Authorization'
=>
@auth
)
end
end
end
end
context
'when pushing a lfs object that does not exist'
do
context
'when pushing a lfs object that does not exist'
do
before
do
before
do
body
=
{
body
=
{
'operation'
=>
'upload'
,
'objects'
=>
[{
'objects'
=>
[
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
'size'
=>
1575078
}],
}]
'operation'
=>
'upload'
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
end
end
...
@@ -514,26 +507,25 @@ describe Gitlab::Lfs::Router do
...
@@ -514,26 +507,25 @@ describe Gitlab::Lfs::Router do
expect
(
response_body
[
'objects'
].
first
[
'oid'
]).
to
eq
(
"91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897"
)
expect
(
response_body
[
'objects'
].
first
[
'oid'
]).
to
eq
(
"91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897"
)
expect
(
response_body
[
'objects'
].
first
[
'size'
]).
to
eq
(
1575078
)
expect
(
response_body
[
'objects'
].
first
[
'size'
]).
to
eq
(
1575078
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
not_to
include
(
project
.
id
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
not_to
include
(
project
.
id
)
expect
(
response_body
[
'objects'
].
first
[
'
_link
s'
][
'upload'
][
'href'
]).
to
eq
(
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
path_with_namespace
}
.git/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078"
)
expect
(
response_body
[
'objects'
].
first
[
'
action
s'
][
'upload'
][
'href'
]).
to
eq
(
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
path_with_namespace
}
.git/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078"
)
expect
(
response_body
[
'objects'
].
first
[
'
_links'
][
'upload'
][
'header'
]).
to
eq
(
"Authorization"
=>
@auth
)
expect
(
response_body
[
'objects'
].
first
[
'
actions'
][
'upload'
][
'header'
]).
to
eq
(
'Authorization'
=>
@auth
)
end
end
end
end
context
'when pushing one new and one existing lfs object'
do
context
'when pushing one new and one existing lfs object'
do
before
do
before
do
body
=
{
body
=
{
'operation'
=>
'upload'
,
'objects'
=>
[
'objects'
=>
[
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
{
'oid'
=>
'91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897'
,
'size'
=>
1575078
'size'
=>
1575078
},
},
{
'oid'
=>
sample_oid
,
{
'oid'
=>
sample_oid
,
'size'
=>
sample_size
'size'
=>
sample_size
}
}
],
]
'operation'
=>
'upload'
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
p
ublic_p
roject
.
lfs_objects
<<
lfs_object
project
.
lfs_objects
<<
lfs_object
end
end
it
"responds with status 200 with upload hypermedia link for the new object"
do
it
"responds with status 200 with upload hypermedia link for the new object"
do
...
@@ -543,17 +535,14 @@ describe Gitlab::Lfs::Router do
...
@@ -543,17 +535,14 @@ describe Gitlab::Lfs::Router do
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
response_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
last
.
first
)
expect
(
response_body
[
'objects'
]).
to
be_kind_of
(
Array
)
expect
(
response_body
[
'objects'
]).
to
be_kind_of
(
Array
)
expect
(
response_body
[
'objects'
].
first
[
'oid'
]).
to
eq
(
"91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897"
)
expect
(
response_body
[
'objects'
].
first
[
'oid'
]).
to
eq
(
"91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897"
)
expect
(
response_body
[
'objects'
].
first
[
'size'
]).
to
eq
(
1575078
)
expect
(
response_body
[
'objects'
].
first
[
'size'
]).
to
eq
(
1575078
)
expect
(
response_body
[
'objects'
].
first
[
'
_link
s'
][
'upload'
][
'href'
]).
to
eq
(
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
path_with_namespace
}
.git/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078"
)
expect
(
response_body
[
'objects'
].
first
[
'
action
s'
][
'upload'
][
'href'
]).
to
eq
(
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
path_with_namespace
}
.git/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078"
)
expect
(
response_body
[
'objects'
].
first
[
'
_link
s'
][
'upload'
][
'header'
]).
to
eq
(
"Authorization"
=>
@auth
)
expect
(
response_body
[
'objects'
].
first
[
'
action
s'
][
'upload'
][
'header'
]).
to
eq
(
"Authorization"
=>
@auth
)
expect
(
response_body
[
'objects'
].
last
[
'oid'
]).
to
eq
(
sample_oid
)
expect
(
response_body
[
'objects'
].
last
[
'oid'
]).
to
eq
(
sample_oid
)
expect
(
response_body
[
'objects'
].
last
[
'size'
]).
to
eq
(
sample_size
)
expect
(
response_body
[
'objects'
].
last
[
'size'
]).
to
eq
(
sample_size
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
to_not
include
(
project
.
id
)
expect
(
response_body
[
'objects'
].
last
).
to_not
have_key
(
'actions'
)
expect
(
lfs_object
.
projects
.
pluck
(
:id
)).
to
include
(
public_project
.
id
)
expect
(
response_body
[
'objects'
].
last
).
to
have_key
(
'_links'
)
end
end
end
end
end
end
...
@@ -592,11 +581,11 @@ describe Gitlab::Lfs::Router do
...
@@ -592,11 +581,11 @@ describe Gitlab::Lfs::Router do
describe
'unsupported'
do
describe
'unsupported'
do
before
do
before
do
body
=
{
'o
bjects'
=>
[{
body
=
{
'o
peration'
=>
'other'
,
'oid'
=>
sample_oid
,
'objects'
=>
[
'size'
=>
sample_size
{
'oid'
=>
sample_oid
,
}],
'size'
=>
sample_size
'operation'
=>
'other'
}]
}.
to_json
}.
to_json
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
env
[
'rack.input'
]
=
StringIO
.
new
(
body
)
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