summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/jstests.cpp
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@mongodb.com>2020-01-08 21:05:40 +0000
committerevergreen <evergreen@mongodb.com>2020-01-08 21:05:40 +0000
commit11911e624ececb7546350f79c30f2abd45af5d92 (patch)
tree6fd07e5920fe093b1d602e3848b4a102fb005c53 /src/mongo/dbtests/jstests.cpp
parenta1a1e4f0c14ab71a5fc8bc7913af25571089b65f (diff)
downloadmongo-11911e624ececb7546350f79c30f2abd45af5d92.tar.gz
SERVER-45361 Sanitize random seeds for mongo shell
Diffstat (limited to 'src/mongo/dbtests/jstests.cpp')
-rw-r--r--src/mongo/dbtests/jstests.cpp38
1 files changed, 1 insertions, 37 deletions
diff --git a/src/mongo/dbtests/jstests.cpp b/src/mongo/dbtests/jstests.cpp
index 635fbd3088b..5efcb146d5e 100644
--- a/src/mongo/dbtests/jstests.cpp
+++ b/src/mongo/dbtests/jstests.cpp
@@ -1452,34 +1452,13 @@ public:
ASSERT_EQUALS(scopeShardKey, trueShardKey);
}
- void checkWithSeed(shared_ptr<Scope> s, const mongo::BSONObj& o, int seed) {
- s->setObject("o", o, true);
- s->setNumber("seed", seed);
- s->invoke("return convertShardKeyToHashed(o, seed);", nullptr, nullptr);
- const auto scopeShardKey = s->getNumber("__returnValue");
-
- // Wrapping to form a proper element
- const auto wrapO = BSON("" << o);
- const auto e = wrapO[""];
- const auto trueShardKey = mongo::BSONElementHasher::hash64(e, seed);
-
- ASSERT_EQUALS(scopeShardKey, trueShardKey);
- }
-
void checkNoArgs(shared_ptr<Scope> s) {
s->invoke("return convertShardKeyToHashed();", nullptr, nullptr);
}
void checkWithExtraArg(shared_ptr<Scope> s, const mongo::BSONObj& o, int seed) {
s->setObject("o", o, true);
- s->setNumber("seed", seed);
- s->invoke("return convertShardKeyToHashed(o, seed, 1);", nullptr, nullptr);
- }
-
- void checkWithBadSeed(shared_ptr<Scope> s, const mongo::BSONObj& o) {
- s->setObject("o", o, true);
- s->setString("seed", "sunflower");
- s->invoke("return convertShardKeyToHashed(o, seed);", nullptr, nullptr);
+ s->invoke("return convertShardKeyToHashed(o, 1);", nullptr, nullptr);
}
void run() {
@@ -1499,23 +1478,8 @@ public:
BSON("A" << 1 << "B"
<< "Shardy"));
- // Check a few different seeds
- checkWithSeed(s,
- BSON(""
- << "Shardy"),
- mongo::BSONElementHasher::DEFAULT_HASH_SEED);
- checkWithSeed(s,
- BSON(""
- << "Shardy"),
- 0);
- checkWithSeed(s,
- BSON(""
- << "Shardy"),
- -1);
-
ASSERT_THROWS(checkNoArgs(s), mongo::DBException);
ASSERT_THROWS(checkWithExtraArg(s, BSON("" << 10.0), 0), mongo::DBException);
- ASSERT_THROWS(checkWithBadSeed(s, BSON("" << 1)), mongo::DBException);
}
};