Bug 1517025 - Use mock API server so fetchSignedObjects doesn't fail because of BAD URL r=Gijs
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 11 Feb 2019 21:50:56 +0000
changeset 458576 c4c141df786bf5904bf1c6860bb91cc6b24d055a
parent 458575 2b799d86aeff7d34406b5022829018b5f91b2910
child 458577 41e7f49db5a64bb3930fd192cab4f0b3b1b76c5e
push id77923
push uservalentin.gosu@gmail.com
push dateMon, 11 Feb 2019 21:52:38 +0000
treeherderautoland@41e7f49db5a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1517025
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1517025 - Use mock API server so fetchSignedObjects doesn't fail because of BAD URL r=Gijs We now disallow the % sign in the hostname of a URL. If the app.normandy.api_url pref isn't set explicitly, it'll remain the default set in xpcshell/user.js: https://%(server)s/selfsupport-dummy/. As you can see, this one has a % sign in it; and the test will fail. Otherwise, the error we catch is not a NormandyApi.InvalidSignatureError, but NS_ERROR_MALFORMED_URI. Differential Revision: https://phabricator.services.mozilla.com/D16695
toolkit/components/normandy/test/unit/test_NormandyApi.js
--- a/toolkit/components/normandy/test/unit/test_NormandyApi.js
+++ b/toolkit/components/normandy/test/unit/test_NormandyApi.js
@@ -158,17 +158,17 @@ add_task(async function test_fetchSigned
   }
 
   getApiUrl.restore();
   get.restore();
 });
 
 // Test validation errors due to validation throwing an exception (e.g. when
 // parameters passed to validation are malformed).
-add_task(async function test_fetchSignedObjects_validation_error() {
+add_task(withMockApiServer(async function test_fetchSignedObjects_validation_error() {
   const getApiUrl = sinon.stub(NormandyApi, "getApiUrl").resolves("http://localhost/object/");
 
   // Mock two URLs: object and the x5u
   const get = sinon.stub(NormandyApi, "get").callsFake(async url => {
     if (url.endsWith("object/")) {
       return new MockResponse(CanonicalJSON.stringify([
         {
           object: {a: 1, b: 2},
@@ -188,17 +188,17 @@ add_task(async function test_fetchSigned
     ok(false, "fetchSignedObjects did not throw for a validation error");
   } catch (err) {
     ok(err instanceof NormandyApi.InvalidSignatureError, "Error is an InvalidSignatureError");
     ok(/signature/.test(err), "Error is due to a validation error");
   }
 
   getApiUrl.restore();
   get.restore();
-});
+}));
 
 // Test validation errors due to validation returning false (e.g. when parameters
 // passed to validation are correctly formed, but not valid for the data).
 const invalidSignatureServer = makeMockApiServer(do_get_file("invalid_recipe_signature_api"));
 add_task(withServer(invalidSignatureServer, async function test_fetchSignedObjects_invalid_signature() {
   try {
     await NormandyApi.fetchSignedObjects("recipe");
     ok(false, "fetchSignedObjects did not throw for an invalid signature");