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 IO validation on upload_endpoint #446

Merged
merged 2 commits into from Feb 3, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -135,9 +135,14 @@ def get_multipart_upload(request)
end

error!(400, "Upload Not Found") if value.nil?
error!(400, "Upload Not Valid") unless value.is_a?(Hash) && value[:tempfile]

@shrine_class.rack_file(value)
if value.is_a?(Hash) && value[:tempfile]
@shrine_class.rack_file(value)
elsif %i[read rewind eof? close].all? { |m| value.respond_to?(m) }
value
else
error!(400, "Upload Not Valid")
end
end

# Returns a hash of information containing `:action` and `:request`
@@ -51,6 +51,15 @@ def endpoint
assert_equal "Too Many Files", response.body_binary
end

it "accepts already wrapped uploaded file (Rails)" do
Rack::Request.any_instance.stubs(:params).returns({ "file" => fakeio("file") })

response = app.post "/", multipart: { file: image }

assert_equal 200, response.status
assert_equal "file", @shrine.uploaded_file(response.body_json).read
end

it "validates maximum size" do
@shrine.plugin :upload_endpoint, max_size: 10
response = app.post "/", multipart: { file: image }
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.