summaryrefslogtreecommitdiffstats
path: root/netwerk/test/gtest/TestDNSPacket.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /netwerk/test/gtest/TestDNSPacket.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/gtest/TestDNSPacket.cpp')
-rw-r--r--netwerk/test/gtest/TestDNSPacket.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/netwerk/test/gtest/TestDNSPacket.cpp b/netwerk/test/gtest/TestDNSPacket.cpp
new file mode 100644
index 0000000000..49530b80e0
--- /dev/null
+++ b/netwerk/test/gtest/TestDNSPacket.cpp
@@ -0,0 +1,69 @@
+#include "gtest/gtest.h"
+
+#include "mozilla/net/DNSPacket.h"
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
+using namespace mozilla::net;
+
+void AssertDnsPadding(uint32_t PaddingLength, unsigned int WithPadding,
+ unsigned int WithoutPadding, bool DisableEcn,
+ const nsCString& host) {
+ DNSPacket encoder;
+ nsCString buf;
+
+ ASSERT_EQ(Preferences::SetUint("network.trr.padding.length", PaddingLength),
+ NS_OK);
+
+ ASSERT_EQ(Preferences::SetBool("network.trr.padding", true), NS_OK);
+ ASSERT_EQ(encoder.EncodeRequest(buf, host, 1, DisableEcn), NS_OK);
+ ASSERT_EQ(buf.Length(), WithPadding);
+
+ ASSERT_EQ(Preferences::SetBool("network.trr.padding", false), NS_OK);
+ ASSERT_EQ(encoder.EncodeRequest(buf, host, 1, DisableEcn), NS_OK);
+ ASSERT_EQ(buf.Length(), WithoutPadding);
+}
+
+TEST(TestDNSPacket, PaddingLenEcn)
+{
+ AssertDnsPadding(16, 48, 41, true, "a.de"_ns);
+ AssertDnsPadding(16, 48, 42, true, "ab.de"_ns);
+ AssertDnsPadding(16, 48, 43, true, "abc.de"_ns);
+ AssertDnsPadding(16, 48, 44, true, "abcd.de"_ns);
+ AssertDnsPadding(16, 64, 45, true, "abcde.de"_ns);
+ AssertDnsPadding(16, 64, 46, true, "abcdef.de"_ns);
+ AssertDnsPadding(16, 64, 47, true, "abcdefg.de"_ns);
+ AssertDnsPadding(16, 64, 48, true, "abcdefgh.de"_ns);
+}
+
+TEST(TestDNSPacket, PaddingLenDisableEcn)
+{
+ AssertDnsPadding(16, 48, 22, false, "a.de"_ns);
+ AssertDnsPadding(16, 48, 23, false, "ab.de"_ns);
+ AssertDnsPadding(16, 48, 24, false, "abc.de"_ns);
+ AssertDnsPadding(16, 48, 25, false, "abcd.de"_ns);
+ AssertDnsPadding(16, 48, 26, false, "abcde.de"_ns);
+ AssertDnsPadding(16, 48, 27, false, "abcdef.de"_ns);
+ AssertDnsPadding(16, 48, 32, false, "abcdefghijk.de"_ns);
+ AssertDnsPadding(16, 48, 33, false, "abcdefghijkl.de"_ns);
+ AssertDnsPadding(16, 64, 34, false, "abcdefghijklm.de"_ns);
+ AssertDnsPadding(16, 64, 35, false, "abcdefghijklmn.de"_ns);
+}
+
+TEST(TestDNSPacket, PaddingLengths)
+{
+ AssertDnsPadding(0, 45, 41, true, "a.de"_ns);
+ AssertDnsPadding(1, 45, 41, true, "a.de"_ns);
+ AssertDnsPadding(2, 46, 41, true, "a.de"_ns);
+ AssertDnsPadding(3, 45, 41, true, "a.de"_ns);
+ AssertDnsPadding(4, 48, 41, true, "a.de"_ns);
+ AssertDnsPadding(16, 48, 41, true, "a.de"_ns);
+ AssertDnsPadding(32, 64, 41, true, "a.de"_ns);
+ AssertDnsPadding(42, 84, 41, true, "a.de"_ns);
+ AssertDnsPadding(52, 52, 41, true, "a.de"_ns);
+ AssertDnsPadding(80, 80, 41, true, "a.de"_ns);
+ AssertDnsPadding(128, 128, 41, true, "a.de"_ns);
+ AssertDnsPadding(256, 256, 41, true, "a.de"_ns);
+ AssertDnsPadding(1024, 1024, 41, true, "a.de"_ns);
+ AssertDnsPadding(1025, 1024, 41, true, "a.de"_ns);
+}