Skip to content

Commit

Permalink
Merge branch 'weisslj/httpd_add_script_tests/OTP-11260' into maint
Browse files Browse the repository at this point in the history
* weisslj/httpd_add_script_tests/OTP-11260:
  Test nocache option of mod_cgi and mod_esi
  • Loading branch information
rimmius committed Sep 4, 2013
2 parents 7dcd6b1 + 3ed082f commit 9c5426c
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/inets/test/Makefile
Expand Up @@ -215,7 +215,7 @@ INETS_FILES = inets.config $(INETS_SPECS)
# inets_tftp_suite

INETS_DATADIRS = inets_SUITE_data inets_sup_SUITE_data
HTTPD_DATADIRS = httpd_test_data httpd_SUITE_data
HTTPD_DATADIRS = httpd_test_data httpd_SUITE_data httpd_basic_SUITE_data
HTTPC_DATADIRS = httpc_SUITE_data httpc_proxy_SUITE_data
FTP_DATADIRS = ftp_SUITE_data

Expand Down
2 changes: 1 addition & 1 deletion lib/inets/test/httpd_SUITE.erl
Expand Up @@ -1919,7 +1919,7 @@ ticket_5865(Config) ->
" HTTP/1.1\r\nHost:"
++Host++"\r\n\r\n",
[{statuscode, 200},
{no_last_modified,
{no_header,
"last-modified"}]),
ok;
{error, Reason} ->
Expand Down
63 changes: 62 additions & 1 deletion lib/inets/test/httpd_basic_SUITE.erl
Expand Up @@ -19,6 +19,7 @@
%%
-module(httpd_basic_SUITE).

-include_lib("kernel/include/file.hrl").
-include_lib("common_test/include/ct.hrl").
-include("inets_test_lib.hrl").

Expand All @@ -35,6 +36,7 @@ all() ->
uri_too_long_414,
header_too_long_413,
erl_script_nocache_opt,
script_nocache,
escaped_url_in_error_body,
slowdose
].
Expand Down Expand Up @@ -63,6 +65,7 @@ init_per_suite(Config) ->
"~n Config: ~p", [Config]),
ok = inets:start(),
PrivDir = ?config(priv_dir, Config),
DataDir = ?config(data_dir, Config),

Dummy =
"<HTML>
Expand All @@ -75,6 +78,18 @@ DUMMY
</HTML>",

DummyFile = filename:join([PrivDir,"dummy.html"]),
CgiDir = filename:join(PrivDir, "cgi-bin"),
ok = file:make_dir(CgiDir),
Cgi = case test_server:os_type() of
{win32, _} ->
"printenv.bat";
_ ->
"printenv.sh"
end,
inets_test_lib:copy_file(Cgi, DataDir, CgiDir),
AbsCgi = filename:join([CgiDir, Cgi]),
{ok, FileInfo} = file:read_file_info(AbsCgi),
ok = file:write_file_info(AbsCgi, FileInfo#file_info{mode = 8#00755}),
{ok, Fd} = file:open(DummyFile, [write]),
ok = file:write(Fd, Dummy),
ok = file:close(Fd),
Expand All @@ -85,7 +100,7 @@ DUMMY
{document_root, PrivDir},
{bind_address, "localhost"}],

[{httpd_conf, HttpdConf} | Config].
[{httpd_conf, HttpdConf}, {cgi_dir, CgiDir}, {cgi_script, Cgi} | Config].

%%--------------------------------------------------------------------
%% Function: end_per_suite(Config) -> _
Expand Down Expand Up @@ -205,6 +220,52 @@ erl_script_nocache_opt(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
%%-------------------------------------------------------------------------

script_nocache(doc) ->
["Test nocache option for mod_cgi and mod_esi"];
script_nocache(suite) ->
[];
script_nocache(Config) when is_list(Config) ->
Normal = {no_header, "cache-control"},
NoCache = {header, "cache-control", "no-cache"},
verify_script_nocache(Config, false, false, Normal, Normal),
verify_script_nocache(Config, true, false, NoCache, Normal),
verify_script_nocache(Config, false, true, Normal, NoCache),
verify_script_nocache(Config, true, true, NoCache, NoCache),
ok.

verify_script_nocache(Config, CgiNoCache, EsiNoCache, CgiOption, EsiOption) ->
HttpdConf = ?config(httpd_conf, Config),
CgiScript = ?config(cgi_script, Config),
CgiDir = ?config(cgi_dir, Config),
{ok, Pid} = inets:start(httpd, [{port, 0},
{script_alias,
{"/cgi-bin/", CgiDir ++ "/"}},
{script_nocache, CgiNoCache},
{erl_script_alias,
{"/cgi-bin/erl", [httpd_example,io]}},
{erl_script_nocache, EsiNoCache}
| HttpdConf]),
Info = httpd:info(Pid),
Port = proplists:get_value(port, Info),
Address = proplists:get_value(bind_address, Info),
ok = httpd_test_lib:verify_request(ip_comm, Address, Port, node(),
"GET /cgi-bin/" ++ CgiScript ++
" HTTP/1.0\r\n\r\n",
[{statuscode, 200},
CgiOption,
{version, "HTTP/1.0"}]),
ok = httpd_test_lib:verify_request(ip_comm, Address, Port, node(),
"GET /cgi-bin/erl/httpd_example:get "
"HTTP/1.0\r\n\r\n",
[{statuscode, 200},
EsiOption,
{version, "HTTP/1.0"}]),
inets:stop(httpd, Pid).


%%-------------------------------------------------------------------------
%%-------------------------------------------------------------------------

escaped_url_in_error_body(doc) ->
["Test Url-encoding see OTP-8940"];
escaped_url_in_error_body(suite) ->
Expand Down
1 change: 1 addition & 0 deletions lib/inets/test/httpd_basic_SUITE_data/printenv.bat
1 change: 1 addition & 0 deletions lib/inets/test/httpd_basic_SUITE_data/printenv.sh
15 changes: 15 additions & 0 deletions lib/inets/test/httpd_mod.erl
Expand Up @@ -842,6 +842,14 @@ cgi(Type, Port, Host, Node) ->
{version, "HTTP/1.0"}]),

%% tsp("cgi -> done"),

%% Check "ScriptNoCache" directive (default: false)
ok = httpd_test_lib:verify_request(Type, Host, Port, Node,
"GET /cgi-bin/" ++ Script ++
" HTTP/1.0\r\n\r\n",
[{statuscode, 200},
{no_header, "cache-control"},
{version, "HTTP/1.0"}]),
ok.


Expand Down Expand Up @@ -899,6 +907,13 @@ esi(Type, Port, Host, Node) ->
" HTTP/1.0\r\n\r\n",
[{statuscode, 302},
{version, "HTTP/1.0"}]),
%% Check "ErlScriptNoCache" directive (default: false)
ok = httpd_test_lib:verify_request(Type, Host, Port, Node,
"GET /cgi-bin/erl/httpd_example:get"
" HTTP/1.0\r\n\r\n",
[{statuscode, 200},
{no_header, "cache-control"},
{version, "HTTP/1.0"}]),
ok.


Expand Down
2 changes: 1 addition & 1 deletion lib/inets/test/httpd_test_lib.erl
Expand Up @@ -361,7 +361,7 @@ do_validate(Header, [{header, HeaderField, Value}|Rest],N,P) ->
tsf({wrong_header_field_value, LowerHeaderField, Header})
end,
do_validate(Header, Rest, N, P);
do_validate(Header,[{no_last_modified, HeaderField}|Rest],N,P) ->
do_validate(Header,[{no_header, HeaderField}|Rest],N,P) ->
case lists:keysearch(HeaderField,1,Header) of
{value,_} ->
tsf({wrong_header_field_value, HeaderField, Header});
Expand Down

0 comments on commit 9c5426c

Please sign in to comment.