Permalink
Browse files

Merge branch 'trunk' into updater_dedicated_fd

  • Loading branch information...
2 parents 3f87e10 + 0232ac2 commit 8a41d2b1f6e8b928b7fede5150c836bcec0c82c1 @fdmanana committed Dec 7, 2010
View
@@ -243,7 +243,7 @@ fi
erlang_version_error="The installed Erlang version is less than 5.6.5 (R12B05)."
-version="`${ERL} -version 2>&1 | ${SED} "s/[[^0-9]]/ /g"`"
+version="`${ERL} -version 2>&1 | ${SED} 's/[[^0-9]]/ /g'`"
if test `echo $version | ${AWK} "{print \\$1}"` -lt 5; then
AC_MSG_ERROR([$erlang_version_error])
@@ -42,15 +42,15 @@ couchTests.attachment_ranges = function(debug) {
TEquals("bytes 0-28/29", xhr.getResponseHeader("Content-Range"));
TEquals("29", xhr.getResponseHeader("Content-Length"));
- // Fetch the whole entity without an end offset is a 206.
+ // Fetch the whole entity without an end offset is a 200.
var xhr = CouchDB.request("GET", "/test_suite_db/bin_doc/foo.txt", {
headers: {
"Range": "bytes=0-"
}
});
- TEquals(206, xhr.status, "fetch 0-");
+ TEquals(200, xhr.status, "fetch 0-");
TEquals("This is a base64 encoded text", xhr.responseText);
- TEquals("bytes 0-28/29", xhr.getResponseHeader("Content-Range"));
+ TEquals(null, xhr.getResponseHeader("Content-Range"));
TEquals("29", xhr.getResponseHeader("Content-Length"));
// Badly formed range header is a 200.
@@ -374,8 +374,11 @@ couchTests.changes = function(debug) {
filters: {
foo:
'fun({Doc}, Req) -> ' +
- ' Value = couch_util:get_value(<<"value">>, Doc),' +
- ' (Value rem 2) =:= 0' +
+ ' case couch_util:get_value(<<"value">>, Doc) of' +
+ ' undefined -> false;' +
+ ' Value -> (Value rem 2) =:= 0;' +
+ ' _ -> false' +
+ ' end ' +
'end.'
}
};
@@ -712,7 +712,7 @@ couchTests.replication = function(debug) {
);
T(false, "replication should have failed");
} catch(x) {
- T(x.error === "db_not_found");
+ T(x.error === "unauthorized");
}
atts_ddoc_copy = dbB.open(atts_ddoc._id);
@@ -101,7 +101,9 @@ handle_replicate_req(#httpd{method='POST'}=Req) ->
end
catch
throw:{db_not_found, Msg} ->
- send_json(Req, 404, {[{error, db_not_found}, {reason, Msg}]})
+ send_json(Req, 404, {[{error, db_not_found}, {reason, Msg}]});
+ throw:{unauthorized, Msg} ->
+ send_json(Req, 404, {[{error, unauthorized}, {reason, Msg}]})
end;
handle_replicate_req(Req) ->
send_method_not_allowed(Req, "POST").
@@ -186,7 +186,14 @@ ddoc(State, {DDoc}, [FunPath, Args]) ->
ddoc(State, {_, Fun}, [<<"validate_doc_update">>], Args) ->
{State, (catch apply(Fun, Args))};
ddoc(State, {_, Fun}, [<<"filters">>|_], [Docs, Req]) ->
- Resp = lists:map(fun(Doc) -> (catch Fun(Doc, Req)) =:= true end, Docs),
+ FilterFunWrapper = fun(Doc) ->
+ case catch Fun(Doc, Req) of
+ true -> true;
+ false -> false;
+ {'EXIT', Error} -> ?LOG_ERROR("~p", [Error])
+ end
+ end,
+ Resp = lists:map(FilterFunWrapper, Docs),
{State, [true, Resp]};
ddoc(State, {_, Fun}, [<<"shows">>|_], Args) ->
Resp = case (catch apply(Fun, Args)) of
View
@@ -121,8 +121,12 @@ get_result(Server, {BaseId, _Extension}, {Props} = PostBody, UserCtx) ->
end.
init(InitArgs) ->
- try do_init(InitArgs)
- catch throw:{db_not_found, DbUrl} -> {stop, {db_not_found, DbUrl}} end.
+ try
+ do_init(InitArgs)
+ catch
+ throw:Error ->
+ {stop, Error}
+ end.
do_init([RepId, {PostProps} = RepDoc, UserCtx] = InitArgs) ->
process_flag(trap_exit, true),
@@ -308,13 +312,19 @@ start_replication_server(Replicator) ->
?LOG_DEBUG("replication ~p already running at ~p", [RepId, Pid]),
Pid;
{error, {db_not_found, DbUrl}} ->
- throw({db_not_found, <<"could not open ", DbUrl/binary>>})
+ throw({db_not_found, <<"could not open ", DbUrl/binary>>});
+ {error, {unauthorized, DbUrl}} ->
+ throw({unauthorized,
+ <<"unauthorized to access database ", DbUrl/binary>>})
end;
{error, {already_started, Pid}} ->
?LOG_DEBUG("replication ~p already running at ~p", [RepId, Pid]),
Pid;
{error, {{db_not_found, DbUrl}, _}} ->
- throw({db_not_found, <<"could not open ", DbUrl/binary>>})
+ throw({db_not_found, <<"could not open ", DbUrl/binary>>});
+ {error, {{unauthorized, DbUrl}, _}} ->
+ throw({unauthorized,
+ <<"unauthorized to access database ", DbUrl/binary>>})
end.
compare_replication_logs(SrcDoc, TgtDoc) ->
@@ -597,18 +607,24 @@ open_db(<<"http://",_/binary>>=Url, _, ProxyParams, CreateTarget) ->
open_db(<<"https://",_/binary>>=Url, _, ProxyParams, CreateTarget) ->
open_db({[{<<"url">>,Url}]}, [], ProxyParams, CreateTarget);
open_db(<<DbName/binary>>, UserCtx, _ProxyParams, CreateTarget) ->
- case CreateTarget of
- true ->
- ok = couch_httpd:verify_is_server_admin(UserCtx),
- couch_server:create(DbName, [{user_ctx, UserCtx}]);
- false -> ok
- end,
+ try
+ case CreateTarget of
+ true ->
+ ok = couch_httpd:verify_is_server_admin(UserCtx),
+ couch_server:create(DbName, [{user_ctx, UserCtx}]);
+ false ->
+ ok
+ end,
- case couch_db:open(DbName, [{user_ctx, UserCtx}]) of
- {ok, Db} ->
- couch_db:monitor(Db),
- Db;
- {not_found, no_db_file} -> throw({db_not_found, DbName})
+ case couch_db:open(DbName, [{user_ctx, UserCtx}]) of
+ {ok, Db} ->
+ couch_db:monitor(Db),
+ Db;
+ {not_found, no_db_file} ->
+ throw({db_not_found, DbName})
+ end
+ catch throw:{unauthorized, _} ->
+ throw({unauthorized, DbName})
end.
schedule_checkpoint(#state{checkpoint_scheduled = nil} = State) ->
@@ -103,6 +103,8 @@ db_exists(Req, CanonicalUrl, CreateDB) ->
{ok, "303", RespHeaders, _} ->
RedirectUrl = redirect_url(RespHeaders, Req#http_db.url),
db_exists(Req#http_db{method = get, url = RedirectUrl}, CanonicalUrl);
+ {ok, "401", _, _} ->
+ throw({unauthorized, ?l2b(Url)});
Error ->
?LOG_DEBUG("DB at ~s could not be found because ~p", [Url, Error]),
throw({db_not_found, ?l2b(Url)})

0 comments on commit 8a41d2b

Please sign in to comment.