Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
922fb741
Commit
922fb741
authored
7 years ago
by
Akihiko Odaki
Committed by
Eugen Rochko
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Remove methods from ObfuscateFilename and spec (#3347)
* Remove methods from ObfuscateFilename * Spec ObfuscateFilename
parent
7bf2d6cb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/concerns/obfuscate_filename.rb
+7
-13
7 additions, 13 deletions
app/controllers/concerns/obfuscate_filename.rb
spec/controllers/concerns/obfuscate_filename_spec.rb
+30
-0
30 additions, 0 deletions
spec/controllers/concerns/obfuscate_filename_spec.rb
with
37 additions
and
13 deletions
app/controllers/concerns/obfuscate_filename.rb
+
7
−
13
View file @
922fb741
...
...
@@ -4,19 +4,13 @@ module ObfuscateFilename
extend
ActiveSupport
::
Concern
class_methods
do
def
obfuscate_filename
(
*
args
)
before_action
{
obfuscate_filename
(
*
args
)
}
end
end
def
obfuscate_filename
(
path
)
file
=
params
.
dig
(
*
path
)
return
if
file
.
nil?
def
obfuscate_filename
(
path
)
before_action
do
file
=
params
.
dig
(
*
path
)
next
if
file
.
nil?
file
.
original_filename
=
secure_token
+
File
.
extname
(
file
.
original_filename
)
end
def
secure_token
(
length
=
16
)
SecureRandom
.
hex
(
length
/
2
)
file
.
original_filename
=
SecureRandom
.
hex
(
8
)
+
File
.
extname
(
file
.
original_filename
)
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/controllers/concerns/obfuscate_filename_spec.rb
0 → 100644
+
30
−
0
View file @
922fb741
# frozen_string_literal: true
require
'rails_helper'
describe
ApplicationController
,
type: :controller
do
controller
do
include
ObfuscateFilename
obfuscate_filename
:file
def
file
render
plain:
params
[
:file
]
&
.
original_filename
end
end
before
do
routes
.
draw
{
get
'file'
=>
'anonymous#file'
}
end
it
'obfusticates filename if the given parameter is specified'
do
file
=
fixture_file_upload
(
'files/imports.txt'
,
'text/plain'
)
post
'file'
,
params:
{
file:
file
}
expect
(
response
.
body
).
to
end_with
'.txt'
expect
(
response
.
body
).
not_to
include
'imports'
end
it
'does nothing if the given parameter is not specified'
do
post
'file'
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment