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

Write commands allow illegal collection names

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.5
    • Affects Version/s: 2.5.4
    • Component/s: None
    • Labels:
      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);

      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
      

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

              Created:
              Updated:
              Resolved: