-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathhttp2_spec_6_2_SUITE.erl
88 lines (72 loc) · 2.55 KB
/
http2_spec_6_2_SUITE.erl
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-module(http2_spec_6_2_SUITE).
-include("http2.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-compile([export_all]).
all() ->
[
sends_header_with_invalid_pad_length,
sends_go_example
].
init_per_suite(Config) ->
application:ensure_started(crypto),
chatterbox_test_buddy:start(Config).
end_per_suite(Config) ->
chatterbox_test_buddy:stop(Config),
ok.
sends_header_with_invalid_pad_length(_Config) ->
{ok, Client} = http2c:start_link(),
RequestHeaders =
[
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"chattercli/0.0.1 :D">>}
],
{ok, {HeadersBin, _}} = hpack:encode(RequestHeaders, hpack:new_context()),
L = byte_size(HeadersBin)+1,
PaddedBin = <<L,HeadersBin/binary>>,
F = {
#frame_header{
stream_id=1,
flags=?FLAG_END_HEADERS bor ?FLAG_PADDED
},
h2_frame_headers:new(PaddedBin)
},
http2c:send_unaltered_frames(Client, [F]),
Resp = http2c:wait_for_n_frames(Client, 0, 1),
ct:pal("Resp: ~p", [Resp]),
?assertEqual(1, (length(Resp))),
[{GoAwayH, GoAway}] = Resp,
?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)),
?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))),
ok.
sends_go_example(_Config) ->
RequestHeaders =
[
{<<":method">>, <<"GET">>},
{<<":path">>, <<"/index.html">>},
{<<":scheme">>, <<"https">>},
{<<":authority">>, <<"localhost:8080">>},
{<<"accept">>, <<"*/*">>},
{<<"accept-encoding">>, <<"gzip, deflate">>},
{<<"user-agent">>, <<"chattercli/0.0.1 :D">>}
],
{ok, {HeadersBin, _}} = hpack:encode(RequestHeaders, hpack:new_context()),
L = byte_size(HeadersBin)+1,
%_PaddedBin = <<L,HeadersBin/binary>>,
{ok, Client} = http2c:start_link(),
http2c:send_binary(Client, <<L:24,16#01,16#0d,16#00,16#00,16#00,16#01>>),
%% Sending one byte is really bad!
http2c:send_binary(Client, <<L>>),
http2c:send_binary(Client, HeadersBin),
Resp = http2c:wait_for_n_frames(Client, 0, 1),
ct:pal("Resp: ~p", [Resp]),
?assertEqual(1, (length(Resp))),
[{GoAwayH, GoAway}] = Resp,
?assertEqual(?GOAWAY, (GoAwayH#frame_header.type)),
?assertEqual(?PROTOCOL_ERROR, (h2_frame_goaway:error_code(GoAway))),
ok.