summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_ohttp.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/test/unit/test_ohttp.js
parentInitial commit. (diff)
downloadthunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz
thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_ohttp.js')
-rw-r--r--netwerk/test/unit/test_ohttp.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_ohttp.js b/netwerk/test/unit/test_ohttp.js
new file mode 100644
index 0000000000..b7bd2f1d06
--- /dev/null
+++ b/netwerk/test/unit/test_ohttp.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+function test_known_config() {
+ let ohttp = Cc["@mozilla.org/network/oblivious-http;1"].getService(
+ Ci.nsIObliviousHttp
+ );
+ let encodedConfig = hexStringToBytes(
+ "0100209403aafe76dfd4568481e04e44b42d744287eae4070b50e48baa7a91a4e80d5600080001000100010003"
+ );
+ let request = hexStringToBytes(
+ "00034745540568747470730b6578616d706c652e636f6d012f"
+ );
+ let ohttpRequest = ohttp.encapsulateRequest(encodedConfig, request);
+ ok(ohttpRequest);
+}
+
+function test_with_server() {
+ let ohttp = Cc["@mozilla.org/network/oblivious-http;1"].getService(
+ Ci.nsIObliviousHttp
+ );
+ let server = ohttp.server();
+ ok(server.encodedConfig);
+ let request = hexStringToBytes(
+ "00034745540568747470730b6578616d706c652e636f6d012f"
+ );
+ let ohttpRequest = ohttp.encapsulateRequest(server.encodedConfig, request);
+ let ohttpResponse = server.decapsulate(ohttpRequest.encRequest);
+ ok(ohttpResponse);
+ deepEqual(ohttpResponse.request, request);
+ let response = hexStringToBytes("0140c8");
+ let encResponse = ohttpResponse.encapsulate(response);
+ deepEqual(ohttpRequest.response.decapsulate(encResponse), response);
+}
+
+function run_test() {
+ test_known_config();
+ test_with_server();
+}