Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit extensions id to 255 characters max (matches addons-server database limit) #2643

Merged
merged 3 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/schema/imported/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@
"type": "string",
"pattern": "^[a-zA-Z0-9-._]*@[a-zA-Z0-9-._]+$"
}
]
],
"maxLength": 255
},
"FirefoxSpecificProperties": {
"type": "object",
Expand Down
3 changes: 3 additions & 0 deletions src/schema/updates/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
}
}
},
"ExtensionID": {
"maxLength": 255
},
"WebExtensionManifest": {
"allOf": [
{
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/parsers/test.manifestjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,40 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind documenting here, that we don't have to care about unicode validation as this is handled by the schema as well?

});
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: {} });
Expand Down