summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Pervin <artem.pervin@kaspersky.com>2016-12-01 11:16:33 -0500
committerArtem Pervin <artem.pervin@kaspersky.com>2016-12-01 11:16:33 -0500
commit603683bca1ec067e7490405fd308cdabbc442702 (patch)
tree1151668bb2d59905a34009d5c6456a3e632fb9e9
parentc0184eae706f6c2bf7bcf8fc1db03c0569cb73c1 (diff)
1394: restore original proxy spec after tests
-rw-r--r--test/rebar_utils_SUITE.erl27
1 files changed, 21 insertions, 6 deletions
diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl
index 6307b42..bdbffb0 100644
--- a/test/rebar_utils_SUITE.erl
+++ b/test/rebar_utils_SUITE.erl
@@ -278,19 +278,34 @@ tup_merge(_Config) ->
proxy_auth(_Config) ->
Host = "host:",
Port = "1234",
+
+ proxy_auth(_Config, "http_proxy"),
+ proxy_auth(_Config, "https_proxy").
+
+proxy_auth(_Config, ProxyEnvKey) ->
+ %% remember current proxy specification
+ OldProxySpec = os:getenv(ProxyEnvKey),
- application:unset_env(rebar, proxy_auth),
%% proxy auth not set
+ application:unset_env(rebar, proxy_auth),
?assertEqual([], rebar_utils:get_proxy_auth()),
+
%% proxy auth with regular username/password
- os:putenv("http_proxy", "http://Username:Password@" ++ Host ++ Port),
+ os:putenv(ProxyEnvKey, "http://Username:Password@" ++ Host ++ Port),
rebar_utils:set_httpc_options(),
?assertEqual([{proxy_auth, {"Username", "Password"}}],
rebar_utils:get_proxy_auth()),
+
%% proxy auth with username missing and url encoded password
- os:putenv("http_proxy", "http://:%3F!abc%23%24@" ++ Host ++ Port),
+ os:putenv(ProxyEnvKey, "http://:%3F!abc%23%24@" ++ Host ++ Port),
rebar_utils:set_httpc_options(),
?assertEqual([{proxy_auth, {"", "?!abc#$"}}],
- rebar_utils:get_proxy_auth()).
-
-
+ rebar_utils:get_proxy_auth()),
+
+ %% restore original proxy specification if any
+ restore_proxy_env(OldProxySpec).
+
+restore_proxy_env(false) ->
+ ok;
+restore_proxy_env(ProxySpec) ->
+ os:putenv("http_proxy", ProxySpec).