Sha256: c55e75a0d9938bd21f0b9e2b34790b5c2f462d92b2aa507896601965e52b8a51

Contents?: true

Size: 1.65 KB

Versions: 8

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Server draft 04 handshake' do
  let(:handshake) { WebSocket::Handshake::Server.new }
  let(:version) { 4 }
  let(:client_request) { client_handshake_04(@request_params || {}) }
  let(:server_response) { server_handshake_04(@request_params || {}) }

  it_behaves_like 'all server drafts'

  it 'disallows request without Sec-WebSocket-Key' do
    handshake << client_request.gsub(/^Sec-WebSocket-Key:.*\n/, '')

    expect(handshake).to be_finished
    expect(handshake).not_to be_valid
    expect(handshake.error).to be(:invalid_handshake_authentication)
  end

  context 'protocol header specified' do
    let(:handshake) { WebSocket::Handshake::Server.new(protocols: %w[binary xmpp]) }

    context 'single protocol requested' do
      it 'returns with the same protocol' do
        @request_params = { headers: { 'Sec-WebSocket-Protocol' => 'binary' } }
        handshake << client_request

        expect(handshake.to_s).to match('Sec-WebSocket-Protocol: binary')
      end
    end

    context 'multiple protocols requested' do
      it 'returns with the first supported protocol' do
        @request_params = { headers: { 'Sec-WebSocket-Protocol' => 'xmpp, binary' } }
        handshake << client_request

        expect(handshake.to_s).to match('Sec-WebSocket-Protocol: xmpp')
      end
    end

    context 'unsupported protocol requested' do
      it 'reutrns with an empty protocol header' do
        @request_params = { headers: { 'Sec-WebSocket-Protocol' => 'generic' } }
        handshake << client_request

        expect(handshake.to_s).to match("Sec-WebSocket-Protocol: \r\n")
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/websocket-1.2.10/spec/handshake/server_04_spec.rb
websocket-1.2.11 spec/handshake/server_04_spec.rb
websocket-1.2.10 spec/handshake/server_04_spec.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/websocket-1.2.9/spec/handshake/server_04_spec.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/websocket-1.2.9/spec/handshake/server_04_spec.rb
websocket-1.2.9 spec/handshake/server_04_spec.rb
websocket-1.2.8 spec/handshake/server_04_spec.rb
websocket-1.2.7 spec/handshake/server_04_spec.rb