Skip to content

Commit

Permalink
Prevent the use of the enterprise flag (#5331)
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand authored Jun 13, 2024
1 parent 961f431 commit 7cb36f3
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,11 @@ <h2 id="web-extensions-%2F-manifest.json" tabindex="-1">Web Extensions / manifes
<td>warning</td>
<td>The incognito &quot;split&quot; value is unsupported in Firefox</td>
</tr>
<tr>
<td><code>ADMIN_INSTALL_ONLY_PROP_RESERVED</code></td>
<td>error</td>
<td>The &quot;admin_install_only&quot; property is reserved and can only be used in enterprise add-ons</td>
</tr>
</tbody>
</table>
<h3 id="static-theme-%2F-manifest.json" tabindex="-1">Static Theme / manifest.json <a class="header-anchor" href="#static-theme-%2F-manifest.json"></a></h3>
Expand Down
1 change: 1 addition & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Rules are sorted by severity.
| `VERSION_FORMAT_INVALID` | error | The version string is not valid because its format is too complex. |
| `MANIFEST_V3_FIREFOX_ANDROID_LIMITATIONS` | warning | The extension is marked as compatible with a Firefox for Android version that doesn't fully support Manifest Version 3 |
| `INCOGNITO_SPLIT_UNSUPPORTED` | warning | The incognito "split" value is unsupported in Firefox |
| `ADMIN_INSTALL_ONLY_PROP_RESERVED` | error | The "admin_install_only" property is reserved and can only be used in enterprise add-ons |

### Static Theme / manifest.json

Expand Down
8 changes: 8 additions & 0 deletions src/messages/manifestjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,11 @@ export const INCOGNITO_SPLIT_UNSUPPORTED = {
file, if your extension is compatible with Firefox's private browsing mode.`),
file: MANIFEST_JSON,
};

export const ADMIN_INSTALL_ONLY_PROP_RESERVED = {
code: 'ADMIN_INSTALL_ONLY_PROP_RESERVED',
message: i18n._('The "admin_install_only" property is reserved.'),
description: i18n._(`The "admin_install_only" property is reserved and can
only be used in enterprise add-ons.`),
file: MANIFEST_JSON,
};
8 changes: 8 additions & 0 deletions src/parsers/manifestjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ export default class ManifestJSONParser extends JSONParser {
};
}

if (
typeof this.parsedJSON.applications?.gecko?.admin_install_only !==
'undefined'
) {
this.collector.addError(messages.ADMIN_INSTALL_ONLY_PROP_RESERVED);
this.isValid = false;
}

if (
this.parsedJSON.manifest_version >= 3 &&
this.parsedJSON.browser_specific_settings?.gecko_android
Expand Down
4 changes: 4 additions & 0 deletions src/schema/imported/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,10 @@
"default": "*",
"description": "Maximum version of Gecko to support. Defaults to '*'. (Requires Gecko 45)",
"pattern": "^[0-9]{1,3}(\\.[a-z0-9*]+)+$"
},
"admin_install_only": {
"type": "boolean",
"optional": true
}
}
},
Expand Down
86 changes: 86 additions & 0 deletions tests/unit/parsers/test.manifestjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -5478,4 +5478,90 @@ describe('ManifestJSONParser', () => {
]);
});
});

describe('admin_install_only', () => {
it.each([
{
manifest_version: 2,
applications: { gecko: { id: '@test-id', admin_install_only: true } },
},
{
manifest_version: 2,
applications: { gecko: { id: '@test-id', admin_install_only: false } },
},
{
manifest_version: 2,
browser_specific_settings: {
gecko: { id: '@test-id', admin_install_only: true },
},
},
{
manifest_version: 2,
browser_specific_settings: {
gecko: { id: '@test-id', admin_install_only: false },
},
},
{
manifest_version: 2,
browser_specific_settings: {
gecko: { id: '@test-id', admin_install_only: false },
gecko_android: { strict_min_version: '123.0' },
},
},
{
manifest_version: 3,
browser_specific_settings: {
gecko: { id: '@test-id', admin_install_only: true },
},
},
{
manifest_version: 3,
browser_specific_settings: {
gecko: { id: '@test-id', admin_install_only: false },
},
},
{
manifest_version: 3,
browser_specific_settings: {
gecko: { id: '@test-id', admin_install_only: false },
gecko_android: { strict_min_version: '123.0' },
},
},
])(
'emits an error when the admin_install_only flag is present - %o',
(manifestProps) => {
const linter = new Linter({ _: ['bar'] });

const manifestJSONParser = new ManifestJSONParser(
JSON.stringify({
name: 'some name',
version: '1',
...manifestProps,
}),
linter.collector
);

expect(manifestJSONParser.isValid).toEqual(false);
if (manifestProps.applications) {
expect(linter.collector.warnings).toEqual([
expect.objectContaining(messages.APPLICATIONS_DEPRECATED),
]);
} else if (
manifestProps.manifest_version === 3 &&
manifestProps?.browser_specific_settings?.gecko_android
) {
expect(linter.collector.warnings).toEqual([
expect.objectContaining(
messages.MANIFEST_V3_FIREFOX_ANDROID_LIMITATIONS
),
]);
} else {
expect(linter.collector.warnings).toEqual([]);
}
expect(linter.collector.errors).toEqual([
expect.objectContaining(messages.ADMIN_INSTALL_ONLY_PROP_RESERVED),
]);
}
);
});
});

0 comments on commit 7cb36f3

Please sign in to comment.