2015-07-12 12:59:46 -04:00
|
|
|
require 'test_helper'
|
|
|
|
require 'stubs/test_server'
|
|
|
|
|
2015-10-15 22:11:49 -04:00
|
|
|
class ActionCable::Connection::AuthorizationTest < ActionCable::TestCase
|
2015-07-12 12:59:46 -04:00
|
|
|
class Connection < ActionCable::Connection::Base
|
|
|
|
attr_reader :websocket
|
|
|
|
|
|
|
|
def connect
|
|
|
|
reject_unauthorized_connection
|
|
|
|
end
|
2015-11-04 13:38:43 -05:00
|
|
|
|
|
|
|
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
|
2015-11-04 13:38:43 -05:00
|
|
|
server.config.allowed_request_origins = %w( http://rubyonrails.com )
|
|
|
|
|
|
|
|
env = Rack::MockRequest.env_for "/test", 'HTTP_CONNECTION' => 'upgrade', 'HTTP_UPGRADE' => 'websocket',
|
2016-03-01 19:50:19 -05:00
|
|
|
'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)
|
|
|
|
connection.websocket.expects(:close)
|
2015-11-04 13:38:43 -05:00
|
|
|
|
2015-10-15 22:11:49 -04:00
|
|
|
connection.process
|
|
|
|
end
|
2015-07-12 12:59:46 -04:00
|
|
|
end
|
|
|
|
end
|