test_utils.html (4026B)
1 <!DOCTYPE HTML> 2 <html> 3 4 <head> 5 <title>Test for Messaging Layer Security</title> 6 <!-- SimpleTest Helpers --> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 9 <!-- Local Helpers --> 10 <script src="head_mls.js"></script> 11 </head> 12 13 <body> 14 <pre id="test"> 15 <script class="testbody" type="text/javascript"> 16 17 async function test_utils_get_group_identifier_and_epoch() { 18 19 const mls = new MLS(); 20 21 // Generate Identities for Alice and Bob 22 let alice = await mls.generateIdentity(); 23 let bob = await mls.generateIdentity(); 24 25 // Generate Credentials for Alice and Bob 26 let credential_alice = await mls.generateCredential("alice"); 27 let credential_bob = await mls.generateCredential("bob"); 28 29 // Generate a KeyPackage for Bob 30 let kp_bob = await mls.generateKeyPackage(bob, credential_bob); 31 32 // Creation of a Group by Alice 33 let group_alice = await mls.groupCreate(alice, credential_alice); 34 35 // Test: compare the group identifier to the invalid value 36 info("Group Id:", byteArrayToHexString(group_alice.groupId)); 37 isnot(byteArrayToHexString(group_alice.groupId), "", "Group Identifier != ''"); 38 39 // Alice adds Bob to a group 40 let commit_output = await group_alice.add(kp_bob); 41 42 // Test: compare the commit output to the invalid value 43 info("Commit Output:", byteArrayToHexString(commit_output.commit)); 44 isnot(byteArrayToHexString(commit_output.commit), "", "Commit != ''"); 45 46 // Get the group details 47 let details = await group_alice.details(); 48 info("Group Id:", byteArrayToHexString(details.groupId)); 49 info("Group Epoch:", byteArrayToHexString(details.groupEpoch)); 50 51 // Get the group identifier from the commit 52 let gid_commit = await mls.getGroupIdFromMessage(commit_output.commit); 53 info("Group Id from Commit Message:", byteArrayToHexString(gid_commit.content)); 54 55 // Get the group identifier from the commit 56 let epoch_commit = await mls.getGroupEpochFromMessage(commit_output.commit); 57 info("Group Epoch from Commit Message:", byteArrayToHexString(epoch_commit.content)); 58 59 // Note: the following is forbidden because Welcome is not an MLSMessage 60 // let gid_welcome = await mls.getGroupIdFromMessage(commit_output.welcome); 61 // info("Group Id from Welcome Message:", byteArrayToHexString(gid_welcome.content)); 62 63 // Test: compare the group id of the commit to the current group id 64 is(byteArrayToHexString(details.groupId), byteArrayToHexString(gid_commit.content)); 65 // Test: compare the group epoch of the commit to the current group epoch 66 is(byteArrayToHexString(details.groupEpoch), byteArrayToHexString(epoch_commit.content)); 67 68 // Alice: process her Add commit 69 await group_alice.receive(commit_output.commit); 70 71 // Get the group details after processing the commit 72 let details2 = await group_alice.details(); 73 info("Group Epoch 2:", byteArrayToHexString(details2.groupEpoch)); 74 75 // Alice: removed Bob 76 let commit_output2 = await group_alice.remove(bob); 77 78 // Get the group identifier from the commit 79 let gid_commit2 = await mls.getGroupIdFromMessage(commit_output2.commit); 80 info("Group Id 2 from Commit Message 2:", byteArrayToHexString(gid_commit2.content)); 81 82 // Get the group identifier from the commit2 83 let epoch_commit2 = await mls.getGroupEpochFromMessage(commit_output2.commit); 84 info("Group Epoch 2 from Commit Message 2:", byteArrayToHexString(epoch_commit2.content)); 85 86 // Test: compare the group id of the commit to the current group id 87 is(byteArrayToHexString(details2.groupId), byteArrayToHexString(gid_commit2.content)); 88 // Test: compare the group epoch of the commit to the current group epoch 89 is(byteArrayToHexString(details2.groupEpoch), byteArrayToHexString(epoch_commit2.content)); 90 91 SimpleTest.finish(); 92 } 93 94 SimpleTest.waitForExplicitFinish(); 95 test_utils_get_group_identifier_and_epoch(); 96 97 </script> 98 </pre> 99 </body> 100 101 </html>