Skip to content

Commit

Permalink
COUCHDB-945 - ensure validation funs are still applied after compaction.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1033640 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rnewson committed Nov 10, 2010
1 parent 61a64a2 commit 1f7e7cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
21 changes: 14 additions & 7 deletions share/www/script/test/security_validation.js
Expand Up @@ -136,13 +136,20 @@ couchTests.security_validation = function(debug) {
doc.foo=2; doc.foo=2;
T(userDb.save(doc).ok); T(userDb.save(doc).ok);


// Save a document that's missing an author field. // Save a document that's missing an author field (before and after compaction)
try { for (var i=0; i<2; i++) {
userDb.save({foo:1}); try {
T(false && "Can't get here. Should have thrown an error 2"); userDb.save({foo:1});
} catch (e) { T(false && "Can't get here. Should have thrown an error 2");
T(e.error == "forbidden"); } catch (e) {
T(userDb.last_req.status == 403); T(e.error == "forbidden");
T(userDb.last_req.status == 403);
}
// compact.
T(db.compact().ok);
T(db.last_req.status == 202);
// compaction isn't instantaneous, loop until done
while (db.info().compact_running) {};
} }


// Now attempt to update the document as a different user, Jan // Now attempt to update the document as a different user, Jan
Expand Down
5 changes: 3 additions & 2 deletions src/couchdb/couch_db_updater.erl
Expand Up @@ -186,9 +186,10 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
couch_file:delete(RootDir, Filepath), couch_file:delete(RootDir, Filepath),
ok = file:rename(CompactFilepath, Filepath), ok = file:rename(CompactFilepath, Filepath),
close_db(Db), close_db(Db),
ok = gen_server:call(Db#db.main_pid, {db_updated, NewDb2}, infinity), NewDb3 = refresh_validate_doc_funs(NewDb2),
ok = gen_server:call(Db#db.main_pid, {db_updated, NewDb3}, infinity),
?LOG_INFO("Compaction for db \"~s\" completed.", [Db#db.name]), ?LOG_INFO("Compaction for db \"~s\" completed.", [Db#db.name]),
{noreply, NewDb2#db{compactor_pid=nil}}; {noreply, NewDb3#db{compactor_pid=nil}};
false -> false ->
?LOG_INFO("Compaction file still behind main file " ?LOG_INFO("Compaction file still behind main file "
"(update seq=~p. compact update seq=~p). Retrying.", "(update seq=~p. compact update seq=~p). Retrying.",
Expand Down

0 comments on commit 1f7e7cb

Please sign in to comment.