From ffc2cf98d390a35cf3f61c7c0bf5f26e3552fd2c Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Wed, 30 Nov 2016 13:45:06 -0500 Subject: 1394: added fix for rebar_utils, moved setting of http_options into init_config, added unit tests --- test/rebar_utils_SUITE.erl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index b32992d..0d496a3 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -31,7 +31,8 @@ nonblacklisted_otp_version/1, blacklisted_otp_version/1, sh_does_not_miss_messages/1, - tup_merge/1]). + tup_merge/1, + proxy_auth/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -46,7 +47,8 @@ end_per_testcase(_, _Config) -> all() -> [{group, args_to_tasks}, sh_does_not_miss_messages, - tup_merge]. + tup_merge, + proxy_auth]. groups() -> [{args_to_tasks, [], [empty_arglist, @@ -272,3 +274,15 @@ tup_merge(_Config) -> rebar_utils:tup_sort([{a,a},{a,a,a},a,{b,a,a},b,{z,a},{z,a,a},{b,a},z]) ) ). + +proxy_auth(_Config) -> + %% proxy auth with regular username/password + rebar_utils:set_proxy_auth("Username", "Password"), + ?assertEqual([{proxy_auth, {"Username", "Password"}}], + rebar_utils:get_proxy_auth()), + %% proxy auth with username missing and url encoded password + rebar_utils:set_proxy_auth("", "?!abc#$"), + ?assertEqual([{proxy_auth, {"", "%3F!abc%23%24"}}], + rebar_utils:get_proxy_auth()). + + -- cgit v1.1 From 8a546cae8eab79ea2107476e0978247457d89acb Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Wed, 30 Nov 2016 13:48:22 -0500 Subject: 1394: fixed typo --- test/rebar_utils_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index 0d496a3..6cbac1a 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -277,11 +277,11 @@ tup_merge(_Config) -> proxy_auth(_Config) -> %% proxy auth with regular username/password - rebar_utils:set_proxy_auth("Username", "Password"), + rebar_utils:set_proxy_auth("Username:Password"), ?assertEqual([{proxy_auth, {"Username", "Password"}}], rebar_utils:get_proxy_auth()), %% proxy auth with username missing and url encoded password - rebar_utils:set_proxy_auth("", "?!abc#$"), + rebar_utils:set_proxy_auth(":?!abc#$"), ?assertEqual([{proxy_auth, {"", "%3F!abc%23%24"}}], rebar_utils:get_proxy_auth()). -- cgit v1.1 From f8873147abe49baa4e692b6dd93be1b8db89e172 Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Wed, 30 Nov 2016 13:52:23 -0500 Subject: 1394: fixed typos --- test/rebar_utils_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index 6cbac1a..ad37e00 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -281,8 +281,8 @@ proxy_auth(_Config) -> ?assertEqual([{proxy_auth, {"Username", "Password"}}], rebar_utils:get_proxy_auth()), %% proxy auth with username missing and url encoded password - rebar_utils:set_proxy_auth(":?!abc#$"), - ?assertEqual([{proxy_auth, {"", "%3F!abc%23%24"}}], + rebar_utils:set_proxy_auth(":%3F!abc%23%24"), + ?assertEqual([{proxy_auth, {"", "?!abc#$"}}], rebar_utils:get_proxy_auth()). -- cgit v1.1 From e60562fb307a8ff59f56746427e60ed3b2a1227a Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Thu, 1 Dec 2016 02:49:53 -0500 Subject: 1394: one more test --- test/rebar_utils_SUITE.erl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index ad37e00..e8f33a3 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -276,6 +276,9 @@ tup_merge(_Config) -> ). proxy_auth(_Config) -> + application:unset_env(rebar, proxy_auth), + %% proxy auth not set + ?assertEqual([], rebar_utils:get_proxy_auth()), %% proxy auth with regular username/password rebar_utils:set_proxy_auth("Username:Password"), ?assertEqual([{proxy_auth, {"Username", "Password"}}], -- cgit v1.1 From c0184eae706f6c2bf7bcf8fc1db03c0569cb73c1 Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Thu, 1 Dec 2016 10:27:07 -0500 Subject: 1394: refined export list and tests --- test/rebar_utils_SUITE.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index e8f33a3..6307b42 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -276,15 +276,20 @@ tup_merge(_Config) -> ). proxy_auth(_Config) -> + Host = "host:", + Port = "1234", + application:unset_env(rebar, proxy_auth), %% proxy auth not set ?assertEqual([], rebar_utils:get_proxy_auth()), %% proxy auth with regular username/password - rebar_utils:set_proxy_auth("Username:Password"), + os:putenv("http_proxy", "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 - rebar_utils:set_proxy_auth(":%3F!abc%23%24"), + os:putenv("http_proxy", "http://:%3F!abc%23%24@" ++ Host ++ Port), + rebar_utils:set_httpc_options(), ?assertEqual([{proxy_auth, {"", "?!abc#$"}}], rebar_utils:get_proxy_auth()). -- cgit v1.1 From 603683bca1ec067e7490405fd308cdabbc442702 Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Thu, 1 Dec 2016 11:16:33 -0500 Subject: 1394: restore original proxy spec after tests --- test/rebar_utils_SUITE.erl | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'test') 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). -- cgit v1.1 From 9ace3ba9fc1b2a1a7096e4fe62d9867f737cff1d Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Thu, 1 Dec 2016 11:17:07 -0500 Subject: 1394: fixed typo --- test/rebar_utils_SUITE.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index bdbffb0..57b6474 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -276,13 +276,13 @@ tup_merge(_Config) -> ). proxy_auth(_Config) -> - Host = "host:", - Port = "1234", - proxy_auth(_Config, "http_proxy"), proxy_auth(_Config, "https_proxy"). proxy_auth(_Config, ProxyEnvKey) -> + Host = "host:", + Port = "1234", + %% remember current proxy specification OldProxySpec = os:getenv(ProxyEnvKey), -- cgit v1.1 From 8df95d53bfd5dc892e69364dfe87ecf95c6897a2 Mon Sep 17 00:00:00 2001 From: Artem Pervin Date: Thu, 1 Dec 2016 11:20:58 -0500 Subject: 1394: fixed typo --- test/rebar_utils_SUITE.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index 57b6474..dd92bbf 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -303,9 +303,9 @@ proxy_auth(_Config, ProxyEnvKey) -> rebar_utils:get_proxy_auth()), %% restore original proxy specification if any - restore_proxy_env(OldProxySpec). + restore_proxy_env(ProxyEnvKey, OldProxySpec). -restore_proxy_env(false) -> +restore_proxy_env(_, false) -> ok; -restore_proxy_env(ProxySpec) -> - os:putenv("http_proxy", ProxySpec). +restore_proxy_env(ProxyEnvKey, ProxySpec) -> + os:putenv(ProxyEnvKey, ProxySpec). -- cgit v1.1 From 2c155ead23abeedb39ff761e4db5269f7b2a78ca Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Thu, 1 Dec 2016 11:47:05 -0500 Subject: Fully clean up after test utils for proxy --- test/rebar_utils_SUITE.erl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index dd92bbf..8b8769b 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -303,9 +303,10 @@ proxy_auth(_Config, ProxyEnvKey) -> rebar_utils:get_proxy_auth()), %% restore original proxy specification if any - restore_proxy_env(ProxyEnvKey, OldProxySpec). + restore_proxy_env(ProxyEnvKey, OldProxySpec), + application:unset_env(rebar, proxy_auth). -restore_proxy_env(_, false) -> - ok; +restore_proxy_env(ProxyEnvKey, false) -> + os:putenv(ProxyEnvKey, ""); restore_proxy_env(ProxyEnvKey, ProxySpec) -> - os:putenv(ProxyEnvKey, ProxySpec). + os:putenv(ProxyEnvKey, ProxySpec). -- cgit v1.1