Bug 1292226 - Reject non-object ping payloads submitted to Telemetry. r=gfritzsche, data-r=bsmedberg

This commit is contained in:
rthyberg 2016-09-22 18:29:34 +01:00
Родитель e3c241f754
Коммит ecd9601cc0
4 изменённых файлов: 36 добавлений и 1 удалений

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

@ -5513,6 +5513,13 @@
"keyed": true,
"description": "Count of individual invalid ping types that were submitted to Telemetry."
},
"TELEMETRY_INVALID_PAYLOAD_SUBMITTED": {
"alert_emails": ["telemetry-client-dev@mozilla.com"],
"expires_in_version": "never",
"bug_numbers": [1292226],
"kind": "count",
"description": "Count of individual invalid payloads that were submitted to Telemetry."
},
"TELEMETRY_PING_EVICTED_FOR_SERVER_ERRORS": {
"alert_emails": ["telemetry-client-dev@mozilla.com"],
"expires_in_version": "never",

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

@ -501,6 +501,13 @@ var Impl = {
histogram.add(aType, 1);
return Promise.reject(new Error("Invalid type string submitted."));
}
// Enforce that the payload is an object.
if (aPayload === null || typeof aPayload !== 'object' || Array.isArray(aPayload)) {
this._log.error("submitExternalPing - invalid payload type: " + typeof aPayload);
let histogram = Telemetry.getHistogramById("TELEMETRY_INVALID_PAYLOAD_SUBMITTED");
histogram.add(1);
return Promise.reject(new Error("Invalid payload type submitted."));
}
let promise = this._submitPingLogic(aType, aPayload, aOptions);
this._trackPendingPingTask(promise);

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

@ -447,6 +447,27 @@ add_task(function* test_InvalidPingType() {
}
});
add_task(function* test_InvalidPayloadType() {
const PAYLOAD_TYPES = [
19,
"string",
[1, 2, 3, 4],
null,
undefined,
];
let histogram = Telemetry.getHistogramById("TELEMETRY_INVALID_PAYLOAD_SUBMITTED");
for (let i = 0; i < PAYLOAD_TYPES.length; i++) {
histogram.clear();
Assert.equal(histogram.snapshot().sum, 0,
"Should not have counted this invalid payload yet: " + JSON.stringify(PAYLOAD_TYPES[i]));
Assert.ok(yield promiseRejects(TelemetryController.submitExternalPing("payload-test", PAYLOAD_TYPES[i])),
"Payload type should have been rejected.");
Assert.equal(histogram.snapshot().sum, 1,
"Should have counted this as an invalid payload type.");
}
});
add_task(function* test_currentPingData() {
yield TelemetryController.testSetup();

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

@ -255,7 +255,7 @@ add_task(function* test_discardBigPings() {
const TEST_PING_TYPE = "test-ping-type";
// Generate a 2MB string and create an oversized payload.
const OVERSIZED_PAYLOAD = generateRandomString(2 * 1024 * 1024);
const OVERSIZED_PAYLOAD = {"data": generateRandomString(2 * 1024 * 1024)};
// Reset the histograms.
Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_SEND").clear();