Sha256: 1026bfd2bd2067405aa575d63a56c39044294b1e46cc7bf7bc2bfec3b41e3131

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require 'helper'

describe "draft06" do
  before :each do
    @request = {
      :port => 80,
      :method => "GET",
      :path => "/demo",
      :headers => {
        'Host' => 'example.com',
        'Upgrade' => 'websocket',
        'Connection' => 'Upgrade',
        'Sec-WebSocket-Key' => 'dGhlIHNhbXBsZSBub25jZQ==',
        'Sec-WebSocket-Protocol' => 'sample',
        'Sec-WebSocket-Origin' => 'http://example.com',
        'Sec-WebSocket-Version' => '6'
      }
    }

    @response = {
      :protocol => "HTTP/1.1 101 Switching Protocols\r\n",
      :headers => {
        "Upgrade" => "websocket",
        "Connection" => "Upgrade",
        "Sec-WebSocket-Accept" => "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",
      }
    }
  end
  
  def start_server
    EM::WebSocket.start(:host => "0.0.0.0", :port => 12345) { |ws|
      yield ws
    }
  end

  def start_client
    client = EM.connect('0.0.0.0', 12345, Draft03FakeWebSocketClient)
    client.send_data(format_request(@request))
    yield client if block_given?
  end
  
  it "should open connection" do
    EM.run {
      start_server { |server|
        server.onopen {
          server.instance_variable_get(:@handler).class.should == EventMachine::WebSocket::Handler06
        }
      }
      
      start_client { |client|
        client.onopen {
          client.handshake_response.lines.sort.
            should == format_response(@response).lines.sort
          EM.stop
        }
      }
    }
  end
  
  it "should accept a single-frame text message (masked)" do
    EM.run do
      start_server { |server|
        server.onmessage { |msg|
          msg.should == 'Hello'
          EM.stop
        }
        server.onerror {
          failed
        }
      }
  
      start_client { |client|
        client.onopen {
          client.send_data("\x00\x00\x01\x00\x84\x05Ielln")
        }
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
em-websocket-0.3.1 spec/integration/draft06_spec.rb
em-websocket-0.3.0 spec/integration/draft06_spec.rb