зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1900401 - Fix path for prefFlips schema in FeatureManifest r=emcminn
The feature manifest validation logic now checks that schema paths exist. A test has been added to ensure all schema URIs can be resolved with fetch() in the browser. Differential Revision: https://phabricator.services.mozilla.com/D212449
This commit is contained in:
Родитель
2c22458672
Коммит
642ef706e5
|
@ -75,7 +75,7 @@ prefFlips:
|
|||
description: "The prefs to set."
|
||||
schema:
|
||||
uri: resource://nimbus/schemas/PrefFlipsFeature.schema.json
|
||||
path: toolkit/component/nimbus/schemas/PrefFlipsFeature.schema.json
|
||||
path: toolkit/components/nimbus/schemas/PrefFlipsFeature.schema.json
|
||||
|
||||
|
||||
# `search` is for search engine experimentation features which do not require
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import jsonschema
|
||||
import yaml
|
||||
|
@ -38,6 +39,8 @@ def write_fm_headers(fd):
|
|||
|
||||
|
||||
def validate_feature_manifest(schema_path, manifest_path, manifest):
|
||||
TOPSRCDIR = Path(__file__).parent.parent.parent.parent.parent
|
||||
|
||||
with open(schema_path, "r") as f:
|
||||
schema = json.load(f)
|
||||
|
||||
|
@ -117,6 +120,17 @@ def validate_feature_manifest(schema_path, manifest_path, manifest):
|
|||
)
|
||||
raise Exception("Set prefs and fallback prefs cannot overlap")
|
||||
|
||||
if "schema" in feature:
|
||||
schema_path = TOPSRCDIR / feature["schema"]["path"]
|
||||
if not schema_path.exists():
|
||||
raise Exception(f"Schema does not exist at {schema_path}")
|
||||
|
||||
uri = urlparse(feature["schema"]["uri"])
|
||||
if uri.scheme not in ("resource", "chrome"):
|
||||
raise Exception(
|
||||
"Only resource:// and chrome:// URIs are supported for schemas"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print("Error while validating FeatureManifest.yaml")
|
||||
print(f"On key: {feature_id}")
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const { FeatureManifest } = ChromeUtils.importESModule(
|
||||
"resource://nimbus/FeatureManifest.sys.mjs"
|
||||
);
|
||||
|
||||
add_task(async function testSchemaUris() {
|
||||
for (const [featureId, featureDfn] of Object.entries(FeatureManifest)) {
|
||||
if (typeof featureDfn.schema !== "undefined") {
|
||||
info(`${featureId}: schema URI: ${featureDfn.schema.uri}`);
|
||||
try {
|
||||
const json = await fetch(featureDfn.schema.uri).then(rsp => rsp.text());
|
||||
Assert.ok(true, `${featureId}: schema fetch success`);
|
||||
JSON.parse(json);
|
||||
Assert.ok(true, `${featureId}: schema parses as JSON`);
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`Could not fetch schema for ${featureId} at ${featureDfn.schema.uri}: ${e}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.ok(true, "All schemas fetched successfully");
|
||||
});
|
|
@ -42,3 +42,5 @@ run-sequentially = "very high failure rate in parallel"
|
|||
["test_SharedDataMap.js"]
|
||||
|
||||
["test_localization.js"]
|
||||
|
||||
["test_schema_uris.js"]
|
||||
|
|
Загрузка…
Ссылка в новой задаче