diff options
author | Suprabh Shukla <suprabh@google.com> | 2024-02-15 10:35:15 -0800 |
---|---|---|
committer | Suprabh Shukla <suprabh@google.com> | 2024-02-15 17:52:56 -0800 |
commit | b7574d4e63000b1248d2b64e6e58fcfb91d1aef9 (patch) | |
tree | d691f0e51797ee9835b6bf4e2cff3d30da65be30 | |
parent | c22d1055a308406db5a7885d72940af01a40de92 (diff) | |
download | DnsResolver-b7574d4e63000b1248d2b64e6e58fcfb91d1aef9.tar.gz |
Allow background networking for test uids
These tests try to run as uids 99999 and 99998 which need to be exempt
from the BACKGROUND_MATCH allowlist chain which can be enabled at boot.
Test: atest resolv_integration_test
Test: atest resolv_unit_test
Bug: 304347838
Bug: 325150155
Change-Id: Ia989304877b661182129c2c49986205733f6a609
-rw-r--r-- | tests/Android.bp | 1 | ||||
-rw-r--r-- | tests/resolv_callback_unit_test.cpp | 2 | ||||
-rw-r--r-- | tests/resolv_integration_test.cpp | 8 | ||||
-rw-r--r-- | tests/resolv_test_utils.cpp | 13 | ||||
-rw-r--r-- | tests/resolv_test_utils.h | 1 |
5 files changed, 24 insertions, 1 deletions
diff --git a/tests/Android.bp b/tests/Android.bp index 7f10d378..7cb4a2a4 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -285,6 +285,7 @@ cc_test { "netd_aidl_interface-lateststable-ndk", "netd_event_listener_interface-lateststable-ndk", "libcrypto_static", + "libconnectivity_native_test_utils", "libcutils", "libdoh_ffi_for_test", "libgmock", diff --git a/tests/resolv_callback_unit_test.cpp b/tests/resolv_callback_unit_test.cpp index 6814697e..391951b9 100644 --- a/tests/resolv_callback_unit_test.cpp +++ b/tests/resolv_callback_unit_test.cpp @@ -108,6 +108,7 @@ class CallbackTest : public NetNativeTestBase { initDnsResolverCallbacks(); // Create cache for test android::net::gDnsResolv->resolverCtrl.createNetworkCache(TEST_NETID); + AllowNetworkInBackground(TEST_UID, true); } void TearDown() override { @@ -116,6 +117,7 @@ class CallbackTest : public NetNativeTestBase { resetDnsResolverCallbacks(); // Delete cache for test android::net::gDnsResolv->resolverCtrl.destroyNetworkCache(TEST_NETID); + AllowNetworkInBackground(TEST_UID, false); } int SetResolvers() { diff --git a/tests/resolv_integration_test.cpp b/tests/resolv_integration_test.cpp index d3e0c59e..a7cc7a8b 100644 --- a/tests/resolv_integration_test.cpp +++ b/tests/resolv_integration_test.cpp @@ -221,8 +221,14 @@ class ResolverTest : public NetNativeTestBase { // Start the binder thread pool for listening DNS metrics events and receiving death // recipient. ABinderProcess_startThreadPool(); + AllowNetworkInBackground(TEST_UID, true); + AllowNetworkInBackground(TEST_UID2, true); + } + static void TearDownTestSuite() { + AIBinder_DeathRecipient_delete(sResolvDeathRecipient); + AllowNetworkInBackground(TEST_UID, false); + AllowNetworkInBackground(TEST_UID2, false); } - static void TearDownTestSuite() { AIBinder_DeathRecipient_delete(sResolvDeathRecipient); } protected: void SetUp() { diff --git a/tests/resolv_test_utils.cpp b/tests/resolv_test_utils.cpp index 4b09b213..a1a9e4e6 100644 --- a/tests/resolv_test_utils.cpp +++ b/tests/resolv_test_utils.cpp @@ -21,6 +21,7 @@ #include <android-base/chrono_utils.h> #include <android-base/logging.h> +#include <firewall.h> using android::netdutils::ScopedAddrinfo; @@ -230,6 +231,18 @@ void RemoveMdnsRoute() { EXPECT_EQ(0, ForkAndRun(args_v6)); } +void AllowNetworkInBackground(int uid, bool allow) { + if (android::modules::sdklevel::IsAtLeastV()) { + // Background networking is always allowed on earlier versions. + Firewall* firewall = Firewall::getInstance(); + if (allow) { + firewall->addRule(uid, BACKGROUND_MATCH); + } else { + firewall->removeRule(uid, BACKGROUND_MATCH); + } + } +} + bool is64bitAbi() { return android::base::GetProperty("ro.product.cpu.abi", "").find("64") != std::string::npos; } diff --git a/tests/resolv_test_utils.h b/tests/resolv_test_utils.h index e3f744ce..7dc1c994 100644 --- a/tests/resolv_test_utils.h +++ b/tests/resolv_test_utils.h @@ -431,6 +431,7 @@ android::netdutils::ScopedAddrinfo safe_getaddrinfo(const char* node, const char void SetMdnsRoute(); void RemoveMdnsRoute(); +void AllowNetworkInBackground(int uid, bool allow); #define SKIP_IF_BEFORE_T \ do { \ |