Bug 1558784 - Truncate abuse report properties that may be longer than allowed by the API endpoint. r=mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D34768

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2019-06-12 20:39:53 +00:00
Родитель 3149681bcf
Коммит b0ca6a0f20
2 изменённых файлов: 48 добавлений и 2 удалений

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

@ -9,6 +9,10 @@ const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm")
Cu.importGlobalProperties(["fetch"]);
const PREF_ABUSE_REPORT_URL = "extensions.abuseReport.url";
// Maximum length of the string properties sent to the API endpoint.
const MAX_STRING_LENGTH = 255;
// Minimum time between report submissions (in ms).
const MIN_MS_BETWEEN_SUBMITS = 30000;
@ -124,11 +128,15 @@ const AbuseReporter = {
* An object that contains the collected details.
*/
async getReportData(addon) {
const truncateString = (text) =>
typeof text == "string" ? text.slice(0, MAX_STRING_LENGTH) : text;
const data = {
addon: addon.id,
addon_version: addon.version,
addon_summary: addon.description,
addon_install_origin: addon.sourceURI && addon.sourceURI.spec,
addon_name: truncateString(addon.name),
addon_summary: truncateString(addon.description),
addon_install_origin: addon.sourceURI && truncateString(addon.sourceURI.spec),
install_date: addon.installDate && addon.installDate.toISOString(),
};

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

@ -449,3 +449,41 @@ add_task(async function test_submission_aborting() {
// task completed).
resolvePendingResponses();
});
add_task(async function test_truncated_string_properties() {
const generateString = len => (new Array(len)).fill("a").join("");
const LONG_STRINGS_ADDON_ID = "addon-with-long-strings-props@mochi.test";
const {extension} = await installTestExtension({
manifest: {
name: generateString(400),
description: generateString(400),
applications: {gecko: {id: LONG_STRINGS_ADDON_ID}},
},
});
// Override the test api server request handler, to be able to
// intercept the properties actually submitted.
let reportSubmitted;
apiRequestHandler = ({data, request, response}) => {
reportSubmitted = JSON.parse(data);
handleSubmitRequest({request, response});
};
const report = await AbuseReporter.createAbuseReport(
LONG_STRINGS_ADDON_ID, REPORT_OPTIONS);
await report.submit({message: "fake-message", reason: "fake-reason"});
const expected = {
addon_name: generateString(255),
addon_summary: generateString(255),
};
Assert.deepEqual({
addon_name: reportSubmitted.addon_name,
addon_summary: reportSubmitted.addon_summary,
}, expected, "Got the long strings truncated as expected");
await extension.unload();
});