diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/http_SUITE.erl | 14 | ||||
-rw-r--r-- | test/http_SUITE_data/rest_forbidden_resource.erl | 2 | ||||
-rw-r--r-- | test/http_SUITE_data/ssl/cert.pem | 14 | ||||
-rw-r--r-- | test/http_SUITE_data/ssl/key.pem | 18 | ||||
-rw-r--r-- | test/spdy_SUITE.erl | 163 |
5 files changed, 168 insertions, 43 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index 98d4376..21cdd4b 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -209,11 +209,8 @@ init_per_group(http, Config) -> {transport, Transport}, {client, Client}|Config1]; init_per_group(https, Config) -> Transport = ranch_ssl, - Opts = [ - {certfile, ?config(data_dir, Config) ++ "ssl/cert.pem"}, - {keyfile, ?config(data_dir, Config) ++ "ssl/key.pem"}, - {password, "cowboy"} - ], + {_, Cert, Key} = ct_helper:make_certs(), + Opts = [{cert, Cert}, {key, Key}], Config1 = init_static_dir(Config), application:start(public_key), application:start(ssl), @@ -241,11 +238,8 @@ init_per_group(http_compress, Config) -> {transport, Transport}, {client, Client}|Config1]; init_per_group(https_compress, Config) -> Transport = ranch_ssl, - Opts = [ - {certfile, ?config(data_dir, Config) ++ "ssl/cert.pem"}, - {keyfile, ?config(data_dir, Config) ++ "ssl/key.pem"}, - {password, "cowboy"} - ], + {_, Cert, Key} = ct_helper:make_certs(), + Opts = [{cert, Cert}, {key, Key}], Config1 = init_static_dir(Config), application:start(public_key), application:start(ssl), diff --git a/test/http_SUITE_data/rest_forbidden_resource.erl b/test/http_SUITE_data/rest_forbidden_resource.erl index 287ff62..920ba31 100644 --- a/test/http_SUITE_data/rest_forbidden_resource.erl +++ b/test/http_SUITE_data/rest_forbidden_resource.erl @@ -28,4 +28,4 @@ to_text(Req, State) -> from_text(Req, State) -> {Path, Req2} = cowboy_req:path(Req), - {Path, Req2, State}. + {{true, Path}, Req2, State}. diff --git a/test/http_SUITE_data/ssl/cert.pem b/test/http_SUITE_data/ssl/cert.pem deleted file mode 100644 index a772007..0000000 --- a/test/http_SUITE_data/ssl/cert.pem +++ /dev/null @@ -1,14 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICKTCCAZICCQCl9gdHk5NqUjANBgkqhkiG9w0BAQUFADBZMQswCQYDVQQGEwJB -VTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0 -cyBQdHkgTHRkMRIwEAYDVQQDDAlsb2NhbGhvc3QwHhcNMTEwNDA4MTMxNTE3WhcN -MTEwNTA4MTMxNTE3WjBZMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0 -ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRIwEAYDVQQDDAls -b2NhbGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOjgFPS0dP4d8F1e -bNJPB+kAjM2FyTZGmkFCLUYONTPrdGOUIHL/UOGtU22BQzlskE+a6/j2Kg72tm8x -4X7yf+6s7CdRe086idNx9+GymZ64ZTnly33rD3AJffbBeWHwT2e9fuBeFk9WGC8v -kqECFZyqf7+znS0o48oBNcx3ePB5AgMBAAEwDQYJKoZIhvcNAQEFBQADgYEASTkv -oHuZyO8DgT8bIE6W3yM2fvlNshkhh7Thgpf32qQoVOxRU9EF0KpuJCCAHQHQNQlI -nf9Zc4UzOrLhxZBGocNhkkn4WLw2ysto/7+/+9xHah0M0l4auHLQagVLCoOsHUn2 -JX+A2NrbvuX5wnUrZGOdgY70tvMBeU/xLtp3af8= ------END CERTIFICATE----- diff --git a/test/http_SUITE_data/ssl/key.pem b/test/http_SUITE_data/ssl/key.pem deleted file mode 100644 index 0b699cc..0000000 --- a/test/http_SUITE_data/ssl/key.pem +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,F11262DB77BB804C - -jOJ+ft/dihIxz7CTuuK47fCTGdX7xMLANmA7mRg8y9OYhNZQiCz5GjcWLqe0NNl5 -qXPW0uvT/9B5O9o21Y2i/CKU1BqRLuXHXDsjHg7RGaSH6wIavWt+lR+I1sjieFbX -VByK1KHXjEU704DEILKJIA9gVzoYAgMzo+FTw2e/2jusXntxk8HXyF5zKTzjHBtI -NQGweJqTmfZjX3SgPP4Co/ShrA6fUG0uTp1HwbByJnwtAeT3xWJrAD4QSn7+qrlv -3qmEIqVXsvLrfZRY1WZ4uIsbLK8wkvxboSIoIK55VV9R2zRbwQULon6QJwKYujAr -J2WUYkHHQOMpaAzUmalaT+8GUt8/A1oSK4BdiSZywsMMm46/hDadXBzFg+dPL5g2 -Td+7/L0S6tUVWq4+YBp5EalZH6VQ4cqPYDJZUZ9xt6+yY7V5748lSdA7cHCROnbG -bKbSW9WbF7MPDHCjvCAfq+s1dafHJgyIOlMg2bm7V8eHWAA0xKQ/o7i5EyEyaKYR -UXGeAf+KfXcclEZ77v2RCXZvd6ceWkifm59qWv/3TCYaHiS2Aa3lVToMKTwYzzXQ -p5X5os6wv3IAi2nGyAIOoSDisdHmFteZNXNQsw0n3XCAYfsNMk+r5/r5YqDffURH -c8SMOCP4BIPoZ/abi/gnEntGqsx1YALg0aosHwHGDJ/l+QJC6u6PZk310YzRw4GL -K9+wscFgEub2OO+R83Vkfesj4tYzgOjab7+92a/soHdW0zhGejlvehODOgNZ6NUG -MPQlT+qpF9Jh5IThYXupXXFzJzQe3O/qVXy89m69JGa+AWRvbu+M/A== ------END RSA PRIVATE KEY----- diff --git a/test/spdy_SUITE.erl b/test/spdy_SUITE.erl new file mode 100644 index 0000000..df29281 --- /dev/null +++ b/test/spdy_SUITE.erl @@ -0,0 +1,163 @@ +%% Copyright (c) 2013, Loïc Hoguin <[email protected]> +%% +%% Permission to use, copy, modify, and/or distribute this software for any +%% purpose with or without fee is hereby granted, provided that the above +%% copyright notice and this permission notice appear in all copies. +%% +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +-module(spdy_SUITE). + +-include_lib("common_test/include/ct.hrl"). +-include("../src/cowboy_spdy.hrl"). + +%% ct. +-export([all/0]). +-export([groups/0]). +-export([init_per_suite/1]). +-export([end_per_suite/1]). +-export([init_per_group/2]). +-export([end_per_group/2]). + +%% Tests. +-export([check_status/1]). + +%% ct. + +all() -> + [{group, spdy}]. + +groups() -> + [{spdy, [], [ + check_status + ]}]. + +init_per_suite(Config) -> + application:start(crypto), + application:start(ranch), + application:start(cowboy), + application:start(public_key), + application:start(ssl), + Config. + +end_per_suite(_Config) -> + application:stop(ssl), + application:stop(public_key), + application:stop(cowboy), + application:stop(ranch), + application:stop(crypto), + ok. + +init_per_group(Name, Config) -> + {_, Cert, Key} = ct_helper:make_certs(), + Opts = [{cert, Cert}, {key, Key}], + {ok, _} = cowboy:start_spdy(Name, 100, Opts ++ [{port, 0}], [ + {env, [{dispatch, init_dispatch(Config)}]} + ]), + Port = ranch:get_port(Name), + [{port, Port}|Config]. + +end_per_group(Name, _) -> + cowboy:stop_listener(Name), + ok. + +%% Dispatch configuration. + +init_dispatch(_) -> + cowboy_router:compile([ + {"localhost", [ + {"/chunked", http_chunked, []}, + {"/", http_handler, []} + ]} + ]). + +%% Convenience functions. + +quick_get(Host, Path, ExpectedFlags, Config) -> + {_, Port} = lists:keyfind(port, 1, Config), + {ok, Socket} = ssl:connect("localhost", Port, [ + binary, {active, false}, + {client_preferred_next_protocols, client, [<<"spdy/3">>]} + ]), + {Zdef, Zinf} = zlib_init(), + ReqHeaders = headers_encode(Zdef, [ + {<<":method">>, <<"GET">>}, + {<<":path">>, list_to_binary(Path)}, + {<<":version">>, <<"HTTP/1.1">>}, + {<<":host">>, list_to_binary(Host)}, + {<<":scheme">>, <<"https">>} + ]), + ReqLength = 10 + byte_size(ReqHeaders), + StreamID = 1, + ok = ssl:send(Socket, << 1:1, 3:15, 1:16, 0:8, ReqLength:24, + 0:1, StreamID:31, 0:1, 0:31, 0:3, 0:5, 0:8, ReqHeaders/binary >>), + {ok, Packet} = ssl:recv(Socket, 0, 1000), + << 1:1, 3:15, 2:16, Flags:8, RespLength:24, + _:1, StreamID:31, RespHeaders/bits >> = Packet, + Flags = ExpectedFlags, + RespLength = 4 + byte_size(RespHeaders), + [<< NbHeaders:32, Rest/bits >>] = try + zlib:inflate(Zinf, RespHeaders) + catch _:_ -> + ok = zlib:inflateSetDictionary(Zinf, ?ZDICT), + zlib:inflate(Zinf, <<>>) + end, + RespHeaders2 = headers_decode(Zinf, Rest, []), + NbHeaders = length(RespHeaders2), + {_, << Status:3/binary, _/bits >>} + = lists:keyfind(<<":status">>, 1, RespHeaders2), + StatusCode = list_to_integer(binary_to_list(Status)), + ok = ssl:close(Socket), + zlib_terminate(Zdef, Zinf), + {StatusCode, RespHeaders2}. + +zlib_init() -> + Zdef = zlib:open(), + ok = zlib:deflateInit(Zdef), + _ = zlib:deflateSetDictionary(Zdef, ?ZDICT), + Zinf = zlib:open(), + ok = zlib:inflateInit(Zinf), + {Zdef, Zinf}. + +zlib_terminate(Zdef, Zinf) -> + zlib:close(Zdef), + zlib:close(Zinf). + +headers_encode(Zdef, Headers) -> + NbHeaders = length(Headers), + Headers2 = << << (begin + SizeN = byte_size(N), + SizeV = byte_size(V), + << SizeN:32, N/binary, SizeV:32, V/binary >> + end)/binary >> || {N, V} <- Headers >>, + Headers3 = << NbHeaders:32, Headers2/binary >>, + iolist_to_binary(zlib:deflate(Zdef, Headers3, full)). + +headers_decode(_, <<>>, Acc) -> + lists:reverse(Acc); +headers_decode(Zinf, << SizeN:32, Rest/bits >>, Acc) -> + << Name:SizeN/binary, SizeV:32, Rest2/bits >> = Rest, + << Value:SizeV/binary, Rest3/bits >> = Rest2, + headers_decode(Zinf, Rest3, [{Name, Value}|Acc]). + +%% Tests. + +check_status(Config) -> + Tests = [ + {200, nofin, "localhost", "/"}, + {200, nofin, "localhost", "/chunked"}, + {400, fin, "bad-host", "/"}, + {400, fin, "localhost", "bad-path"}, + {404, fin, "localhost", "/this/path/does/not/exist"} + ], + _ = [{Status, Fin, Host, Path} = begin + RespFlags = case Fin of fin -> 1; nofin -> 0 end, + {Ret, _} = quick_get(Host, Path, RespFlags, Config), + {Ret, Fin, Host, Path} + end || {Status, Fin, Host, Path} <- Tests]. |