tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_register_invalid_endpoint.js (1639B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const userAgentID = "c9a12e81-ea5e-40f9-8bf4-acee34621671";
      7 const channelID = "c0660af8-b532-4931-81f0-9fd27a12d6ab";
      8 
      9 function run_test() {
     10  do_get_profile();
     11  setPrefs();
     12  run_next_test();
     13 }
     14 
     15 add_task(async function test_register_invalid_endpoint() {
     16  let db = PushServiceWebSocket.newPushDB();
     17  registerCleanupFunction(() => {
     18    return db.drop().then(_ => db.close());
     19  });
     20 
     21  PushServiceWebSocket._generateID = () => channelID;
     22  PushService.init({
     23    serverURI: "wss://push.example.org/",
     24    db,
     25    makeWebSocket(uri) {
     26      return new MockWebSocket(uri, {
     27        onHello() {
     28          this.serverSendMsg(
     29            JSON.stringify({
     30              messageType: "hello",
     31              status: 200,
     32              uaid: userAgentID,
     33            })
     34          );
     35        },
     36        onRegister() {
     37          this.serverSendMsg(
     38            JSON.stringify({
     39              messageType: "register",
     40              status: 200,
     41              channelID,
     42              uaid: userAgentID,
     43              pushEndpoint: "!@#$%^&*",
     44            })
     45          );
     46        },
     47      });
     48    },
     49  });
     50 
     51  await Assert.rejects(
     52    PushService.register({
     53      scope: "https://example.net/page/invalid-endpoint",
     54      originAttributes: ChromeUtils.originAttributesToSuffix({
     55        inIsolatedMozBrowser: false,
     56      }),
     57    }),
     58    /Registration error/,
     59    "Expected error for invalid endpoint"
     60  );
     61 
     62  let record = await db.getByKeyID(channelID);
     63  ok(!record, "Should not store records with invalid endpoints");
     64 });