tor-browser

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

test_register_invalid_channel.js (1573B)


      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 = "52b2b04c-b6cc-42c6-abdf-bef9cbdbea00";
      7 const channelID = "cafed00d";
      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_channel() {
     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              uaid: userAgentID,
     32              status: 200,
     33            })
     34          );
     35        },
     36        onRegister() {
     37          this.serverSendMsg(
     38            JSON.stringify({
     39              messageType: "register",
     40              status: 403,
     41              channelID,
     42              error: "Invalid channel ID",
     43            })
     44          );
     45        },
     46      });
     47    },
     48  });
     49 
     50  await Assert.rejects(
     51    PushService.register({
     52      scope: "https://example.com/invalid-channel",
     53      originAttributes: ChromeUtils.originAttributesToSuffix({
     54        inIsolatedMozBrowser: false,
     55      }),
     56    }),
     57    /Registration error/,
     58    "Expected error for invalid channel ID"
     59  );
     60 
     61  let record = await db.getByKeyID(channelID);
     62  ok(!record, "Should not store records for error responses");
     63 });