BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0c372271
Commit
0c372271
authored
Feb 12, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ac/4878-fix-attachments-ext' into 'master'
Honour workhorse provided file name See merge request gitlab-org/gitlab-ce!17059
parents
253e8f14
34c2a59c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
multipart.rb
lib/gitlab/middleware/multipart.rb
+4
-4
multipart_spec.rb
spec/lib/gitlab/middleware/multipart_spec.rb
+7
-3
No files found.
lib/gitlab/middleware/multipart.rb
View file @
0c372271
...
...
@@ -42,7 +42,7 @@ module Gitlab
key
,
value
=
parsed_field
.
first
if
value
.
nil?
value
=
open_file
(
tmp_path
)
value
=
open_file
(
tmp_path
,
@request
.
params
[
"
#{
key
}
.name"
]
)
@open_files
<<
value
else
value
=
decorate_params_value
(
value
,
@request
.
params
[
key
],
tmp_path
)
...
...
@@ -70,7 +70,7 @@ module Gitlab
case
path_value
when
nil
value_hash
[
path_key
]
=
open_file
(
tmp_path
)
value_hash
[
path_key
]
=
open_file
(
tmp_path
,
value_hash
.
dig
(
path_key
,
'.name'
)
)
@open_files
<<
value_hash
[
path_key
]
value_hash
when
Hash
...
...
@@ -81,8 +81,8 @@ module Gitlab
end
end
def
open_file
(
path
)
::
UploadedFile
.
new
(
path
,
File
.
basename
(
path
),
'application/octet-stream'
)
def
open_file
(
path
,
name
)
::
UploadedFile
.
new
(
path
,
name
||
File
.
basename
(
path
),
'application/octet-stream'
)
end
end
...
...
spec/lib/gitlab/middleware/multipart_spec.rb
View file @
0c372271
...
...
@@ -5,15 +5,17 @@ require 'tempfile'
describe
Gitlab
::
Middleware
::
Multipart
do
let
(
:app
)
{
double
(
:app
)
}
let
(
:middleware
)
{
described_class
.
new
(
app
)
}
let
(
:original_filename
)
{
'filename'
}
it
'opens top-level files'
do
Tempfile
.
open
(
'top-level'
)
do
|
tempfile
|
env
=
post_env
({
'file'
=>
tempfile
.
path
},
{
'file.name'
=>
'filename'
},
Gitlab
::
Workhorse
.
secret
,
'gitlab-workhorse'
)
env
=
post_env
({
'file'
=>
tempfile
.
path
},
{
'file.name'
=>
original_filename
},
Gitlab
::
Workhorse
.
secret
,
'gitlab-workhorse'
)
expect
(
app
).
to
receive
(
:call
)
do
|
env
|
file
=
Rack
::
Request
.
new
(
env
).
params
[
'file'
]
expect
(
file
).
to
be_a
(
::
UploadedFile
)
expect
(
file
.
path
).
to
eq
(
tempfile
.
path
)
expect
(
file
.
original_filename
).
to
eq
(
original_filename
)
end
middleware
.
call
(
env
)
...
...
@@ -34,13 +36,14 @@ describe Gitlab::Middleware::Multipart do
it
'opens files one level deep'
do
Tempfile
.
open
(
'one-level'
)
do
|
tempfile
|
in_params
=
{
'user'
=>
{
'avatar'
=>
{
'.name'
=>
'filename'
}
}
}
in_params
=
{
'user'
=>
{
'avatar'
=>
{
'.name'
=>
original_filename
}
}
}
env
=
post_env
({
'user[avatar]'
=>
tempfile
.
path
},
in_params
,
Gitlab
::
Workhorse
.
secret
,
'gitlab-workhorse'
)
expect
(
app
).
to
receive
(
:call
)
do
|
env
|
file
=
Rack
::
Request
.
new
(
env
).
params
[
'user'
][
'avatar'
]
expect
(
file
).
to
be_a
(
::
UploadedFile
)
expect
(
file
.
path
).
to
eq
(
tempfile
.
path
)
expect
(
file
.
original_filename
).
to
eq
(
original_filename
)
end
middleware
.
call
(
env
)
...
...
@@ -49,13 +52,14 @@ describe Gitlab::Middleware::Multipart do
it
'opens files two levels deep'
do
Tempfile
.
open
(
'two-levels'
)
do
|
tempfile
|
in_params
=
{
'project'
=>
{
'milestone'
=>
{
'themesong'
=>
{
'.name'
=>
'filename'
}
}
}
}
in_params
=
{
'project'
=>
{
'milestone'
=>
{
'themesong'
=>
{
'.name'
=>
original_filename
}
}
}
}
env
=
post_env
({
'project[milestone][themesong]'
=>
tempfile
.
path
},
in_params
,
Gitlab
::
Workhorse
.
secret
,
'gitlab-workhorse'
)
expect
(
app
).
to
receive
(
:call
)
do
|
env
|
file
=
Rack
::
Request
.
new
(
env
).
params
[
'project'
][
'milestone'
][
'themesong'
]
expect
(
file
).
to
be_a
(
::
UploadedFile
)
expect
(
file
.
path
).
to
eq
(
tempfile
.
path
)
expect
(
file
.
original_filename
).
to
eq
(
original_filename
)
end
middleware
.
call
(
env
)
...
...
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