Prevent language packs from having additional webextension properties

This commit is contained in:
Mathieu Pillard 2018-08-02 13:40:57 +02:00
Родитель 9622916d1c
Коммит a07476696d
2 изменённых файлов: 45 добавлений и 13 удалений

Просмотреть файл

@ -69,21 +69,9 @@ export const validateAddon = (...args) => {
return isValid;
};
const _validateLangPack = validator.compile({
...schemaObject,
id: 'langpack-manifest',
$ref: '#/types/WebExtensionLangpackManifest',
});
export const validateLangPack = (...args) => {
const isValid = _validateLangPack(...args);
validateLangPack.errors = filterErrors(_validateLangPack.errors);
return isValid;
};
// Create a new schema object that merges theme.json and the regular
// manifest.json schema.
// Then modify the result of that to allow `additionalProperties = false`
// Then modify the result of that to set `additionalProperties = false`
// so that additional properties are not allowed for themes.
// We have to use deepmerge here to make sure we can overwrite the nested
// structure and can use object-destructuring at the root level
@ -113,6 +101,34 @@ export const validateStaticTheme = (...args) => {
return isValid;
};
// Like with static themes, we don't want additional properties in langpacks.
// The only difference is, this time, there is no additional schema file, we
// just need to reference WebExtensionLangpackManifest and merge it with the
// object that has additionalProperties: false.
const _validateLangPack = validator.compile({
...merge(
schemaObject, {
types: {
WebExtensionLangpackManifest: {
$merge: {
with: {
additionalProperties: false,
},
},
},
},
}
),
id: 'langpack-manifest',
$ref: '#/types/WebExtensionLangpackManifest',
});
export const validateLangPack = (...args) => {
const isValid = _validateLangPack(...args);
validateLangPack.errors = filterErrors(_validateLangPack.errors);
return isValid;
};
const _validateLocaleMessages = validator.compile({
...messagesSchemaObject,
id: 'messages',

Просмотреть файл

@ -1104,6 +1104,22 @@ describe('ManifestJSONParser', () => {
);
expect(manifestJSONParser.isValid).toEqual(false);
});
it('throws warning on additional properties', () => {
const linter = new Linter({ _: ['bar'] });
const json = validLangpackManifestJSON({ content_scripts: ['foo.js'] });
const manifestJSONParser = new ManifestJSONParser(
json, linter.collector, {
io: { files: {} },
}
);
expect(manifestJSONParser.isValid).toEqual(false);
assertHasMatchingError(linter.collector.errors, {
code: messages.JSON_INVALID.code,
message: '"/content_scripts" is an invalid additional property',
description: 'Your JSON file could not be parsed.',
});
});
});
describe('static theme', () => {