tor-browser

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

test_password_validator.js (4876B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 const { PasswordValidator } = ChromeUtils.importESModule(
      5  "resource://services-sync/engines/passwords.sys.mjs"
      6 );
      7 
      8 function getDummyServerAndClient() {
      9  return {
     10    server: [
     11      {
     12        id: "11111",
     13        guid: "11111",
     14        hostname: "https://www.11111.com",
     15        formSubmitURL: "https://www.11111.com",
     16        password: "qwerty123",
     17        passwordField: "pass",
     18        username: "foobar",
     19        usernameField: "user",
     20        httpRealm: null,
     21      },
     22      {
     23        id: "22222",
     24        guid: "22222",
     25        hostname: "https://www.22222.org",
     26        formSubmitURL: "https://www.22222.org",
     27        password: "hunter2",
     28        passwordField: "passwd",
     29        username: "baz12345",
     30        usernameField: "user",
     31        httpRealm: null,
     32      },
     33      {
     34        id: "33333",
     35        guid: "33333",
     36        hostname: "https://www.33333.com",
     37        formSubmitURL: "https://www.33333.com",
     38        password: "p4ssw0rd",
     39        passwordField: "passwad",
     40        username: "quux",
     41        usernameField: "user",
     42        httpRealm: null,
     43      },
     44    ],
     45    client: [
     46      {
     47        id: "11111",
     48        guid: "11111",
     49        hostname: "https://www.11111.com",
     50        formSubmitURL: "https://www.11111.com",
     51        password: "qwerty123",
     52        passwordField: "pass",
     53        username: "foobar",
     54        usernameField: "user",
     55        httpRealm: null,
     56      },
     57      {
     58        id: "22222",
     59        guid: "22222",
     60        hostname: "https://www.22222.org",
     61        formSubmitURL: "https://www.22222.org",
     62        password: "hunter2",
     63        passwordField: "passwd",
     64        username: "baz12345",
     65        usernameField: "user",
     66        httpRealm: null,
     67      },
     68      {
     69        id: "33333",
     70        guid: "33333",
     71        hostname: "https://www.33333.com",
     72        formSubmitURL: "https://www.33333.com",
     73        password: "p4ssw0rd",
     74        passwordField: "passwad",
     75        username: "quux",
     76        usernameField: "user",
     77        httpRealm: null,
     78      },
     79    ],
     80  };
     81 }
     82 
     83 add_task(async function test_valid() {
     84  let { server, client } = getDummyServerAndClient();
     85  let validator = new PasswordValidator();
     86  let { problemData, clientRecords, records, deletedRecords } =
     87    await validator.compareClientWithServer(client, server);
     88  equal(clientRecords.length, 3);
     89  equal(records.length, 3);
     90  equal(deletedRecords.length, 0);
     91  deepEqual(problemData, validator.emptyProblemData());
     92 });
     93 
     94 add_task(async function test_missing() {
     95  let validator = new PasswordValidator();
     96  {
     97    let { server, client } = getDummyServerAndClient();
     98 
     99    client.pop();
    100 
    101    let { problemData, clientRecords, records, deletedRecords } =
    102      await validator.compareClientWithServer(client, server);
    103 
    104    equal(clientRecords.length, 2);
    105    equal(records.length, 3);
    106    equal(deletedRecords.length, 0);
    107 
    108    let expected = validator.emptyProblemData();
    109    expected.clientMissing.push("33333");
    110    deepEqual(problemData, expected);
    111  }
    112  {
    113    let { server, client } = getDummyServerAndClient();
    114 
    115    server.pop();
    116 
    117    let { problemData, clientRecords, records, deletedRecords } =
    118      await validator.compareClientWithServer(client, server);
    119 
    120    equal(clientRecords.length, 3);
    121    equal(records.length, 2);
    122    equal(deletedRecords.length, 0);
    123 
    124    let expected = validator.emptyProblemData();
    125    expected.serverMissing.push("33333");
    126    deepEqual(problemData, expected);
    127  }
    128 });
    129 
    130 add_task(async function test_deleted() {
    131  let { server, client } = getDummyServerAndClient();
    132  let deletionRecord = { id: "444444", guid: "444444", deleted: true };
    133 
    134  server.push(deletionRecord);
    135  let validator = new PasswordValidator();
    136 
    137  let { problemData, clientRecords, records, deletedRecords } =
    138    await validator.compareClientWithServer(client, server);
    139 
    140  equal(clientRecords.length, 3);
    141  equal(records.length, 4);
    142  deepEqual(deletedRecords, [deletionRecord]);
    143 
    144  let expected = validator.emptyProblemData();
    145  deepEqual(problemData, expected);
    146 });
    147 
    148 add_task(async function test_duplicates() {
    149  let validator = new PasswordValidator();
    150  {
    151    let { server, client } = getDummyServerAndClient();
    152    client.push(Cu.cloneInto(client[0], {}));
    153 
    154    let { problemData } = await validator.compareClientWithServer(
    155      client,
    156      server
    157    );
    158 
    159    let expected = validator.emptyProblemData();
    160    expected.clientDuplicates.push("11111");
    161    deepEqual(problemData, expected);
    162  }
    163  {
    164    let { server, client } = getDummyServerAndClient();
    165    server.push(Cu.cloneInto(server[server.length - 1], {}));
    166 
    167    let { problemData } = await validator.compareClientWithServer(
    168      client,
    169      server
    170    );
    171 
    172    let expected = validator.emptyProblemData();
    173    expected.duplicates.push("33333");
    174    deepEqual(problemData, expected);
    175  }
    176 });