Skip to content

Commit

Permalink
fix unit tests for Erlang/OTP R16
Browse files Browse the repository at this point in the history
Fix two problems with the unit tests for R16:

1. Code failed to compile due to warnings caused by calls to the deprecated
crypto:md5/1 with compiler option warnings_as_errors in effect. Use the
existing {d,old_hash} erlc define to call crypto:hash/2 instead on Erlang
versions newer than R15B01.

2. Tests involving POSTs and status code 303 redirects failed due to a
missing {autodirect,false} option on httpc:request/4 calls. In older
versions of Erlang httpc didn't redirect for such calls, but that changed
in commit 4b9b5cc6 in the Erlang/OTP github repository, which fixed
OTP-10765 as part of the R16B release. Also verify that the presence of the
{autoredirect,false} option doesn't break the tests for older R15 or R14
releases.
  • Loading branch information
vinoski committed Sep 8, 2013
1 parent a169963 commit e0c1cbe
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/decision_core_test.erl
Expand Up @@ -27,6 +27,14 @@
-define(HTML_CONTENT, "<html><body>Foo</body></html>").
-define(TEXT_CONTENT, ?HTML_CONTENT).

-ifndef(old_hash).
md5(Bin) ->
crypto:hash(md5,Bin).
-else.
md5(Bin) ->
crypto:md5(Bin).
-endif.

-define(HTTP_1_0_METHODS, ['GET', 'POST', 'HEAD']).
-define(HTTP_1_1_METHODS, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE',
'CONNECT', 'OPTIONS']).
Expand Down Expand Up @@ -642,7 +650,7 @@ content_md5_valid_b9a() ->
ContentType = "text/plain",
put_setting(content_types_accepted, [{ContentType, to_html}]),
Body = "foo",
MD5Sum = base64:encode_to_string(crypto:md5(Body)),
MD5Sum = base64:encode_to_string(md5(Body)),
Headers = [{"Content-MD5", MD5Sum}],
PutRequest = {url("new"), Headers, ContentType, Body},
{ok, Result} = httpc:request(put, PutRequest, [], []),
Expand All @@ -659,7 +667,7 @@ content_md5_valid_b9a_validated() ->
ContentType = "text/plain",
put_setting(content_types_accepted, [{ContentType, to_html}]),
Body = "foo",
MD5Sum = base64:encode_to_string(crypto:md5(Body)),
MD5Sum = base64:encode_to_string(md5(Body)),
Headers = [{"Content-MD5", MD5Sum}],
PutRequest = {url("new"), Headers, ContentType, Body},
{ok, Result} = httpc:request(put, PutRequest, [], []),
Expand Down Expand Up @@ -886,7 +894,7 @@ see_other_n11() ->
put_setting(content_types_accepted, [{ContentType, to_html}]),
put_setting(process_post, {set_resp_redirect, ?RESOURCE_PATH ++ "/new1"}),
PostRequest = {url("post"), [], ContentType, "foo"},
{ok, Result} = httpc:request(post, PostRequest, [], []),
{ok, Result} = httpc:request(post, PostRequest, [{autoredirect,false}], []),
?assertMatch({{"HTTP/1.1", 303, "See Other"}, _, _}, Result),
ExpectedDecisionTrace = ?PATH_TO_N11_VIA_M7_NO_ACPTHEAD,
?assertEqual(ExpectedDecisionTrace, get_decision_ids()),
Expand Down Expand Up @@ -933,7 +941,7 @@ see_other_n11_resource_calls_base_uri(Value) ->
put_setting(create_path, {set_resp_redirect, ?RESOURCE_PATH ++ "/new1"}),
put_setting(base_uri, Value),
PostRequest = {url("post"), [], ContentType, "foo"},
{ok, Result} = httpc:request(post, PostRequest, [], []),
{ok, Result} = httpc:request(post, PostRequest, [{autoredirect,false}], []),
?assertMatch({{"HTTP/1.1", 303, "See Other"}, _, _}, Result),
ExpectedDecisionTrace = ?PATH_TO_N11_VIA_M7_NO_ACPTHEAD,
?assertEqual(ExpectedDecisionTrace, get_decision_ids()),
Expand All @@ -949,7 +957,7 @@ see_other_n5() ->
put_setting(allow_missing_post, true),
put_setting(process_post, {set_resp_redirect, ?RESOURCE_PATH ++ "/new1"}),
PostRequest = {url("post"), [], ContentType, "foo"},
{ok, Result} = httpc:request(post, PostRequest, [], []),
{ok, Result} = httpc:request(post, PostRequest, [{autoredirect,false}], []),
?assertMatch({{"HTTP/1.1", 303, "See Other"}, _, _}, Result),
ExpectedDecisionTrace = ?PATH_TO_N11_VIA_N5_NO_ACPTHEAD,
?assertEqual(ExpectedDecisionTrace, get_decision_ids()),
Expand Down Expand Up @@ -1237,7 +1245,7 @@ stream_content_md5() ->
put_setting(allow_missing_post, true),
ContentType = "text/plain",
Content = "foo",
ValidMD5Sum = base64:encode_to_string(crypto:md5(Content)),
ValidMD5Sum = base64:encode_to_string(md5(Content)),
ibrowse:start(),
Url = url("post"),
Headers = [{"Content-Type", ContentType},
Expand Down

0 comments on commit e0c1cbe

Please sign in to comment.