|
42 | 42 | %% Seconds before successful auths timeout. |
43 | 43 | -define(AUTH_TIMEOUT,5). |
44 | 44 | -define(URL_START, "http://"). |
45 | | - |
| 45 | +-define(URL_START_HTTPS, "https://"). |
| 46 | +-define(SSL_NO_VERIFY, {ssl, [{verify, verify_none}]}). |
46 | 47 | %%-------------------------------------------------------------------- |
47 | 48 | %% Common Test interface functions ----------------------------------- |
48 | 49 | %%-------------------------------------------------------------------- |
@@ -133,13 +134,14 @@ groups() -> |
133 | 134 | {security, [], [security_1_1, security_1_0]}, |
134 | 135 | {logging, [], [disk_log_internal, disk_log_exists, |
135 | 136 | disk_log_bad_size, disk_log_bad_file]}, |
136 | | - {http_1_1, [], [esi_propagate, esi_atom_leak, {group, http_1_1_parallel}] ++ load()}, |
| 137 | + {http_1_1, [], [esi_propagate, esi_atom_leak, {group, http_1_1_parallel}, |
| 138 | + cgi_bin_env] ++ load()}, |
137 | 139 | {http_1_1_parallel, [parallel], |
138 | 140 | [host, chunked, expect, cgi, cgi_chunked_encoding_test, |
139 | 141 | trace, range, if_modified_since, mod_esi_chunk_timeout, |
140 | 142 | esi_put, esi_patch, esi_post, esi_headers] |
141 | 143 | ++ http_head() ++ http_get()}, |
142 | | - {http_1_0, [], [{group, http_1_0_parallel} | load()]}, |
| 144 | + {http_1_0, [], [cgi_bin_env, {group, http_1_0_parallel} | load()]}, |
143 | 145 | {http_1_0_parallel, [parallel], [host, cgi, trace] ++ http_head() ++ http_get()}, |
144 | 146 | {http_rel_path_script_alias, [], [cgi]}, |
145 | 147 | {esi, [], [erl_script_timeout_default, |
@@ -1291,6 +1293,51 @@ alias(Config) when is_list(Config) -> |
1291 | 1293 | [Test301(T) || T <- TestURIs301], |
1292 | 1294 | ok. |
1293 | 1295 |
|
| 1296 | +cgi_bin_env() -> |
| 1297 | +[{doc, "Test whether HTTP_PROXY header is not applied to an environment |
| 1298 | +that runs the cgi script"}]. |
| 1299 | +cgi_bin_env(Config) -> |
| 1300 | + Proto = case proplists:get_value(type, Config, undefined) =:= ssl of |
| 1301 | + true -> https; |
| 1302 | + _ -> http |
| 1303 | + end, |
| 1304 | + Cgi = case os:type() of |
| 1305 | + {win32, _} -> |
| 1306 | + "printenv.bat"; |
| 1307 | + _ -> |
| 1308 | + "printenv.sh" |
| 1309 | + end, |
| 1310 | + HttpOpts = case Proto of |
| 1311 | + https -> [?SSL_NO_VERIFY]; |
| 1312 | + _ -> [] |
| 1313 | + end, |
| 1314 | + RandomString = base64:encode(crypto:strong_rand_bytes(9)), |
| 1315 | + Endpoint = "/cgi-bin/" ++ Cgi, |
| 1316 | + Env = os:env(), |
| 1317 | + %% Grab the value of HTTP_PROXY from the environment before the request |
| 1318 | + HttpProxyEnv = proplists:get_value("HTTP_PROXY", Env, undefined), |
| 1319 | + Url = url(Proto, Endpoint, Config), |
| 1320 | + {ok, {_Status, _Headers, Body}} = httpc:request(get, {Url, [{"PROXY", RandomString}, |
| 1321 | + {"proxy", RandomString}]}, |
| 1322 | + HttpOpts, []), |
| 1323 | + %% The script prints the system's environment to the body so we need to |
| 1324 | + %% grab the value of interest |
| 1325 | + HttpEnv = re:split(Body, "\n"), |
| 1326 | + BinSize = size(<<"HTTP_PROXY">>) * 8, |
| 1327 | + %% Filter keys of interest, while converting to proplist |
| 1328 | + EnvProp = [{binary_to_list(Key), binary_to_list(Val)} || |
| 1329 | + <<Key:BinSize/bitstring, "=", Val/bitstring>> <- HttpEnv, |
| 1330 | + Key =:= <<"HTTP_PROXY">>], |
| 1331 | + %% EnvProp should only have HTTP_PROXY or be an empty list |
| 1332 | + RespHttpProxyEnv = proplists:get_value("HTTP_PROXY", EnvProp, undefined), |
| 1333 | + case HttpProxyEnv of |
| 1334 | + undefined -> |
| 1335 | + %% HTTP_PROXY was not set before the request |
| 1336 | + ?assertEqual([], EnvProp); |
| 1337 | + _ -> |
| 1338 | + %% HTTP_PROXY was set, so ensure it's the same in the body |
| 1339 | + ?assertEqual(HttpProxyEnv, RespHttpProxyEnv) |
| 1340 | + end. |
1294 | 1341 | %%------------------------------------------------------------------------- |
1295 | 1342 | actions() -> |
1296 | 1343 | [{doc, "Test mod_actions"}]. |
@@ -1983,10 +2030,15 @@ tls_alert(Config) when is_list(Config) -> |
1983 | 2030 | %%-------------------------------------------------------------------- |
1984 | 2031 | %% Internal functions ----------------------------------- |
1985 | 2032 | %%-------------------------------------------------------------------- |
| 2033 | +url(https, End, Config) -> |
| 2034 | + ?URL_START_HTTPS ++ url(End, Config); |
1986 | 2035 | url(http, End, Config) -> |
| 2036 | + ?URL_START ++ url(End, Config). |
| 2037 | + |
| 2038 | +url(End, Config) -> |
1987 | 2039 | Port = proplists:get_value(port, Config), |
1988 | 2040 | {ok,Host} = inet:gethostname(), |
1989 | | - ?URL_START ++ Host ++ ":" ++ integer_to_list(Port) ++ End. |
| 2041 | + Host ++ ":" ++ integer_to_list(Port) ++ End. |
1990 | 2042 |
|
1991 | 2043 | http_get_url(Port0, HeaderDelay, ChunkDelay, BadChunkDelay) -> |
1992 | 2044 | {ok, Host} = inet:gethostname(), |
|
0 commit comments