зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1835824
- Add a test to validate search-config against the schema. r=search-reviewers,mcheang,daleharvey
This will also ensure that if we add new properties to the search-config, we'll also need to add them to the schema. Differential Revision: https://phabricator.services.mozilla.com/D179496
This commit is contained in:
Родитель
c7bb8cdb11
Коммит
5e5d6f7b3f
|
@ -393,6 +393,9 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"title": "Override",
|
"title": "Override",
|
||||||
"description": "This section will override previous appliesTo sections, but not add new locations where this engine is deployed to."
|
"description": "This section will override previous appliesTo sections, but not add new locations where this engine is deployed to."
|
||||||
|
},
|
||||||
|
"suggestExtraParams": {
|
||||||
|
"$ref": "#/definitions/extraParams"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
ChromeUtils.defineESModuleGetters(this, {
|
||||||
|
JsonSchema: "resource://gre/modules/JsonSchema.sys.mjs",
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if a value is an object or not.
|
||||||
|
*
|
||||||
|
* @param {*} value
|
||||||
|
* The value to check.
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function isObject(value) {
|
||||||
|
return value != null && typeof value == "object" && !Array.isArray(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function modifies the schema to prevent allowing additional properties
|
||||||
|
* on objects. This is used to enforce that the schema contains everything that
|
||||||
|
* we deliver via the search configuration.
|
||||||
|
*
|
||||||
|
* These checks are not enabled in-product, as we want to allow older versions
|
||||||
|
* to keep working if we add new properties for whatever reason.
|
||||||
|
*
|
||||||
|
* @param {object} section
|
||||||
|
* The section to check to see if an additionalProperties flag should be added.
|
||||||
|
*/
|
||||||
|
function disallowAdditionalProperties(section) {
|
||||||
|
if (section.type == "object") {
|
||||||
|
section.additionalProperties = false;
|
||||||
|
}
|
||||||
|
for (let value of Object.values(section)) {
|
||||||
|
if (isObject(value)) {
|
||||||
|
disallowAdditionalProperties(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add_task(async function test_search_config_validates_to_schema() {
|
||||||
|
let schema = await IOUtils.readJSON(
|
||||||
|
PathUtils.join(do_get_cwd().path, "search-engine-config-schema.json")
|
||||||
|
);
|
||||||
|
disallowAdditionalProperties(schema);
|
||||||
|
|
||||||
|
let selector = new SearchEngineSelector(() => {});
|
||||||
|
let searchConfig = await selector.getEngineConfiguration();
|
||||||
|
let validator = new JsonSchema.Validator(schema);
|
||||||
|
|
||||||
|
for (let entry of searchConfig) {
|
||||||
|
// Records in Remote Settings contain additional properties independent of
|
||||||
|
// the schema. Hence, we don't want to validate their presence.
|
||||||
|
delete entry.schema;
|
||||||
|
delete entry.id;
|
||||||
|
delete entry.last_modified;
|
||||||
|
|
||||||
|
let result = validator.validate(entry);
|
||||||
|
let message = `Should validate ${entry.webExtension?.id}`;
|
||||||
|
if (!result.valid) {
|
||||||
|
message += `:\n${JSON.stringify(result.errors, null, 2)}`;
|
||||||
|
}
|
||||||
|
Assert.ok(result.valid, message);
|
||||||
|
}
|
||||||
|
});
|
|
@ -29,6 +29,9 @@ requesttimeoutfactor = 2
|
||||||
[test_mailru.js]
|
[test_mailru.js]
|
||||||
[test_qwant.js]
|
[test_qwant.js]
|
||||||
[test_rakuten.js]
|
[test_rakuten.js]
|
||||||
|
[test_searchconfig_validates.js]
|
||||||
|
support-files =
|
||||||
|
../../../schema/search-engine-config-schema.json
|
||||||
[test_selector_db_out_of_date.js]
|
[test_selector_db_out_of_date.js]
|
||||||
[test_yahoojp.js]
|
[test_yahoojp.js]
|
||||||
[test_yandex.js]
|
[test_yandex.js]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче