Bug 1535995 - Check that group information is up to date; r=asuth
authorJan Varga <jan.varga@gmail.com>
Mon, 18 Mar 2019 07:14:26 +0100
changeset 506572 93677154ad256f4b7e04c67ba2c28bfe27ad7565
parent 506571 dc47fddd9a63007e027366366652723268e53cbe
child 506573 fe798624cda039ae74289929e35487560d354db2
push id138
push usermtabara@mozilla.com
push dateWed, 20 Mar 2019 18:12:49 +0000
reviewersasuth
bugs1535995
milestone68.0a1
Bug 1535995 - Check that group information is up to date; r=asuth Differential Revision: https://phabricator.services.mozilla.com/D23822
dom/localstorage/test/unit/groupMismatch_profile.zip
dom/localstorage/test/unit/test_groupMismatch.js
dom/localstorage/test/unit/xpcshell.ini
dom/quota/ActorsParent.cpp
dom/quota/test/unit/groupMismatch_profile.zip
dom/quota/test/unit/test_groupMismatch.js
dom/quota/test/unit/xpcshell.ini
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..182b013de0f35607e7655415cde3a3fc558d3d5d
GIT binary patch
literal 1706
zc$^FHW@h1H00I9wxqb{tfP+DXp|~W!C^0=%KQx4sf!WNrGe+01Gp4kHn}Lz#D<cB~
ziwIC%08SGGkW5HPO-n4zDIwCN18620U@<A9q@<u&TU$FVKVL5?u}CjBzbZ2)Cs8*u
zzeF#;C>>%GhaXOxM8JMzo15#moYS4z2*|SsVoNe?(#uUPNlZyBNd#Nj1GKIO)5_$8
z+<(WXr<U|JHa6Ou@7FR`R}VBd-tVHnUqe<yWqx2#P(aSo_4B9AUq5|H#FF-PEJ%(7
z1xMq{qccH{^Z{ZUN*t+MW&{r!1zhed^_j@X`{DVs@YH8dR9>Y$oBrad_)_N9C&pf0
zTwQCwe7*eX^Vdm2-Cr(DMGnl1^K$(h`QG;%fZ~jafq@U<PQBv7oXnC`u+1+6J7Yi?
z&1P=CFDG?8Lp@IGpYqiSG)PNGN=Qj52na|3f|jH^4V?`(9{cCHnd!T{)sSdGwwGr`
zp<i7y`@u^<o;uJt9-zI+MX8A;sqraEdRfI_Tf>+4#eguHt+xFK{SF%lxV-<@73!DC
zY8K-tGa+F8+9TpSzNtl?{3un;>?QdB+_EM)_gUZF9)DwdV7gvl$C|0fJR783dPMdl
zuq004e7I$fFl)u*o59<<e3YJ^+!=6@yEf@T<+D3F*Dp@ZHji8Vu4(Gs#kB=#?|VMx
zo@H!PWmi0>aN|krhAnmJ`$DBc6a%!LIviE6XcT<<MgDi5bnY%IgWH?emp$WN`s96Q
zYV^CZ^KQDFtXg$CTH(y8lNQS@zH|Rb`2|;*Ka*0N8U9RPE?pe3$XDX`{x!YwpSc6P
z8JXmmab;==c;<ZT2%-^LoE4HWF|rD7(*#gVb3!r=k=+TKikaDwP3^&AD&efp3Q6Bs
zZN-)GCEzY-X#7Totw_ZHE2J2}V?Ab;Mp(b3aW*3b)`K%R;Q+wQtjGc2%*23^by*=<
o7mt~k84+S8BiPK{Kr>OZB`YLbVwlLv2GYe2ga?6oE;EC80N9G!?*IS*
new file mode 100644
--- /dev/null
+++ b/dom/localstorage/test/unit/test_groupMismatch.js
@@ -0,0 +1,46 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * This test is mainly to verify that metadata files with old group information
+ * get updated, so writing to local storage won't cause a crash because of null
+ * quota object. See bug 1516333.
+ */
+
+async function testSteps()
+{
+  const principal = getPrincipal("https://foo.bar.mozilla-iot.org");
+
+  info("Clearing");
+
+  let request = clear();
+  await requestFinished(request);
+
+  info("Installing package");
+
+  // The profile contains one initialized origin directory, a script for origin
+  // initialization and the storage database:
+  // - storage/default/https+++foo.bar.mozilla-iot.org
+  // - create_db.js
+  // - storage.sqlite
+  // The file create_db.js in the package was run locally, specifically it was
+  // temporarily added to xpcshell.ini and then executed:
+  //   mach xpcshell-test --interactive dom/localstorage/test/unit/create_db.js
+  // Note: to make it become the profile in the test, additional manual steps
+  // are needed.
+  // 1. Manually change the group in .metadata and .metadata-v2 from
+  //    "bar.mozilla-iot.org" to "mozilla-iot.org".
+  // 2. Remove the folder "storage/temporary".
+  // 3. Remove the file "storage/ls-archive.sqlite".
+  installPackage("groupMismatch_profile");
+
+  info("Getting storage");
+
+  let storage = getLocalStorage(principal);
+
+  info("Adding item");
+
+  storage.setItem("foo", "bar");
+}
--- a/dom/localstorage/test/unit/xpcshell.ini
+++ b/dom/localstorage/test/unit/xpcshell.ini
@@ -2,16 +2,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 [DEFAULT]
 head = head.js
 support-files =
   archive_profile.zip
   corruptedDatabase_profile.zip
+  groupMismatch_profile.zip
   migration_profile.zip
   stringLength_profile.zip
 
 [test_archive.js]
 [test_corruptedDatabase.js]
 [test_databaseShadowing1.js]
 run-sequentially = test_databaseShadowing2.js depends on a file produced by this test
 [test_databaseShadowing2.js]
@@ -25,13 +26,14 @@ run-sequentially = test_databaseShadowin
 [test_databaseShadowing_clearOriginsByPattern2.js]
 run-sequentially = this test depends on a file produced by test_databaseShadowing_clearOriginsByPattern1.js
 [test_databaseShadowing_clearOriginsByPrefix1.js]
 run-sequentially = test_databaseShadowing_clearOriginsByPrefix2.js depends on a file produced by this test
 [test_databaseShadowing_clearOriginsByPrefix2.js]
 run-sequentially = this test depends on a file produced by test_databaseShadowing_clearOriginsByPrefix1.js
 [test_eviction.js]
 [test_groupLimit.js]
+[test_groupMismatch.js]
 [test_migration.js]
 [test_originInit.js]
 [test_snapshotting.js]
 [test_stringLength.js]
 [test_usage.js]
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -3567,16 +3567,76 @@ nsresult QuotaManager::GetDirectoryMetad
 
   // Currently unused (used to be isApp).
   bool dummy;
   rv = binaryStream->ReadBoolean(&dummy);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
+  rv = binaryStream->Close();
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+ if (!origin.EqualsLiteral(kChromeOrigin)) {
+    OriginAttributes originAttributes;
+    nsCString originNoSuffix;
+    if (NS_WARN_IF(!originAttributes.PopulateFromOrigin(origin,
+                                                        originNoSuffix))) {
+      return NS_ERROR_FAILURE;
+    }
+
+    RefPtr<MozURL> url;
+    rv = MozURL::Init(getter_AddRefs(url), originNoSuffix);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+
+    nsCString baseDomain;
+    rv = url->BaseDomain(baseDomain);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return rv;
+    }
+
+    nsCString upToDateGroup = baseDomain + suffix;
+
+    if (group != upToDateGroup) {
+      group = upToDateGroup;
+
+      rv = CreateDirectoryMetadata(
+          aDirectory, timestamp, suffix, group, origin);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+
+      rv = CreateDirectoryMetadata2(
+          aDirectory, timestamp, persisted, suffix, group, origin);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+      }
+
+  #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
+      ContentPrincipalInfo contentPrincipalInfo;
+      contentPrincipalInfo.attrs() = originAttributes;
+      contentPrincipalInfo.originNoSuffix() = originNoSuffix;
+      contentPrincipalInfo.spec() = originNoSuffix;
+      contentPrincipalInfo.baseDomain() = baseDomain;
+
+      PrincipalInfo principalInfo(contentPrincipalInfo);
+
+      nsTArray<PrincipalInfo> principalInfos;
+      principalInfos.AppendElement(principalInfo);
+
+      RefPtr<PrincipalVerifier> principalVerifier =
+          PrincipalVerifier::CreateAndDispatch(std::move(principalInfos));
+  #endif
+    }
+  }
+
   *aTimestamp = timestamp;
   *aPersisted = persisted;
   aSuffix = suffix;
   aGroup = group;
   aOrigin = origin;
   return NS_OK;
 }
 
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..182b013de0f35607e7655415cde3a3fc558d3d5d
GIT binary patch
literal 1706
zc$^FHW@h1H00I9wxqb{tfP+DXp|~W!C^0=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* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * This test is mainly to verify that metadata files with old group information
+ * get updated. See bug 1535995.
+ */
+
+async function testSteps()
+{
+  const principal = getPrincipal("https://foo.bar.mozilla-iot.org");
+  const metadataFile = getRelativeFile(
+    "storage/default/https+++foo.bar.mozilla-iot.org/.metadata-v2");
+
+  async function readMetadataFile() {
+    let file = await File.createFromNsIFile(metadataFile);
+
+    let buffer = await new Promise(resolve => {
+      let reader = new FileReader();
+      reader.onloadend = () => resolve(reader.result);
+      reader.readAsArrayBuffer(file);
+    });
+
+    return buffer;
+  }
+
+  info("Clearing");
+
+  let request = clear();
+  await requestFinished(request);
+
+  info("Installing package");
+
+  // The profile contains one initialized origin directory, a script for origin
+  // initialization and the storage database:
+  // - storage/default/https+++foo.bar.mozilla-iot.org
+  // - create_db.js
+  // - storage.sqlite
+  // The file create_db.js in the package was run locally, specifically it was
+  // temporarily added to xpcshell.ini and then executed:
+  //   mach xpcshell-test --interactive dom/localstorage/test/unit/create_db.js
+  // Note: to make it become the profile in the test, additional manual steps
+  // are needed.
+  // 1. Manually change the group in .metadata and .metadata-v2 from
+  //    "bar.mozilla-iot.org" to "mozilla-iot.org".
+  // 2. Remove the folder "storage/temporary".
+  // 3. Remove the file "storage/ls-archive.sqlite".
+  installPackage("groupMismatch_profile");
+
+  info("Reading out contents of metadata file");
+
+  let metadataBuffer = await readMetadataFile();
+
+  info("Initializing origin");
+
+  request = initOrigin(principal, "default");
+  await requestFinished(request);
+
+  info("Reading out contents of metadata file");
+
+  let metadataBuffer2 = await readMetadataFile();
+
+  info("Verifying blobs differ");
+
+  ok(!compareBuffers(metadataBuffer, metadataBuffer2), "Metadata differ");
+}
--- a/dom/quota/test/unit/xpcshell.ini
+++ b/dom/quota/test/unit/xpcshell.ini
@@ -4,16 +4,17 @@
 
 [DEFAULT]
 head = head.js
 support-files =
   basics_profile.zip
   createLocalStorage_profile.zip
   defaultStorageUpgrade_profile.zip
   getUsage_profile.zip
+  groupMismatch_profile.zip
   idbSubdirUpgrade1_profile.zip
   idbSubdirUpgrade2_profile.zip
   morgueCleanup_profile.zip
   obsoleteOriginAttributes_profile.zip
   originAttributesUpgrade_profile.zip
   removeAppsUpgrade_profile.zip
   removeLocalStorage1_profile.zip
   removeLocalStorage2_profile.zip
@@ -21,16 +22,17 @@ support-files =
   tempMetadataCleanup_profile.zip
   version2_1upgrade_profile.zip
 
 [test_basics.js]
 [test_bad_origin_directory.js]
 [test_createLocalStorage.js]
 [test_defaultStorageUpgrade.js]
 [test_getUsage.js]
+[test_groupMismatch.js]
 [test_idbSubdirUpgrade.js]
 [test_initTemporaryStorage.js]
 [test_morgueCleanup.js]
 [test_obsoleteOriginAttributesUpgrade.js]
 [test_originAttributesUpgrade.js]
 [test_persist.js]
 [test_persist_eviction.js]
 [test_persist_globalLimit.js]