tor-browser

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

test_group_add.html (2782B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Messaging Layer Security</title>
      5  <!-- SimpleTest Helpers -->
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8  <!-- Local Helpers -->
      9  <script src="head_mls.js"></script>
     10 </head>
     11 <body>
     12 <pre id="test">
     13 <script class="testbody" type="text/javascript">
     14 
     15 async function test_group_add() {
     16 
     17  const mls = new MLS();
     18 
     19  // Generate Signature KeyPairs for Alice and Bob
     20  let alice = await mls.generateIdentity();
     21  let bob = await mls.generateIdentity();
     22 
     23  // Generate Credentials for Alice and Bob
     24  let credential_alice = await mls.generateCredential("alice");
     25  let credential_bob = await mls.generateCredential("bob");
     26 
     27  // Generate a KeyPackage for Bob
     28  let kp_bob = await mls.generateKeyPackage(bob, credential_bob);
     29 
     30  // Creation of a Group by Alice
     31  let group_alice = await mls.groupCreate(alice, credential_alice);
     32  let members_alice_0 = await group_alice.details();
     33 
     34  // Test: compare the group identifier to the invalid value
     35  info("Group ID:", byteArrayToHexString(group_alice.groupId));
     36  isnot(byteArrayToHexString(group_alice.groupId), "", "Group Identifier != ''");
     37 
     38  // Alice adds Bob to a group
     39  let commit_output = await group_alice.add(kp_bob);
     40 
     41  // Test: compare the commit output to the invalid value
     42  info("Commit Output:", byteArrayToHexString(commit_output.commit));
     43  isnot(byteArrayToHexString(commit_output.commit), "", "Commit != ''");
     44 
     45  // Alice receives the commit
     46  let group_and_epoch_1_alice = await group_alice.receive(commit_output.commit);
     47 
     48  // Test: make sure that the group epoch has been incremented by one
     49  const expectedEpoch = new Uint8Array(new BigUint64Array([1n]).buffer);
     50  is(byteArrayToHexString(group_and_epoch_1_alice.groupEpoch), byteArrayToHexString(expectedEpoch), "Group Epoch = 1");
     51 
     52  // Get the group details
     53  let members_alice_1 = await group_alice.details();
     54 
     55  // Test: the group should have exactly one member at epoch 0
     56  is(members_alice_0.members.length, 1, "There should be exactly one member in the group");
     57 
     58  // Test: the group should have exactly two members at epoch 1
     59  is(members_alice_1.members.length, 2, "There should be exactly two members in the group");
     60 
     61  // Test: compare the group members to the expected value
     62  is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(bob.content)), true, "Bob should be in the group");
     63  is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be in the group");
     64 
     65  SimpleTest.finish();
     66 }
     67 
     68 SimpleTest.waitForExplicitFinish();
     69 test_group_add();
     70 
     71 </script>
     72 </pre>
     73 </body>
     74 </html>