Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/initializers/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module ActiveStorageDirectUploadsControllerExtensions
included do
include Authentication
include Authorization
skip_forgery_protection if: :authenticate_by_bearer_token
skip_forgery_protection if: -> { authenticate_by_bearer_token || (authenticated? && request.format.json?) }
Comment thread
rbarbosa marked this conversation as resolved.
Outdated
end
end

Expand Down
21 changes: 21 additions & 0 deletions test/controllers/active_storage/direct_uploads_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ class ActiveStorage::DirectUploadsControllerTest < ActionDispatch::IntegrationTe
assert_includes response.parsed_body.keys, "direct_upload"
end

test "create with session token" do
sign_in_as :david

post rails_direct_uploads_path,
params: @blob_params,
as: :json

assert_response :success
assert_includes response.parsed_body.keys, "direct_upload"
end

test "create with session token in another account is forbidden" do
sign_in_as :david

post rails_direct_uploads_path(script_name: "/#{ActiveRecord::FixtureSet.identify("initech")}"),
params: @blob_params,
as: :json

assert_response :forbidden
end
Comment thread
rbarbosa marked this conversation as resolved.

test "create with read-only access token" do
post rails_direct_uploads_path,
params: @blob_params,
Expand Down
Loading