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
028562a0
Commit
028562a0
authored
Feb 21, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix 500 error when loading an invalid upload URL
parent
09220278
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
1 deletion
+40
-1
app/controllers/concerns/uploads_actions.rb
app/controllers/concerns/uploads_actions.rb
+4
-1
app/uploaders/gitlab_uploader.rb
app/uploaders/gitlab_uploader.rb
+4
-0
app/uploaders/personal_file_uploader.rb
app/uploaders/personal_file_uploader.rb
+6
-0
changelogs/unreleased/fix-500-for-invalid-upload-path.yml
changelogs/unreleased/fix-500-for-invalid-upload-path.yml
+5
-0
spec/controllers/projects/uploads_controller_spec.rb
spec/controllers/projects/uploads_controller_spec.rb
+8
-0
spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb
...d_examples/controllers/uploads_actions_shared_examples.rb
+13
-0
No files found.
app/controllers/concerns/uploads_actions.rb
View file @
028562a0
...
...
@@ -24,7 +24,7 @@ module UploadsActions
# - or redirect to its URL
#
def
show
return
render_404
unless
uploader
.
exists?
return
render_404
unless
uploader
&
.
exists?
if
uploader
.
file_storage?
disposition
=
uploader
.
image_or_video?
?
'inline'
:
'attachment'
...
...
@@ -71,6 +71,9 @@ module UploadsActions
def
build_uploader_from_params
uploader
=
uploader_class
.
new
(
model
,
secret:
params
[
:secret
])
return
nil
unless
uploader
.
model_valid?
uploader
.
retrieve_from_store!
(
params
[
:filename
])
uploader
end
...
...
app/uploaders/gitlab_uploader.rb
View file @
028562a0
...
...
@@ -67,6 +67,10 @@ class GitlabUploader < CarrierWave::Uploader::Base
super
||
file
&
.
filename
end
def
model_valid?
!!
model
end
private
# Designed to be overridden by child uploaders that have a dynamic path
...
...
app/uploaders/personal_file_uploader.rb
View file @
028562a0
...
...
@@ -14,6 +14,12 @@ class PersonalFileUploader < FileUploader
File
.
join
(
model
.
class
.
to_s
.
underscore
,
model
.
id
.
to_s
)
end
# model_path_segment does not require a model to be passed, so we can always
# generate a path, even when there's no model.
def
model_valid?
true
end
# Revert-Override
def
store_dir
File
.
join
(
base_dir
,
dynamic_segment
)
...
...
changelogs/unreleased/fix-500-for-invalid-upload-path.yml
0 → 100644
View file @
028562a0
---
title
:
Fix 500 error when loading an invalid upload URL
merge_request
:
author
:
type
:
fixed
spec/controllers/projects/uploads_controller_spec.rb
View file @
028562a0
...
...
@@ -7,4 +7,12 @@ describe Projects::UploadsController do
end
it_behaves_like
'handle uploads'
context
'when the URL the old style, without /-/system'
do
it
'responds with a redirect to the login page'
do
get
:show
,
namespace_id:
'project'
,
project_id:
'avatar'
,
filename:
'foo.png'
,
secret:
'bar'
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb
View file @
028562a0
...
...
@@ -89,6 +89,19 @@ shared_examples 'handle uploads' do
end
end
context
"when neither the uploader nor the model exists"
do
before
do
allow_any_instance_of
(
Upload
).
to
receive
(
:build_uploader
).
and_return
(
nil
)
allow
(
controller
).
to
receive
(
:find_model
).
and_return
(
nil
)
end
it
"responds with status 404"
do
show_upload
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
context
"when the file doesn't exist"
do
before
do
allow_any_instance_of
(
FileUploader
).
to
receive
(
:exists?
).
and_return
(
false
)
...
...
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