Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11968

Write commands allow illegal collection names

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.5.5
    • 2.5.4
    • None
    • None
    • ALL
    • Hide

      //
      // Ensures that mongod respects the batch write protocols
      //
       
      var collectionName = "batch_write_protocol";
      var coll = db.getCollection(collectionName);
       
      jsTest.log("Starting insert tests...");
       
      coll.remove({});
       
      var request;
      var result;
       
      // Drop collection
      coll.dropIndexes();
      coll.drop();
       
      //
      // Illegal collection name should fail
      var illegalCollectionName = "A\0Z";
      request = {insert : illegalCollectionName, documents : [{a : 1}], writeConcern:{w:1}, ordered: true};
      result = coll.runCommand(request)
      assert.eq(0, result.ok);
      assert.eq('number', typeof result.code);
      assert.eq('string', typeof result.errmsg);
       
      request = {update : illegalCollectionName, updates: [
      	{q: {a:1}, u: {$set: {a:1}, upsert:true}}
      ], writeConcern:{w:1}, ordered:true};
      result = coll.runCommand(request)
      assert.eq(0, result.ok);
      assert.eq('number', typeof result.code);
      assert.eq('string', typeof result.errmsg);
       
      request = {delete : illegalCollectionName, deletes: [
      	{q:{a:1}, top:0}
      ], writeConcern:{w:1}, ordered:true};
      result = coll.runCommand(request)
      assert.eq(0, result.ok);
      assert.eq('number', typeof result.code);
      assert.eq('string', typeof result.errmsg);

      Show
      // // Ensures that mongod respects the batch write protocols //   var collectionName = "batch_write_protocol"; var coll = db.getCollection(collectionName);   jsTest.log("Starting insert tests...");   coll.remove({});   var request; var result;   // Drop collection coll.dropIndexes(); coll.drop();   // // Illegal collection name should fail var illegalCollectionName = "A\0Z"; request = {insert : illegalCollectionName, documents : [{a : 1}], writeConcern:{w:1}, ordered: true}; result = coll.runCommand(request) assert.eq(0, result.ok); assert.eq('number', typeof result.code); assert.eq('string', typeof result.errmsg);   request = {update : illegalCollectionName, updates: [ {q: {a:1}, u: {$set: {a:1}, upsert:true}} ], writeConcern:{w:1}, ordered:true}; result = coll.runCommand(request) assert.eq(0, result.ok); assert.eq('number', typeof result.code); assert.eq('string', typeof result.errmsg);   request = {delete : illegalCollectionName, deletes: [ {q:{a:1}, top:0} ], writeConcern:{w:1}, ordered:true}; result = coll.runCommand(request) assert.eq(0, result.ok); assert.eq('number', typeof result.code); assert.eq('string', typeof result.errmsg);

    Description

      null bytes in collection name does not trigger an error

      result after running the test

      > show dbs
      local  0.078GB
      test   0.078GB
      admin  (empty)
      > use test
      switched to db test
      > show collections
      A
      batch_write_protocol
      system.indexes

      Attachments

        Activity

          People

            randolph@mongodb.com Randolph Tan
            christkv Christian Amor Kvalheim
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: