You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2016/04/23 12:26:04 UTC
[08/10] couchdb commit: updated refs/heads/master to 82d2eb1
Harden view sandboxing test
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/46620bdb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/46620bdb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/46620bdb
Branch: refs/heads/master
Commit: 46620bdb031106f922b611449d68b8ce5a06f144
Parents: 0306da2
Author: sebastianro <se...@apache.org>
Authored: Thu Apr 14 20:15:32 2016 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Sat Apr 23 12:25:33 2016 +0200
----------------------------------------------------------------------
test/javascript/tests/view_sandboxing.js | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/46620bdb/test/javascript/tests/view_sandboxing.js
----------------------------------------------------------------------
diff --git a/test/javascript/tests/view_sandboxing.js b/test/javascript/tests/view_sandboxing.js
index 52fd718..2676e7f 100644
--- a/test/javascript/tests/view_sandboxing.js
+++ b/test/javascript/tests/view_sandboxing.js
@@ -18,20 +18,22 @@ couchTests.view_sandboxing = function(debug) {
var doc = {integer: 1, string: "1", array: [1, 2, 3]};
T(db.save(doc).ok);
-/*
+
// make sure that attempting to change the document throws an error
var results = db.query(function(doc) {
doc.integer = 2;
emit(null, doc);
- });
- T(results.total_rows == 0);
+ }, null, {"include_docs": true});
+ // either we have an error or our doc is unchanged
+ T(results.total_rows == 0 || results.rows[0].doc.integer == 1);
var results = db.query(function(doc) {
doc.array[0] = 0;
emit(null, doc);
- });
- T(results.total_rows == 0);
-*/
+ }, null, {"include_docs": true});
+ // either we have an error or our doc is unchanged
+ T(results.total_rows == 0 || results.rows[0].doc.array[0] == 1);
+
// make sure that a view cannot invoke interpreter internals such as the
// garbage collector
var results = db.query(function(doc) {
@@ -123,17 +125,22 @@ couchTests.view_sandboxing = function(debug) {
TEquals(3, view2Results.rows[0].value[2]);
}
- TEquals(1, view2Results.rows[1].value["a"]);
- TEquals(2, view2Results.rows[1].value["b"]);
- TEquals('undefined', typeof view2Results.rows[1].value["c"],
- "doc2.tokens object was not sealed");
+ // we can't be 100% sure about the order for the same key
+ T(view2Results.rows[1].value["a"] == 1 || view2Results.rows[1].value[0] == "foo");
+ T(view2Results.rows[1].value["b"] == 2 || view2Results.rows[1].value[1] == "bar");
+ T(view2Results.rows[2].value["a"] == 1 || view2Results.rows[2].value[0] == "foo");
+ T(view2Results.rows[2].value["b"] == 2 || view2Results.rows[2].value[1] == "bar");
+ TEquals('undefined', typeof view2Results.rows[1].value["c"], "doc2.tokens object was not sealed");
+ TEquals('undefined', typeof view2Results.rows[2].value["c"], "doc2.tokens object was not sealed");
+/* (see above)
TEquals(2, view2Results.rows[2].value.length,
"Warning: installed SpiderMonkey version doesn't allow sealing of arrays");
if (view2Results.rows[2].value.length === 2) {
TEquals("foo", view2Results.rows[2].value[0]);
TEquals("bar", view2Results.rows[2].value[1]);
}
+*/
// cleanup
db.deleteDb();