aboutsummaryrefslogtreecommitdiffstats
path: root/test/plum/connection/test_handle_frame.rb
blob: ca4ef18dc83d534f8fcdf8d21616f3f9dc110876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require "test_helper"

using Plum::BinaryString

class ServerConnectionHandleFrameTest < Minitest::Test
  ## SETTINGS
  def test_server_handle_settings
    open_server_connection { |con|
      assert_equal(4096, con.remote_settings[:header_table_size])
      con << Frame.craft(type: :settings, stream_id: 0, payload: "\x00\x01\x00\x00\x10\x10").assemble
      assert_equal(0x1010, con.remote_settings[:header_table_size])
    }
  end

  def test_server_handle_settings
    open_server_connection { |con|
      assert_no_error {
        con << Frame.craft(type: :settings, stream_id: 0, flags: [:ack], payload: "").assemble
      }
      assert_connection_error(:frame_size_error) {
        con << Frame.craft(type: :settings, stream_id: 0, flags: [:ack], payload: "\x00").assemble
      }
    }
  end

  def test_server_handle_settings_invalid
    open_server_connection { |con|
      assert_no_error {
        con << Frame.craft(type: :settings, stream_id: 0, payload: "\xff\x01\x00\x00\x10\x10").assemble
      }
    }
  end

  ## PING
  def test_server_handle_ping
    open_server_connection { |con|
      con << Frame.craft(type: :ping, flags: [], stream_id: 0, payload: "AAAAAAAA").assemble
      last = sent_frames.last
      assert_equal(:ping, last.type)
      assert_equal([:ack], last.flags)
      assert_equal("AAAAAAAA", last.payload)
    }
  end

  def test_server_handle_ping_error
    open_server_connection { |con|
      assert_connection_error(:frame_size_error) {
        con << Frame.craft(type: :ping, stream_id: 0, payload: "A" * 7).assemble
      }
    }
  end

  def test_server_handle_ping_ack
    open_server_connection { |con|
      con << Frame.craft(type: :ping, flags: [:ack], stream_id: 0, payload: "A" * 8).assemble
      last = sent_frames.last
      refute_equal(:ping, last.type) if last
    }
  end

  ## GOAWAY
  def test_server_handle_goaway_reply
    open_server_connection { |con|
      assert_no_error {
        begin
          con << Frame::Goaway.new(1, :stream_closed).assemble
        rescue LocalHTTPError
        end
      }
      assert_equal(:goaway, sent_frames.last.type)
    }
  end
end