test_ohttp.js (1327B)
1 /* Any copyright is dedicated to the Public Domain. 2 * https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 function test_known_config() { 7 let ohttp = Cc["@mozilla.org/network/oblivious-http;1"].getService( 8 Ci.nsIObliviousHttp 9 ); 10 let encodedConfig = hexStringToBytes( 11 "0100209403aafe76dfd4568481e04e44b42d744287eae4070b50e48baa7a91a4e80d5600080001000100010003" 12 ); 13 let request = hexStringToBytes( 14 "00034745540568747470730b6578616d706c652e636f6d012f" 15 ); 16 let ohttpRequest = ohttp.encapsulateRequest(encodedConfig, request); 17 ok(ohttpRequest); 18 } 19 20 function test_with_server() { 21 let ohttp = Cc["@mozilla.org/network/oblivious-http;1"].getService( 22 Ci.nsIObliviousHttp 23 ); 24 let server = ohttp.server(); 25 ok(server.encodedConfig); 26 let request = hexStringToBytes( 27 "00034745540568747470730b6578616d706c652e636f6d012f" 28 ); 29 let ohttpRequest = ohttp.encapsulateRequest(server.encodedConfig, request); 30 let ohttpResponse = server.decapsulate(ohttpRequest.encRequest); 31 ok(ohttpResponse); 32 deepEqual(ohttpResponse.request, request); 33 let response = hexStringToBytes("0140c8"); 34 let encResponse = ohttpResponse.encapsulate(response); 35 deepEqual(ohttpRequest.response.decapsulate(encResponse), response); 36 } 37 38 function run_test() { 39 test_known_config(); 40 test_with_server(); 41 }