summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/test/qa-tests/jstests/bson/bad_files.js
diff options
context:
space:
mode:
authorRamon Fernandez <ramon@mongodb.com>2016-08-25 16:34:34 -0400
committerRamon Fernandez <ramon@mongodb.com>2016-08-25 16:54:18 -0400
commitc330c9991ab45e7d0685d53e699ef26dba065660 (patch)
tree3dc5cd06b5f6c7eaaa4cb20cbe763504c14a772b /src/mongo/gotools/test/qa-tests/jstests/bson/bad_files.js
parenteb62b862d5ebf179a1bcd9f394070e69c30188ab (diff)
downloadmongo-c330c9991ab45e7d0685d53e699ef26dba065660.tar.gz
Import tools: 5b883d86fdb4df55036d5dba2ca6f9dfa0750b44 from branch v3.3
ref: 1ac1389bda..5b883d86fd for: 3.3.12 SERVER-25814 Initial vendor import: tools
Diffstat (limited to 'src/mongo/gotools/test/qa-tests/jstests/bson/bad_files.js')
-rw-r--r--src/mongo/gotools/test/qa-tests/jstests/bson/bad_files.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mongo/gotools/test/qa-tests/jstests/bson/bad_files.js b/src/mongo/gotools/test/qa-tests/jstests/bson/bad_files.js
new file mode 100644
index 00000000000..1728aa1e999
--- /dev/null
+++ b/src/mongo/gotools/test/qa-tests/jstests/bson/bad_files.js
@@ -0,0 +1,41 @@
+// This test makes sure that certain invalid BSON succeeds or fails
+// with both JSON and debug output types AND --objcheck
+(function() {
+ load('jstests/libs/extended_assert.js');
+ var assert = extendedAssert;
+
+ var x = _runMongoProgram("bsondump", "--objcheck", "jstests/bson/testdata/random_bytes.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given random bytes");
+ x = _runMongoProgram("bsondump", "--objcheck", "jstests/bson/testdata/bad_cstring.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given a non-terminated cstring");
+ x = _runMongoProgram("bsondump", "--objcheck", "jstests/bson/testdata/bad_type.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given a bad type value");
+ x = _runMongoProgram("bsondump", "--objcheck", "jstests/bson/testdata/partial_file.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given only the start of a file");
+ x = _runMongoProgram("bsondump", "--objcheck", "jstests/bson/testdata/invalid_field_name.bson");
+ assert.neq(x, 0, "bsondump should exit with an error given invalid field names");
+ x = _runMongoProgram("bsondump", "--objcheck", "--type=debug", "jstests/bson/testdata/random_bytes.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given random bytes");
+ x = _runMongoProgram("bsondump", "--objcheck", "--type=debug", "jstests/bson/testdata/bad_cstring.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given a non-terminated cstring");
+ x = _runMongoProgram("bsondump", "--objcheck", "--type=debug", "jstests/bson/testdata/bad_type.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given a bad type value");
+ x = _runMongoProgram("bsondump", "--objcheck", "--type=debug", "jstests/bson/testdata/partial_file.bson");
+ assert.neq(x, 0, "bsondump should exit with an error when given only the start of a file");
+ x = _runMongoProgram("bsondump", "--objcheck", "--type=debug", "jstests/bson/testdata/invalid_field_name.bson");
+ assert.neq(x, 0, "bsondump should exit with an error given invalid field names");
+
+ // This should pass, but the content of the output might be erroneous
+ x = _runMongoProgram("bsondump", "--objcheck", "jstests/bson/testdata/broken_array.bson");
+ assert.eq(x, 0, "bsondump should exit with success when given a bad array document");
+ x = _runMongoProgram("bsondump", "--objcheck", "--type=debug", "jstests/bson/testdata/broken_array.bson");
+ assert.eq(x, 0, "bsondump should exit with success when given a bad array document");
+
+ // Make sure recoverable cases do not return an error by default
+ clearRawMongoProgramOutput();
+ x = _runMongoProgram("bsondump", "jstests/bson/testdata/bad_cstring.bson");
+ assert.eq(x, 0, "bsondump should not exit with an error when given a non-terminated cstring without --objcheck");
+ assert.strContains.soon("corrupted", rawMongoProgramOutput,
+ "one of the documents should have been labelled as corrupted");
+
+}());