зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1575974 - Add tests for pingsender url parsing r=gsvelto
Differential Revision: https://phabricator.services.mozilla.com/D44706 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0f4f0040bc
Коммит
74eb064c8e
|
@ -315,14 +315,17 @@ var TelemetrySend = {
|
|||
* @param {String} aUrl The telemetry server URL
|
||||
* @param {String} aPingFilePath The path to the file holding the ping
|
||||
* contents, if if sent successfully the pingsender will delete it.
|
||||
* @param {callback} observer A function called with parameters
|
||||
(subject, topic, data) and a topic of "process-finished" or
|
||||
"process-failed" after pingsender completion.
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE if we couldn't find or run the pingsender
|
||||
* executable.
|
||||
* @throws NS_ERROR_NOT_IMPLEMENTED on Android as the pingsender is not
|
||||
* available.
|
||||
*/
|
||||
testRunPingSender(url, pingPath) {
|
||||
TelemetrySendImpl.runPingSender(url, pingPath);
|
||||
testRunPingSender(url, pingPath, observer) {
|
||||
return TelemetrySendImpl.runPingSender(url, pingPath, observer);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1553,7 +1556,7 @@ var TelemetrySendImpl = {
|
|||
};
|
||||
},
|
||||
|
||||
runPingSender(url, pingPath) {
|
||||
runPingSender(url, pingPath, observer) {
|
||||
if (AppConstants.platform === "android") {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
@ -1570,6 +1573,6 @@ var TelemetrySendImpl = {
|
|||
process.init(exe);
|
||||
process.startHidden = true;
|
||||
process.noShell = true;
|
||||
process.run(/* blocking */ false, [url, pingPath], 2);
|
||||
process.runAsync([url, pingPath], 2, observer);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -96,7 +96,24 @@ add_task(async function test_pingSender() {
|
|||
|
||||
// Try to send it using the pingsender.
|
||||
const url = "http://localhost:" + PingServer.port + "/submit/telemetry/";
|
||||
TelemetrySend.testRunPingSender(url, pingPath);
|
||||
TelemetrySend.testRunPingSender(url, pingPath, (_, topic, __) => {
|
||||
switch (topic) {
|
||||
case "process-finished": // finished indicates an exit code of 0
|
||||
Assert.equal(
|
||||
true,
|
||||
true,
|
||||
"Pingsender should be able to post to localhost"
|
||||
);
|
||||
break;
|
||||
case "process-failed": // failed indicates an exit code != 0
|
||||
Assert.equal(
|
||||
true,
|
||||
false,
|
||||
"Pingsender should be able to post to localhost"
|
||||
);
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
let req = await PingServer.promiseNextRequest();
|
||||
let ping = decodeRequestPayload(req);
|
||||
|
@ -132,6 +149,42 @@ add_task(async function test_pingSender() {
|
|||
// Check that the PingSender removed the pending ping.
|
||||
await waitForPingDeletion(data.id);
|
||||
|
||||
// Confirm we can't send a ping to another destination url
|
||||
let bannedUris = [
|
||||
"https://example.com",
|
||||
"http://localhost.com",
|
||||
"http://localHOST.com",
|
||||
"http://localhost@example.com",
|
||||
"http://localhost:bob@example.com",
|
||||
"http://localhost:localhost@localhost.example.com",
|
||||
];
|
||||
for (let indx in bannedUris) {
|
||||
TelemetrySend.testRunPingSender(
|
||||
bannedUris[indx],
|
||||
pingPath,
|
||||
(_, topic, __) => {
|
||||
switch (topic) {
|
||||
case "process-finished": // finished indicates an exit code of 0
|
||||
Assert.equal(
|
||||
false,
|
||||
true,
|
||||
"Pingsender should not be able to post to any banned urls: " +
|
||||
bannedUris[indx]
|
||||
);
|
||||
break;
|
||||
case "process-failed": // failed indicates an exit code != 0
|
||||
Assert.equal(
|
||||
true,
|
||||
true,
|
||||
"Pingsender should not be able to post to any banned urls: " +
|
||||
bannedUris[indx]
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Shut down the failing server. We do this now, and not right after using it,
|
||||
// to make sure we're not interfering with the test.
|
||||
await new Promise(r => failingServer.stop(r));
|
||||
|
|
Загрузка…
Ссылка в новой задаче