summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2012-11-19 10:55:57 +0000
committerRobert Newson <rnewson@apache.org>2012-11-19 10:56:31 +0000
commit5d4ef93048f4aca24bef00fb5b2c13c54c2bbbb3 (patch)
tree3e8277ec1722185f6116157de1c61fbc989b6adb
parentd9566c831d002be16f866f0065a905bc23773cf9 (diff)
downloadcouchdb-5d4ef93048f4aca24bef00fb5b2c13c54c2bbbb3.tar.gz
Make cardinality of result explicit, remove join hacks
-rw-r--r--src/couchdb/couch_httpd_auth.erl14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl
index 5226a56a6..a967e091f 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/src/couchdb/couch_httpd_auth.erl
@@ -26,7 +26,7 @@ special_test_authentication_handler(Req) ->
case header_value(Req, "WWW-Authenticate") of
"X-Couch-Test-Auth " ++ NamePass ->
% NamePass is a colon separated string: "joe schmoe:a password".
- [Name, Pass] = re:split(NamePass, ":", [{return, list}]),
+ [Name, Pass] = re:split(NamePass, ":", [{return, list}, {parts, 2}]),
case {Name, Pass} of
{"Jan Lehnardt", "apple"} -> ok;
{"Christopher Lenz", "dog food"} -> ok;
@@ -47,14 +47,13 @@ basic_name_pw(Req) ->
AuthorizationHeader = header_value(Req, "Authorization"),
case AuthorizationHeader of
"Basic " ++ Base64Value ->
- case string:tokens(?b2l(base64:decode(Base64Value)),":") of
+ case re:split(base64:decode(Base64Value), ":",
+ [{return, list}, {parts, 2}]) of
["_", "_"] ->
% special name and pass to be logged out
nil;
[User, Pass] ->
{User, Pass};
- [User | Pass] ->
- {User, string:join(Pass, ":")};
_ ->
nil
end;
@@ -158,9 +157,10 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) ->
undefined -> Req;
[] -> Req;
Cookie ->
- [User, TimeStr | HashParts] = try
+ [User, TimeStr, HashStr] = try
AuthSession = couch_util:decodeBase64Url(Cookie),
- [_A, _B | _Cs] = re:split(?b2l(AuthSession), ":", [{return, list}])
+ [_A, _B, _Cs] = re:split(?b2l(AuthSession), ":",
+ [{return, list}, {parts, 3}])
catch
_:_Error ->
Reason = <<"Malformed AuthSession cookie. Please clear your cookies.">>,
@@ -180,7 +180,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) ->
UserSalt = couch_util:get_value(<<"salt">>, UserProps, <<"">>),
FullSecret = <<Secret/binary, UserSalt/binary>>,
ExpectedHash = crypto:sha_mac(FullSecret, User ++ ":" ++ TimeStr),
- Hash = ?l2b(string:join(HashParts, ":")),
+ Hash = ?l2b(HashStr),
Timeout = list_to_integer(
couch_config:get("couch_httpd_auth", "timeout", "600")),
?LOG_DEBUG("timeout ~p", [Timeout]),