summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2016-05-25 10:58:50 -0400
committerFred Hebert <mononcqc@ferd.ca>2016-05-25 13:15:44 -0400
commitc15c31f35c46e8184dd76bc8463eb6f4ffd65978 (patch)
tree1f76e28c4eef3cc911226a7c6364668654a59cd8
parent00e06c1999e0e6e1dafdc4d7c835c89b473b65aa (diff)
Testing expected hash behaviour and errors in pkgs
- also making sure unlocking works fine
-rw-r--r--test/rebar_pkg_SUITE.erl38
-rw-r--r--test/rebar_test_utils.erl10
-rw-r--r--test/rebar_unlock_SUITE.erl43
-rw-r--r--test/rebar_unlock_SUITE_data/pkg.rebar.lock32
4 files changed, 116 insertions, 7 deletions
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl
index 7fdf55e..30cc0a8 100644
--- a/test/rebar_pkg_SUITE.erl
+++ b/test/rebar_pkg_SUITE.erl
@@ -11,6 +11,7 @@
-define(good_checksum, <<"1C6CE379D191FBAB41B7905075E0BF87CBBE23C77CECE775C5A0B786B2244C35">>).
all() -> [good_uncached, good_cached, badindexchk, badpkg,
+ badhash_nocache, badhash_cache,
bad_to_good, good_disconnect, bad_disconnect, pkgs_provider,
find_highest_matching].
@@ -58,6 +59,19 @@ init_per_testcase(badpkg=Name, Config0) ->
{pkg, {<<"badpkg">>, <<"1.0.0">>}}
| Config0],
mock_config(Name, Config);
+init_per_testcase(badhash_nocache=Name, Config0) ->
+ Config = [{good_cache, false},
+ {pkg, {<<"goodpkg">>, <<"1.0.0">>}}
+ | Config0],
+ mock_config(Name, Config);
+init_per_testcase(badhash_cache=Name, Config0) ->
+ Pkg = {<<"goodpkg">>, <<"1.0.0">>},
+ Config1 = [{good_cache, true},
+ {pkg, Pkg}
+ | Config0],
+ Config = mock_config(Name, Config1),
+ copy_to_cache(Pkg, Config),
+ Config;
init_per_testcase(bad_to_good=Name, Config0) ->
Config1 = [{good_cache, false},
{pkg, {<<"goodpkg">>, <<"1.0.0">>}}
@@ -139,6 +153,30 @@ badpkg(Config) ->
Cache = ?config(cache_dir, Config),
?assert(filelib:is_regular(filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>))).
+badhash_nocache(Config) ->
+ Tmp = ?config(tmp_dir, Config),
+ {Pkg,Vsn} = ?config(pkg, Config),
+ State = ?config(state, Config),
+ ?assertMatch({unexpected_hash, _Path, ?bad_checksum, ?good_checksum},
+ rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?bad_checksum}, State)),
+ %% The cached file is there for forensic purposes
+ Cache = ?config(cache_dir, Config),
+ ?assert(filelib:is_regular(filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>))).
+
+badhash_cache(Config) ->
+ Tmp = ?config(tmp_dir, Config),
+ {Pkg,Vsn} = ?config(pkg, Config),
+ Cache = ?config(cache_dir, Config),
+ State = ?config(state, Config),
+ CachedFile = filename:join(Cache, <<Pkg/binary, "-", Vsn/binary, ".tar">>),
+ ?assert(filelib:is_regular(CachedFile)),
+ {ok, Content} = file:read_file(CachedFile),
+ ?assertMatch({unexpected_hash, _Path, ?bad_checksum, ?good_checksum},
+ rebar_pkg_resource:download(Tmp, {pkg, Pkg, Vsn, ?bad_checksum}, State)),
+ %% The cached file is there still, unchanged.
+ ?assert(filelib:is_regular(CachedFile)),
+ ?assertEqual({ok, Content}, file:read_file(CachedFile)).
+
bad_to_good(Config) ->
Tmp = ?config(tmp_dir, Config),
{Pkg,Vsn} = ?config(pkg, Config),
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index 7e62109..8c177c9 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -317,9 +317,10 @@ check_results(AppDir, Expected, ProfileRun) ->
case lists:keyfind(iolist_to_binary(Name), 1, Locks) of
false ->
error({lock_not_found, Name});
- {_LockName, {pkg, _, LockVsn, _}, _} ->
+ {_LockName, {pkg, _, LockVsn, Hash}, _} ->
?assertEqual(iolist_to_binary(Vsn),
- iolist_to_binary(LockVsn));
+ iolist_to_binary(LockVsn)),
+ ?assertNotEqual(undefined, Hash);
{_LockName, {_, _, {ref, LockVsn}}, _} ->
?assertEqual(iolist_to_binary(Vsn),
iolist_to_binary(LockVsn))
@@ -329,9 +330,10 @@ check_results(AppDir, Expected, ProfileRun) ->
case lists:keyfind(iolist_to_binary(Name), 1, Locks) of
false ->
error({lock_not_found, Name});
- {_LockName, {pkg, _, LockVsn, _}, _} ->
+ {_LockName, {pkg, _, LockVsn, Hash}, _} ->
?assertEqual(iolist_to_binary(Vsn),
- iolist_to_binary(LockVsn));
+ iolist_to_binary(LockVsn)),
+ ?assertNotEqual(undefined, Hash);
{_LockName, {_, _, {ref, LockVsn}}, _} ->
error({source_lock, {Name, LockVsn}})
end
diff --git a/test/rebar_unlock_SUITE.erl b/test/rebar_unlock_SUITE.erl
index 31dca72..8dbdb3a 100644
--- a/test/rebar_unlock_SUITE.erl
+++ b/test/rebar_unlock_SUITE.erl
@@ -3,8 +3,14 @@
-include_lib("eunit/include/eunit.hrl").
-compile(export_all).
-all() -> [unlock, unlock_all].
+all() -> [pkgunlock, unlock, unlock_all].
+init_per_testcase(pkgunlock, Config0) ->
+ Config = rebar_test_utils:init_rebar_state(Config0, "pkgunlock"),
+ Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
+ ec_file:copy(filename:join(?config(data_dir, Config), "pkg.rebar.lock"),
+ Lockfile),
+ [{lockfile, Lockfile} | Config];
init_per_testcase(Case, Config0) ->
Config = rebar_test_utils:init_rebar_state(Config0, atom_to_list(Case)),
Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
@@ -15,6 +21,23 @@ init_per_testcase(Case, Config0) ->
end_per_testcase(_, Config) ->
Config.
+pkgunlock(Config) ->
+ Locks = read_locks(Config),
+ Hashes = read_hashes(Config),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}),
+ Locks = read_locks(Config),
+ Hashes = read_hashes(Config),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", "bbmustache"], {ok, []}),
+ ?assertEqual(Locks -- ["bbmustache"], read_locks(Config)),
+ ?assertEqual(Hashes -- ["bbmustache"], read_hashes(Config)),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", "cf,certifi"], {ok, []}),
+ ?assertEqual(Locks -- ["bbmustache","cf","certifi"], read_locks(Config)),
+ ?assertEqual(Hashes -- ["bbmustache","cf","certifi"], read_hashes(Config)),
+ rebar_test_utils:run_and_check(Config, [], ["unlock", string:join(Locks,",")], {ok, []}),
+ ?assertEqual({error, enoent}, read_locks(Config)),
+ ?assertEqual({error, enoent}, read_hashes(Config)),
+ ok.
+
unlock(Config) ->
Locks = read_locks(Config),
rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}),
@@ -35,6 +58,20 @@ unlock_all(Config) ->
read_locks(Config) ->
case file:consult(?config(lockfile, Config)) of
- {ok, [Locks]} -> [binary_to_list(element(1,Lock)) || Lock <- Locks];
- Other -> Other
+ {ok, _} ->
+ Locks = rebar_config:consult_lock_file(?config(lockfile, Config)),
+ [binary_to_list(element(1,Lock)) || Lock <- Locks];
+ Other ->
+ Other
+ end.
+
+read_hashes(Config) ->
+ case file:consult(?config(lockfile, Config)) of
+ {ok, [{_Vsn, _Locks},Props|_]} ->
+ Hashes = proplists:get_value(pkg_hash, Props, []),
+ [binary_to_list(element(1,Hash)) || Hash <- Hashes];
+ {ok, [{_Vsn, _Locks}]} ->
+ [];
+ Other ->
+ Other
end.
diff --git a/test/rebar_unlock_SUITE_data/pkg.rebar.lock b/test/rebar_unlock_SUITE_data/pkg.rebar.lock
new file mode 100644
index 0000000..38e22e5
--- /dev/null
+++ b/test/rebar_unlock_SUITE_data/pkg.rebar.lock
@@ -0,0 +1,32 @@
+{"1.1.0",[{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.0.4">>},0},
+ {<<"certifi">>,{pkg,<<"certifi">>,<<"0.4.0">>},0},
+ {<<"cf">>,{pkg,<<"cf">>,<<"0.2.1">>},0},
+ {<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.2.2">>},0},
+ {<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"0.21.0">>},0},
+ {<<"eunit_formatters">>,{pkg,<<"eunit_formatters">>,<<"0.3.1">>},0},
+ {<<"getopt">>,{pkg,<<"getopt">>,<<"0.8.2">>},0},
+ {<<"providers">>,{pkg,<<"providers">>,<<"1.6.0">>},0},
+ {<<"relx">>,{pkg,<<"relx">>,<<"3.19.0">>},0},
+ {<<"ssl_verify_hostname">>,
+ {pkg,<<"ssl_verify_hostname">>,<<"1.0.5">>},
+ 0}]}.
+[{pkg_hash,[{<<"bbmustache">>,
+ <<"7BA94F971C5AFD7B6617918A4BB74705E36CAB36EB84B19B6A1B7EE06427AA38">>},
+ {<<"certifi">>,
+ <<"A7966EFB868B179023618D29A407548F70C52466BF1849B9E8EBD0E34B7EA11F">>},
+ {<<"cf">>,
+ <<"69D0B1349FD4D7D4DC55B7F407D29D7A840BF9A1EF5AF529F1EBE0CE153FC2AB">>},
+ {<<"cth_readable">>,
+ <<"983913A8E8572310B7EAF5F2631148B7D70B3C090D2120DCFE777A93AA4165FB">>},
+ {<<"erlware_commons">>,
+ <<"A04433071AD7D112EDEFC75AC77719DD3E6753E697AC09428FC83D7564B80B15">>},
+ {<<"eunit_formatters">>,
+ <<"7A6FC351EB5B873E2356B8852EB751E20C13A72FBCA03393CF682B8483509573">>},
+ {<<"getopt">>,
+ <<"B17556DB683000BA50370B16C0619DF1337E7AF7ECBF7D64FBF8D1D6BCE3109B">>},
+ {<<"providers">>,
+ <<"DB0E2F9043AE60C0155205FCD238D68516331D0E5146155E33D1E79DC452964A">>},
+ {<<"relx">>,
+ <<"286DD5244B4786F56AAC75D5C8E2D1FB4CFD306810D4EC8548F3AE1B3AADB8F7">>},
+ {<<"ssl_verify_hostname">>,
+ <<"2E73E068CD6393526F9FA6D399353D7C9477D6886BA005F323B592D389FB47BE">>}]}].