Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 182ef397 authored by Ken Chen's avatar Ken Chen
Browse files

[Test] DNS query on network uspecified case

Verify that DNS queries can be made for hostnames that exist in
etc/hosts when the default network is not set and the application does
not specify a network.

Bug: 265503240
Bug: 263219497
Test: atest
Change-Id: I50fecdaa696c1d96ab716b42ed13ab76c0684aaf
parent 1bf24426
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -7871,3 +7871,19 @@ TEST_F(ResolverTest, NegativeValueInExperimentFlag) {
        EXPECT_EQ(config.expectedBaseTimeoutMsec, resolvInfo.value().params.base_timeout_msec);
    }
}

// Verify that DNS queries can be made for hostnames that exist in etc/hosts when the default
// network is not set and the application does not specify a network. (See
// NetworkController::isUidAllowed for implementation details.)
TEST_F(ResolverTest, NetworkUnspecified_localhost) {
    ScopedDefaultNetwork scopedDefaultNetwork(mDnsClient.netdService(), NETID_UNSET);
    ScopedSetNetworkForProcess scopedSetNetworkForProcess(NETID_UNSET);

    ScopedAddrinfo result = safe_getaddrinfo(kLocalHost, nullptr, nullptr);
    EXPECT_TRUE(result != nullptr);
    EXPECT_EQ(kLocalHostAddr, ToString(result));

    result = safe_getaddrinfo(kIp6LocalHost, nullptr, nullptr);
    EXPECT_TRUE(result != nullptr);
    EXPECT_EQ(kIp6LocalHostAddr, ToString(result));
}
+17 −0
Original line number Diff line number Diff line
@@ -104,6 +104,23 @@ class ScopedSystemProperties {
    std::string mStoredValue;
};

class ScopedDefaultNetwork {
    using INetd = aidl::android::net::INetd;

  public:
    ScopedDefaultNetwork(INetd* netSrv, uid_t testDefaultNetwork) : mNetSrv(netSrv) {
        EXPECT_TRUE(mNetSrv->networkGetDefault(&mStoredDefaultNetwork).isOk());
        EXPECT_TRUE(mNetSrv->networkSetDefault(testDefaultNetwork).isOk());
    };
    ~ScopedDefaultNetwork() {
        EXPECT_TRUE(mNetSrv->networkSetDefault(mStoredDefaultNetwork).isOk());
    }

  private:
    INetd* mNetSrv;
    int mStoredDefaultNetwork;
};

struct DnsRecord {
    std::string host_name;  // host name
    ns_type type;           // record type