Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E04DB2A33 for ; Mon, 25 Apr 2011 23:45:55 +0000 (UTC) Received: (qmail 55394 invoked by uid 500); 25 Apr 2011 23:45:55 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 55342 invoked by uid 500); 25 Apr 2011 23:45:54 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 55335 invoked by uid 99); 25 Apr 2011 23:45:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Apr 2011 23:45:54 +0000 X-ASF-Spam-Status: No, hits=-1994.5 required=5.0 tests=ALL_TRUSTED,T_URIBL_BLACK_OVERLAP,URIBL_BLACK,URIBL_JP_SURBL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Apr 2011 23:45:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 45FD523889DA; Mon, 25 Apr 2011 23:45:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1096635 - in /couchdb/trunk: src/couchdb/couch_httpd_vhost.erl test/etap/160-vhosts.t Date: Mon, 25 Apr 2011 23:45:33 -0000 To: commits@couchdb.apache.org From: jan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110425234533.45FD523889DA@eris.apache.org> Author: jan Date: Mon Apr 25 23:45:32 2011 New Revision: 1096635 URL: http://svn.apache.org/viewvc?rev=1096635&view=rev Log: Fix vhosts for https and fix vhost dependence on sorting of values in the config system which isn't guaranteed. Make vhost test cases more robust. Closes COUCHDB-1103 Source patch by Benoit and tests patch by me. Modified: couchdb/trunk/src/couchdb/couch_httpd_vhost.erl couchdb/trunk/test/etap/160-vhosts.t Modified: couchdb/trunk/src/couchdb/couch_httpd_vhost.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_vhost.erl?rev=1096635&r1=1096634&r2=1096635&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_httpd_vhost.erl (original) +++ couchdb/trunk/src/couchdb/couch_httpd_vhost.erl Mon Apr 25 23:45:32 2011 @@ -210,6 +210,7 @@ make_target([P|Rest], Bindings, Remainin %% bind port bind_port(Port, Port) -> ok; +bind_port('*', _) -> ok; bind_port(_,_) -> fail. %% bind bhost @@ -238,15 +239,17 @@ bind_path(_, _) -> %% create vhost list from ini make_vhosts() -> - lists:reverse(lists:foldl(fun({Vhost, Path}, Acc) -> + Vhosts = lists:foldl(fun({Vhost, Path}, Acc) -> [{parse_vhost(Vhost), split_path(Path)}|Acc] - end, [], couch_config:get("vhosts"))). + end, [], couch_config:get("vhosts")), + + lists:reverse(lists:usort(Vhosts)). parse_vhost(Vhost) -> case urlsplit_netloc(Vhost, []) of {[], Path} -> - {make_spec("*", []), 80, Path}; + {make_spec("*", []), '*', Path}; {HostPort, []} -> {H, P} = split_host_port(HostPort), H1 = make_spec(H, []), @@ -261,13 +264,13 @@ parse_vhost(Vhost) -> split_host_port(HostAsString) -> case string:rchr(HostAsString, $:) of 0 -> - {split_host(HostAsString), 80}; + {split_host(HostAsString), '*'}; N -> HostPart = string:substr(HostAsString, 1, N-1), case (catch erlang:list_to_integer(string:substr(HostAsString, N+1, length(HostAsString)))) of {'EXIT', _} -> - {split_host(HostAsString), 80}; + {split_host(HostAsString), '*'}; Port -> {split_host(HostPart), Port} end Modified: couchdb/trunk/test/etap/160-vhosts.t URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/160-vhosts.t?rev=1096635&r1=1096634&r2=1096635&view=diff ============================================================================== --- couchdb/trunk/test/etap/160-vhosts.t (original) +++ couchdb/trunk/test/etap/160-vhosts.t Mon Apr 25 23:45:32 2011 @@ -155,9 +155,9 @@ test_regular_request() -> test_vhost_request() -> case ibrowse:send_req(server(), [], get, [], [{host_header, "example.com"}]) of {ok, _, _, Body} -> - {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]} - = ejson:decode(Body), - etap:is(true, true, "should return database info"); + {JsonBody} = ejson:decode(Body), + HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody), + etap:is(HasDbNameInfo, true, "should return database info"); _Else -> etap:is(false, true, <<"ibrowse fail">>) end. @@ -222,9 +222,9 @@ test_vhost_request_wildcard()-> test_vhost_request_replace_var() -> case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example1.com"}]) of {ok, _, _, Body} -> - {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]} - = ejson:decode(Body), - etap:is(true, true, "should return database info"); + {JsonBody} = ejson:decode(Body), + HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody), + etap:is(HasDbNameInfo, true, "should return database info"); _Else -> etap:is(false, true, <<"ibrowse fail">>) end. @@ -242,9 +242,9 @@ test_vhost_request_replace_var1() -> test_vhost_request_replace_wildcard() -> case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example2.com"}]) of {ok, _, _, Body} -> - {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]} - = ejson:decode(Body), - etap:is(true, true, "should return database info"); + {JsonBody} = ejson:decode(Body), + HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody), + etap:is(HasDbNameInfo, true, "should return database info"); _Else -> etap:is(false, true, <<"ibrowse fail">>) end. @@ -252,9 +252,9 @@ test_vhost_request_path() -> Uri = server() ++ "test", case ibrowse:send_req(Uri, [], get, [], [{host_header, "example.com"}]) of {ok, _, _, Body} -> - {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]} - = ejson:decode(Body), - etap:is(true, true, "should return database info"); + {JsonBody} = ejson:decode(Body), + HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody), + etap:is(HasDbNameInfo, true, "should return database info"); _Else -> etap:is(false, true, <<"ibrowse fail">>) end. @@ -272,9 +272,9 @@ test_vhost_request_path2() -> Uri = server() ++ "test", case ibrowse:send_req(Uri, [], get, [], [{host_header,"etap-test-db.example2.com"}]) of {ok, _, _, Body} -> - {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]} - = ejson:decode(Body), - etap:is(true, true, "should return database info"); + {JsonBody} = ejson:decode(Body), + HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody), + etap:is(HasDbNameInfo, true, "should return database info"); _Else -> etap:is(false, true, <<"ibrowse fail">>) end.