1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actioncable/test/connection/authorization_test.rb

37 lines
995 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require "test_helper"
2018-04-22 12:33:40 -04:00
require "active_support/testing/method_call_assertions"
require "stubs/test_server"
2015-07-12 12:59:46 -04:00
2015-10-15 22:11:49 -04:00
class ActionCable::Connection::AuthorizationTest < ActionCable::TestCase
2018-04-22 12:33:40 -04:00
include ActiveSupport::Testing::MethodCallAssertions
2015-07-12 12:59:46 -04:00
class Connection < ActionCable::Connection::Base
attr_reader :websocket
def connect
reject_unauthorized_connection
end
def send_async(method, *args)
send method, *args
end
2015-07-12 12:59:46 -04:00
end
test "unauthorized connection" do
2015-10-15 22:11:49 -04:00
run_in_eventmachine do
server = TestServer.new
server.config.allowed_request_origins = %w( http://rubyonrails.com )
env = Rack::MockRequest.env_for "/test", "HTTP_CONNECTION" => "upgrade", "HTTP_UPGRADE" => "websocket",
"HTTP_HOST" => "localhost", "HTTP_ORIGIN" => "http://rubyonrails.com"
2015-07-12 12:59:46 -04:00
2015-10-15 22:11:49 -04:00
connection = Connection.new(server, env)
2018-04-22 12:33:40 -04:00
assert_called(connection.websocket, :close) do
connection.process
end
2015-10-15 22:11:49 -04:00
end
2015-07-12 12:59:46 -04:00
end
end