Skip to content

Commit

Permalink
feat: Import API schema data for Firefox 92 (#3873)
Browse files Browse the repository at this point in the history
* feat: Imported Firefox 92.0b7 API schema
* chore: Add some additional tests to cover the behaviors expected on host_permissions in MV2 and MV3
  • Loading branch information
rpl authored Aug 24, 2021
1 parent 42f3c37 commit 227967e
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/schema/imported/downloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"default": false,
"type": "boolean"
},
"cookieStoreId": {
"type": "string",
"description": "The cookie store ID of the contextual identity; requires \"cookies\" permission."
},
"conflictAction": {
"$ref": "#/types/FilenameConflictAction"
},
Expand Down Expand Up @@ -627,6 +631,10 @@
"description": "False if this download is recorded in the history, true if it is not recorded.",
"type": "boolean"
},
"cookieStoreId": {
"type": "string",
"description": "The cookie store ID of the contextual identity."
},
"danger": {
"allOf": [
{
Expand Down Expand Up @@ -851,6 +859,10 @@
"description": "Absolute local path.",
"type": "string"
},
"cookieStoreId": {
"type": "string",
"description": "The cookie store ID of the contextual identity."
},
"danger": {
"allOf": [
{
Expand Down
54 changes: 45 additions & 9 deletions src/schema/imported/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,38 @@
]
},
"permissions": {
"type": "array",
"default": [],
"items": {
"allOf": [
{
"$ref": "#/types/PermissionOrOrigin"
},
{
"onError": "warn"
"anyOf": [
{
"max_manifest_version": 2,
"type": "array",
"items": {
"allOf": [
{
"$ref": "#/types/PermissionOrOrigin"
},
{
"onError": "warn"
}
]
}
],
},
{
"min_manifest_version": 3,
"type": "array",
"items": {
"allOf": [
{
"$ref": "#/types/Permission"
},
{
"onError": "warn"
}
]
}
}
],
"items": {
"anyOf": [
{},
{
Expand All @@ -235,6 +256,21 @@
},
"uniqueItems": true
},
"host_permissions": {
"min_manifest_version": 3,
"type": "array",
"items": {
"allOf": [
{
"$ref": "#/types/MatchPattern"
},
{
"onError": "warn"
}
]
},
"default": []
},
"optional_permissions": {
"type": "array",
"items": {
Expand Down
122 changes: 122 additions & 0 deletions tests/unit/parsers/test.manifestjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,128 @@ describe('ManifestJSONParser', () => {
});
});

describe('host permissions', () => {
it('allows host permissions in permissions manifest key in MV2', () => {
const addonLinter = new Linter({ _: ['bar'] });
const json = validManifestJSON({
manifest_version: 2,
permissions: ['*://example.org/*', '<all_urls>'],
});

const manifestJSONParser = new ManifestJSONParser(
json,
addonLinter.collector
);
expect(manifestJSONParser.collector.errors).toEqual([]);
});

it('disallows host permissions in permissions manifest key in MV3', () => {
const addonLinter = new Linter({ _: ['bar'] });
const json = validManifestJSON({
manifest_version: 3,
permissions: ['*://example.org/*'],
});

const manifestJSONParser = new ManifestJSONParser(
json,
addonLinter.collector,
{ schemaValidatorOptions: { maxManifestVersion: 3 } }
);
expect(manifestJSONParser.collector.warnings).toEqual(
expect.arrayContaining([
expect.objectContaining({
code: 'MANIFEST_PERMISSIONS',
dataPath: '/permissions/0',
message: expect.stringMatching(
/Unknown permissions "\*:\/\/example\.org\/\*" at 0/
),
}),
])
);
expect(manifestJSONParser.collector.errors).toEqual(
expect.arrayContaining([
expect.objectContaining({
code: 'MANIFEST_BAD_PERMISSION',
dataPath: '/permissions',
}),
])
);
});

it('ignores host_permissions manifest key in MV2', () => {
const addonLinter = new Linter({ _: ['bar'] });
const json = validManifestJSON({
manifest_version: 2,
host_permissions: ['*://example.org/*'],
});

const manifestJSONParser = new ManifestJSONParser(
json,
addonLinter.collector
);
expect(manifestJSONParser.collector.errors).toEqual([]);
expect(manifestJSONParser.collector.warnings).toEqual(
expect.arrayContaining([
expect.objectContaining({
code: 'MANIFEST_FIELD_UNSUPPORTED',
dataPath: '/host_permissions',
message: expect.stringMatching(
/not supported in manifest versions < 3/
),
}),
])
);
});

it('allows host_permissions manifest key in MV3', () => {
// Test with only valid host permissions.
const addonLinter = new Linter({ _: ['bar'] });
const json = validManifestJSON({
manifest_version: 3,
host_permissions: ['*://example.org/*'],
});
const manifestJSONParser = new ManifestJSONParser(
json,
addonLinter.collector,
{ schemaValidatorOptions: { maxManifestVersion: 3 } }
);
expect(manifestJSONParser.collector.errors).toEqual([]);
});

it('disallows <all_urls> in MV3 permissions', () => {
// Test with invalid permission and host permissions.
const addonLinter = new Linter({ _: ['bar'] });
const json_with_warnings = validManifestJSON({
manifest_version: 3,
permissions: ['<all_urls>'],
});
const manifestJSONParser = new ManifestJSONParser(
json_with_warnings,
addonLinter.collector,
{ schemaValidatorOptions: { maxManifestVersion: 3 } }
);
expect(manifestJSONParser.collector.errors).toEqual(
expect.arrayContaining([
expect.objectContaining({
code: 'MANIFEST_BAD_PERMISSION',
dataPath: '/permissions',
}),
])
);
expect(manifestJSONParser.collector.warnings).toEqual(
expect.arrayContaining([
expect.objectContaining({
code: 'MANIFEST_PERMISSIONS',
dataPath: '/permissions/0',
message: expect.stringMatching(
/Unknown permissions "<all_urls>" at 0/
),
}),
])
);
});
});

describe('bad permissions', () => {
for (const manifestKey of ['permissions', 'optional_permissions']) {
it(`should not error if ${manifestKey} is a string (even if unknown)`, () => {
Expand Down

0 comments on commit 227967e

Please sign in to comment.