tor-browser

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

test_group_join.html (4590B)


      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_join() {
     16 
     17  const mls = new MLS();
     18 
     19  // Generate Identity KeyPairs for Alice and Bob
     20  let alice = await mls.generateIdentity();
     21  let bob = await mls.generateIdentity();
     22 
     23  info("Alice Client ID:", byteArrayToHexString(alice.content));
     24  info("Bob Client ID:", byteArrayToHexString(bob.content));
     25 
     26 
     27  // Generate Credentials for Alice and Bob
     28  let credential_alice = await mls.generateCredential("alice");
     29  let credential_bob = await mls.generateCredential("bob");
     30 
     31  // Generate a KeyPackage for Bob
     32  let kp_bob = await mls.generateKeyPackage(bob, credential_bob);
     33 
     34  // Creation of a Group by Alice
     35  let group_alice = await mls.groupCreate(alice, credential_alice);
     36  info("Group Alice:", JSON.stringify(group_alice));
     37 
     38  // Get membership of the group
     39  let members_alice_0 = await group_alice.details();
     40 
     41  // Test that the returned group membership is not null
     42  info("Membership @ Epoch 0:", JSON.stringify(members_alice_0));
     43  is(members_alice_0.members.length, 1, "There should be exactly one member in the group");
     44  info("Member Client ID:", byteArrayToHexString(members_alice_0.members[0].clientId));
     45  info("Alice Client ID:", byteArrayToHexString(alice.content));
     46  is(byteArrayToHexString(members_alice_0.members[0].clientId), byteArrayToHexString(alice.content), "The client ID of the member should match Alice's client ID");
     47 
     48  // Alice adds Bob to a group
     49  let commit_output = await group_alice.add(kp_bob);
     50 
     51  // Test that the returned commit output is not null
     52  info("Commit Output 1:", JSON.stringify(commit_output));
     53  isnot(byteArrayToHexString(commit_output.commit), "", "Commit Output commit should not be an empty string");
     54 
     55  // Alice receives the commit
     56  let group_and_epoch_1_alice = await group_alice.receive(commit_output.commit);
     57 
     58  // Test that the new group identifier and epoch are valid
     59  info("Alice's Group Identifier and Epoch:", JSON.stringify(group_and_epoch_1_alice));
     60  isnot(byteArrayToHexString(group_and_epoch_1_alice.groupId), "", "Group ID should not be an empty string");
     61  isnot(byteArrayToHexString(group_and_epoch_1_alice.groupEpoch), "", "Group Epoch should not be an empty string");
     62 
     63  // Get membership of the group
     64  let members_alice_1 = await group_alice.details();
     65 
     66  // Bob joins the group
     67  let group_bob = await mls.groupJoin(bob, commit_output.welcome);
     68  let members_bob_1 = await group_bob.details();
     69 
     70  // Test: compare the group identifier after the join
     71  is(byteArrayToHexString(group_alice.groupId), byteArrayToHexString(group_bob.groupId), "Alice GID == Bob GID");
     72 
     73  // Test: the group should have two members
     74  info("Membership @ Epoch 1:", JSON.stringify(members_alice_1));
     75  is(members_alice_1.members.length, 2, "There should be exactly two members in the group");
     76 
     77  // Test: the group should have exactly two members at epoch 0
     78  is(members_alice_0.members.length, 1, "There should be exactly one member in the group");
     79 
     80  // Test: the group should have exactly two members at epoch 1
     81  is(members_alice_1.members.length, 2, "There should be exactly two members in the group");
     82  is(members_bob_1.members.length, 2, "There should be exactly two members in the group");
     83 
     84  // Test: Bob should be in the group according to Alice's view
     85  is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(bob.content)), true, "Bob should be in the group");
     86 
     87  // Test: Alice should be in the group according to Alice's view
     88  is(members_alice_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be in the group");
     89 
     90  // Test: Bob should be in the group according to Bob's view
     91  is(members_bob_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(bob.content)), true, "Bob should be in the group");
     92 
     93  // Test: Alice should be in the group according to Bob's view
     94  is(members_bob_1.members.some(member => byteArrayToHexString(member.clientId) === byteArrayToHexString(alice.content)), true, "Alice should be in the group");
     95 
     96  SimpleTest.finish();
     97 }
     98 
     99 SimpleTest.waitForExplicitFinish();
    100 test_group_join();
    101 
    102 </script>
    103 </pre>
    104 </body>
    105 </html>