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

Prevent invocation of channel action if rejected connection #23759

Merged
merged 1 commit into from
Aug 21, 2016
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
2 changes: 1 addition & 1 deletion actioncable/lib/action_cable/channel/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def extract_action(data)
end

def processable_action?(action)
self.class.action_methods.include?(action.to_s)
self.class.action_methods.include?(action.to_s) unless subscription_rejected?
end

def dispatch_action(action, data)
Expand Down
15 changes: 15 additions & 0 deletions actioncable/test/channel/rejection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class SecretChannel < ActionCable::Channel::Base
def subscribed
reject if params[:id] > 0
end

def secret_action
end
end

setup do
Expand All @@ -21,4 +24,16 @@ def subscribed
expected = { "identifier" => "{id: 1}", "type" => "reject_subscription" }
assert_equal expected, @connection.last_transmission
end

test "does not execute action if subscription is rejected" do
@connection.expects(:subscriptions).returns mock().tap { |m| m.expects(:remove_subscription).with instance_of(SecretChannel) }
@channel = SecretChannel.new @connection, "{id: 1}", id: 1

expected = { "identifier" => "{id: 1}", "type" => "reject_subscription" }
assert_equal expected, @connection.last_transmission
assert_equal 1, @connection.transmissions.size

@channel.perform_action("action" => :secret_action)
assert_equal 1, @connection.transmissions.size
end
end