Bug 790397: set deleted = false for each record stored via PUT or POST.
authorNick Alexander <nalexander@mozilla.com>
Tue, 11 Sep 2012 17:22:21 -0700
changeset 111073 7d1bd831b95dc4a11e73f1ad43efa869ad09dfaf
parent 111071 d4e5dcfca00dde4af38015224282d265970cc101
child 111074 2a728027d8f65e8e7ff279b25347e3dba7dc3cac
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
bugs790397
milestone18.0a1
Bug 790397: set deleted = false for each record stored via PUT or POST.
services/common/modules-testing/storageserver.js
services/common/tests/unit/test_storage_server.js
--- a/services/common/modules-testing/storageserver.js
+++ b/services/common/modules-testing/storageserver.js
@@ -244,16 +244,17 @@ ServerBSO.prototype = {
         default:
           this._log.warn("Unexpected field in BSO record: " + key);
           sendMozSvcError(request, response, "8");
           return true;
       }
     }
 
     this.modified = request.timestamp;
+    this.deleted = false;
     response.setHeader("X-Last-Modified", "" + this.modified, false);
 
     response.setStatusLine(request.httpVersion, code, status);
   },
 };
 
 /**
  * Represent a collection on the server.
@@ -545,16 +546,17 @@ StorageServerCollection.prototype = {
           this._log.debug("Creating BSO " + JSON.stringify(record.id) +
                           " on the fly.");
           bso = new ServerBSO(record.id);
           this.insertBSO(bso);
         }
         if (bso) {
           bso.payload = record.payload;
           bso.modified = timestamp;
+          bso.deleted = false;
           success.push(record.id);
 
           if (record.sortindex) {
             bso.sortindex = parseInt(record.sortindex, 10);
           }
 
         } else {
           failed[record.id] = "no bso configured";
--- a/services/common/tests/unit/test_storage_server.js
+++ b/services/common/tests/unit/test_storage_server.js
@@ -587,8 +587,51 @@ add_test(function test_x_num_records() {
     let col = localRequest("/2.0/123/storage/crypto");
     col.get(function (err) {
       // Collection fetches do.
       do_check_eq(this.response.headers["x-num-records"], "2");
       server.stop(run_next_test);
     });
   });
 });
+
+add_test(function test_put_delete_put() {
+  _("Bug 790397: Ensure BSO deleted flag is reset on PUT.");
+
+  let server = new StorageServer();
+  server.registerUser("123", "password");
+  server.createContents("123", {
+    test: {bso: {foo: "bar"}}
+  });
+  server.startSynchronous(PORT);
+
+  _("Ensure we can PUT an existing record.");
+  let request1 = localRequest("/2.0/123/storage/test/bso", "123", "password");
+  request1.setHeader("Content-Type", "application/json");
+  let payload1 = JSON.stringify({"payload": "foobar"});
+  let error1 = doPutRequest(request1, payload1);
+  do_check_eq(null, error1);
+  do_check_eq(request1.response.status, 204);
+
+  _("Ensure we can DELETE it.");
+  let request2 = localRequest("/2.0/123/storage/test/bso", "123", "password");
+  let error2 = doDeleteRequest(request2);
+  do_check_eq(error2, null);
+  do_check_eq(request2.response.status, 204);
+  do_check_false("content-type" in request2.response.headers);
+
+  _("Ensure we can PUT a previously deleted record.");
+  let request3 = localRequest("/2.0/123/storage/test/bso", "123", "password");
+  request3.setHeader("Content-Type", "application/json");
+  let payload3 = JSON.stringify({"payload": "foobar"});
+  let error3 = doPutRequest(request3, payload3);
+  do_check_eq(null, error3);
+  do_check_eq(request3.response.status, 201);
+
+  _("Ensure we can GET the re-uploaded record.");
+  let request4 = localRequest("/2.0/123/storage/test/bso", "123", "password");
+  let error4 = doGetRequest(request4);
+  do_check_eq(error4, null);
+  do_check_eq(request4.response.status, 200);
+  do_check_eq(request4.response.headers["content-type"], "application/json");
+
+  server.stop(run_next_test);
+});