test_appupdatepin.js (2606B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { TelemetryTestUtils } = ChromeUtils.importESModule( 7 "resource://testing-common/TelemetryTestUtils.sys.mjs" 8 ); 9 10 /** 11 * Note that these tests only ensure that the pin is properly added to the 12 * update URL and to the telemetry. They do not test that the update applied 13 * will be of the correct version. This is because we are not attempting to have 14 * Firefox check if the update provided is valid given the pin, we are leaving 15 * it to the update server (Balrog) to find and serve the correct version. 16 */ 17 18 async function test_update_pin(pinString, pinIsValid = true) { 19 await setupPolicyEngineWithJson({ 20 policies: { 21 AppUpdateURL: "https://www.example.com/update.xml", 22 AppUpdatePin: pinString, 23 }, 24 }); 25 Services.telemetry.clearScalars(); 26 27 equal( 28 Services.policies.status, 29 Ci.nsIEnterprisePolicies.ACTIVE, 30 "Engine is active" 31 ); 32 33 let policies = Services.policies.getActivePolicies(); 34 equal( 35 "AppUpdatePin" in policies, 36 pinIsValid, 37 "AppUpdatePin policy should only be active if the pin was valid." 38 ); 39 40 let checker = Cc["@mozilla.org/updates/update-checker;1"].getService( 41 Ci.nsIUpdateChecker 42 ); 43 let updateURL = await checker.getUpdateURL(checker.BACKGROUND_CHECK); 44 45 let expected = pinIsValid 46 ? `https://www.example.com/update.xml?pin=${pinString}` 47 : "https://www.example.com/update.xml"; 48 49 equal(updateURL, expected, "App Update URL should match expected URL."); 50 51 let scalars = TelemetryTestUtils.getProcessScalars("parent", false, true); 52 if (pinIsValid) { 53 TelemetryTestUtils.assertScalar( 54 scalars, 55 "update.version_pin", 56 pinString, 57 "Update pin telemetry should be set" 58 ); 59 } else { 60 TelemetryTestUtils.assertScalarUnset(scalars, "update.version_pin"); 61 } 62 } 63 64 add_task(async function test_app_update_pin() { 65 await test_update_pin("102."); 66 await test_update_pin("102.0."); 67 await test_update_pin("102.1."); 68 await test_update_pin("102.1.1", false); 69 await test_update_pin("102.1.1.", false); 70 await test_update_pin("102", false); 71 await test_update_pin("foobar", false); 72 await test_update_pin("-102.1.", false); 73 await test_update_pin("102.-1.", false); 74 await test_update_pin("102a.1.", false); 75 await test_update_pin("102.1a.", false); 76 await test_update_pin("0102.1.", false); 77 // Should not accept version numbers that will never be in Balrog's pinning 78 // table (i.e. versions before 102.0). 79 await test_update_pin("101.1.", false); 80 });