summaryrefslogtreecommitdiff
path: root/lib/compiler/test/compile_SUITE.erl
diff options
context:
space:
mode:
authorLukas Larsson <lukas@erlang.org>2021-12-13 09:40:03 +0100
committerLukas Larsson <lukas@erlang.org>2021-12-13 09:40:03 +0100
commit771bc6badedf186b7487130bb6e1d6e1b3ad2881 (patch)
tree7974bb1fa39e4e113acdb9c051fcdb2b73316469 /lib/compiler/test/compile_SUITE.erl
parentf9e367c1992735164b0e6c96881c35a30890aed2 (diff)
parent508b27117fb181ec6e52064fa3ac7878faf961e2 (diff)
downloaderlang-771bc6badedf186b7487130bb6e1d6e1b3ad2881.tar.gz
Merge branch 'lukas/kernel/xdg-erlang-config/OTP-17554/OTP-17821'
* lukas/kernel/xdg-erlang-config/OTP-17554/OTP-17821: stdlib: Fix filename:basedir documentation erl_docgen: Better missing module fault indication debugger: Fix debugger settings to use XDG dialyzer: Place default plt in $XDG_CACHE_HOME stdlib: Search $XDG_CONFIG_HOME for .erlang.crypt kernel: Search $XDG_CONFIG_HOME for .erlang kernel: Search $XDG_CONFIG_HOME for erlang cookie
Diffstat (limited to 'lib/compiler/test/compile_SUITE.erl')
-rw-r--r--lib/compiler/test/compile_SUITE.erl95
1 files changed, 75 insertions, 20 deletions
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index 4860837912..8b9027dd17 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -666,7 +666,7 @@ encrypted_abstr(Config) when is_list(Config) ->
%% Now run the tests that require crypto.
encrypted_abstr_1(Simple, Target),
ok = file:delete(Target),
- ok = file:del_dir(filename:dirname(Target))
+ ok = file:del_dir_r(filename:dirname(Target))
end,
%% Cleanup.
@@ -710,22 +710,77 @@ encrypted_abstr_1(Simple, Target) ->
error = compile:file(Simple,
[debug_info,{debug_info_key,42},report]),
- %% Place the crypto key in .erlang.crypt.
beam_lib:clear_crypto_key_fun(),
- {ok,OldCwd} = file:get_cwd(),
- ok = file:set_cwd(TargetDir),
- error = compile:file(Simple, [encrypt_debug_info,report]),
-
- NewKey = "better use another key here",
- write_crypt_file(["[{debug_info,des3_cbc,simple,\"",NewKey,"\"}].\n"]),
- {ok,simple} = compile:file(Simple, [encrypt_debug_info,report]),
- verify_abstract("simple.beam", erl_abstract_code),
- ok = file:delete(".erlang.crypt"),
- beam_lib:clear_crypto_key_fun(),
- {error,beam_lib,{key_missing_or_invalid,"simple.beam",abstract_code}} =
- beam_lib:chunks("simple.beam", [abstract_code]),
- ok = file:set_cwd(OldCwd),
+ %% Test to place the crypto file on disk. The test is dependent on the
+ %% $HOME of the emulator, so we do this test in another node.
+ TestHome = filename:join(TargetDir, "home"),
+ filelib:ensure_dir(TestHome),
+ HomeEnv = case os:type() of
+ {win32, _} ->
+ [Drive | Path] = filename:split(TestHome),
+ [{"APPDATA", filename:join(TestHome,"AppData")},
+ {"HOMEDRIVE", Drive}, {"HOMEPATH", Path}];
+ _ ->
+ [{"HOME", TestHome}]
+ end,
+
+ {ok, Peer, Node} = ?CT_PEER(#{ env => HomeEnv }),
+
+ erpc:call(
+ Node,
+ fun() ->
+ {ok,OldCwd} = file:get_cwd(),
+ ok = file:set_cwd(TargetDir),
+
+ error = compile:file(Simple, [encrypt_debug_info,report]),
+
+ CWDKey = "better use another key here",
+ CWDFile = ".erlang.crypt",
+ XDGKey = "better use yet another key here",
+ XDGFile = filename:join(
+ filename:basedir(user_config,"erlang"),
+ ".erlang.crypt"),
+ HOMEKey = "better use the home key here",
+ HOMEFile = filename:join(TestHome,".erlang.crypt"),
+
+ write_crypt_file(CWDFile, CWDKey),
+ write_crypt_file(XDGFile, XDGKey),
+ write_crypt_file(HOMEFile, HOMEKey),
+
+ %% First we test that .erlang.crypt in cwd works
+ {ok,simple} = compile:file(Simple, [encrypt_debug_info,report]),
+ verify_abstract("simple.beam", erl_abstract_code),
+ ok = file:delete(CWDFile),
+ beam_lib:clear_crypto_key_fun(),
+
+ %% Then we test that .erlang.crypt in HOME does **not** work
+ {error,beam_lib,{key_missing_or_invalid,"simple.beam",abstract_code}} =
+ beam_lib:chunks("simple.beam", [abstract_code]),
+
+ %% Then we test that .erlang.crypt in HOME does work
+ {ok,simple} = compile:file(Simple, [encrypt_debug_info,report]),
+ verify_abstract("simple.beam", erl_abstract_code),
+ ok = file:delete(HOMEFile),
+ beam_lib:clear_crypto_key_fun(),
+
+ %% Then we test that .erlang.crypt in XDG does **not** work
+ {error,beam_lib,{key_missing_or_invalid,"simple.beam",abstract_code}} =
+ beam_lib:chunks("simple.beam", [abstract_code]),
+
+
+ %% Then we test that .erlang.crypt in XDG does work
+ {ok,simple} = compile:file(Simple, [encrypt_debug_info,report]),
+ verify_abstract("simple.beam", erl_abstract_code),
+ ok = file:delete(XDGFile),
+
+ beam_lib:clear_crypto_key_fun(),
+ {error,beam_lib,{key_missing_or_invalid,"simple.beam",abstract_code}} =
+ beam_lib:chunks("simple.beam", [abstract_code])
+
+ end),
+
+ peer:stop(Peer),
%% Test key compatibility by reading a BEAM file produced before
%% the update to the new crypto functions.
@@ -738,11 +793,11 @@ encrypted_abstr_1(Simple, Target) ->
ok.
-
-write_crypt_file(Contents0) ->
- Contents = list_to_binary([Contents0]),
- io:format("~s\n", [binary_to_list(Contents)]),
- ok = file:write_file(".erlang.crypt", Contents).
+write_crypt_file(File, Key) ->
+ Contents = ["[{debug_info,des3_cbc,simple,\"",Key,"\"}].\n"],
+ io:format("~s: ~s\n", [File, Contents]),
+ ok = filelib:ensure_dir(File),
+ ok = file:write_file(File, Contents).
encrypted_abstr_no_crypto(Simple, Target) ->
io:format("simpe: ~p~n", [Simple]),