From 9db88adebf539338ff2a4c8bc69b8f683fa962c0 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Mon, 18 Mar 2019 07:14:26 +0100 Subject: [PATCH] Bug 1535995 - Check that group information is up to date; r=asuth Differential Revision: https://phabricator.services.mozilla.com/D23822 --- .../test/unit/groupMismatch_profile.zip | Bin 0 -> 1706 bytes .../test/unit/test_groupMismatch.js | 46 ++++++++++++ dom/localstorage/test/unit/xpcshell.ini | 2 + dom/quota/ActorsParent.cpp | 60 ++++++++++++++++ dom/quota/test/unit/groupMismatch_profile.zip | Bin 0 -> 1706 bytes dom/quota/test/unit/test_groupMismatch.js | 68 ++++++++++++++++++ dom/quota/test/unit/xpcshell.ini | 2 + 7 files changed, 178 insertions(+) create mode 100644 dom/localstorage/test/unit/groupMismatch_profile.zip create mode 100644 dom/localstorage/test/unit/test_groupMismatch.js create mode 100644 dom/quota/test/unit/groupMismatch_profile.zip create mode 100644 dom/quota/test/unit/test_groupMismatch.js diff --git a/dom/localstorage/test/unit/groupMismatch_profile.zip b/dom/localstorage/test/unit/groupMismatch_profile.zip new file mode 100644 index 0000000000000000000000000000000000000000..182b013de0f35607e7655415cde3a3fc558d3d5d GIT binary patch literal 1706 zcmWIWW@h1H00I9wxqe^x?O_;AUWC`O3(^ zz#;-v8-UXU0VESrQqvMkb4rLb=>VEr46vA#QBqP+tgWq`mY=Velvt#fn_rcglar{M znO~xpUz859i38|f9Bu}=or8gGZm!>QPIqP_AkQ9%Ey=J+FE_O$F(t7i5gbfCKr2BQ zEtrxMa{nElo?6n^*w|=qzF*5&T|Lm;c)yGOehpa-mHB}|K>;~S*Uz6efBp0+5lh;z&?%G`>7K6XZxAAhw~zk-B9@V0VIoMgf;QOMNCX@_u;!EIjqu6O~tK&!)e4 zD!!Dt^@*{U7gyKXFJCWz`uug0Q1_P$Qy~ce;?9fna{V0n-uD{--N?Yiz`%!ar(SVk zPG(6e*yfjkoiQMc7DC*7Ury?HhI*XVKjo_vXpokWl#r5A5D<_61T9H-8af+nJoe9X zGt+l@t0B>XY%kA>Lch9Z_Jfyz)~W;3B@fWvk9SDWHpO%l$j8)e(e$Q9pBUNe{NZmocpZrZjZmQJuqD_ zuw%{CW1bCCE&u>TFMaa9Gd22M*?BizPFAft9j$QY)Jcow7T>vlr2K-b%%4dq&J2I1FPAP3 zSmZ15d;gkV`On+|-i%Cg%(ybO1SoERK!D+`BZx+1aaKqcM++Z(rU@`0o92XM8X~(B zHWf3oBb(ZT#Z#-C8kf6ksr4iOIX`BsA z#IT5g1tlR*!>tEraKZtAnOPAoXlQf>W?!fa;8_=FCYEfA>?_QS2r(1r9blmD2AYYQ bErBLt$&vxytZYCH4D3L75UA%eGl&NO*oxZk literal 0 HcmV?d00001 diff --git a/dom/localstorage/test/unit/test_groupMismatch.js b/dom/localstorage/test/unit/test_groupMismatch.js new file mode 100644 index 000000000000..a238a1349abd --- /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"); +} diff --git a/dom/localstorage/test/unit/xpcshell.ini b/dom/localstorage/test/unit/xpcshell.ini index f02b594c313d..cc1b6193d304 100644 --- a/dom/localstorage/test/unit/xpcshell.ini +++ b/dom/localstorage/test/unit/xpcshell.ini @@ -7,6 +7,7 @@ head = head.js support-files = archive_profile.zip corruptedDatabase_profile.zip + groupMismatch_profile.zip migration_profile.zip stringLength_profile.zip @@ -30,6 +31,7 @@ run-sequentially = test_databaseShadowing_clearOriginsByPrefix2.js depends on a 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] diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index 71ec93889e70..a5f4cc24d4df 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -3572,6 +3572,66 @@ nsresult QuotaManager::GetDirectoryMetadata2( 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 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 principalInfos; + principalInfos.AppendElement(principalInfo); + + RefPtr principalVerifier = + PrincipalVerifier::CreateAndDispatch(std::move(principalInfos)); + #endif + } + } + *aTimestamp = timestamp; *aPersisted = persisted; aSuffix = suffix; diff --git a/dom/quota/test/unit/groupMismatch_profile.zip b/dom/quota/test/unit/groupMismatch_profile.zip new file mode 100644 index 0000000000000000000000000000000000000000..182b013de0f35607e7655415cde3a3fc558d3d5d GIT binary patch literal 1706 zcmWIWW@h1H00I9wxqe^x?O_;AUWC`O3(^ zz#;-v8-UXU0VESrQqvMkb4rLb=>VEr46vA#QBqP+tgWq`mY=Velvt#fn_rcglar{M znO~xpUz859i38|f9Bu}=or8gGZm!>QPIqP_AkQ9%Ey=J+FE_O$F(t7i5gbfCKr2BQ zEtrxMa{nElo?6n^*w|=qzF*5&T|Lm;c)yGOehpa-mHB}|K>;~S*Uz6efBp0+5lh;z&?%G`>7K6XZxAAhw~zk-B9@V0VIoMgf;QOMNCX@_u;!EIjqu6O~tK&!)e4 zD!!Dt^@*{U7gyKXFJCWz`uug0Q1_P$Qy~ce;?9fna{V0n-uD{--N?Yiz`%!ar(SVk zPG(6e*yfjkoiQMc7DC*7Ury?HhI*XVKjo_vXpokWl#r5A5D<_61T9H-8af+nJoe9X zGt+l@t0B>XY%kA>Lch9Z_Jfyz)~W;3B@fWvk9SDWHpO%l$j8)e(e$Q9pBUNe{NZmocpZrZjZmQJuqD_ zuw%{CW1bCCE&u>TFMaa9Gd22M*?BizPFAft9j$QY)Jcow7T>vlr2K-b%%4dq&J2I1FPAP3 zSmZ15d;gkV`On+|-i%Cg%(ybO1SoERK!D+`BZx+1aaKqcM++Z(rU@`0o92XM8X~(B zHWf3oBb(ZT#Z#-C8kf6ksr4iOIX`BsA z#IT5g1tlR*!>tEraKZtAnOPAoXlQf>W?!fa;8_=FCYEfA>?_QS2r(1r9blmD2AYYQ bErBLt$&vxytZYCH4D3L75UA%eGl&NO*oxZk literal 0 HcmV?d00001 diff --git a/dom/quota/test/unit/test_groupMismatch.js b/dom/quota/test/unit/test_groupMismatch.js new file mode 100644 index 000000000000..f0e8edafabfa --- /dev/null +++ b/dom/quota/test/unit/test_groupMismatch.js @@ -0,0 +1,68 @@ +/** + * 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"); +} diff --git a/dom/quota/test/unit/xpcshell.ini b/dom/quota/test/unit/xpcshell.ini index 019e4d731f99..d1dcde3dca18 100644 --- a/dom/quota/test/unit/xpcshell.ini +++ b/dom/quota/test/unit/xpcshell.ini @@ -9,6 +9,7 @@ support-files = createLocalStorage_profile.zip defaultStorageUpgrade_profile.zip getUsage_profile.zip + groupMismatch_profile.zip idbSubdirUpgrade1_profile.zip idbSubdirUpgrade2_profile.zip morgueCleanup_profile.zip @@ -26,6 +27,7 @@ support-files = [test_createLocalStorage.js] [test_defaultStorageUpgrade.js] [test_getUsage.js] +[test_groupMismatch.js] [test_idbSubdirUpgrade.js] [test_initTemporaryStorage.js] [test_morgueCleanup.js]