couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r820624 - in /couchdb/branches/0.10.x: ./ etc/default/couchdb share/www/script/test/oauth.js src/couchdb/couch_httpd_auth.erl src/couchdb/couch_rep_httpc.erl
Date Thu, 01 Oct 2009 12:14:33 GMT
Author: kocolosk
Date: Thu Oct  1 12:14:33 2009
New Revision: 820624

URL: http://svn.apache.org/viewvc?rev=820624&view=rev
Log:
merging cookie, oauth+replication fixes per Jason's recommendation

Modified:
    couchdb/branches/0.10.x/   (props changed)
    couchdb/branches/0.10.x/etc/default/couchdb   (props changed)
    couchdb/branches/0.10.x/share/www/script/test/oauth.js
    couchdb/branches/0.10.x/src/couchdb/couch_httpd_auth.erl
    couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl

Propchange: couchdb/branches/0.10.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Oct  1 12:14:33 2009
@@ -3,4 +3,4 @@
 /couchdb/branches/form:729440-730015
 /couchdb/branches/list-iterator:782292-784593
 /couchdb/branches/tail_header:775760-778477
-/couchdb/trunk:806983,807208-807478,807771,808574,808632,808716,808876,809134,809977,810015,810028,810350,810358,810435,811910,813803,815921,817278,817398,817400,817403,817749,817793,818249,819091,819341,819343,819436,819799,819977,820495
+/couchdb/trunk:806983,807208-807478,807771,808574,808632,808716,808876,809134,809977,810015,810028,810350,810358,810435,811910,813803,815921,817278,817398,817400,817403,817749,817793,818249,818357,819091,819341,819343,819436,819799,819977,820344,820469,820495

Propchange: couchdb/branches/0.10.x/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Oct  1 12:14:33 2009
@@ -3,5 +3,5 @@
 /couchdb/branches/form/etc/default/couchdb:729440-730015
 /couchdb/branches/list-iterator/etc/default/couchdb:782292-784593
 /couchdb/branches/tail_header/etc/default/couchdb:775760-778477
-/couchdb/trunk/etc/default/couchdb:806983,807208-807478,807771,808574,808632,808716,808876,809134,809977,810015,810028,810350,810358,810435,811910,813803,815921,817277-817278,817398,817400,817403,817749,817793,818249,819091,819341,819343,819436,819799,819977,820495
+/couchdb/trunk/etc/default/couchdb:806983,807208-807478,807771,808574,808632,808716,808876,809134,809977,810015,810028,810350,810358,810435,811910,813803,815921,817277-817278,817398,817400,817403,817749,817793,818249,818357,819091,819341,819343,819436,819799,819977,820344,820469,820495
 /incubator/couchdb/trunk/etc/default/couchdb:642419-694440

Modified: couchdb/branches/0.10.x/share/www/script/test/oauth.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.10.x/share/www/script/test/oauth.js?rev=820624&r1=820623&r2=820624&view=diff
==============================================================================
--- couchdb/branches/0.10.x/share/www/script/test/oauth.js (original)
+++ couchdb/branches/0.10.x/share/www/script/test/oauth.js Thu Oct  1 12:14:33 2009
@@ -51,7 +51,7 @@
         });
       }
     } else {
-      return CouchDB.request("GET", path, {
+      return CouchDB.request(method, path, {
         headers: {Authorization: OAuth.getAuthorizationHeader('', parameters)}
       });
     }
@@ -62,6 +62,11 @@
   var admintokenSecret = generateSecret(64);
   var testadminPassword = "ohsosecret";
 
+  var adminBasicAuthHeaderValue = function() {
+    var retval = 'Basic ' + binb2b64(str2binb("testadmin:" + testadminPassword));
+    return retval;
+  }
+
   var host = CouchDB.host;
   var dbPair = {
     source: {
@@ -75,14 +80,12 @@
         }
       }
     },
-    target: "http://" + host + "/test_suite_db_b"
+    target: {
+      url: "http://" + host + "/test_suite_db_b",
+      headers: {"Authorization": adminBasicAuthHeaderValue()}
+    }
   };
 
-  var adminBasicAuthHeaderValue = function() {
-    var retval = 'Basic ' + binb2b64(str2binb("testadmin:" + testadminPassword));
-    return retval;
-  }
-
   // this function will be called on the modified server
   var testFun = function () {
     try {
@@ -91,6 +94,16 @@
         body: JSON.stringify(testadminPassword)
       });
 
+      CouchDB.request("GET", "/_sleep?time=50");
+
+      CouchDB.request("PUT", "http://" + host + "/_config/couch_httpd_auth/require_valid_user",
{
+        headers: {
+          "X-Couch-Persist": "false",
+          "Authorization": adminBasicAuthHeaderValue()
+        },
+        body: JSON.stringify("true")
+      });
+
       var usersDb = new CouchDB("test_suite_users", {
         "X-Couch-Full-Commit":"false",
         "Authorization": adminBasicAuthHeaderValue()
@@ -156,7 +169,9 @@
           T(xhr.status == expectedCode);
 
           // Replication
-          var result = CouchDB.replicate(dbPair.source, dbPair.target);
+          var result = CouchDB.replicate(dbPair.source, dbPair.target, {
+            headers: {"Authorization": adminBasicAuthHeaderValue()}
+          });
           T(result.ok);
 
           // Test auth via admin user defined in .ini
@@ -178,6 +193,15 @@
         }
       }
     } finally {
+      var xhr = CouchDB.request("PUT", "http://" + host + "/_config/couch_httpd_auth/require_valid_user",
{
+        headers: {
+          "Authorization": adminBasicAuthHeaderValue(),
+          "X-Couch-Persist": "false"
+        },
+        body: JSON.stringify("false")
+      });
+      T(xhr.status == 200);
+
       var xhr = CouchDB.request("DELETE", "http://" + host + "/_config/admins/testadmin",
{
         headers: {
           "Authorization": adminBasicAuthHeaderValue(),

Modified: couchdb/branches/0.10.x/src/couchdb/couch_httpd_auth.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.10.x/src/couchdb/couch_httpd_auth.erl?rev=820624&r1=820623&r2=820624&view=diff
==============================================================================
--- couchdb/branches/0.10.x/src/couchdb/couch_httpd_auth.erl (original)
+++ couchdb/branches/0.10.x/src/couchdb/couch_httpd_auth.erl Thu Oct  1 12:14:33 2009
@@ -263,17 +263,15 @@
     %    or logout handler.
     % The login and logout handlers need to set the AuthSession cookie
     % themselves.
-    case proplists:get_value("Set-Cookie", Headers) of
-    undefined -> [];
-    Cookie -> 
-        case proplists:get_value("AuthSession",
-            mochiweb_cookies:parse_cookie(Cookie), undefined) of
-        undefined ->
-            {NowMS, NowS, _} = erlang:now(),
-            TimeStamp = NowMS * 1000000 + NowS,
-            [cookie_auth_cookie(?b2l(User), Secret, TimeStamp)];
-        _Else -> []
-        end
+    CookieHeader = proplists:get_value("Set-Cookie", Headers, ""),
+    Cookies = mochiweb_cookies:parse_cookie(CookieHeader),
+    AuthSession = proplists:get_value("AuthSession", Cookies),
+    if AuthSession == undefined ->
+        {NowMS, NowS, _} = erlang:now(),
+        TimeStamp = NowMS * 1000000 + NowS,
+        [cookie_auth_cookie(?b2l(User), Secret, TimeStamp)];
+    true ->
+        []
     end;
 cookie_auth_header(_Req, _Headers) -> [].
 

Modified: couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl?rev=820624&r1=820623&r2=820624&view=diff
==============================================================================
--- couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl (original)
+++ couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl Thu Oct  1 12:14:33 2009
@@ -26,18 +26,19 @@
 do_request(Req) ->
     #http_db{
         auth = Auth,
+        body = B,
+        conn = Conn,
         headers = Headers0,
         method = Method,
-        body = B,
         options = Opts,
-        conn = Conn
+        qs = QS
     } = Req,
     Url = full_url(Req),
     Headers = case proplists:get_value(<<"oauth">>, Auth) of
     undefined ->
         Headers0;
     {OAuthProps} ->
-        [oauth_header(Url, Method, OAuthProps) | Headers0]
+        [oauth_header(Url, QS, Method, OAuthProps) | Headers0]
     end,
     Body = case B of
     {Fun, InitialState} when is_function(Fun) ->
@@ -60,9 +61,16 @@
 
 db_exists(Req, CanonicalUrl) ->
     #http_db{
-        url = Url,
-        headers = Headers
+        auth = Auth,
+        headers = Headers0,
+        url = Url
     } = Req,
+    Headers = case proplists:get_value(<<"oauth">>, Auth) of
+    undefined ->
+        Headers0;
+    {OAuthProps} ->
+        [oauth_header(Url, [], head, OAuthProps) | Headers0]
+    end,
     case catch ibrowse:send_req(Url, Headers, head) of
     {ok, "200", _, _} ->
         Req#http_db{url = CanonicalUrl};
@@ -168,7 +176,8 @@
         Body
     end.
 
-oauth_header(Url, Action, Props) ->
+oauth_header(Url, QS, Action, Props) ->
+    QSL = [{couch_util:to_list(K), couch_util:to_list(V)} || {K,V} <- QS],
     ConsumerKey = ?b2l(proplists:get_value(<<"consumer_key">>, Props)),
     Token = ?b2l(proplists:get_value(<<"token">>, Props)),
     TokenSecret = ?b2l(proplists:get_value(<<"token_secret">>, Props)),
@@ -177,7 +186,9 @@
     Method = case Action of
         get -> "GET";
         post -> "POST";
-        put -> "PUT"
+        put -> "PUT";
+        head -> "HEAD"
     end,
-    Params = oauth:signed_params(Method, Url, [], Consumer, Token, TokenSecret),
+    Params = oauth:signed_params(Method, Url, QSL, Consumer, Token, TokenSecret)
+        -- QSL,
     {"Authorization", "OAuth " ++ oauth_uri:params_to_header_string(Params)}.



Mime
View raw message