Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enforce tempfile to be a Tempfile object #1844

Merged
merged 1 commit into from Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

* Your contribution here.
* [#1833](https://github.com/ruby-grape/grape/pull/1833): Allows to set the `ParamBuilder` globally - [@myxoh](https://github.com/myxoh).
* [#1844](https://github.com/ruby-grape/grape/pull/1844): Fix: enforce `:tempfile` to be a `Tempfile` object in `File` validator - [@Nyangawa](https://github.com/Nyangawa).

#### Fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/types/file.rb
Expand Up @@ -19,7 +19,7 @@ def value_coerced?(value)
# Rack::Request creates a Hash with filename,
# content type and an IO object. Do a bit of basic
# duck-typing.
value.is_a?(::Hash) && value.key?(:tempfile)
value.is_a?(::Hash) && value.key?(:tempfile) && value[:tempfile].is_a?(Tempfile)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/grape/validations/validators/coerce_spec.rb
Expand Up @@ -397,6 +397,10 @@ def self.parsed?(value)
post '/upload', file: 'not a file'
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('file is invalid')

post '/upload', file: { filename: 'fake file', tempfile: '/etc/passwd' }
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('file is invalid')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we're just copy-pasting, but for next time each of these should be a separate spec with a before block that sets up the subject.

end

it 'Nests integers' do
Expand Down