tor-browser

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

test_group_remove.html (3603B)


      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_remove() {
     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 = await mls.groupCreate(alice, credential_alice);
     32 
     33  // Get membership of the group
     34  let membership_0 = await group.details();
     35 
     36  // Test that the returned group membership is not null
     37  info("Membership @ Epoch 0:", JSON.stringify(membership_0));
     38  is(membership_0.members.length, 1, "There should be one member in the group");
     39 
     40  // Alice adds Bob to a group
     41  let commit_output = await group.add(kp_bob);
     42 
     43  // Test that the returned commit output is not null
     44  info("Commit 1:", byteArrayToHexString(commit_output.commit));
     45  isnot(byteArrayToHexString(commit_output.commit), "", "Commit != ''");
     46 
     47  // Alice receives the commit
     48  await group.receive(commit_output.commit);
     49 
     50  // Get membership of the group
     51  let membership_1 = await group.details();
     52 
     53  // Test that the returned group membership is not null
     54  info("Membership @ Epoch 1:", JSON.stringify(membership_1));
     55  is(membership_1.members.length, 2, "There should be two members in the group");
     56 
     57  // Alice removes Bob from the group
     58  let commit_output_2 = await group.remove(bob);
     59 
     60  // Alice receives the commit
     61  await group.receive(commit_output_2.commit);
     62 
     63  // Get membership of the group
     64  let membership_2 = await group.details();
     65 
     66  // Test that the returned group membership is not null
     67  info("Membership @ Epoch 2:", JSON.stringify(membership_2));
     68  is(membership_2.members.length, 1, "There should be one member in the group");
     69 
     70  // Verify that Alice is the only member in the group at epoch 0
     71  is(membership_0.members.length, 1, "Alice should be alone in the group at epoch 0");
     72  is(membership_0.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be alone in the group at epoch 0");
     73 
     74  // Verify that both Alice and Bob are members in the group at epoch 1
     75  is(membership_1.members.length, 2, "There should be two members in the group at epoch 1");
     76  is(membership_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(bob.content)), true, "Bob should be in the group at epoch 1");
     77  is(membership_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be in the group at epoch 1");
     78 
     79  // Verify that Alice is the only member in the group at epoch 2
     80  is(membership_2.members.length, 1, "Alice should be alone in the group at epoch 2");
     81  is(membership_2.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be alone in the group at epoch 2");
     82 
     83  SimpleTest.finish();
     84 }
     85 
     86 SimpleTest.waitForExplicitFinish();
     87 test_group_remove();
     88 
     89 </script>
     90 </pre>
     91 </body>
     92 </html>