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/07 17:25:56 UTC

[couchdb-ibrowse] branch upstream-rebase updated (6d6fab7 -> 16e73e0)

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

vatamane pushed a change to branch upstream-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git.


    omit 6d6fab7  Strip sensitive data from state
    omit 89844ae  Get a new lb pid if existing pid is not alive
     new 6c81151  Add strictly monotonic timestamp (#173)
     new d775155  Increase timeout in pipelining test (#174)
     new a361105  Get a new lb pid if existing pid is not alive
     new a62d4a6  Strip sensitive data from state
     new 16e73e0  Unquote basic auth username and password (#5)

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (6d6fab7)
            \
             N -- N -- N   refs/heads/upstream-rebase (16e73e0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 5 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.


Summary of changes:
 src/ibrowse_http_client.erl | 20 +++++++++++++-------
 src/ibrowse_lib.erl         | 43 +++++++++++++++++++++++++++++++++++++++++--
 test/ibrowse_tests.erl      |  2 +-
 3 files changed, 55 insertions(+), 10 deletions(-)

[couchdb-ibrowse] 01/05: Add strictly monotonic timestamp (#173)

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

vatamane pushed a commit to branch upstream-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git

commit 6c811515914266fde875c4f868cb8ff0a341c23f
Author: Noah Shaw <no...@yahoo.com>
AuthorDate: Sun Jun 6 19:49:06 2021 -0400

    Add strictly monotonic timestamp (#173)
---
 src/ibrowse_http_client.erl | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl
index 5443fe7..98a475f 100644
--- a/src/ibrowse_http_client.erl
+++ b/src/ibrowse_http_client.erl
@@ -484,6 +484,15 @@ accumulate_response(Data, #state{reply_buffer      = RepBuf,
             State#state{reply_buffer = RepBuf_1}
     end.
 
+generate_timestamp() ->
+    case catch erlang:unique_integer([positive]) of
+        {'EXIT', _} ->
+            erlang:apply(erlang, now, []);
+        Unique ->
+            {A,B,C} = os:timestamp(),
+            {A * 1000000 + B, C, Unique}
+    end.
+
 make_tmp_filename(true) ->
     DownloadDir = ibrowse:get_config_value(download_dir, filename:absname("./")),
     {A,B,C} = os:timestamp(),
@@ -2050,12 +2059,7 @@ cancel_timer(Ref, {eat_message, Msg}) ->
     end.
 
 make_req_id() ->
-    case catch erlang:unique_integer() of
-        {'EXIT', _} ->
-            erlang:apply(erlang, now, []);
-        V ->
-            V
-    end.
+    generate_timestamp().
 
 to_lower(Str) when is_binary(Str) ->
     to_lower(binary_to_list(Str));

[couchdb-ibrowse] 04/05: Strip sensitive data from state

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

vatamane pushed a commit to branch upstream-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git

commit a62d4a6d236729e5869842c70447ad46b3409912
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Thu Jul 23 08:15:02 2020 -0700

    Strip sensitive data from state
---
 src/ibrowse_http_client.erl | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl
index 98a475f..bee6a70 100644
--- a/src/ibrowse_http_client.erl
+++ b/src/ibrowse_http_client.erl
@@ -33,7 +33,8 @@
          handle_cast/2,
          handle_info/2,
          terminate/2,
-         code_change/3
+         code_change/3,
+         format_status/2
         ]).
 
 -include("ibrowse.hrl").
@@ -321,10 +322,47 @@ terminate(_Reason, #state{lb_ets_tid = Tid} = State) ->
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
+
+%%--------------------------------------------------------------------
+%% Function: format_status/2
+%% Purpose: Clean process state before logging
+%% Returns: key value list
+%%--------------------------------------------------------------------
+format_status(_Opt, [_PDict, State]) ->
+    #state{
+        reqs=Reqs,
+        reply_buffer=ReplyBuf,
+        recvd_headers=RCVDHeaders,
+        raw_headers=RawHeaders,
+        chunk_size_buffer=ChunkSizeBuf,
+        cur_req=Request
+    } = State,
+    ScrubbedReq = Request#request{url=url_strip_password(Request#request.url)},
+    Scrubbed = State#state{
+        reqs={queue_length, queue:len(Reqs)},
+        reply_buffer={byte_size, byte_size(ReplyBuf)},
+        recvd_headers=lists:map(fun({K, _V}) -> K end, RCVDHeaders),
+        raw_headers={byte_size, byte_size(RawHeaders)},
+        chunk_size_buffer={byte_size, byte_size(ChunkSizeBuf)},
+        cur_req=ScrubbedReq
+    },
+    [{data, [{"State",
+        lists:zip(
+            record_info(fields, state),
+            tl(tuple_to_list(Scrubbed))
+        )
+    }]}].
+
 %%--------------------------------------------------------------------
 %%% Internal functions
 %%--------------------------------------------------------------------
 
+url_strip_password(Url) ->
+    re:replace(Url,
+        "(http|https|socks5)://([^:]+):[^@]+@(.*)$",
+        "\\1://\\2:*****@\\3",
+        [{return, list}]).
+
 %%--------------------------------------------------------------------
 %% Handles data recvd on the socket
 %%--------------------------------------------------------------------

[couchdb-ibrowse] 02/05: Increase timeout in pipelining test (#174)

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

vatamane pushed a commit to branch upstream-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git

commit d775155a134ce310ff86ad8b29a806cb0b3ccacc
Author: Nick Vatamaniuc <ni...@users.noreply.github.com>
AuthorDate: Sun Jun 6 19:54:19 2021 -0400

    Increase timeout in pipelining test (#174)
    
    In CouchDB's CI the small_pipeline test intermittently fails with
    something like:
    
    ```
    in function ibrowse_tests:'-small_pipeline/0-fun-5-'/1 (test/ibrowse_tests.erl, line 150)
      {line,150},
      {expression,"Counts"},
      {expected,"\n\n\n\n\n\n\n\n\n\n"},
      {value,"\n\n\n\n\n\n\n\n\t\n"}]}
    ```
    
    Increasing the timeout a bit seems to help in local tests.
---
 test/ibrowse_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/ibrowse_tests.erl b/test/ibrowse_tests.erl
index 594b8ed..5693f79 100644
--- a/test/ibrowse_tests.erl
+++ b/test/ibrowse_tests.erl
@@ -15,7 +15,7 @@
 -define(BASE_URL, "http://localhost:" ++ integer_to_list(?SERVER_PORT)).
 -define(SHORT_TIMEOUT_MS, 5000).
 -define(LONG_TIMEOUT_MS, 30000).
--define(PAUSE_FOR_CONNECTIONS_MS, 2000).
+-define(PAUSE_FOR_CONNECTIONS_MS, 4000).
 
 %%-compile(export_all).
 

[couchdb-ibrowse] 03/05: Get a new lb pid if existing pid is not alive

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

vatamane pushed a commit to branch upstream-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git

commit a361105e32c4d441d47f0072526859fe352914cf
Author: Jay Doane <ja...@apache.org>
AuthorDate: Mon Apr 8 23:32:52 2019 -0700

    Get a new lb pid if existing pid is not alive
    
    It's possible for the connection process associated with a pid in the
    ibrowse_lb ets table to die, yet remain in the table, in which case
    subsequent requests to the corresponding {Host, Port} will result in an
    error like the following:
    
    (node1@127.0.0.1)9> ibrowse:send_req("http://localhost:15984", [], get).
                    ** exception exit: {noproc,
                           {gen_server,call,
                               [<0.2451.0>,
                                {spawn_connection,
                                    {url,"http://localhost:15984","localhost",15984,
                                        undefined,undefined,"/",http,hostname},
                                    10,10,
                                    {[],false},
                                    []}]}}
         in function  gen_server:call/2 (gen_server.erl, line 215)
         in call from ibrowse:try_routing_request/14 (src/ibrowse.erl, line 377)
    
    This checks whether the pid about to be returned from the table is alive,
    and if not, the entry is deleted, and a new pid is obtained.
---
 src/ibrowse.erl       | 21 +++++++++++++++------
 test/ibrowse_test.erl | 22 ++++++++++++++++++++--
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/ibrowse.erl b/src/ibrowse.erl
index 2066799..5adf047 100644
--- a/src/ibrowse.erl
+++ b/src/ibrowse.erl
@@ -342,12 +342,7 @@ send_req(Url, Headers, Method, Body, Options, Timeout) ->
         #url{host = Host,
              port = Port,
              protocol = Protocol} = Parsed_url ->
-            Lb_pid = case ets:lookup(ibrowse_lb, {Host, Port}) of
-                         [] ->
-                             get_lb_pid(Parsed_url);
-                         [#lb_pid{pid = Lb_pid_1}] ->
-                             Lb_pid_1
-                     end,
+            Lb_pid = lb_pid(Host, Port, Parsed_url),
             Max_sessions = get_max_sessions(Host, Port, Options),
             Max_pipeline_size = get_max_pipeline_size(Host, Port, Options),
             Max_attempts = get_max_attempts(Host, Port, Options),
@@ -367,6 +362,20 @@ send_req(Url, Headers, Method, Body, Options, Timeout) ->
             {error, {url_parsing_failed, Err}}
     end.
 
+lb_pid(Host, Port, Url) ->
+    case ets:lookup(ibrowse_lb, {Host, Port}) of
+        [] ->
+            get_lb_pid(Url);
+        [#lb_pid{pid = Pid}] ->
+            case is_process_alive(Pid) of
+                true ->
+                    Pid;
+                false ->
+                    ets:delete(ibrowse_lb, {Host, Port}),
+                    get_lb_pid(Url)
+            end
+    end.
+
 try_routing_request(Lb_pid, Parsed_url,
                     Max_sessions, 
                     Max_pipeline_size,
diff --git a/test/ibrowse_test.erl b/test/ibrowse_test.erl
index cd78049..9a7b192 100644
--- a/test/ibrowse_test.erl
+++ b/test/ibrowse_test.erl
@@ -40,7 +40,8 @@
 	 test_save_to_file_no_content_length/0,
          socks5_noauth/0,
          socks5_auth_succ/0,
-         socks5_auth_fail/0
+         socks5_auth_fail/0,
+         test_dead_lb_pid/0
 	]).
 
 -include_lib("ibrowse/include/ibrowse.hrl").
@@ -64,7 +65,8 @@
                       {local_test_fun, test_retry_of_requests, []},
 		      {local_test_fun, verify_chunked_streaming, []},
 		      {local_test_fun, test_chunked_streaming_once, []},
-		      {local_test_fun, test_generate_body_0, []}
+		      {local_test_fun, test_generate_body_0, []},
+		      {local_test_fun, test_dead_lb_pid, []}
                      ]).
 
 -define(TEST_LIST, [{"http://intranet/messenger", get},
@@ -877,6 +879,22 @@ test_generate_body_0() ->
         ets:delete(Tid)
     end.
 
+%% Test that when an lb process dies, its entry is removed from the ibrowse_lb
+%% table by the next requestor and replaced with a new process
+%%------------------------------------------------------------------------------
+test_dead_lb_pid() ->
+    {Host, Port} = {"localhost", 8181},
+    Url = "http://" ++ Host ++ ":" ++ integer_to_list(Port),
+    {ok, "200", _, _} = ibrowse:send_req(Url, [], get),
+    [{lb_pid, {Host, Port}, Pid, _}] = ets:lookup(ibrowse_lb, {Host, Port}),
+    true = exit(Pid, kill),
+    false = is_process_alive(Pid),
+    {ok, "200", _, _} = ibrowse:send_req(Url, [], get),
+    [{lb_pid, {Host, Port}, NewPid, _}] = ets:lookup(ibrowse_lb, {Host, Port}),
+    true = NewPid /= Pid,
+    true = is_process_alive(NewPid),
+    success.
+
 do_trace(Fmt, Args) ->
     do_trace(get(my_trace_flag), Fmt, Args).
 

[couchdb-ibrowse] 05/05: Unquote basic auth username and password (#5)

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

vatamane pushed a commit to branch upstream-rebase
in repository https://gitbox.apache.org/repos/asf/couchdb-ibrowse.git

commit 16e73e0a9ad7b5fce1a73d322f7fed8b414dcfb6
Author: Jiahui Li <54...@users.noreply.github.com>
AuthorDate: Wed May 5 08:06:49 2021 -0500

    Unquote basic auth username and password (#5)
    
    Unquote username and password which were parsed by ibrowse_lib:parse_url/1 before inserting them in the basic auth header.
    
    Previously if the user had characters like @ in their username or password, and they were percent-encoded, they were inserted encoded in the basic auth header which lead to authentication failure.
---
 src/ibrowse_http_client.erl |  4 +++-
 src/ibrowse_lib.erl         | 43 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl
index bee6a70..e3bc698 100644
--- a/src/ibrowse_http_client.erl
+++ b/src/ibrowse_http_client.erl
@@ -1066,7 +1066,9 @@ add_auth_headers(#url{username = User,
                                 [{"Authorization", ["Basic ", http_auth_basic(U, P)]} | Headers]
                         end;
                     _ ->
-                        [{"Authorization", ["Basic ", http_auth_basic(User, UPw)]} | Headers]
+                        User1 = ibrowse_lib:unquote(User),
+                        UPw1 = ibrowse_lib:unquote(UPw),
+                        [{"Authorization", ["Basic ", http_auth_basic(User1, UPw1)]} | Headers]
                 end,
     add_proxy_auth_headers(State, Headers_1).
 
diff --git a/src/ibrowse_lib.erl b/src/ibrowse_lib.erl
index 6c1883d..581ebfd 100644
--- a/src/ibrowse_lib.erl
+++ b/src/ibrowse_lib.erl
@@ -30,9 +30,14 @@
          get_value/3,
          parse_url/1,
          printable_date/0,
-         printable_date/1
+         unquote/1
         ]).
 
+-define(PERCENT, 37).  % $\%
+-define(IS_HEX(C), ((C >= $0 andalso C =< $9) orelse
+                    (C >= $a andalso C =< $f) orelse
+                    (C >= $A andalso C =< $F))).
+
 get_trace_status(Host, Port) ->
     ibrowse:get_config_value({trace, Host, Port}, false).
 
@@ -389,6 +394,29 @@ printable_date(Now) ->
      $:,
      integer_to_list(MicroSecs div 1000)].
 
+%% @spec unquote(string() | binary()) -> string()
+%% @doc Unquote a URL encoded string.
+unquote(Binary) when is_binary(Binary) ->
+    unquote(binary_to_list(Binary));
+unquote(String) ->
+    qs_revdecode(lists:reverse(String)).
+
+qs_revdecode(S) ->
+    qs_revdecode(S, []).
+
+qs_revdecode([], Acc) ->
+    Acc;
+qs_revdecode([$+ | Rest], Acc) ->
+    qs_revdecode(Rest, [$\s | Acc]);
+qs_revdecode([Lo, Hi, ?PERCENT | Rest], Acc) when ?IS_HEX(Lo), ?IS_HEX(Hi) ->
+    qs_revdecode(Rest, [(unhexdigit(Lo) bor (unhexdigit(Hi) bsl 4)) | Acc]);
+qs_revdecode([C | Rest], Acc) ->
+    qs_revdecode(Rest, [C | Acc]).
+
+unhexdigit(C) when C >= $0, C =< $9 -> C - $0;
+unhexdigit(C) when C >= $a, C =< $f -> C - $a + 10;
+unhexdigit(C) when C >= $A, C =< $F -> C - $A + 10.
+
 do_trace(Fmt, Args) ->
     do_trace(get(my_trace_flag), Fmt, Args).
 
@@ -462,4 +490,15 @@ parse_url_test() ->
               ?assertMatch(Expected_result, parse_url(Url))
       end, Urls).
 
--endif.
+unquote_test() ->
+    ?assertEqual("foo bar",
+        unquote("foo+bar")),
+    ?assertEqual("foo bar",
+        unquote("foo%20bar")),
+    ?assertEqual("foo\r\n",
+        unquote("foo%0D%0A")),
+    ?assertEqual("foo\r\n",
+        unquote(<<"foo%0D%0A">>)),
+    ok.
+
+-endif.
\ No newline at end of file