Github user kxepal commented on a diff in the pull request:

    https://github.com/apache/couchdb-chttpd/pull/109#discussion_r59890962
  
    --- Diff: src/chttpd.erl ---
    @@ -1074,3 +1075,60 @@ respond_(#httpd{mochi_req = MochiReq}, Code, 
Headers, _Args, start_response) ->
         MochiReq:start_response({Code, Headers});
     respond_(#httpd{mochi_req = MochiReq}, Code, Headers, Args, Type) ->
         MochiReq:Type({Code, Headers, Args}).
    +
    +get_user(#httpd{user_ctx = #user_ctx{name = User}}) ->
    +    couch_util:url_encode(User);
    +get_user(#httpd{user_ctx = undefined}) ->
    +    "undefined".
    +
    +-ifdef(TEST).
    +-include_lib("eunit/include/eunit.hrl").
    +
    +log_format_test() ->
    +    ?assertEqual(
    +        "nonce 127.0.0.1 127.0.0.1:15984 undefined "
    +        "GET /_cluster_setup 201 ok 10000",
    +        test_log_request("/_cluster_setup", undefined)),
    +    ?assertEqual(
    +        "nonce 127.0.0.1 127.0.0.1:15984 user_foo "
    +        "GET /_all_dbs 201 ok 10000",
    +        test_log_request("/_all_dbs", #user_ctx{name = <<"user_foo">>})),
    +
    +    %% Utf8Name = unicode:characters_to_binary(Something),
    +    Utf8User = <<227,130,136,227,129,134,227,129,147,227,129,157>>,
    +    ?assertEqual(
    +        "nonce 127.0.0.1 127.0.0.1:15984 
%E3%82%88%E3%81%86%E3%81%93%E3%81%9D "
    +        "GET /_all_dbs 201 ok 10000",
    +        test_log_request("/_all_dbs", #user_ctx{name = Utf8User})),
    +
    +    ok.
    +
    +test_log_request(RawPath, UserCtx) ->
    +    Headers = mochiweb_headers:make([{"HOST", "127.0.0.1:15984"}]),
    +    MochiReq = mochiweb_request:new(socket, [], 'POST', RawPath, version, 
Headers),
    +    Req = #httpd{
    +        mochi_req = MochiReq,
    +        begin_ts = {1458,588713,124003},
    +        original_method = 'GET',
    +        peer = "127.0.0.1",
    +        nonce = "nonce",
    +        user_ctx = UserCtx
    +    },
    +    Resp = #httpd_resp{
    +        end_ts = {1458,588723,124303},
    +        code = 201,
    +        status = ok
    +    },
    +    ok = meck:new(couch_log, [passthrough]),
    +    ok = meck:expect(couch_log, notice, fun(Format, Args) ->
    +        lists:flatten(io_lib:format(Format, Args))
    +    end),
    +    Message = maybe_log(Req, Resp),
    +    ok = meck:unload(couch_log),
    +    Message.
    +
    +
    +
    --- End diff --
    
    Reserved for future tests? (:


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to