From 9e3c08db40b8916968b9f30096c7be3f00ce9647 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:44:51 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- netwerk/test/gtest/TestHttpAuthUtils.cpp | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 netwerk/test/gtest/TestHttpAuthUtils.cpp (limited to 'netwerk/test/gtest/TestHttpAuthUtils.cpp') diff --git a/netwerk/test/gtest/TestHttpAuthUtils.cpp b/netwerk/test/gtest/TestHttpAuthUtils.cpp new file mode 100644 index 0000000000..78fb40d4d0 --- /dev/null +++ b/netwerk/test/gtest/TestHttpAuthUtils.cpp @@ -0,0 +1,43 @@ +#include "gtest/gtest.h" + +#include "mozilla/net/HttpAuthUtils.h" +#include "mozilla/Preferences.h" +#include "nsNetUtil.h" + +namespace mozilla { +namespace net { + +#define TEST_PREF "network.http_test.auth_utils" + +TEST(TestHttpAuthUtils, Bug1351301) +{ + nsCOMPtr url; + nsAutoCString spec; + + ASSERT_EQ(Preferences::SetCString(TEST_PREF, "bar.com"), NS_OK); + spec = "http://bar.com"; + ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK); + ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), true); + + spec = "http://foo.bar.com"; + ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK); + ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), true); + + spec = "http://foobar.com"; + ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK); + ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), false); + + ASSERT_EQ(Preferences::SetCString(TEST_PREF, ".bar.com"), NS_OK); + spec = "http://foo.bar.com"; + ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK); + ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), true); + + spec = "http://bar.com"; + ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK); + ASSERT_EQ(auth::URIMatchesPrefPattern(url, TEST_PREF), false); + + ASSERT_EQ(Preferences::ClearUser(TEST_PREF), NS_OK); +} + +} // namespace net +} // namespace mozilla -- cgit v1.2.3