summaryrefslogtreecommitdiff
path: root/jstests/core/invalid_db_name.js
blob: 23cec76d446d2860813f8d9e8e2f7eaea83327fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Ensures that invalid DB names are reported as write errors
//
// Can't shard collection with invalid db name.
// @tags: [assumes_unsharded_collection]
(function() {
var invalidDB = db.getSiblingDB("NonExistentDB");

// This is a hack to bypass invalid database name checking by the DB constructor
invalidDB._name = "Invalid DB Name";

assert.writeError(invalidDB.coll.insert({x: 1}));

// Ensure that no database was created
var dbList = db.getSiblingDB('admin').runCommand({listDatabases: 1}).databases;
dbList.forEach(function(dbInfo) {
    assert.neq('Invalid DB Name', dbInfo.name, 'database with invalid name was created');
});
}());