You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2021/06/30 07:34:43 UTC

[couchdb] branch update-socks-proxy-settings created (now 0843fe5)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch update-socks-proxy-settings
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 0843fe5  Use correct socks5 proxy ibrowse options

This branch includes the following new commits:

     new 0843fe5  Use correct socks5 proxy ibrowse options

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[couchdb] 01/01: Use correct socks5 proxy ibrowse options

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch update-socks-proxy-settings
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0843fe5cc196e5ca07afb9e96296de7de9eb0b41
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Wed Jun 30 03:32:39 2021 -0400

    Use correct socks5 proxy ibrowse options
    
    This is a port of the 3.x PR https://github.com/apache/couchdb/pull/3634 to main
---
 .../src/couch_replicator_api_wrap.erl              | 14 +++++++++
 .../test/eunit/couch_replicator_proxy_tests.erl    | 34 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/couch_replicator/src/couch_replicator_api_wrap.erl b/src/couch_replicator/src/couch_replicator_api_wrap.erl
index f182ecd..2fa9feb 100644
--- a/src/couch_replicator/src/couch_replicator_api_wrap.erl
+++ b/src/couch_replicator/src/couch_replicator_api_wrap.erl
@@ -1035,6 +1035,10 @@ db_from_json(#{} = DbMap) ->
         [],
         Headers0
     ),
+    Socks5 = case maps:get(<<"proxy_protocol">>, IBrowseOptions0, undefined) of
+        <<"socks5">> -> true;
+        _ -> false
+    end,
     IBrowseOptions = maps:fold(
         fun
             (<<"socket_options">>, #{} = SockOpts, Acc) ->
@@ -1043,6 +1047,16 @@ db_from_json(#{} = DbMap) ->
             (<<"ssl_options">>, #{} = SslOpts, Acc) ->
                 SslOptsKVs = maps:fold(fun ssl_opts_fold/3, [], SslOpts),
                 [{ssl_options, SslOptsKVs} | Acc];
+            (<<"proxy_protocol">>, _Val, Acc) ->
+                Acc;
+            (<<"proxy_host">>, Val, Acc) when Socks5, is_binary(Val) ->
+                [{socks5_host, binary_to_list(Val)} | Acc];
+            (<<"proxy_port">>, Val, Acc) when Socks5, is_integer(Val) ->
+                [{socks5_port, Val} | Acc];
+            (<<"proxy_user">>, Val, Acc) when Socks5, is_binary(Val) ->
+                [{socks5_user, binary_to_list(Val)} | Acc];
+            (<<"proxy_password">>, Val, Acc) when Socks5, is_binary(Val) ->
+                [{socks5_password, binary_to_list(Val)} | Acc];
             (K, V, Acc) when is_binary(V) ->
                 [{binary_to_atom(K, utf8), binary_to_list(V)} | Acc];
             (K, V, Acc) ->
diff --git a/src/couch_replicator/test/eunit/couch_replicator_proxy_tests.erl b/src/couch_replicator/test/eunit/couch_replicator_proxy_tests.erl
index 8cbaf15..fdfb579 100644
--- a/src/couch_replicator/test/eunit/couch_replicator_proxy_tests.erl
+++ b/src/couch_replicator/test/eunit/couch_replicator_proxy_tests.erl
@@ -14,6 +14,7 @@
 
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch_replicator/src/couch_replicator.hrl").
+-include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
 -include_lib("fabric/test/fabric2_test.hrl").
 
 replicator_proxy_test_() ->
@@ -28,7 +29,8 @@ replicator_proxy_test_() ->
                 ?TDEF(parse_rep_doc_with_proxy),
                 ?TDEF(parse_rep_source_target_proxy),
                 ?TDEF(mutually_exclusive_proxy_and_source_proxy),
-                ?TDEF(mutually_exclusive_proxy_and_target_proxy)
+                ?TDEF(mutually_exclusive_proxy_and_target_proxy),
+                ?TDEF(sock5_proxy_in_db_from_json)
             ])
         }
     }.
@@ -100,3 +102,33 @@ mutually_exclusive_proxy_and_target_proxy(_) ->
         {bad_rep_doc, _},
         couch_replicator_parse:parse_rep_doc(ProxyDoc)
     ).
+
+sock5_proxy_in_db_from_json(_) ->
+    SrcProxyURL = <<"socks5://u1:p1@mysrcproxy.com:1234">>,
+    TgtProxyURL = <<"http://u2:p2@mytgtproxy.com:9999">>,
+    ProxyDoc =
+        {[
+            {<<"source">>, <<"http://unproxied.com">>},
+            {<<"target">>, <<"http://otherunproxied.com">>},
+            {<<"source_proxy">>, SrcProxyURL},
+            {<<"target_proxy">>, TgtProxyURL}
+        ]},
+    Rep = couch_replicator_parse:parse_rep_doc(ProxyDoc),
+    Src = maps:get(?SOURCE, Rep),
+    Tgt = maps:get(?TARGET, Rep),
+    ?assertEqual(SrcProxyURL, maps:get(<<"proxy_url">>, Src)),
+    ?assertEqual(TgtProxyURL, maps:get(<<"proxy_url">>, Tgt)),
+    SrcHttpDb = couch_replicator_api_wrap:db_from_json(Src),
+    TgtHttpDb = couch_replicator_api_wrap:db_from_json(Tgt),
+    SrcOpts = SrcHttpDb#httpdb.ibrowse_options,
+    TgtOpts = TgtHttpDb#httpdb.ibrowse_options,
+    ?assertEqual(undefined, couch_util:get_value(proxy_protocol, SrcOpts)),
+    ?assertEqual(undefined, couch_util:get_value(proxy_protocol, TgtOpts)),
+    ?assertEqual("mysrcproxy.com", couch_util:get_value(socks5_host, SrcOpts)),
+    ?assertEqual("mytgtproxy.com", couch_util:get_value(proxy_host, TgtOpts)),
+    ?assertEqual(1234, couch_util:get_value(socks5_port, SrcOpts)),
+    ?assertEqual(9999, couch_util:get_value(proxy_port, TgtOpts)),
+    ?assertEqual("u1", couch_util:get_value(socks5_user, SrcOpts)),
+    ?assertEqual("u2", couch_util:get_value(proxy_user, TgtOpts)),
+    ?assertEqual("p1", couch_util:get_value(socks5_password, SrcOpts)),
+    ?assertEqual("p2", couch_util:get_value(proxy_password, TgtOpts)).