4
%% Copyright Ericsson AB 2007-2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
20
-module(httpd_basic_SUITE).
22
-include_lib("common_test/include/ct.hrl").
24
%% Note: This directive should only be used in test suites.
27
-define(URL_START, "http://localhost:").
29
suite() -> [{ct_hooks,[ts_install_cth]}].
32
[uri_too_long_414, header_too_long_413, escaped_url_in_error_body].
37
init_per_group(_GroupName, Config) ->
40
end_per_group(_GroupName, Config) ->
43
%%--------------------------------------------------------------------
44
%% Function: init_per_suite(Config) -> Config
46
%% A list of key/value pairs, holding the test case configuration.
47
%% Description: Initiation before the whole suite
49
%% Note: This function is free to add any key/value pairs to the Config
50
%% variable, but should NOT alter/remove any existing entries.
51
%%--------------------------------------------------------------------
52
init_per_suite(Config) ->
54
PrivDir = ?config(priv_dir, Config),
55
HttpdConf = [{port, 0}, {ipfamily, inet},
56
{server_name, "httpd_test"}, {server_root, PrivDir},
57
{document_root, PrivDir}, {bind_address, "localhost"}],
58
[{httpd_conf, HttpdConf} | Config].
60
%%--------------------------------------------------------------------
61
%% Function: end_per_suite(Config) -> _
63
%% A list of key/value pairs, holding the test case configuration.
64
%% Description: Cleanup after the whole suite
65
%%--------------------------------------------------------------------
66
end_per_suite(_Config) ->
70
%%--------------------------------------------------------------------
71
%% Function: init_per_testcase(Case, Config) -> Config
73
%% Name of the test case that is about to be run.
75
%% A list of key/value pairs, holding the test case configuration.
77
%% Description: Initiation before each test case
79
%% Note: This function is free to add any key/value pairs to the Config
80
%% variable, but should NOT alter/remove any existing entries.
81
%%--------------------------------------------------------------------
82
init_per_testcase(_Case, Config) ->
85
%%--------------------------------------------------------------------
86
%% Function: end_per_testcase(Case, Config) -> _
88
%% Name of the test case that is about to be run.
90
%% A list of key/value pairs, holding the test case configuration.
91
%% Description: Cleanup after each test case
92
%%--------------------------------------------------------------------
93
end_per_testcase(_, Config) ->
96
%%-------------------------------------------------------------------------
97
%% Test cases starts here.
98
%%-------------------------------------------------------------------------
99
uri_too_long_414(doc) ->
100
["Test that too long uri's get 414 HTTP code"];
101
uri_too_long_414(suite) ->
103
uri_too_long_414(Config) when is_list(Config) ->
104
HttpdConf = ?config(httpd_conf, Config),
105
{ok, Pid} = inets:start(httpd, [{port, 0}, {max_uri_size, 10}
107
Info = httpd:info(Pid),
108
Port = proplists:get_value(port, Info),
109
Address = proplists:get_value(bind_address, Info),
110
ok = httpd_test_lib:verify_request(ip_comm, Address, Port, node(),
111
"GET /morethantenchars "
114
%% Server will send lowest version
115
%% as it will not get to the
118
{version, "HTTP/0.9"}]),
119
inets:stop(httpd, Pid).
121
header_too_long_413(doc) ->
122
["Test that too long headers's get 413 HTTP code"];
123
header_too_long_413(suite) ->
125
header_too_long_413(Config) when is_list(Config) ->
126
HttpdConf = ?config(httpd_conf, Config),
127
{ok, Pid} = inets:start(httpd, [{port, 0}, {max_header_size, 10}
129
Info = httpd:info(Pid),
130
Port = proplists:get_value(port, Info),
131
Address = proplists:get_value(bind_address, Info),
132
ok = httpd_test_lib:verify_request(ip_comm, Address, Port, node(),
135
"Connection:close \r\n\r\n ",
137
{version, "HTTP/1.1"}]),
138
inets:stop(httpd, Pid).
140
escaped_url_in_error_body(doc) ->
141
["Test Url-encoding see OTP-8940"];
142
escaped_url_in_error_body(suite) ->
144
escaped_url_in_error_body(Config) when is_list(Config) ->
145
HttpdConf = ?config(httpd_conf, Config),
146
{ok, Pid} = inets:start(httpd, [{port, 0} | HttpdConf]),
147
Info = httpd:info(Pid),
148
Port = proplists:get_value(port, Info),
149
Address = proplists:get_value(bind_address, Info),
150
Path = "/<b>this_is_bold<b>",
151
URL = ?URL_START ++ integer_to_list(Port) ++ Path,
152
EscapedPath = http_uri:encode(Path),
153
{ok, {404, Body}} = httpc:request(get, {URL, []},
154
[{url_encode, true}],
155
[{version, "HTTP/1.0"}, {full_result, false}]),
156
EscapedPath = find_URL_path(string:tokens(Body, " ")),
157
{ok, {404, Body1}} = httpc:request(get, {URL, []}, [],
158
[{version, "HTTP/1.0"}, {full_result, false}]),
159
EscapedPath = find_URL_path(string:tokens(Body1, " ")),
160
inets:stop(httpd, Pid).
164
find_URL_path(["URL", URL | _]) ->
166
find_URL_path([_ | Rest]) ->