Bug 1656947 - Vendor application-services to import fix on webext-storage component. r=markh

Differential Revision: https://phabricator.services.mozilla.com/D86487
This commit is contained in:
Luca Greco 2020-08-10 00:32:24 +00:00
parent 9fb7a14b52
commit e4fa86648a
10 changed files with 94 additions and 34 deletions

View file

@ -20,7 +20,7 @@ rev = "63325444ae3388599f2f222775eebdde4c2f9f30"
[source."https://github.com/mozilla/application-services"]
git = "https://github.com/mozilla/application-services"
replace-with = "vendored-sources"
rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b"
rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26"
[source."https://github.com/mozilla-spidermonkey/jsparagus"]
git = "https://github.com/mozilla-spidermonkey/jsparagus"

26
Cargo.lock generated
View file

@ -1318,7 +1318,7 @@ checksum = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
[[package]]
name = "error-support"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"failure",
]
@ -1663,7 +1663,7 @@ dependencies = [
[[package]]
name = "fxa-client"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"base64 0.12.0",
"byteorder",
@ -2349,7 +2349,7 @@ dependencies = [
[[package]]
name = "interrupt-support"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
[[package]]
name = "intl-memoizer"
@ -3307,7 +3307,7 @@ dependencies = [
[[package]]
name = "nss"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"base64 0.12.0",
"error-support",
@ -3321,12 +3321,12 @@ dependencies = [
[[package]]
name = "nss_build_common"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
[[package]]
name = "nss_sys"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"nss_build_common",
]
@ -3985,7 +3985,7 @@ dependencies = [
[[package]]
name = "rc_crypto"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"base64 0.12.0",
"ece",
@ -4578,7 +4578,7 @@ dependencies = [
[[package]]
name = "sql-support"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"ffi-support",
"interrupt-support",
@ -4776,7 +4776,7 @@ dependencies = [
[[package]]
name = "sync-guid"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"base64 0.12.0",
"rand",
@ -4787,7 +4787,7 @@ dependencies = [
[[package]]
name = "sync15"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"base16",
"base64 0.12.0",
@ -4810,7 +4810,7 @@ dependencies = [
[[package]]
name = "sync15-traits"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"failure",
"ffi-support",
@ -5395,7 +5395,7 @@ checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
[[package]]
name = "viaduct"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"failure",
"failure_derive",
@ -5517,7 +5517,7 @@ dependencies = [
[[package]]
name = "webext-storage"
version = "0.1.0"
source = "git+https://github.com/mozilla/application-services?rev=61dcc364ac0d6d0816ab88a494bbf20d824b009b#61dcc364ac0d6d0816ab88a494bbf20d824b009b"
source = "git+https://github.com/mozilla/application-services?rev=9ba519a5739b1976f1d333923d34b7f4916b9e26#9ba519a5739b1976f1d333923d34b7f4916b9e26"
dependencies = [
"error-support",
"failure",

View file

@ -21,4 +21,4 @@ nsstring = { path = "../../../../xpcom/rust/nsstring" }
xpcom = { path = "../../../../xpcom/rust/xpcom" }
storage_variant = { path = "../../../../storage/variant" }
thin-vec = { version = "0.1", features = ["gecko-ffi"] }
fxa-client = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b", features = ["gecko"] }
fxa-client = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26", features = ["gecko"] }

View file

@ -8,14 +8,14 @@ edition = "2018"
[dependencies]
atomic_refcell = "0.1"
cstr = "0.1"
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b" }
interrupt-support = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26" }
log = "0.4"
moz_task = { path = "../../../xpcom/rust/moz_task" }
nserror = { path = "../../../xpcom/rust/nserror" }
nsstring = { path = "../../../xpcom/rust/nsstring" }
serde_json = "1"
storage_variant = { path = "../../../storage/variant" }
sync15-traits = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b" }
sync15-traits = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26" }
xpcom = { path = "../../../xpcom/rust/xpcom" }
[dependencies.thin-vec]

View file

@ -1 +1 @@
{"files":{"Cargo.toml":"ffce3f5619bd479ed23e09780ed814f7e2b16a7b82e21cc00b2b91373e205d44","README.md":"1fd617294339930ee1ad5172377648b268cce0216fc3971facbfe7c6839e9ab1","build.rs":"2b827a62155a3d724cdb4c198270ea467439e537403f82fa873321ac55a69a63","sql/create_schema.sql":"cbb6d432e578c69614199f9e82f8103da5c1f6df5d7af4f77ea1be5869000b26","sql/create_sync_temp_tables.sql":"76517b1ec8022ca2ef53cf8c98b2ad0c289e7f2e2eb2a4b7abb7ad441fe27c6c","src/api.rs":"ec63be053b1142f84f443053ba325d521dd87f6f9de9caec7f5eef0c90b4d64d","src/db.rs":"e04f19ab2e3da4423ce49d43b6c9a6d86be4e573f54421061bea04ef875afb2a","src/error.rs":"c956152633ad6c787f8b7322b619f807354d4c3cb2ecc35c549c3b4bcd98079e","src/lib.rs":"373734d481e7bbd6a49a769d1212686c6f4105ba1eba985624d48208df91d174","src/migration.rs":"ca655d8e556c90e2aebb672bc3e2ad86192854459e4c1a1cfc89cc28156e7abb","src/schema.rs":"cd5a03c2d2dc1eebdea30054c6f6a7a6b302184e9ad1f40de659f6b972c481cf","src/store.rs":"f73c0eac2353d2aa9b64f779998f2d7a1b4576b331a55c2c1acedc32833e5478","src/sync/bridge.rs":"e60fec0f8f167f893bb2055f4623c9cc4dc6921acafd13dcc4e6cfd228b3cb42","src/sync/incoming.rs":"0bcbe042340a9989ce9d18dde5eb38e81580d824d9496c34d890ff8a18f92730","src/sync/mod.rs":"7255fa036635de1ab9223ccdb34fc6164e6978024ae480a9268743a203860448","src/sync/outgoing.rs":"2e0434359ba5005d730aebdac2e29980005f56e62003d89e7def78fcf8d13c5a","src/sync/sync_tests.rs":"e2c665046f3ad2a665eee2b5b33a89ae8804af42bf93fe7b2694280eb5b2a9cc"},"package":null}
{"files":{"Cargo.toml":"ffce3f5619bd479ed23e09780ed814f7e2b16a7b82e21cc00b2b91373e205d44","README.md":"1fd617294339930ee1ad5172377648b268cce0216fc3971facbfe7c6839e9ab1","build.rs":"2b827a62155a3d724cdb4c198270ea467439e537403f82fa873321ac55a69a63","sql/create_schema.sql":"cbb6d432e578c69614199f9e82f8103da5c1f6df5d7af4f77ea1be5869000b26","sql/create_sync_temp_tables.sql":"76517b1ec8022ca2ef53cf8c98b2ad0c289e7f2e2eb2a4b7abb7ad441fe27c6c","src/api.rs":"85e337f7e506a41891eb745791e23f909adef0c9783f14e7fb0f97385bec9637","src/db.rs":"e04f19ab2e3da4423ce49d43b6c9a6d86be4e573f54421061bea04ef875afb2a","src/error.rs":"c956152633ad6c787f8b7322b619f807354d4c3cb2ecc35c549c3b4bcd98079e","src/lib.rs":"373734d481e7bbd6a49a769d1212686c6f4105ba1eba985624d48208df91d174","src/migration.rs":"ca655d8e556c90e2aebb672bc3e2ad86192854459e4c1a1cfc89cc28156e7abb","src/schema.rs":"cd5a03c2d2dc1eebdea30054c6f6a7a6b302184e9ad1f40de659f6b972c481cf","src/store.rs":"f73c0eac2353d2aa9b64f779998f2d7a1b4576b331a55c2c1acedc32833e5478","src/sync/bridge.rs":"e60fec0f8f167f893bb2055f4623c9cc4dc6921acafd13dcc4e6cfd228b3cb42","src/sync/incoming.rs":"0bcbe042340a9989ce9d18dde5eb38e81580d824d9496c34d890ff8a18f92730","src/sync/mod.rs":"7255fa036635de1ab9223ccdb34fc6164e6978024ae480a9268743a203860448","src/sync/outgoing.rs":"2e0434359ba5005d730aebdac2e29980005f56e62003d89e7def78fcf8d13c5a","src/sync/sync_tests.rs":"e2c665046f3ad2a665eee2b5b33a89ae8804af42bf93fe7b2694280eb5b2a9cc"},"package":null}

View file

@ -23,6 +23,12 @@ pub const SYNC_MAX_ITEMS: usize = 512;
type JsonMap = Map<String, JsonValue>;
enum StorageChangeOp {
Clear,
Set(JsonValue),
SetWithoutQuota(JsonValue),
}
fn get_from_db(conn: &Connection, ext_id: &str) -> Result<Option<JsonMap>> {
Ok(
match conn.try_query_one::<String>(
@ -42,13 +48,14 @@ fn get_from_db(conn: &Connection, ext_id: &str) -> Result<Option<JsonMap>> {
)
}
fn save_to_db(tx: &Transaction<'_>, ext_id: &str, val: &JsonValue) -> Result<()> {
fn save_to_db(tx: &Transaction<'_>, ext_id: &str, val: &StorageChangeOp) -> Result<()> {
// This function also handles removals. Either an empty map or explicit null
// is a removal. If there's a mirror record for this extension ID, then we
// must leave a tombstone behind for syncing.
let is_delete = match val {
JsonValue::Null => true,
JsonValue::Object(m) => m.is_empty(),
StorageChangeOp::Clear => true,
StorageChangeOp::Set(JsonValue::Object(v)) => v.is_empty(),
StorageChangeOp::SetWithoutQuota(JsonValue::Object(v)) => v.is_empty(),
_ => false,
};
if is_delete {
@ -84,11 +91,19 @@ fn save_to_db(tx: &Transaction<'_>, ext_id: &str, val: &JsonValue) -> Result<()>
)?;
}
} else {
// Convert to bytes so we can enforce the quota.
let sval = val.to_string();
if sval.len() > SYNC_QUOTA_BYTES {
return Err(ErrorKind::QuotaError(QuotaReason::TotalBytes).into());
}
// Convert to bytes so we can enforce the quota if necessary.
let sval = match val {
StorageChangeOp::Set(v) => {
let sv = v.to_string();
if sv.len() > SYNC_QUOTA_BYTES {
return Err(ErrorKind::QuotaError(QuotaReason::TotalBytes).into());
}
sv
}
StorageChangeOp::SetWithoutQuota(v) => v.to_string(),
StorageChangeOp::Clear => unreachable!(),
};
log::trace!("saving data for '{}': writing", ext_id);
tx.execute_named_cached(
"INSERT INTO storage_sync_data(ext_id, data, sync_change_counter)
@ -105,7 +120,7 @@ fn save_to_db(tx: &Transaction<'_>, ext_id: &str, val: &JsonValue) -> Result<()>
}
fn remove_from_db(tx: &Transaction<'_>, ext_id: &str) -> Result<()> {
save_to_db(tx, ext_id, &JsonValue::Null)
save_to_db(tx, ext_id, &StorageChangeOp::Clear)
}
// This is a "helper struct" for the callback part of the chrome.storage spec,
@ -206,7 +221,11 @@ pub fn set(tx: &Transaction<'_>, ext_id: &str, val: JsonValue) -> Result<Storage
current.insert(k, v);
}
save_to_db(tx, ext_id, &JsonValue::Object(current))?;
save_to_db(
tx,
ext_id,
&StorageChangeOp::Set(JsonValue::Object(current)),
)?;
Ok(changes)
}
@ -281,7 +300,11 @@ pub fn remove(tx: &Transaction<'_>, ext_id: &str, keys: JsonValue) -> Result<Sto
}
}
if !result.is_empty() {
save_to_db(tx, ext_id, &JsonValue::Object(existing))?;
save_to_db(
tx,
ext_id,
&StorageChangeOp::SetWithoutQuota(JsonValue::Object(existing)),
)?;
}
Ok(result)
}
@ -581,6 +604,43 @@ mod tests {
Ok(())
}
#[test]
fn test_quota_bytes() -> Result<()> {
let mut db = new_mem_db();
let tx = db.transaction()?;
let ext_id = "xyz";
let val = "x".repeat(SYNC_QUOTA_BYTES + 1);
// Init an over quota db with a single key.
save_to_db(
&tx,
ext_id,
&StorageChangeOp::SetWithoutQuota(json!({ "x": val })),
)?;
// Adding more data fails.
let e = set(&tx, &ext_id, json!({ "y": "newvalue" })).unwrap_err();
match e.kind() {
ErrorKind::QuotaError(QuotaReason::TotalBytes) => {}
_ => panic!("unexpected error type"),
};
// Remove data does not fails.
remove(&tx, &ext_id, json!["x"])?;
// Restore the over quota data.
save_to_db(
&tx,
ext_id,
&StorageChangeOp::SetWithoutQuota(json!({ "y": val })),
)?;
// Overwrite with less data does not fail.
set(&tx, &ext_id, json!({ "y": "lessdata" }))?;
Ok(())
}
#[test]
fn test_get_bytes_in_use() -> Result<()> {
let mut db = new_mem_db();

View file

@ -18,5 +18,5 @@ xpcom = { path = "../../../../../xpcom/rust/xpcom" }
serde = "1"
serde_json = "1"
storage_variant = { path = "../../../../../storage/variant" }
sql-support = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b" }
webext-storage = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b" }
sql-support = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26" }
webext-storage = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26" }

View file

@ -15,7 +15,7 @@ xpcom = { path = "../../../xpcom/rust/xpcom" }
once_cell = "1.2.0"
fog = { path = "./api" }
cstr = "0.1"
viaduct = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b" } # Copied from toolkit/library/rust/shared/Cargo.toml
viaduct = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26" } # Copied from toolkit/library/rust/shared/Cargo.toml
url = "2.1" # Copied from viaduct's deps, see https://github.com/mozilla/application-services/issues/3062
[features]

View file

@ -67,7 +67,7 @@ fluent-ffi = { path = "../../../../intl/l10n/rust/fluent-ffi" }
firefox-accounts-bridge = { path = "../../../../services/fxaccounts/rust-bridge/firefox-accounts-bridge", optional=true }
[target.'cfg(not(target_os = "android"))'.dependencies]
viaduct = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b"}
viaduct = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26"}
webext_storage_bridge = { path = "../../../components/extensions/storage/webext_storage_bridge" }
[build-dependencies]

View file

@ -13,7 +13,7 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
url = "2.1"
viaduct = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b"}
viaduct = { git = "https://github.com/mozilla/application-services", rev = "9ba519a5739b1976f1d333923d34b7f4916b9e26"}
wineventlog = { path = "../../../components/updateagent/wineventlog"}
wio = "0.2"
winapi = { version = "0.3", features = ["errhandlingapi", "handleapi", "minwindef", "winerror", "wininet", "winuser"] }