From 70cea60d16d3c1e5d120931e9a8ecfc33f6c6c00 Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Thu, 13 Jun 2019 17:52:46 +0200 Subject: [PATCH 1/3] Limit extensions id to 255 characters max (matches addons-server database limit) --- src/schema/imported/manifest.json | 3 ++- src/schema/updates/manifest.json | 3 +++ tests/unit/parsers/test.manifestjson.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/schema/imported/manifest.json b/src/schema/imported/manifest.json index 89ec5e88b35..fd613ff95da 100644 --- a/src/schema/imported/manifest.json +++ b/src/schema/imported/manifest.json @@ -598,7 +598,8 @@ "type": "string", "pattern": "^[a-zA-Z0-9-._]*@[a-zA-Z0-9-._]+$" } - ] + ], + "maxLength": 255 }, "FirefoxSpecificProperties": { "type": "object", diff --git a/src/schema/updates/manifest.json b/src/schema/updates/manifest.json index d7339ea143a..30b108756d0 100644 --- a/src/schema/updates/manifest.json +++ b/src/schema/updates/manifest.json @@ -18,6 +18,9 @@ } } }, + "ExtensionID": { + "maxLength": 255 + }, "WebExtensionManifest": { "allOf": [ { diff --git a/tests/unit/parsers/test.manifestjson.js b/tests/unit/parsers/test.manifestjson.js index 3cfb485e857..4f607d2abfe 100644 --- a/tests/unit/parsers/test.manifestjson.js +++ b/tests/unit/parsers/test.manifestjson.js @@ -102,6 +102,22 @@ describe('ManifestJSONParser', () => { }); }); + it('should fail on id longer than 255 characters', () => { + const addonLinter = new Linter({ _: ['bar'] }); + const json = validManifestJSON({ + applications: { gecko: { id: '@' + 'a'.repeat(255) } }, // 256 chars. + }); + const manifestJSONParser = new ManifestJSONParser( + json, + addonLinter.collector + ); + expect(manifestJSONParser.isValid).toEqual(false); + assertHasMatchingError(addonLinter.collector.errors, { + code: messages.JSON_INVALID.code, + message: /"\/applications\/gecko\/id" should NOT be longer than 255 characters/, + }); + }); + it('should return null if undefined', () => { const addonLinter = new Linter({ _: ['bar'] }); const json = validManifestJSON({ applications: {} }); From 1a6b655551160031bb72e39c0039e07c6f6c26e9 Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Fri, 14 Jun 2019 09:45:16 +0200 Subject: [PATCH 2/3] Fix eslint warnings --- tests/unit/parsers/test.manifestjson.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/parsers/test.manifestjson.js b/tests/unit/parsers/test.manifestjson.js index 4f607d2abfe..6d270e96b25 100644 --- a/tests/unit/parsers/test.manifestjson.js +++ b/tests/unit/parsers/test.manifestjson.js @@ -105,7 +105,7 @@ describe('ManifestJSONParser', () => { it('should fail on id longer than 255 characters', () => { const addonLinter = new Linter({ _: ['bar'] }); const json = validManifestJSON({ - applications: { gecko: { id: '@' + 'a'.repeat(255) } }, // 256 chars. + applications: { gecko: { id: `@${'a'.repeat(255)}` } }, // 256 chars }); const manifestJSONParser = new ManifestJSONParser( json, From e00ae5c11b83b8c1ac0f0d032fb88d69f51f1fbf Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Thu, 20 Jun 2019 12:35:45 -0700 Subject: [PATCH 3/3] Add test for ids containing unicode chars and a comment --- tests/unit/parsers/test.manifestjson.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/parsers/test.manifestjson.js b/tests/unit/parsers/test.manifestjson.js index 6d270e96b25..4e5c2c860a1 100644 --- a/tests/unit/parsers/test.manifestjson.js +++ b/tests/unit/parsers/test.manifestjson.js @@ -102,9 +102,27 @@ describe('ManifestJSONParser', () => { }); }); + it('should fail on id containing unicode chars', () => { + const addonLinter = new Linter({ _: ['bar'] }); + const json = validManifestJSON({ + applications: { gecko: { id: '@fĂ´obar' } }, + }); + const manifestJSONParser = new ManifestJSONParser( + json, + addonLinter.collector + ); + expect(manifestJSONParser.isValid).toEqual(false); + assertHasMatchingError(addonLinter.collector.errors, { + code: messages.JSON_INVALID.code, + message: /"\/applications\/gecko\/id" should match pattern/, + }); + }); + it('should fail on id longer than 255 characters', () => { const addonLinter = new Linter({ _: ['bar'] }); const json = validManifestJSON({ + // ids containing non-ascii chars are forbidden per the schema + // definition so we only need to test ascii here. applications: { gecko: { id: `@${'a'.repeat(255)}` } }, // 256 chars }); const manifestJSONParser = new ManifestJSONParser(